<> <> DIRECTORY CedarSnapshot USING [CheckpointProc, Register, RollbackProc], UserExec USING [CommandProc, RegisterCommand], Process USING [Detach], Menus USING [ClickProc, MenuProc], PeanutSendMail, Spell, Rope, PeanutRetrieve, PeanutWindow, TiogaMenuOps, ViewerClasses, ViewerOps, VirtualDesktops; PeanutTopImpl: CEDAR PROGRAM IMPORTS PeanutWindow, PeanutRetrieve, PeanutSendMail, CedarSnapshot, Process, Spell, Rope, UserExec, TiogaMenuOps, VirtualDesktops, ViewerOps = BEGIN NewForm: Menus.MenuProc = { PeanutSendMail.NewMsgForm[mouseButton, shift, control] }; AnswerMessage: Menus.MenuProc = { PeanutSendMail.AnswerMsg[mouseButton, shift, control] }; ForwardMessage: Menus.MenuProc = { PeanutSendMail.ForwardMsg[mouseButton, shift, control] }; SendMessage: Menus.MenuProc = { PeanutSendMail.SendMsg[mouseButton, shift, control] }; NewMail: Menus.MenuProc = { PeanutRetrieve.GetNewMsgs[] }; Abort: Menus.MenuProc = { PeanutWindow.abortFlag _ TRUE }; SaveAll: Menus.MenuProc = { files: LIST OF Rope.ROPE _ mailFiles; WHILE files # NIL DO viewer: ViewerClasses.Viewer _ VirtualDesktops.FindViewer[files.first].viewer; IF viewer # NIL AND viewer.newVersion THEN { PeanutWindow.OutputRope["\nSaving "]; PeanutWindow.OutputRope[files.first]; TiogaMenuOps.Save[viewer] }; files _ files.rest; ENDLOOP; }; MailFileButton: Menus.ClickProc = { IF mouseButton=yellow THEN -- open the message file ViewerOps.OpenIcon[PeanutRetrieve.GetMailViewer[NARROW[clientData]]] ELSE PeanutRetrieve.CopyMessages[to: NARROW[clientData], delete: mouseButton=blue] }; restartAfterRollback: BOOL _ FALSE; PeanutCheckpointProc: CedarSnapshot.CheckpointProc = { CloseDown[]; restartAfterRollback _ TRUE }; PeanutRollbackProc: CedarSnapshot.RollbackProc = { IF restartAfterRollback THEN TRUSTED {Process.Detach[FORK StartPeanut[]]}}; BuildPeanut: UserExec.CommandProc = {StartPeanut[]}; CloseDown: PROC = { PeanutRetrieve.CloseConnection[] }; mailFiles: LIST OF Rope.ROPE; modes: REF Spell.ModesRecord _ NEW[Spell.ModesRecord]; StartPeanut: PROC = { files: LIST OF Rope.ROPE; NullInform: Spell.InformProc = {}; AddName: PROC [fileName: Rope.ROPE] = { name: Rope.ROPE _ Rope.Substr[fileName, 0, Rope.Find[fileName, "."]]; PeanutWindow.AddButton[name: name, proc: MailFileButton, data: fileName] }; modes.inform _ modes.confirm _ modes.disabled _ never; modes.timeout _ -1; modes.defaultConfirm _ FALSE; IF PeanutSendMail.AuthenticateUser[] THEN [] _ PeanutRetrieve.NewUser[PeanutSendMail.userRName]; IF PeanutWindow.Create[] THEN { -- created a new one files _ mailFiles _ Spell.GetMatchingFileList[unknown: "*.Mail", modes: modes, inform: NullInform]; WHILE files # NIL DO AddName[files.first]; files _ files.rest; ENDLOOP } ELSE { -- restarting, probably after Rollback; check for new Mail files IsOld: PROC [name: Rope.ROPE] RETURNS [yes: BOOL] = { fileList: LIST OF Rope.ROPE _ mailFiles; WHILE fileList # NIL DO IF Rope.Equal[name, fileList.first] THEN RETURN [TRUE]; fileList _ fileList.rest; ENDLOOP; RETURN [FALSE] }; files _ Spell.GetMatchingFileList[unknown: "*.Mail", modes: modes, inform: NullInform]; WHILE files # NIL DO IF ~IsOld[files.first] THEN { PeanutWindow.Destroy[]; [] _ PeanutWindow.Create[]; files _ mailFiles _ Spell.GetMatchingFileList[unknown: "*.Mail", modes: modes, inform: NullInform]; WHILE files # NIL DO AddName[files.first]; files _ files.rest; ENDLOOP; EXIT }; files _ files.rest; ENDLOOP }; }; PeanutWindow.AddCommand[name: "NewMail", proc: NewMail]; PeanutWindow.AddCommand[name: "NewForm", proc: NewForm]; PeanutWindow.AddCommand[name: "Answer", proc: AnswerMessage]; PeanutWindow.AddCommand[name: "Forward", proc: ForwardMessage]; PeanutWindow.AddCommand[name: "Send", proc: SendMessage]; PeanutWindow.AddCommand[name: "Abort", proc: Abort]; PeanutWindow.AddCommand[name: "SaveAll", proc: SaveAll]; UserExec.RegisterCommand["Peanut", BuildPeanut, "For retrieving and sending mail"]; TRUSTED {CedarSnapshot.Register[c: PeanutCheckpointProc, r: PeanutRollbackProc]}; StartPeanut[]; END.