home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / batch / mxmnu233.zip / MAIL.MNU < prev    next >
Text File  |  1991-09-27  |  23KB  |  1,069 lines

  1. Comment
  2. ==========================================================
  3.  
  4. Copyright 1991 by Marc Perkel * All right reserved.
  5.  
  6. This is a simple EMAIL program designed for novell networks. It's still
  7. rather new so don't expect perfection. It is a demo menu and you will
  8. need to modify it to suit. It is not designed to compete with major mail
  9. software.
  10.  
  11. This program does not offer high security. In fact, you will have to
  12. grant full access rights to the MAIL directories to everyone. If
  13. security is an issue then this isn't for you. It is designed to elimate
  14. stacks of notes that get lost in small offices where security is not a
  15. problem.
  16.  
  17. To control custom screen features, edit CUSTOM.INC and other INCLUDE
  18. Files.
  19.  
  20. =========================================================
  21. EndComment
  22.  
  23. ;------ Create Variables
  24.  
  25. Var
  26.   MyServer
  27.   NetAddress
  28.   Station
  29.   UserName
  30.   ShortName
  31.   BMess
  32.   TitleBackColor
  33.   TitleInsideColor
  34.  
  35. Var
  36.   AllUsers
  37.   LoggedUsers
  38.   Groups
  39.   SendTo
  40.   FileToSend
  41.   DefFileToSend
  42.   HomeDirPrefix
  43.   MyEditor
  44.   Mail
  45.   InLines
  46.   MailStat
  47.   StatWin
  48.   LastMsgWaiting = -1
  49.   InBox
  50.   NotesFile
  51.   ReplyName
  52.   ReceiptName
  53.   RecName
  54.   DelayName
  55.   FutureName
  56.   ReadyToReceive
  57.   ThisDir
  58.   SkipTest
  59.   TrashFile
  60.   OutFile
  61.   OutFileOpen
  62.   Msg
  63.   Bar
  64.  
  65. Qualifier
  66.   Text
  67.   From
  68.   SendTo
  69.   CarbonCopy
  70.   MsgTime
  71.   Receipt
  72.   Urgent
  73.   Delay
  74.   Subject
  75.  
  76.  
  77. if NovConnection = 0
  78.    ClearScreenOnExit Off
  79.    Writeln 'This program requires a Novell connection to run!'
  80.    ExitMenu
  81. endif
  82.  
  83. MyServer = NovDefaultServer
  84. Station  = Str(NovConnection)
  85. UserName = NovMyLoginName
  86. ShortName = Left(UserName,8)
  87.  
  88. ;------ Read network address
  89.  
  90. NetAddress = NovStationAddress (NovConnection)
  91.  
  92. ;------ Personalize Your Screen Messages
  93.  
  94. StatusLineText = 'User: ' + UserName + '  *  Server: ' + MyServer
  95. StatusLineText = StatusLineText + '  *  Address: ' + NetAddress
  96. if length(StatusLineText) < 64
  97.    StatusLineText = StatusLineText + '  *  Dos: ' + DosVersionString
  98. endif
  99.  
  100. MenuTitle = 'Computer Tyme Message System'
  101.  
  102. ;------ Load menu look and feel include files
  103.  
  104. Include 'CUSTOM.INC'
  105.  
  106. MyEditor = 'ME.EXE'
  107. HomeDirPrefix = 'F:\HOME'
  108. DefFileToSend = HomeDirPrefix + '\' + ShortName + '\' + 'OUT.MSG'
  109. FileToSend = DefFileToSend
  110. InBox = HomeDirPrefix + '\' + ShortName + '\' + 'INBOX.TXT'
  111. TrashFile = HomeDirPrefix + '\' + ShortName + '\' + 'TRASH.TXT'
  112. NotesFile = HomeDirPrefix + '\' + ShortName + '\' + 'NOTES'
  113. ReplyName = HomeDirPrefix + '\' + ShortName + '\' + 'REPLY.MSG'
  114. ReceiptName = HomeDirPrefix + '\' + ShortName + '\' + 'RECEIPT.MSG'
  115. RecName = ForceExtension(MailFile(UserName),'REC')
  116. DelayName = ForceExtension(RecName,'DLY')
  117. FutureName = ForceExtension(RecName,'FTR')
  118.  
  119. Bar = '===================================='
  120.  
  121. RemoveDelayMessages
  122. ReceiveMail
  123. IdleProgram = Loc BackTask
  124. ReadyToReceive
  125.  
  126. ;----- Main Menu
  127.  
  128. AddChoice('Read Messages',1)
  129. AddChoice('Compose a Message',2)
  130. AddChoice('Send Composed Message',3)
  131. AddChoice('Send Form Message',4)
  132. AddChoice('Mail Utilities',5)
  133. AddChoice('Novell Utilities',6)
  134. if NovInGroup('MAILMANAGER')
  135.    AddChoice('Diagnostics',7)
  136. endif
  137.  
  138. CornerStretchBox ('Marx Mail',11,6)
  139.  
  140. OnKey Task(1)
  141.    |ReceiveMail
  142.    |if NumberOfElements(Mail) > 0 then ReadMessage
  143.    |ReceiveMail
  144.  
  145. OnKey Task(2)
  146.    |FileToSend = DefFileToSend
  147.    |InputFileToSend
  148.    |EditFile(FileToSend)
  149.    |LoadFileToSend
  150.  
  151. OnKey Task(3)
  152.    |SendMessages
  153.  
  154. OnKey Task(4)
  155.    |FileToSend = SelectFile('*.MSG')
  156.    |if LastKey = Esc then Return
  157.    |SendMessages
  158.  
  159. OnKey Task(5)
  160.    ^Util
  161.  
  162. OnKey Task(6)
  163.    ^Novell
  164.  
  165. OnKey Task(7)
  166.    ^Diag
  167.  
  168. OnKey ESC
  169.    |LeaveMenu
  170.  
  171.  
  172. ;----- Utility Menu
  173.  
  174. :Util
  175.  
  176. AddChoice("Who's Logged In?",1)
  177. AddChoice("View InBox",2)
  178. AddChoice("Edit InBox",3)
  179. AddChoice("Edit Form Message",4)
  180. if ExistFile(TrashFile)
  181.    AddChoice("Dig Through Trash",5)
  182.    AddChoice("Empty Trash",6)
  183. endif
  184.  
  185. CornerStretchBox ('Utility Menu',43,6)
  186.  
  187. OnKey Task(1)
  188.    |SendTo = PickLoggedUser('Logged Users')
  189.    |Dispose(SendTo)
  190.  
  191. OnKey Task(2)
  192.    |ViewAFile(InBox)
  193.  
  194. OnKey Task(3)
  195.    |EditFile(InBox)
  196.  
  197. OnKey Task(4)
  198.    |FileToSend = SelectFile('*.MSG')
  199.    |if LastKey = Esc then Return
  200.    |EditFile(FileToSend)
  201.  
  202. OnKey Task(5)
  203.    |ViewAFile(TrashFile)
  204.  
  205. OnKey Task(6)
  206.    |EmptyTrash
  207.    |LastKey = Esc
  208.  
  209.  
  210. ;----- Novell Message Menu
  211.  
  212. :Novell
  213.  
  214. AddChoice('Send Novell Message',1)
  215. AddChoice("Block Novell Message",2)
  216. AddChoice("Allow Novell Message",3)
  217. if NovInGroup('MAILMANAGER')
  218.    AddChoice("Novell Syscon",4)
  219. endif
  220.  
  221. CornerStretchBox ('Novell Menu',43,6)
  222.  
  223. OnKey Task(1)
  224.    |PickWhoTo
  225.    |if WhoPicked then SendNovellMessages
  226.  
  227. OnKey Task(2)
  228.    CASTOFF
  229.  
  230. OnKey Task(3)
  231.    CASTON
  232.  
  233. OnKey Task(4)
  234.    Syscon
  235.  
  236.  
  237. ;----- Diagnostics Menu
  238.  
  239. :Diag
  240.  
  241. AddChoice('Edit This Menu',1)
  242. if ExistFile(RecName)
  243.    AddChoice('View REC File',2)
  244. endif
  245. if ExistFile(FutureName)
  246.    AddChoice('View FUT File',3)
  247. endif
  248.  
  249. CornerStretchBox ('Diagnostics Menu',43,6)
  250.  
  251. OnKey Task(1)
  252.    |EditFile(%MenuFileName)
  253.    MarxComp %MenuFileName
  254.  
  255. OnKey Task(2)
  256.    |ViewAFile(RecName)
  257.  
  258. OnKey Task(3)
  259.    |ViewAFile(FutureName)
  260.  
  261. ;=========================================================
  262.  
  263.  
  264. Procedure EmptyTrash
  265. var BackFile
  266.    ShowMessage('Emptying Trash',43,20)
  267.    BackFile = ForceExtension(TrashFile,'BAK')
  268.    DelFile(BackFile)
  269.    FileRename(TrashFile,Backfile)
  270.    Wait 100
  271.    EraseTopWindow
  272. EndProc
  273.  
  274.  
  275. ;----- Process OutGoing File
  276.  
  277. Procedure LoadFileToSend
  278.  
  279. var St Tmp Tmp2 KeyWord X Y SameLine BlindCC
  280.  
  281.    if Msg.From > '' then return
  282.    Msg.From = UserName
  283.    ReadTextFile(FileToSend,Msg.Text)
  284.    Y = NumberOfElements Msg.Text
  285.    X = 1
  286.    While X <= Y
  287.       St = Msg.Text[X]
  288.       Tmp = UpperCase(St)
  289.       KeyWord = NextWord(Tmp)
  290.  
  291.       ;Specify you to send to
  292.  
  293.       if KeyWord = 'SENDTO:'
  294.          while Tmp > ''
  295.             Tmp2 = NextWord(Tmp)
  296.             if Tmp2 <> ','
  297.                AppendArray(Msg.SendTo,Tmp2)
  298.             endif
  299.          endwhile
  300.          Delete(Msg.Text,X,1)
  301.          Y = Y - 1
  302.          SameLine
  303.  
  304.       ;Mail to be delivered in future
  305.  
  306.       elseif KeyWord = 'DELAY:'
  307.          Trim(Tmp)
  308.          Msg.Delay = TimeOf(Tmp) >= Tomorrow
  309.          Msg.Text[X] = 'DELAY: ' + Tmp
  310.  
  311.       ;Mail Subject
  312.  
  313.       elseif KeyWord = 'SUBJECT:'
  314.          Tmp = St
  315.          Msg.Subject = NextWord(Tmp)
  316.          Trim(Tmp)
  317.          Msg.Subject = Tmp
  318.          Msg.Text[X] = 'SUBJECT: ' + Tmp
  319.  
  320.       ;Blind Carbon Copy
  321.  
  322.       elseif KeyWord = 'BCC:'
  323.          KeyWord = 'CC:'
  324.          BlindCC
  325.       endif
  326.  
  327.       ;Carbon Copy
  328.  
  329.       if KeyWord = 'CC:'
  330.          St = 'CC:'
  331.          while Tmp > ''
  332.             Tmp2 = NextWord(Tmp)
  333.             if Tmp2 <> ','
  334.                St = St + ' ' + Tmp2
  335.                AppendArray(Msg.CarbonCopy,Tmp2)
  336.             endif
  337.          endwhile
  338.          if BlindCC
  339.             Delete(Msg.Text,X,1)
  340.             Y = Y - 1
  341.             SameLine
  342.          else
  343.             Msg.Text[X] = St
  344.          Endif
  345.       endif
  346.  
  347.       if Tmp = ''
  348.  
  349.          ;Urgent Mail triggers novell message send
  350.  
  351.          if KeyWord = 'URGENT'
  352.             Msg.Urgent = True
  353.             Msg.Text[X] = KeyWord
  354.          endif
  355.  
  356.          ;Return receipt requested
  357.  
  358.          if KeyWord = 'RECEIPT'
  359.             Msg.Text[X] = KeyWord
  360.          endif
  361.       endif
  362.       if not SameLine then X = X + 1
  363.       SameLine = False
  364.    EndWhile
  365.    if Msg.Delay then Msg.Urgent = False
  366.    TrimText(Loc Msg.Text)
  367.    if NumberOfElements(Msg.SendTo) > 0 then SendTo = Msg.SendTo
  368.    ExpandAndTestSendTo (Loc SendTo)
  369.    ExpandAndTestSendTo (Loc Msg.CarbonCopy)
  370. EndProc
  371.  
  372.  
  373. Procedure ExpandAndTestSendTo (List)
  374. var X Y Users Group
  375.    X = 1
  376.    Y = NumberOfElements(List)
  377.    while X <= Y
  378.       if not UserExists(List[X])
  379.          Group = List[X]
  380.          delete(List,X,1)
  381.          X = X - 1
  382.          Y = Y - 1
  383.          if GroupExists(Group)
  384.             NovGroupMembers(Group,Users)
  385.             Loop Users
  386.                AppendArray(List,Users[LoopIndex])
  387.                Y = Y + 1
  388.             EndLoop
  389.          endif
  390.       endif
  391.       X = X + 1
  392.    endwhile
  393.    RemoveDuplicates (Loc List)
  394. EndProc
  395.  
  396.  
  397. Procedure RemoveDuplicates (List)
  398. var X Y
  399.    SortArray(List)
  400.    X = 1
  401.    Y = NumberOfElements (List) - 1
  402.    while X <= Y
  403.       if List[X] = List[X + 1]
  404.          Delete(List,X,1)
  405.          X = X - 1
  406.          Y = Y - 1
  407.       endif
  408.       X = X + 1
  409.    endwhile
  410. EndProc
  411.  
  412.  
  413. Procedure TrimText (Text)
  414. var X
  415.    while (NumberOfElements (Text) > 0) and (Text[1] = '')
  416.       delete(Text,1,1)
  417.    endwhile
  418.    X = NumberOfElements Text
  419.    while (X > 1) and (Text[X] = '')
  420.       X = X - 1
  421.    endwhile
  422.    delete(Text,X + 1,10000)
  423. EndProc
  424.  
  425.  
  426. Comment
  427. ==========================================================
  428.  
  429. This section of code deals with sending novell messages by shelling the
  430. novell send command. The send is executed if the receiving user is in
  431. the NOTIFY group of the word URGENT is used in the message by the
  432. sender.
  433.  
  434. ==========================================================
  435. EndComment
  436.  
  437.  
  438. Procedure SendNovellMessage (Message,User)
  439. var St
  440.    if UserIsLoggedIn(User)
  441.       St = 'Notifying: ' + User
  442.       ShowMessage (St,45,20)
  443.       ClearScreenFirst Off
  444.       Execute 'Send "' + Message + '" to ' + User + '>nul'
  445.       EraseTopWindow
  446.    endif
  447. EndProc
  448.  
  449.  
  450. Procedure SendNovellMessages
  451. var Message
  452.    if NumberOfElements (SendTo) = 0 then Return
  453.    Message = ReadTextLine('Message:','',0,21)
  454.    if LastKey = Esc then Return
  455.    Loop SendTo
  456.       SendNovellMessage(Message,SendTo[LoopIndex])
  457.    EndLoop
  458.    Dispose SendTo
  459.    Dispose Msg
  460. EndProc
  461.  
  462. ;=========================================================
  463.  
  464. Procedure DrawPickBox (Title,A)
  465.    DrawTheBox(30,10,23,Min(14,NumberOfElements(A) + 4),Title)
  466. EndProc
  467.  
  468. ;----- Reads a list of logged users on the system
  469.  
  470. Procedure ReadLoggedUsers
  471.    if NumberOfElements(LoggedUsers) > 0 then Return
  472.    NovUsersLoggedIn(LoggedUsers)
  473.    SortArray(LoggedUsers)
  474. EndProc
  475.  
  476.  
  477. Procedure PickLoggedUser (Message)
  478.    ReadLoggedUsers
  479.    DrawPickBox(Message,LoggedUsers)
  480.    Return PickOne(LoggedUsers)
  481. EndProc
  482.  
  483. ;----- Reads a list of all users on the system
  484.  
  485. Procedure ReadUsers
  486.    if NumberOfElements(AllUsers) > 0 then Return
  487.    NovUsers(AllUsers)
  488.    SortArray(AllUsers)
  489. EndProc
  490.  
  491.  
  492. Procedure PickUser (Message)
  493.    ReadUsers
  494.    DrawPickBox(Message,AllUsers)
  495.    Return PickOne(AllUsers)
  496. EndProc
  497.  
  498. ;----- Reads a list of all groups on the system
  499.  
  500. Procedure ReadGroups
  501.    if NumberOfElements(Groups) > 0 then Return
  502.    NovGroups(Groups)
  503.    SortArray(Groups)
  504. EndProc
  505.  
  506.  
  507. Procedure PickGroup (Message)
  508.    ReadGroups
  509.    DrawPickBox(Message,Groups)
  510.    Return PickOne(Groups)
  511. EndProc
  512.  
  513.  
  514. Procedure PickUsersFromGroup
  515. var Group Members
  516.    Group = PickGroup('Groups')
  517.    EraseTopWindow
  518.    NovGroupMembers(Group,Members)
  519.    DrawPickBox('Members',Members)
  520.    PickMany(Members,SendTo)
  521. EndProc
  522.  
  523.  
  524. Procedure WhoPicked
  525.    Return NumberOfElements(SendTo) > 0
  526. EndProc
  527.  
  528.  
  529. Procedure PickWhoTo
  530.    if WhoPicked then Return
  531.  
  532.    AddChoice("Pick Logged In User",1)
  533.    AddChoice("Pick from all Users",2)
  534.    AddChoice("Pick a Group",3)
  535.    AddChoice("Pick users from Group",4)
  536.  
  537.    CornerStretchBox ('Who To Menu',43,6)
  538.  
  539.    OnKey Task(1)
  540.       |SendTo[1] = PickLoggedUser('Logged Users')
  541.       |LastKey = Esc
  542.  
  543.    OnKey Task(2)
  544.       |SendTo[1] = PickUser('All Users')
  545.       |LastKey = Esc
  546.  
  547.    OnKey Task(3)
  548.       |SendTo = PickGroup('Groups')
  549.       |NovGroupMembers(SendTo,SendTo)
  550.       |LastKey = Esc
  551.  
  552.    OnKey Task(4)
  553.       |PickUsersFromGroup
  554.       |LastKey = Esc
  555.  
  556. EndProc
  557.  
  558.  
  559. ;=========================================================
  560.  
  561. ;----- Mail Directories
  562.  
  563. Procedure MailDir (User)
  564.    Return 'F:\MAIL\' + NovObjectID(User)
  565. EndProc
  566.  
  567.  
  568. Procedure MyMailDir
  569.    Return MailDir(UserName)
  570. EndProc
  571.  
  572.  
  573. Procedure MyHomeDir
  574.    Return 'F:\HOME\' + ShortName
  575. EndProc
  576.  
  577.  
  578. Procedure MailFile (User)
  579.    Return MailDir(User) + '\' + NovObjectID(User) + '.IN'
  580. EndProc
  581.  
  582. ;----- Input file to send
  583.  
  584. Procedure InputFileToSend
  585.    InputString = FileToSend
  586.    Cursor On
  587.    FileToSend = ReadTextLine('File:','',0,21)
  588. EndProc
  589.  
  590.  
  591. ;----- Check Lists
  592.  
  593. Procedure StringIsInList (St,List)
  594.    Loop List
  595.       if St = List[LoopIndex]
  596.          Return True
  597.       endif
  598.    EndLoop
  599.    Return False
  600. EndProc
  601.  
  602.  
  603. Procedure UserIsLoggedIn (User)
  604.    ReadLoggedUsers
  605.    Return StringIsInList (User,LoggedUsers)
  606. EndProc
  607.  
  608.  
  609. Procedure UserExists (User)
  610.    ReadUsers
  611.    Return StringIsInList (User,AllUsers)
  612. EndProc
  613.  
  614.  
  615. Procedure GroupExists (Group)
  616.    ReadGroups
  617.    Return StringIsInList (Group,Groups)
  618. EndProc
  619.  
  620.  
  621. ;----- Send Messages
  622.  
  623.  
  624. Procedure GetTimeString
  625. var StHour StMinute St Moment
  626.    Moment = Now
  627.    StHour = Str(HourOf(Moment))
  628.    StMinute = Str(MinuteOf(Moment))
  629.    if StHour = '0' then StHour = '12'
  630.    if HourOf(Moment) > 11
  631.       if HourOf(Moment) > 12 then StHour = Str(HourOf(Moment) - 12)
  632.       St = 'p'
  633.    else
  634.       St = 'a'
  635.    endif
  636.    if length(StMinute) = 1 then StMinute = '0' + StMinute
  637.    if length(StHour) = 1 then StHour = '0' + StHour
  638.    St = StHour + ':' + StMinute + St
  639.    Return St
  640. EndProc
  641.  
  642.  
  643. Procedure MessageHeader
  644. var Head
  645.    Head = 'From: ' + UserName
  646.    Head = Head + '  -<*>-  Time: ' + DateString + ' ' + GetTimeString
  647.    WriteOutFile('')
  648.    WriteOutFile(Head)
  649.    WriteOutFile('')
  650. EndProc
  651.  
  652.  
  653. Procedure MessageFooter
  654.    WriteOutFile('')
  655.    WriteOutFile(Bar)
  656. EndProc
  657.  
  658.  
  659. ;=========================================================
  660.  
  661. ;----- Send Messages
  662.  
  663. Procedure SendMessageCC (User,Carbon)
  664. var Name
  665.    ShowMessage('Sending ' + FileToSend + ' to ' + User,11,20)
  666.    Name = MailFile(User)
  667.    if Msg.Delay then Name = ForceExtension(Name,'DLY')
  668.    OpenOutFile(Name)
  669.    MessageHeader
  670.    if Carbon > ''
  671.       WriteOutFile(' * * Carbon Copy of Message Sent To: ' + Carbon + ' * *')
  672.       WriteOutFile('')
  673.    endif
  674.    Loop Msg.Text
  675.       WriteOutFile(Msg.Text[LoopIndex])
  676.    EndLoop
  677.    MessageFooter
  678.    CloseOutFile
  679.    EraseTopWindow
  680.    if NovUserInGroup(User,'NOTIFY') or Msg.Urgent
  681.       if Msg.Subject > ''
  682.          SendNovellMessage(Msg.Subject,User)
  683.       else
  684.          if Msg.Urgent
  685.             SendNovellMessage('* Urgent Incomming Mail *',User)
  686.          else
  687.             SendNovellMessage('* Incomming Mail *',User)
  688.          endif
  689.       endif
  690.    endif
  691. EndProc
  692.  
  693.  
  694. Procedure SendMessage (User)
  695.    SendMessageCC(User,'')
  696.    Loop Msg.CarbonCopy
  697.       SendMessageCC(Msg.CarbonCopy[LoopIndex],User)
  698.    EndLoop
  699. EndProc
  700.  
  701.  
  702. Procedure SendMessages
  703.    LoadFileToSend
  704.    PickWhoTo
  705.    Loop SendTo
  706.       SendMessage(SendTo[LoopIndex])
  707.    EndLoop
  708.    Dispose SendTo
  709.    Dispose Msg
  710.    FileToSend = DefFileToSend
  711. EndProc
  712.  
  713. ;=========================================================
  714.  
  715. ;----- Process Incomming Mail
  716.  
  717. Procedure ReceiveMail
  718. var InFile
  719.    Dispose(Mail)
  720.    InFile = MailFile(UserName)
  721.    AppendFiles(InFile,RecName)
  722.    if ExistFile(RecName)
  723.       BreakMessagesDown
  724.    endif
  725.    UpdateStatus
  726. EndProc
  727.  
  728.  
  729. Procedure BreakMessagesDown
  730. var St Tmp KeyWord ThisMsg
  731.    ReadTextFile(RecName,InLines)
  732.    TrimText (Loc InLines)
  733.    ThisMsg = Loc Mail[1]
  734.    Loop InLines
  735.       St = InLines[LoopIndex]
  736.       Tmp = UpperCase(St)
  737.       KeyWord = NextWord(Tmp)
  738.       if left(St,3) = '==='
  739.          TrimText(Loc ThisMsg.Text)
  740.          if LoopIndex < NumberOfElements InLines
  741.             Actual ThisMsg = Loc Mail[NumberOfElements(Mail) + 1]
  742.          endif
  743.       else
  744.          if ThisMsg.From = ''
  745.             if KeyWord = 'FROM:'
  746.                ThisMsg.From = NextWord(Tmp)
  747.                delete(Tmp,1,pos('TIME: ',Tmp))
  748.                ThisMsg.MsgTime = NextWord(Tmp)
  749.                ThisMsg.MsgTime = Tmp
  750.             endif
  751.          endif
  752.          if KeyWord = 'RECEIPT'
  753.             ThisMsg.Receipt = True
  754.             St = ' ';
  755.          endif
  756.          if St <> ' ' then AppendArray(ThisMsg.Text,St)
  757.       endif
  758.    EndLoop
  759. EndProc
  760.  
  761.  
  762. Procedure RemoveDelayMessages
  763. var MsgStart MsgEnd St Tmp KeyWord Delay Process DelExist FutExist
  764.    DelExist = ExistFile(DelayName)
  765.    FutExist = ExistFile(FutureName)
  766.    if not (DelExist or FutExist) then Return
  767.    if FutExist
  768.       Process = FileTime(FutureName) <> Today
  769.    endif
  770.    if DelExist
  771.       Process = True
  772.       AppendFiles(DelayName,FutureName)
  773.    endif
  774.    if not Process then Return
  775.    MsgStart = 1
  776.    ReadTextFile(FutureName,InLines)
  777.    DelFile(FutureName)
  778.    Loop InLines
  779.       St = InLines[LoopIndex]
  780.       Tmp = UpperCase(St)
  781.       KeyWord = NextWord(Tmp)
  782.       if left(St,3) = '==='
  783.          MsgEnd = LoopIndex
  784.          if Delay
  785.             OpenOutFile(FutureName)
  786.          else
  787.             OpenOutFile(RecName)
  788.          endif
  789.          while MsgStart <= MsgEnd
  790.             WriteOutFile(InLines[MsgStart])
  791.             MsgStart = MsgStart + 1
  792.          endwhile
  793.          CloseOutFile
  794.          Delay = False
  795.       endif
  796.       if KeyWord = 'DELAY:'
  797.          Delay = TimeOf(Tmp) > Today
  798.       endif
  799.    EndLoop
  800. EndProc
  801.  
  802.  
  803. Procedure UpdateStatus
  804. var St
  805.    if NumberOfElements(Mail) = LastMsgWaiting then Return
  806.    LastMsgWaiting = NumberOfElements(Mail)
  807.    St = 'No'
  808.    if NumberOfElements(Mail) > 0 then St = Str(NumberOfElements(Mail))
  809.    if NumberOfElements(Mail) = 1
  810.       MailStat = ' 1 Message Waiting'
  811.    else
  812.       MailStat = ' ' + St + ' Messages Waiting'
  813.    endif
  814.    if StatWin = 0
  815.       NoBoxBorder
  816.       if ColorScreen
  817.          BoxInsideColor White Cyan
  818.       else
  819.          BoxInsideColor Black Grey
  820.       endif
  821.       DrawBox 14 21 length(MailStat) + 4 1
  822.       Cursor Off
  823.       Write MailStat
  824.       StatWin = CurrentWindow
  825.    else
  826.       SetTopWindow StatWin
  827.       ClearScreen
  828.       Write MailStat
  829.       SetWindowUnder(StatWin,StatWin + 1)
  830.    endif
  831. EndProc
  832.  
  833. ;=========================================================
  834.  
  835. ;----- Respond to Mail
  836.  
  837. Procedure SendReceipt
  838. var St
  839.    if Mail[1].Receipt
  840.       DelFile(ReceiptName)
  841.       OpenOutFile(ReceiptName)
  842.       WriteOutFile('* Message Received *')
  843.       Loop Mail[1].Text
  844.          St = Mail[1].Text[LoopIndex]
  845.          if St > '' then St = '>> ' + St
  846.          WriteOutFile(St)
  847.       EndLoop
  848.       CloseOutFile
  849.       FileToSend = ReceiptName
  850.       SendTo[1] = Mail[1].From
  851.       SendMessages
  852.    endif
  853. EndProc
  854.  
  855.  
  856. Procedure SaveMessageToFile (Name,WithBar)
  857.    OpenOutFile(Name)
  858.    if WithBar then WriteOutFile('')
  859.    Loop Mail[1].Text
  860.       WriteOutFile(Mail[1].Text[LoopIndex])
  861.    EndLoop
  862.    if WithBar
  863.       WriteOutFile('')
  864.       WriteOutFile(Bar)
  865.    endif
  866.    CloseOutFile
  867. EndProc
  868.  
  869.  
  870. Procedure WasteMessage (Num)
  871. var X
  872.    X = 1
  873.    while Left(InLines[X],3) <> '==='
  874.       X = X + 1
  875.    EndWhile
  876.    Delete(InLines,1,X)
  877.    WriteTextFile (RecName,InLines)
  878.    Delete(Mail,1,1)
  879.    UpDateStatus
  880. EndProc
  881.  
  882.  
  883. Procedure ReplyToMessage
  884.    SendTo[1] = Mail[1].From
  885.    DelFile(ReplyName)
  886.    SaveMessageToFile(ReplyName,No)
  887.    EditFile(ReplyName)
  888.    DelFile(ForceExtension(ReplyName,'BAK'))
  889.    FileToSend = ReplyName
  890. EndProc
  891.  
  892.  
  893. Procedure ProcessMessage
  894.    SendReceipt
  895.  
  896.    AddChoice('Dispose Message',1)
  897.    AddChoice('Reply to Message',2)
  898.    AddChoice('Forward Message',3)
  899.    AddChoice('Save in InBox File',4)
  900.    AddChoice('Print Message',5)
  901.    AddChoice('Put Back in MailBox',6)
  902.  
  903.    CornerStretchBox('Message Menu',43,6)
  904.  
  905.    OnKey Task(1)
  906.       |SaveMessageToFile(TrashFile,Yes)
  907.       |WasteMessage
  908.       |LastKey = Esc
  909.  
  910.    OnKey Task(2)
  911.       |ReplyToMessage
  912.       |SendMessages
  913.  
  914.    OnKey Task(3)
  915.       |ReplyToMessage
  916.       |Dispose SendTo
  917.       |SendMessages
  918.  
  919.    OnKey Task(4)
  920.       |SaveMessageToFile(InBox,Yes)
  921.       |WasteMessage
  922.       |LastKey = Esc
  923.  
  924.    OnKey Task(5)
  925.       |FileToSend = 'PRN'
  926.       |InputFileToSend
  927.       |SaveMessageToFile(FileToSend,Yes)
  928.  
  929.    OnKey Task(6)
  930.       |SaveMessageToFile(MailFile(UserName),Yes)
  931.       |WasteMessage
  932.       |LastKey = Esc
  933.  
  934.    OnKey Esc
  935.       |LastKey = ' '
  936.  
  937. EndProc
  938.  
  939.  
  940. Procedure ReadMessage
  941.    ReadyToReceive Off
  942.    while NumberOfElements(Mail) > 0
  943.       if Mail[1].Receipt
  944.          BoxHeader = ' * Receipt Pending * '
  945.       endif
  946.       if ColorScreen
  947.          BoxHeaderColor White Green
  948.          BoxInsideColor LCyan MenuBG
  949.       else
  950.          BoxHeaderColor Black Grey
  951.       endif
  952.       DrawBox 1 4 80 21
  953.       ViewArray(Mail[1].Text)
  954.       ProcessMessage
  955.       EraseTopWindow
  956.    EndWhile
  957.    DelFile(RecName)
  958.    Dispose(Mail)
  959.    ReadyToReceive
  960. EndProc
  961.  
  962.  
  963. ;=========================================================
  964.  
  965. ;----- BackGroundTask
  966.  
  967. Procedure BackTask
  968.    if ReadyToReceive and ((Second mod 30) = (NovConnection mod 30))
  969.       if not SkipTest
  970.          ReceiveMail
  971.       endif
  972.       SkipTest
  973.    else
  974.       SkipTest Off
  975.    endif
  976. EndProc
  977.  
  978. ;----- Edit File
  979.  
  980. Procedure EditFile (Name)
  981.    ClearScreenFirst
  982.    Execute(MyEditor + ' ' + Name)
  983. EndProc
  984.  
  985. ;----- Select a File
  986.  
  987. Procedure SelectFile (Mask)
  988. var St
  989.    if Mask = '' then Return ''
  990.    ThisDir = Path
  991.    ChDir(HomeDirPrefix + '\' + ShortName)
  992.    AllowEsc
  993.    St = PickFile Mask 48 9 14
  994.    ChDir(ThisDir)
  995.    Return (HomeDirPrefix + '\' + ShortName + '\' + St)
  996. EndProc
  997.  
  998.  
  999. ;----- Message Output File Routines
  1000.  
  1001. Procedure OpenOutFile (Name)
  1002.    if not OutFileOpen
  1003.       FileAssign(OutFile,Name)
  1004.       FileAppend(OutFile)
  1005.       OutFileOpen = True
  1006.    endif
  1007. EndProc
  1008.  
  1009.  
  1010. Procedure CloseOutFile
  1011.    if OutFileOpen
  1012.       FileClose(OutFile)
  1013.       OutFileOpen = False
  1014.    endif
  1015. EndProc
  1016.  
  1017.  
  1018. Procedure WriteOutFile (St)
  1019.    FileWriteln(OutFile,St)
  1020. EndProc
  1021.  
  1022.  
  1023. Procedure AppendFiles (Source,Dest)
  1024. var Lines Tmp
  1025.    if not ExistFile(Source) then Return
  1026.    if ExistFile(Dest)
  1027.       Tmp = ForceExtension(Source,'$$$')
  1028.       FileRename(Source,Tmp)
  1029.       ReadTextFile(Tmp,Lines)
  1030.       DelFile(Tmp)
  1031.       OpenOutFile(Dest)
  1032.       Loop Lines
  1033.          WriteOutFile(Lines[LoopIndex])
  1034.       EndLoop
  1035.       CloseOutFile
  1036.    else
  1037.       FileRename(Source,Dest)
  1038.    endif
  1039. EndProc
  1040.  
  1041.  
  1042. Procedure ViewAFile (Name)
  1043.    DrawBox 1 4 80 21
  1044.    if ColorScreen then TextColor LCyan MenuBG
  1045.    ViewTextFile(Name)
  1046. EndProc
  1047.  
  1048.  
  1049. Procedure ShowMessage (Message,X,Y)
  1050.    DrawBox X Y length(Message) + 4 3
  1051.    TextColor LCyan Blue
  1052.    Cursor Off
  1053.    Write ' ' Message
  1054.    Wait 25
  1055. EndProc
  1056.  
  1057.  
  1058. ;----- Show Item for Debugging
  1059.  
  1060. Procedure ShowMe (Item)
  1061.    DrawBox 1 23 80 3
  1062.    Write ' '
  1063.    TextColor Yellow Cyan
  1064.    Write Item
  1065.    Wait 300
  1066.    EraseTopWindow
  1067. EndProc ;ShowItem
  1068.  
  1069.