MailSendImpl.mesa
Copyright Ó 1988, 1989, 1990, 1991 by Xerox Corporation. All rights reserved.
Doug Terry, November 11, 1988 12:23:03 pm PST
Wes Irish, January 26, 1989 6:31:17 pm PST
Willie-Sue, February 14, 1990 6:19:34 pm PST
Willie-s, December 10, 1991 3:29 pm PST
Buffers MailSend calls building a message until Send is called. Once Send is called the message now residing in the handle is sent using the appropriate transport (as explicitly specified by the user or determined by this module if not explicitly specified by the user).
DIRECTORY
IO,
MailBasics,
MailSend,
MailSendSidedoor,
Rope;
MailSendImpl: CEDAR MONITOR
IMPORTS IO, Rope
EXPORTS MailSend, MailSendSidedoor
~ BEGIN
ROPE: TYPE ~ Rope.ROPE;
MailSendHandle: TYPE = MailSend.MailSendHandle;
MailSendHandleObject: TYPE = MailSend.MailSendHandleObject;
BodyPartInfo: TYPE = MailSend.BodyPartInfo;
SendingCredentialsList: TYPE = MailSend.SendingCredentialsList;
AbortSendProc: TYPE = MailSendSidedoor.AbortSendProc;
MailSendProcsRef: TYPE = MailSend.MailSendProcsRef;
MailSendSidedoorProcsRef: TYPE = MailSendSidedoor.MailSendSidedoorProcsRef;
Exported procedures
Create: PUBLIC PROC RETURNS [MailSendHandle] ~ {
msH: MailSendHandle ¬ NEW[MailSendHandleObject];
RETURN[msH];
};
StartSend: PUBLIC PROC [msH: MailSendHandle, credentialsList: SendingCredentialsList] ~ {
msH­ ¬ [
credentialsList: credentialsList,
recipients: NIL,
lastRecipient: NIL,
bodyParts: NIL,
lastBodyPart: NIL,
nBodyParts: 0
];
};
AddRecipient: PUBLIC PROC [msH: MailSendHandle, recipient: MailBasics.RName] ~ {
IF msH.recipients = NIL
THEN msH.lastRecipient ¬ msH.recipients ¬ LIST[recipient]
ELSE msH.lastRecipient ¬ msH.lastRecipient.rest ¬ LIST[recipient];
};
StartItem: PUBLIC PROC [msH: MailSendHandle, type: MailBasics.ItemType] ~ {
bodyPartInfo: BodyPartInfo ¬ NEW[MailSend.BodyPartInfoObject ¬ [type, NIL]];
IF msH.bodyParts = NIL
THEN msH.lastBodyPart ¬ msH.bodyParts ¬ LIST[bodyPartInfo]
ELSE msH.lastBodyPart ¬ msH.lastBodyPart.rest ¬ LIST[bodyPartInfo];
msH.nBodyParts ¬ msH.nBodyParts.SUCC;
};
AddToItem: PUBLIC PROC [msH: MailSendHandle, buffer: ROPE] ~ {
msH.lastBodyPart.first.data ¬ Rope.Concat[msH.lastBodyPart.first.data, buffer];
};
Abort: PUBLIC PROC [msH: MailSendHandle] ~ {
msH­ ¬ [
credentialsList: NIL,
recipients: NIL,
lastRecipient: NIL,
bodyParts: NIL,
lastBodyPart: NIL,
nBodyParts: 0
];
};
Send: PUBLIC PROC [msH: MailSendHandle, validate, sendEvenIfInvalidNames: BOOL, transport: ATOM ¬ $any]
RETURNS [sent: BOOL, failureReason: ROPE, invalidNames: MailBasics.RNameList] ~ {
procs: MailSendProcsRef;
IF msH.recipients = NIL THEN RETURN[FALSE, "No recipients.", NIL];
IF msH.bodyParts = NIL THEN RETURN[FALSE, "No Items.", NIL];
IF transport = $any THEN {
IF ( procs ¬ GetRegisteredMailSendProcs[$xns] ) = NIL THEN
procs ¬ GetRegisteredMailSendProcs[$gv];
IF procs = NIL THEN RETURN[FALSE, "No transport available", NIL];
}
ELSE IF (procs ¬ GetRegisteredMailSendProcs[transport]) = NIL THEN
RETURN
[FALSE, IO.PutFR1["Transport: %g not available.", [atom[transport]] ], NIL ];
[sent, failureReason, invalidNames] ¬ procs.Send[msH, validate, sendEvenIfInvalidNames];
};
SendWithAbort: PUBLIC PROC [msH: MailSendHandle, validate, sendEvenIfInvalidNames, allowDLRecipients: BOOL, abortSend: AbortSendProc, transport: ATOM ¬ $any]
RETURNS [sent: BOOL, failureReason: ROPE, invalidNames, dlsNotAllowed, fakeDls: MailBasics.RNameList] ~ {
procs: MailSendSidedoorProcsRef;
IF msH.recipients = NIL THEN RETURN[FALSE, "No recipients.", NIL, NIL, NIL];
IF msH.bodyParts = NIL THEN RETURN[FALSE, "No Items.", NIL, NIL, NIL];
IF transport = $any THEN {
IF ( procs ¬ GetRegisteredMailSendSidedoorProcs[$xns] ) = NIL THEN
procs ¬ GetRegisteredMailSendSidedoorProcs[$gv];
IF procs = NIL THEN RETURN[FALSE, "No transport available", NIL, NIL, NIL];
}
ELSE IF (procs ¬ GetRegisteredMailSendSidedoorProcs[transport]) = NIL THEN
RETURN[FALSE, IO.PutFR1["Transport: %g not available.", [atom[transport]] ], NIL, NIL, NIL ];
[sent, failureReason, invalidNames, dlsNotAllowed, fakeDls] ¬
procs.SendWithAbort[msH, validate, sendEvenIfInvalidNames, allowDLRecipients, abortSend];
};
Registration
sendProcsList: LIST OF MailSendProcsRef ¬ NIL;
sendSDProcsList: LIST OF MailSendSidedoorProcsRef ¬ NIL;
RegisterMailSendProcs: PUBLIC ENTRY PROC [procs: MailSendProcsRef] = {
sendProcsList ¬ CONS[procs, sendProcsList];
};
RegisterMailSendSidedoorProcs: PUBLIC ENTRY PROC [procs: MailSendSidedoorProcsRef] = {
sendSDProcsList ¬ CONS[procs, sendSDProcsList];
};
GetRegisteredSendProcsList: PUBLIC ENTRY PROC RETURNS [LIST OF MailSendProcsRef] = {
RETURN [ sendProcsList ];
};
GetRegisteredMailSendSidedoorProcsList: PUBLIC ENTRY PROC RETURNS [LIST OF MailSendSidedoorProcsRef] = {
RETURN [ sendSDProcsList ];
};
GetRegisteredMailSendProcs: PUBLIC ENTRY PROC[which: ATOM]
RETURNS [MailSendProcsRef] = {
FOR sL: LIST OF MailSendProcsRef ¬ sendProcsList, sL.rest UNTIL sL = NIL DO
IF sL.first.which = which THEN RETURN[sL.first];
ENDLOOP;
RETURN[NIL];
};
GetRegisteredMailSendSidedoorProcs: PUBLIC ENTRY PROC[which: ATOM]
RETURNS [MailSendSidedoorProcsRef] = {
FOR sL: LIST OF MailSendSidedoorProcsRef ¬ sendSDProcsList, sL.rest UNTIL sL = NIL DO
IF sL.first.which = which THEN RETURN[sL.first];
ENDLOOP;
RETURN[NIL];
};
END.