-- TestMail.mesa; edited by HGM,  May 26, 1979  5:12 PM  

-- Copyright  Xerox Corporation 1979, 1980
  
DIRECTORY
  FTPDefs: FROM "ftpdefs" USING [
    FTPInitialize, FTPFinalize,
    FTPUser, FTPCreateUser, FTPSetCredentials, FTPDestroyUser,
    FTPOpenConnection, FTPCloseConnection,
    FTPBeginDeliveryOfMessage, FTPSendRecipientOfMessage,
    FTPIdentifyNextRejectedRecipient,
    FTPSendBlockOfMessage, FTPEndDeliveryOfMessage,
    PupCommunicationPrimitives],
  ImageDefs: FROM "imagedefs" USING [StopMesa],
  IODefs: FROM "iodefs" USING [WriteLine, WriteString, WriteDecimal],
  OsStaticDefs: FROM "osstaticdefs" USING [OsStatics],
  StringDefs: FROM "StringDefs" USING [BcplToMesaString];
  
TestMail: PROGRAM
  IMPORTS
    FTPDefs, ImageDefs, IODefs, StringDefs =
  BEGIN
  OPEN IODefs, FTPDefs;
  
  ftpuser: FTPUser;
  server: STRING = "Maxc";

  Start: PROCEDURE =
    BEGIN
    user: STRING ← [40];
    password: STRING ← [40];
    serverText: STRING = [100];
    FTPInitialize[];
    ftpuser ← FTPCreateUser[NIL,PupCommunicationPrimitives[]];
    StringDefs.BcplToMesaString[OsStaticDefs.OsStatics.UserName, user];
    StringDefs.BcplToMesaString[OsStaticDefs.OsStatics.UserPassword, password];
    FTPSetCredentials[ftpuser, primary, user, password];
    FTPOpenConnection[ftpuser,server,mail,serverText];
    WriteLine[serverText];
    END;

  SendOneMessage: PROCEDURE =
    BEGIN
    SendLine: PROCEDURE [s: STRING] =
      BEGIN
      cr: WORD ← 15B*256;
      FTPSendBlockOfMessage[ftpuser,@s.text,s.length];
      FTPSendBlockOfMessage[ftpuser,@cr,1];
      END;
    FTPBeginDeliveryOfMessage[ftpuser];
    FTPSendRecipientOfMessage[ftpuser,"Murray"];
    FTPSendRecipientOfMessage[ftpuser,"Foo"];
    FTPSendRecipientOfMessage[ftpuser,"Murray (Hal)"];
    FTPSendRecipientOfMessage[ftpuser,"Hal <Murray>"];
    FTPSendRecipientOfMessage[ftpuser,"Mumble"];
    FTPSendRecipientOfMessage[ftpuser,"Foo@Maxc2"];
    CheckRejections[];
    SendLine["To: Murray, Foo, Murray (Hal), Hal <Murray>, Mumble, Foo@Maxc2"];
    SendLine["Subject: Testing"];
    SendLine["Date: March 20, 1979  4:09 PM"];
    SendLine["From: HGM"];
    SendLine[""];
    SendLine["Throw this out!"];
    SendLine["Throw this out!"];
    SendLine["Throw this out!"];
    SendLine["Throw this out too!"];
    CheckRejections[];
    FTPEndDeliveryOfMessage[ftpuser];
    END;

  SendJunkMessage: PROCEDURE =
    BEGIN
    SendLine: PROCEDURE [s: STRING] =
      BEGIN
      cr: WORD ← 15B*256;
      FTPSendBlockOfMessage[ftpuser,@s.text,s.length];
      FTPSendBlockOfMessage[ftpuser,@cr,1];
      END;
    FTPBeginDeliveryOfMessage[ftpuser];
    FTPSendRecipientOfMessage[ftpuser,"Foo"];
    CheckRejections[];
    SendLine["To: Foo"];
    SendLine["Subject: Testing"];
    SendLine["Date: March 20, 1979  4:09 PM"];
    SendLine["From: HGM"];
    SendLine[""];
    SendLine["Throw this out!"];
    SendLine["Throw this out!"];
    SendLine["Throw this out!"];
    SendLine["Throw this out too!"];
    CheckRejections[];
    FTPEndDeliveryOfMessage[ftpuser];
    END;

  CheckRejections: PROCEDURE =
    BEGIN
    n: CARDINAL;
    buffer: STRING = [50];
    DO
      [n,] ← FTPIdentifyNextRejectedRecipient[ftpuser,buffer];
      IF n=0 THEN EXIT;
      WriteString["Troubles sending to # "];
      WriteDecimal[n];
      WriteString[": "];
      WriteLine[buffer];
      ENDLOOP;
    END;

  Stop: PROCEDURE =
    BEGIN
    FTPCloseConnection[ftpuser];
    FTPDestroyUser[ftpuser];
    FTPFinalize[];
    END;


  Start[];
  SendOneMessage[];
  SendJunkMessage[];
  Stop[];

  ImageDefs.StopMesa[];

  END.