SendMailMoreControlImpl.mesa
Copyright Ó 1990, 1992 by Xerox Corporation. All rights reserved.
Willie-s, December 12, 1991 12:34 pm PST
Contents: Control module for SendMail
Last Edited by: Willie-Sue, January 17, 1984 10:20:02 am PST
Last Edited by: Donahue, October 7, 1983 9:42 am
DIRECTORY
Commander USING [CommandProc, Register],
CommanderOps USING [Failed, ParseToList],
IO,
MailBasics USING [RNameList],
MailSend USING [SendingCredentials, SendingCredentialsList, SendingCredentialsRec],
MailUtils USING [Credentials, GetLoggedInUser, GetUserCredentials, LocalNameFromRName],
Menus USING [CreateMenu, Menu],
PFS USING [AbsoluteName],
PFSCanonicalNames USING [ParseName, UnparseName],
RefText,
Rope,
SendMailInternal,
SendMailOps,
UserProfile USING [Boolean],
ViewerClasses USING [Viewer],
ViewerOps USING [DestroyViewer],
ViewerTools USING [TiogaContents, TiogaContentsRec];
SendMailMoreControlImpl:
CEDAR
MONITOR
IMPORTS
Commander, CommanderOps, IO, PFS, PFSCanonicalNames, MailUtils, Menus, RefText, Rope, SendMailInternal, SendMailOps, UserProfile, ViewerOps
EXPORTS
SendMailInternal, SendMailOps = BEGIN OPEN SendMailOps, SendMailInternal;
-- Global types & variables
ROPE: TYPE = Rope.ROPE;
replyToSelf: PUBLIC BOOL ¬ FALSE;
alwaysNewSender: PUBLIC BOOL ¬ FALSE;
needToAuthenticate: PUBLIC BOOL ¬ TRUE;
outBoxLength: PUBLIC INT ¬ 1;
outBox: PUBLIC SendMailOps.OutBoxMsg;
sendCaption: PUBLIC ROPE ¬ "Mail Sender";
sendMenu: PUBLIC Menus.Menu ¬ Menus.CreateMenu[];
formsMenu: PUBLIC Menus.Menu;
sendingMenu: PUBLIC Menus.Menu ¬ Menus.CreateMenu[];
blankMenu: PUBLIC Menus.Menu ¬ Menus.CreateMenu[];
confirmMenu: PUBLIC Menus.Menu ¬ Menus.CreateMenu[];
replyToMenu: PUBLIC Menus.Menu ¬ Menus.CreateMenu[];
userRNameList: PUBLIC MailBasics.RNameList ¬ NIL; -- full user names
simpleUserNameList: PUBLIC LIST OF ROPE ¬ NIL; -- local user names
localRNameList: PUBLIC LIST OF ROPE ¬ NIL;
simpleNameListWithoutSpaces: PUBLIC LIST OF ROPE ¬ NIL; -- local user names w/o spaces
sendingCredentialsList: PUBLIC MailSend.SendingCredentialsList ¬ NIL;
standardDefaultText:
PUBLIC ViewerTools.TiogaContents ¬
NEW[ ViewerTools.TiogaContentsRec ¬
[contents: "\rSubject: \001Topic\002\rTo: \001Recipients\002\rCc: \001Copies To\002\r\r\001Message\002\r",
formatting: "\000\000\000\006\000\000\235\312\000<\000\000\002\230\000J\232\002\320bs\007\234\t\230\020J\232\002\235\002\234\016\230\020J\232\002\235\002\234\r\230\017J\230\000J\230\t\227\000\205\227\000\000\000\000\000>\000\000\000\200\000\000"] ];
standardAnswerText:
PUBLIC ViewerTools.TiogaContents ¬
NEW[ ViewerTools.TiogaContentsRec ¬
[contents: "\rSubject: \001Topic\002\rIn-reply-to: \001Message\002\rTo: \001Recipients\002\rCc: \001Copies To\002\r\r\001Message\002\r\000",
formatting: "\000\000\000\006\000\000\235\312\000I\000\000\002\230\000J\232\002\320bs\007\234\t\230\020J\232\002\235\013\234\013\230\026J\232\002\235\002\234\016\230\020J\232\002\235\002\234\r\230\017J\230\000J\232\001\234\t\230\t\227\000\205\227\000\000\000\000\000V\000\000\000\245\000\000"] ];
standardForwardText:
PUBLIC ViewerTools.TiogaContents ¬
NEW[ ViewerTools.TiogaContentsRec ¬
[contents: "\rSubject: \001Topic\002\rTo: \001Recipients\002\rCc: \001Copies To\002\r\r\001CoveringMessage\002\r\r--------------------------------------\rForwardedMessage\r--------------------------------------\r\r\001ClosingComment\002\r",
formatting: "\000\000\000\006\000\000\235\312\000W\000\000\002\230\000J\232\002\320bs\007\234\t\230\020J\232\002\235\002\234\016\230\020J\232\002\235\002\234\r\230\017J\230\000J\230\021J\230\000\002\232\001\234&\230&J\230\020\227J\232\001\234&\230&J\230\000J\230\020\227\000\205\227\000\000\000\000\000\270\000\000\001\025\000\000"] ];
defaultForm:
PUBLIC SendMailOps.Form ¬
NEW[ SendMailOps.FormRec ¬ [ formText: SendMailOps.defaultText, fields: LIST[ NIL, NIL, NIL] ] ];
SendMailFileUsage: ROPE = "\nUsage: SendMailFile <mail-filename>";
-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
DoUserNameAndRegistry:
PUBLIC
ENTRY
PROC = {
useGV: BOOL ¬ UserProfile.Boolean["SendMailTool.gvSendMail", TRUE];
useXNS: BOOL ¬ UserProfile.Boolean["SendMailTool.xnsSendMail", TRUE];
creds: LIST OF MailUtils.Credentials;
userRNameList ¬ NIL;
simpleUserNameList ¬ NIL;
localRNameList ¬ NIL;
simpleNameListWithoutSpaces ¬ NIL;
sendingCredentialsList ¬ NIL;
SELECT
TRUE
FROM
( useGV AND useXNS ) => creds ¬ MailUtils.GetUserCredentials[];
useGV => creds ¬ MailUtils.GetUserCredentials[$gv];
ENDCASE => creds ¬ MailUtils.GetUserCredentials[$xns];
FOR cL:
LIST
OF MailUtils.Credentials ¬ creds, cL.rest
UNTIL cL =
NIL
DO
sCred: MailSend.SendingCredentials;
this: ROPE;
userRNameList ¬ CONS[cL.first.rName, userRNameList];
simpleUserNameList ¬ CONS[this ¬ MailUtils.GetLoggedInUser[cL.first.rName.ns], simpleUserNameList];
localRNameList ¬ CONS[this ¬ MailUtils.LocalNameFromRName[[cL.first.rName.ns, this]], localRNameList];
simpleNameListWithoutSpaces ¬ CONS[RemoveSpaces[this], simpleNameListWithoutSpaces];
sCred ¬ NEW[MailSend.SendingCredentialsRec ¬ [cL.first, TRUE, cL.first.rName] ];
sendingCredentialsList ¬ CONS[sCred, sendingCredentialsList];
ENDLOOP;
IF localRNameList #
NIL
THEN
defaultForm ¬ NEW[ SendMailOps.FormRec ¬ [ formText: defaultText,
fields: LIST[ NIL, NIL, localRNameList.first] ] ]
ELSE defaultForm ¬ NEW[ SendMailOps.FormRec ¬ [ formText: defaultText,
fields: LIST[ NIL, NIL, NIL] ] ];
};
RemoveSpaces:
PROC[this:
ROPE]
RETURNS[better:
ROPE] = {
new: REF TEXT;
len: NAT;
IF this.Find[" "] < 0 THEN RETURN[this];
new ¬ RefText.ObtainScratch[len ¬ this.Length[]];
FOR i:
INT
IN [0..this.Length[])
DO
ch: CHAR;
IF ( ch ¬ this.Fetch[i] ) # ' THEN new ¬ RefText.AppendChar[new, ch];
ENDLOOP;
better ¬ Rope.FromRefText[new];
RefText.ReleaseScratch[new];
};
ChangeUserRNameList:
PUBLIC
ENTRY
PROC[newUserRNameList: MailBasics.RNameList] = {
this: ROPE;
userRNameList ¬ newUserRNameList;
simpleUserNameList ¬ localRNameList ¬ NIL;
FOR rL: MailBasics.RNameList ¬ newUserRNameList, rL.rest
UNTIL rL =
NIL
DO
simpleUserNameList ¬ CONS[this ¬ MailUtils.GetLoggedInUser[rL.first.ns], simpleUserNameList];
localRNameList ¬ CONS[this ¬ MailUtils.LocalNameFromRName[[rL.first.ns, this]], localRNameList];
ENDLOOP;
defaultForm ¬ NEW[ SendMailOps.FormRec ¬ [ formText: defaultText,
fields: LIST[ NIL, NIL,
IF localRNameList # NIL THEN localRNameList.first ELSE NIL] ] ];
};
IsThisTheCurrentUser:
PUBLIC
ENTRY
PROC[who:
ROPE]
RETURNS[yes:
BOOL ¬
TRUE] = {
FOR rL: MailBasics.RNameList ¬ userRNameList, rL.rest
UNTIL rL =
NIL
DO
IF who.Equal[rL.first.name, FALSE] THEN RETURN;
ENDLOOP;
FOR rL:
LIST
OF
ROPE ¬ simpleUserNameList, rL.rest
UNTIL rL =
NIL
DO
IF who.Equal[rL.first, FALSE] THEN RETURN;
ENDLOOP;
FOR rL:
LIST
OF
ROPE ¬ localRNameList, rL.rest
UNTIL rL =
NIL
DO
IF who.Equal[rL.first, FALSE] THEN RETURN;
ENDLOOP;
RETURN[FALSE];
};
SendMailFileProc: Commander.CommandProc = {
PROC [cmd: Handle] RETURNS [result: REF ← NIL, msg: ROPE ← NIL];
inputList: LIST OF ROPE;
inputList ¬ CommanderOps.ParseToList[cmd: cmd !
CommanderOps.Failed => {cmd.err.PutRope["invalid input format\n"]; GO TO quit}].list;
IF inputList = NIL THEN RETURN[NIL, SendMailFileUsage];
FOR files:
LIST OF ROPE ¬ inputList, files.rest
WHILE files #
NIL
DO
absFileName: ROPE ¬ PFSCanonicalNames.UnparseName[PFS.AbsoluteName[PFSCanonicalNames.ParseName[files.first]]];
IF
NOT SendOneMailFile[absFileName]
THEN
BEGIN
cmd.err.PutF1["Failed to send %g\n", [rope[absFileName]]];
GO TO quit;
END;
ENDLOOP;
EXITS
quit => RETURN[$Failure, NIL];
};
SendOneMailFile:
PROC [file:
ROPE]
RETURNS [sent:
BOOLEAN] = {
msgViewer: ViewerClasses.Viewer;
text: ViewerTools.TiogaContents ¬ SendMailInternal.GetSendForm[file];
form: SendMailOps.Form ¬ NEW[SendMailOps.FormRec ¬ [text]];
[msgViewer] ¬ SendMailOps.BuildSendViewer[TRUE, FALSE, form];
sent ¬ SendMailOps.Send[msgViewer];
IF sent THEN ViewerOps.DestroyViewer[msgViewer];
};
-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Commander.Register[key: "SendMailFile", proc: SendMailFileProc, doc: SendMailFileUsage];