home *** CD-ROM | disk | FTP | other *** search
/ .net 1999 December / netCD65.iso / pc / Software / VirtualA / 32bit / vasetup.exe / %MYDIR% / Hmimail.ebs < prev    next >
Encoding:
Text File  |  1999-10-06  |  44.6 KB  |  1,100 lines

  1. 'T:HMIMAIL.EBS for CompuServe
  2. ' VA 4.52 release
  3. ' 20-11-97 petec - fixed problem with mail reference
  4. ' 30-11-97 petec - mail collection speeded up by using streaming
  5.  
  6. Declare Function ParseString(args As String, delim As String) As String
  7. Declare Function FileName$(fullpath As String)
  8. Declare Sub AddToMsgFile(SourceFileName as String)
  9. Declare Function QueueFile(service As String, sfilename As String, queueflags As Long) As Boolean
  10. Declare Function MyDate$
  11. Declare Sub ReportSuccess(msg As String)
  12. Declare Function ForumName(ByVal forum As String) As String
  13. Declare Function FullErrorMessage() As String
  14. Declare Function MakeDateString(s As HMITIMESTAMP) As String
  15. Declare Function TimeZone(s As EMPTIMEZONE) As String
  16. Declare Sub CaptureLine(textline As String)
  17. Declare Sub AddToFile(TargetFileName As String, SourceFileName as String)
  18. Declare Function FileUrl(fn As String) As String
  19. Declare Function GetMailType(i As Integer) As String
  20.  
  21. Const BlockSize = 2048
  22.  
  23. 'T:iFlags for CompuServe (constant)
  24. Const IM_DELETE = 2048        ' Delete scratchpad file afterwards?
  25.  
  26. Const fRECEIPT = 1         'CIS mail receipt
  27. Const fPRIVATE = 2         'CIS private forum message
  28. Const fNOFORMAT = 4         'CIS unformatted message
  29. Const fBINARY = 8         'CIS binary file
  30. Const fDONTCOPY = 16     'don't copy the message back to you
  31.  
  32. Public DownloadDir As String
  33. Public WorkingPath As String
  34. Public WhereAmI As String
  35. Public currentCAP As Integer
  36. Public EMPconfig As EMPCONFIG
  37. Public MailName As String
  38. Public PersonalAddress As String
  39. Dim MailSubject As String, MailFilename As String, MailId As String
  40. Dim MailAddresses As String
  41. Dim MailAttachments As String
  42. Dim MailCount As Integer, MailFlags As Integer, AttachmentCount As Integer
  43. Dim OldMail As Boolean, MailSent As Boolean
  44.  
  45. Const HMI_STATE_FIRST% = 0
  46. Const HMI_STATE_NEXT% = HMI_STATE_FIRST + 1
  47. Const HMI_STATE_ABORT% = HMI_STATE_NEXT + 1
  48.  
  49. ' enum EMPCONTENTTYPES:
  50. Const EMP_TEXT% = 0                                  ' Ascii Text Object
  51. Const EMP_BINARY% = EMP_TEXT + 1                  ' 8-bit data
  52. Const EMP_GIF% = EMP_BINARY + 1                      ' Graphic Interchange Format
  53. Const EMP_BINARY_FILE% = EMP_GIF + 1              ' Contents_Name contains filename
  54. Const EMP_TEXT_FILE% = EMP_BINARY_FILE + 1          ' Text file
  55. Const EMP_TEXT_OBJECT% = EMP_TEXT_FILE + 1        ' TextObject message
  56. Const EMP_JPEG% = EMP_TEXT_OBJECT + 1
  57.  
  58. ' enum EMPIMPORTANCETYPES:
  59. Const EMP_LOW_IMPORTANCE% = 0
  60. Const EMP_NORMAL_IMPORTANCE% = EMP_LOW_IMPORTANCE + 1
  61. Const EMP_HIGH_IMPORTANCE% = EMP_NORMAL_IMPORTANCE + 1
  62.  
  63. ' enum EMPSENSITIVITYTYPES:
  64. Const EMP_STANDARD% = 0
  65.  
  66. ' enum EMPSEARCHTYPES:
  67. Const EMP_SUBJECT% = 0
  68. Const EMP_ORIGINATOR% = EMP_SUBJECT + 1
  69. Const EMP_IMPORTANCE% = EMP_ORIGINATOR + 1
  70. Const EMP_SENSITIVITY% = EMP_IMPORTANCE + 1
  71. Const EMP_READ% = EMP_SENSITIVITY + 1
  72. Const EMP_UNREAD% = EMP_READ + 1
  73. Const EMP_DATE% = EMP_UNREAD + 1
  74. Const EMP_BEFOREDATE% = EMP_DATE
  75. Const EMP_AFTERDATE% = EMP_DATE
  76. Const EMP_MESSAGEID% = 8
  77.  
  78. ' Options:
  79. Const EMP_CAN_RECEIVE_MULTIPLE% = &H1
  80. Const EMP_AUTO_DELETE% = &H1
  81.  
  82. ' Restrictions:
  83. Const EMP_CANT_SEND% = &H1
  84. Const EMP_ONLY_ONE_CONTENT% = &H2
  85. Const EMP_CANT_DELAY_DELETE% = &H4
  86. Const EMP_NO_FORWARD_MSG% = &H8
  87. Const EMP_NO_SURCHARGES_ON_SEND% = &H10
  88.  
  89. ' Components
  90. Const EMP_SRC_TOTAL_SIZE% = &H4
  91.  
  92. ' Components:
  93. Const EMP_MHC_MSG_ID% = &H1
  94. Const EMP_MHC_DATE% = &H2
  95. Const EMP_MHC_ORIGINATOR_ADDR% = &H4
  96. Const EMP_MHC_RECIPIENT_OPTIONS% = &H8
  97. Const EMP_MHC_PRIMARY_RECIPIENTS% = &H10
  98. Const EMP_MHC_COPY_RECIPIENTS% = &H20
  99. Const EMP_MHC_IN_REPLY_TO% = &H40
  100. Const EMP_MHC_TABLE_OF_CONTENTS% = &H80
  101. Const EMP_MHC_EXTENDED_ENVELOPES% = &H100
  102. Const EMP_MHC_EXPIRATION_TIME% = &H200
  103.  
  104. ' Type of Recipient
  105. ' enum EMPCOPYTYPES:
  106. Const EMP_PRIMARY_RECIPIENT% = 0
  107. Const EMP_COPY_RECIPIENT% = EMP_PRIMARY_RECIPIENT + 1
  108. Const EMP_BLIND_COPY% = EMP_COPY_RECIPIENT + 1
  109.  
  110. ' Msg Release options
  111. Const EMP_MRO_DELAY_RELEASE% = &H1
  112. Const EMP_MRO_SET_EXPIRE% = &H2
  113. Const EMP_MRO_REPLY_TO% = &H4
  114. Const EMP_MRO_APPEND_DISTRIBUTION% = &H8
  115. Const EMP_MRO_EXTENDED_ENVELOPES% = &H10
  116. Const EMP_MRO_FORWARD_MSG% = &H20
  117.  
  118. ' enum EMPRETENTIONTYPES:
  119. Const EMP_USE_DEFAULT_RETENTION% = 0
  120. Const EMP_USE_MAXIMUM_RETENTION% = EMP_USE_DEFAULT_RETENTION + 1
  121. Const EMP_RETAIN_UNTIL_DATE% = EMP_USE_MAXIMUM_RETENTION + 1
  122. Const EMP_DELETE_NORMAL% = EMP_RETAIN_UNTIL_DATE + 1
  123. Const EMP_DELETE_REGARDLESS% = EMP_DELETE_NORMAL + 1
  124. Const EMP_USE_MAXIMUM_RETENTION_REGARDLESS% = EMP_DELETE_REGARDLESS + 1
  125. Const EMP_RETAIN_UNTIL_DATE_REGARDLESS% = EMP_USE_MAXIMUM_RETENTION_REGARDLESS + 1
  126. Const EMP_DELETE_NORMAL_REGARDLESS% = EMP_RETAIN_UNTIL_DATE_REGARDLESS + 1
  127.  
  128. Function HMIGotoMail()
  129.     Dim i As Integer
  130.  
  131.     If WhereAmI="home:mail" Then
  132.         HMIGotoMail = True
  133.         Exit Function
  134.     End If
  135.  
  136.     SetHighMessageNumber
  137.  
  138.     On Error Goto GoMail_Error
  139.     If DoHMIGotoPage("home:mail", -1, CAP_EMAIL, False) Then
  140.         EMPGetConfig EMPconfig, "", "", 0
  141.         WhereAmI = "home:mail"
  142.         HMIGotoMail = True
  143.         If EMPconfig.wRestrictions And EMP_ONLY_ONE_CONTENT% Then OldMail = True
  144.         Exit Function
  145.     End If
  146. GoMail_Error:
  147.     WhereAmI = ""
  148.     HMIGotoMail = False
  149. End Function
  150.  
  151. 'T:MailTo (subroutine) (CompuServe)
  152. Sub MailTo(id As String, user As String, flags As Integer, subject As String, filename As String)
  153.     Dim inpline As String
  154.  
  155.     If Not HMIGotoMail() Then
  156.         LogResult id + " : Failed : Mail is unavailable : " + FullErrorMessage
  157.         Exit Sub
  158.     End If
  159.  
  160.     If EMPconfig.wRestrictions And EMP_CANT_SEND% Then
  161.         LogResult id + " : Failed : You are not allowed to send messages"
  162.         Exit Sub
  163.     End If
  164.     MailSubject = Left$(subject, 40)
  165.     MailFilename = filename
  166.     MailCount = 0
  167.     MailAddresses = ""
  168.     MailAttachments = ""
  169.     AttachmentCount = 0
  170.     MailFlags = flags
  171.  
  172.     ' The primary recipient
  173.     MailCC user
  174. End Sub
  175.  
  176. Sub AddMailInfo(list As String, address As String, realname As String, RecipientType As Integer)
  177.     If list <> "" Then list = list + Chr$(10)
  178.     list = list + Chr$(RecipientType) + address + Chr$(0) + realname
  179. End Sub
  180.  
  181. Sub AddMailDestination(address As String, realname As String, RecipientType As Integer)
  182.     AddMailInfo MailAddresses, address, realname, RecipientType
  183.     MailCount = MailCount + 1
  184. End Sub
  185.  
  186. Function ExtractMailDestination(list As String, address As String, realname As String, RecipientType As Integer) As Boolean
  187.     Dim tmp As String
  188.     
  189.     tmp = ParseString(list, Chr$(10))
  190.     If tmp = "" Then
  191.         ExtractMailDestination = False
  192.         Exit Function
  193.     End If
  194.     RecipientType = Asc(tmp)
  195.     tmp = Mid$(tmp, 2)
  196.     address = ParseString(tmp, Chr$(0))
  197.     realname = tmp
  198.     ExtractMailDestination = True
  199. End Function
  200.  
  201. 'T:MailCC (subroutine) (CompuServe)
  202. Sub MailCC(cc As String)
  203.     Dim realname As String, email As String, ipname As String
  204.     Dim RemoveRecipient As Boolean
  205.  
  206.     ' Get the email address
  207.     AnalyseName cc, realname, email
  208.     If email="" Then email = realname
  209.  
  210.     ' Check to see if we're sending an IP msg to ourselves
  211.     ipname = "internet:"+Session.LoginName+"@compuserve.com"
  212.     ReplaceAllInString ipname, ",", "."
  213.     If StrComp(email, ipname, 1)=0 Then RemoveRecipient = True
  214.     If StrComp(email, Mid$(ipname, 10), 1)=0 Then RemoveRecipient = True
  215.     If StrComp(email, PersonalAddress+"@compuserve.com", 1)=0 Then RemoveRecipient = True
  216.  
  217.     ' Check to see if we're sending an internal msg to ourselves
  218.     If StrComp(email, PersonalAddress, 1)=0 Then RemoveRecipient = True
  219.     If StrComp(email, Session.LoginName, 1)=0 Then RemoveRecipient = True
  220.  
  221.     If RemoveRecipient=False Then
  222.         If MailAddresses="" Then
  223.             AddMailDestination email, realname, EMP_PRIMARY_RECIPIENT%
  224.         Else
  225.             AddMailDestination email, realname, EMP_COPY_RECIPIENT%
  226.         End If
  227.     End If
  228. End Sub
  229.  
  230. 'T:StartMail (subroutine) (CompuServe)
  231. Sub StartMail(id As String, flags As Integer, subject As String, filename As String, encoding As String)
  232.     Dim inpline As String
  233.  
  234.     MailId = id
  235.     If Not HMIGotoMail() Then
  236.         LogResult id + " : Failed : Mail is unavailable : " + FullErrorMessage
  237.         Exit Sub
  238.     End If
  239.  
  240.     If EMPconfig.wRestrictions And EMP_CANT_SEND% Then
  241.         LogResult id + " : Failed : You are not allowed to send messages"
  242.         Exit Sub
  243.     End If
  244.     MailSubject = Left$(subject, 40)
  245.     MailFilename = filename
  246.     MailCount = 0
  247.     MailAddresses = ""
  248.     MailAttachments = ""
  249.     AttachmentCount = 0
  250.     MailFlags = flags
  251. End Sub
  252.  
  253. 'T:AddRecipient (subroutine) (CompuServe)
  254. Sub AddRecipient(email As String, realname As String, mode As String)
  255.     Dim ipname As String
  256.     Dim RemoveRecipient As Boolean
  257.  
  258.     If email="" Then email = realname else if realname = "" Then realname = email
  259.  
  260.     ' Check to see if we're sending an IP msg to ourselves
  261.     ipname = "internet:"+Session.LoginName+"@compuserve.com"
  262.     ReplaceAllInString ipname, ",", "."
  263.     If StrComp(email, ipname, 1)=0 Then RemoveRecipient = True
  264.     If StrComp(email, Mid$(ipname, 10), 1)=0 Then RemoveRecipient = True
  265.     If StrComp(email, PersonalAddress+"@compuserve.com", 1)=0 Then RemoveRecipient = True
  266.  
  267.     ' Check to see if we're sending an internal msg to ourselves
  268.     If StrComp(email, PersonalAddress, 1)=0 Then RemoveRecipient = True
  269.     If StrComp(email, Session.LoginName, 1)=0 Then RemoveRecipient = True
  270.  
  271.     If RemoveRecipient=False Then
  272.         If mode = "bcc" Then
  273.             AddMailDestination email, realname, EMP_BLIND_COPY%
  274.         ElseIf mode = "cc" Then
  275.             AddMailDestination email, realname, EMP_COPY_RECIPIENT%
  276.         Else
  277.             AddMailDestination email, realname, EMP_PRIMARY_RECIPIENT%
  278.         End If
  279.     End If
  280. End Sub
  281.  
  282. 'T:AddAttachment (subroutine) (CompuServe)
  283. Sub AddAttachment(filename As String, truename As String)
  284.     If filename = "" Then filename = truename Else If truename = "" Then truename = filename
  285.     If filename <> "" Then 
  286.         AddMailInfo MailAttachments, filename, truename, 0
  287.         AttachmentCount = AttachmentCount + 1
  288.     End If
  289. End Sub
  290.  
  291. 'T:EndMail (subroutine) (Compuserve)
  292. Sub EndMail
  293.     SendMail MailId
  294. End Sub
  295.  
  296. 'T:SetEnvelope (subroutine) (CompuServe)
  297. Sub SetEnvelope(envelope As EMPENVELOPE, address As String, realname As String, UrgentMail As Boolean, RecipientType As Integer)
  298.     If UrgentMail Then
  299.         envelope.moOptions.cImportance = EMP_HIGH_IMPORTANCE%
  300.     Else
  301.         envelope.moOptions.cImportance = EMP_NORMAL_IMPORTANCE%
  302.     End If
  303.     envelope.moOptions.cSensitivity = EMP_STANDARD%
  304.     envelope.moOptions.cReceiptNotification = 0
  305.     envelope.nType = RecipientType
  306.  
  307.     ' @web.compuserve.com -> CSINET:
  308.     If InStr(address, "@web.compuserve.com", 1)>0 And _
  309.        UCase$(Left$(address, 7))<>"CSINET:" Then
  310.         address = "CSINET:"+address
  311.     End If
  312.  
  313.     ' Check to see if it's a gateway, if it isn't and contains a '@' then
  314.     ' then it must be an internet address
  315.     If InStr(address, ":")=0 And InStr(address, " ")=0 And _
  316.        InStr(address, "@")<>0 Then
  317.         address = "internet:"+address
  318.     End If
  319.  
  320.     ' Remove surrounding [] from the address?
  321.     If Mid$(address, 1, 1)="[" And Right$(address, 1)="]" Then
  322.         address = Mid$(address, 2, Len(address)-2)
  323.     End If
  324.  
  325.     envelope.lpRecipientName = realname
  326.     envelope.lpRecipientAddr = address
  327.     If envelope.lpRecipientName = "" Then
  328.         envelope.lpRecipientName = envelope.lpRecipientAddr
  329.     End If
  330.     If envelope.lpRecipientAddr = "" Then
  331.         envelope.lpRecipientAddr = envelope.lpRecipientName
  332.     End If
  333.  
  334.     'LogResult "name = {" + envelope.lpRecipientName + "}"
  335.     'LogResult "addr = {" + envelope.lpRecipientAddr + "}"
  336. End Sub
  337.  
  338. 'T:PreProcessMail (subroutine) (CompuServe)
  339. Function PreProcessMail(InFileName As String, OutFileName As String, _
  340.                    ByRef InReplyTo As String, ByRef RealName As String, _
  341.                    ByRef UrgentMail As Boolean, AtL As Boolean) As Boolean
  342.     Dim OutFileNum as Integer, InFileNum as Integer
  343.     Dim TheData as String
  344.     Dim count As Long
  345.  
  346.     count = 0
  347.     On Error Goto PreProcessMail_error
  348.  
  349.     InFileNum = FreeFile()
  350.     Open InFileName For Input Access Read Shared As #InFileNum
  351.     
  352.     OutFileNum = FreeFile()
  353.     Open OutFileName for Output Access Write Shared as #OutFileNum
  354.  
  355.     ' Send as shown
  356.     If AtL then Print #OutFileNum, "@l";
  357.     
  358.     ' Operate on blocks of BlockSize at a time
  359.     Do While Not Eof(InFileNum)
  360.         Line Input #InFileNum, TheData
  361.  
  362.         ' Is this from somebody else ?
  363.         If count<3 And Mid$(TheData, 1, 11)="X-VA-From: " Then
  364.             RealName = Mid$(TheData, 12)
  365.         ElseIf count<3 And Mid$(TheData, 1, 13)="In-Reply-To: " Then
  366.             InReplyTo = Mid$(TheData, 15)
  367.             ReplaceAllInString InReplyTo, ">", ""
  368.         ElseIf count<3 And Mid$(TheData, 1, 14)="Priority: High" Then
  369.             UrgentMail = True
  370.         Else
  371.             Print #OutFileNum, TheData + Chr$(10);
  372.         End If
  373.         count = count + 1
  374.     Loop
  375.     Print #OutFileNum, " ";
  376.  
  377.     Close #InFileNum
  378.     Close #OutFileNum
  379.     PreProcessMail = True
  380.     Exit Function
  381.  
  382. PreProcessMail_error:
  383.     LogResult "Error in PreProcessMail : " + Str$(Err) + " in line " + Str$(Erl) + ":" + Error$
  384.     Close #InFileNum
  385.     Close #OutFileNum
  386.     PreProcessMail = False
  387. End Function
  388.  
  389. 'T:SendMail (subroutine) (CompuServe)
  390. Sub SendMail(id As String)
  391.     Dim filename As String, header As String, user As String
  392.     Dim sendresponse As EMPSENDRESPONSE
  393.     Dim envelopes() As EMPENVELOPE
  394.     Dim badenvelopes() As EMPBADENVELOPE
  395.     Dim oldcontents() As EMPCONTENTSDESC, contents() As EMPCONTENTSDESC
  396.     Dim forward As String, InReplyTo As String, RealName As String
  397.     Dim address As String, rname As String
  398.     Dim RecipientType As Integer, LastRecipientType As Integer
  399.     Dim notime As HMITIMESTAMP
  400.     Dim i As Integer, j As Integer, contno As Integer
  401.     Dim addresses As String, badaddresses As String, badcount As Integer
  402.     Dim attachments As String, footer As String
  403.     Dim path As String, sname As String, nState As Integer
  404.     Dim SourceFileNum as Integer, SourceFileAt as Long
  405.     Dim SourceFileLen as Long, TheData as String, BytesToRead as Long
  406.     Dim confirm As EMPCONFIRMATION
  407.     Dim mroOptions As Integer, UrgentMail As Boolean
  408.     Dim tmpFilename As String, tmp As String
  409.  
  410.     On Error Goto SendMail_error
  411.     MailSent = False
  412.     MailCount = MailCount - 1
  413.     Redim contents(0 to AttachmentCount)
  414.     Redim oldcontents(0 to 0)
  415.     ' Just send it to ourself?
  416.     If MailCount < 0 Then
  417.         AddMailDestination Session.LoginName, Session.LoginName, EMP_BLIND_COPY%
  418.         If (MailFlags And fDONTCOPY)=0 Then MailFlags = MailFlags + fDONTCOPY
  419.     End If
  420.  
  421.     Terminal.Print "Sending mail " + MailSubject + Basic.Eoln$
  422.  
  423.     InReplyTo = ""
  424.     RealName = MailName
  425.     UrgentMail = False
  426.     If (MailFlags And fBINARY)=fBINARY Then
  427.         ' Binary mail
  428.         SplitPath MailFilename, path, sname
  429.         contents(0).nType = EMP_BINARY_FILE%
  430.         tmpFilename = MailFilename
  431.     Else
  432.         ' ASCII mail
  433.         sname = "Mail Message"
  434.         contents(0).nType = EMP_TEXT_OBJECT%
  435.  
  436.         ' Process header lines and add formatting codes
  437.         tmpFilename = WorkingPath + "sendmail.txt"
  438.         If Not PreProcessMail(MailFilename, tmpFilename, InReplyTo, RealName, UrgentMail, False) Then 'InStr(MailAddresses, "@")<>0) Then
  439.             Exit Sub
  440.         End If
  441.     End If
  442.     contents(0).dwSize = FileLen(tmpFilename)
  443.     contents(0).dwSurcharge = 0
  444.     attachments = MailAttachments    'Copy attachment list to temp string before parsing
  445.     For i = 1 To AttachmentCount
  446.         If ExtractMailDestination(attachments, address, rname, RecipientType) Then
  447.             contents(i).nType = EMP_BINARY_FILE%
  448.             contents(i).dwSize = FileLen(address)
  449.             contents(i).dwSurcharge = 0
  450.         End If
  451.     Next
  452.     oldcontents(0) = contents(0)
  453.  
  454. SendMail_retry:
  455.     ReDim envelopes(0 To MailCount)
  456.     addresses = MailAddresses
  457.     For i = 0 To MailCount
  458.         If ExtractMailDestination(MailAddresses, address, rname, RecipientType) Then
  459.             SetEnvelope envelopes(i), address, rname, UrgentMail, RecipientType
  460.         End If
  461.     Next
  462.  
  463.     ' Make sure it's a legal In-Reply-To otherwise newmail dies
  464.     tmp = Left$(InReplyTo, 2)
  465.     If tmp<>"MC" And IsNumeric(tmp)=False Then InReplyTo = ""
  466.     If Len(InReplyTo) > 35 Then InReplyTo = ""
  467.  
  468.     envelopes(0).moOptions.cReceiptNotification = ((MailFlags And fRECEIPT) <> 0)
  469.     mroOptions = EMP_MRO_APPEND_DISTRIBUTION%
  470.     If InReplyTo<>"" Then mroOptions = mroOptions Or EMP_MRO_REPLY_TO%
  471.     If OldMail Then
  472.         EMPSendMsgHeader sendresponse, badenvelopes(), mroOptions, _
  473.                 MailSubject, RealName, notime, notime, InReplyTo, envelopes(), _
  474.                 oldcontents(), MailCount + 1, "", forward
  475.     Else
  476.         EMPSendMsgHeader sendresponse, badenvelopes(), mroOptions, _
  477.                 MailSubject, RealName, notime, notime, InReplyTo, envelopes(), _
  478.                 contents(), MailCount + 1, "", forward
  479.     End If
  480.     If sendresponse.wCount > 0 Then
  481.         For i = 0 To Ubound(badenvelopes)
  482.             j = badenvelopes(i).wNumber - 1
  483.             envelopes(j).nType = badenvelopes(i).cReason
  484.             envelopes(j).moOptions.cImportance = 255
  485.         Next
  486.         MailCount = -1
  487.         MailAddresses = ""
  488.         For i = 0 To Ubound(envelopes)
  489.             If ExtractMailDestination(MailAddresses, address, rname, RecipientType) Then
  490.                 If envelopes(i).moOptions.cImportance = 255 Then
  491.                     LogResult id + " : Invalid address (" & _
  492.                         envelopes(i).nType & "): " + address
  493.                     badaddresses = badaddresses + rname + " [" + address + "]" + Chr$(10)
  494.                     badcount = badcount + 1
  495.                 Else
  496.                     AddMailDestination address, rname, RecipientType
  497.                 End If
  498.             End If
  499.         Next
  500.         If MailCount >= 0 Then Goto SendMail_retry
  501.         LogResult id+" : SendMail Failed : No valid destination addresses"
  502.         Exit Sub
  503.     End If
  504.  
  505.     attachments = MailAttachments    'Copy attachment list to temp string before parsing
  506.     For contno = 0 To AttachmentCount
  507.         partno = contno + 1
  508.         If contno = 0 Then
  509.             filename = tmpFilename
  510.         Else
  511.             If OldMail then
  512.                 partno = 1
  513.                 oldcontents(0) = contents(contno)
  514.                 EMPSendMsgHeader sendresponse, badenvelopes(), mroOptions, _
  515.                                  MailSubject, RealName, notime, notime, _
  516.                                  InReplyTo, envelopes(), oldcontents(), _
  517.                                  MailCount + 1, "", forward
  518.             End If
  519.             If ExtractMailDestination(attachments, filename, rname, RecipientType) Then
  520.                 SplitPath rname, path, sname
  521.             End If
  522.         End If
  523.         ' Find out length of the message/file
  524.         SourceFileLen = FileLen(filename)
  525.         If SourceFileLen <= 0 Then
  526.             LogResult id+" : SendMail Failed : Can't upload file"
  527.             Exit Sub
  528.         End If
  529.  
  530.         ' Send the file
  531.         BytesToRead = SourceFileLen
  532.         SourceFileNum = FreeFile()
  533.         Open filename for Binary Access Read Shared as #SourceFileNum
  534.         SourceFileAt = 1        'read point
  535.  
  536.         TheData = String$(BlockSize, " ")
  537.         nState = HMI_STATE_FIRST%
  538.         Terminal.TransferStatus True, sname, 0, SourceFileLen
  539.  
  540.         ' Operate on blocks of BlockSize at a time
  541.         Do While BytesToRead > BlockSize
  542.             Get #SourceFileNum, SourceFileAt, TheData
  543.             i = EMPSendMsgContents(nState, partno, MailSubject, sname, contents(contno).nType, TheData)
  544.             BytesToRead = BytesToRead - BlockSize
  545.             SourceFileAt = SourceFileAt + BlockSize
  546.             nState = HMI_STATE_NEXT%
  547.             Terminal.TransferStatus True, sname, SourceFileAt-1, SourceFileLen
  548.         Loop
  549.  
  550.         ' Now do the last block of less than BlockSize
  551.         If BytesToRead > 0 then
  552.             TheData = String$(BytesToRead, " ")
  553.             Get #SourceFileNum, SourceFileAt, TheData
  554.             i = EMPSendMsgContents(nState, partno, MailSubject, sname, contents(contno).nType, TheData)
  555.         End If
  556.         Terminal.TransferStatus True, sname, SourceFileLen, SourceFileLen
  557.         i = EMPSendMsgContents(HMI_STATE_NEXT%, partno, MailSubject, sname, contents(contno).nType, "")
  558.         Close #SourceFileNum
  559.         Terminal.TransferStatus
  560.  
  561.         If OldMail and contno=0 then
  562.             ' Check it succeeded
  563.             EMPGetConfirmation confirm
  564.             If confirm.lpMsgID <> "" Then
  565.                 ReportSuccess id & " : Posted Mail " & MailSubject & " VA:"  & Session.Service & ":mail#<" & confirm.lpMsgID & ">"
  566.                 MailSent = True
  567.             End If
  568.         End If
  569.     Next
  570.  
  571.     If not OldMail then
  572.         ' Check it succeeded
  573.         EMPGetConfirmation confirm
  574.         If confirm.lpMsgID <> "" Then
  575.             ReportSuccess id & " : Posted Mail " & MailSubject & " VA:"  & Session.Service & ":mail#<" & confirm.lpMsgID & ">"
  576.             MailSent = True
  577.         End If
  578.     End If
  579.  
  580.     If (MailFlags And fDONTCOPY)=0 Then
  581.         ' Write message back to yourself
  582.         header = "Date: " + MakeDateString(confirm.wtTimeSent.tsTime) + TimeZone(confirm.wtTimeSent.tzZone) + Chr$(10)
  583.         If PersonalAddress="" Then
  584.             header = header + "From: " + RealName + " [" + Session.LoginName + "]" + Chr$(10)
  585.         Else
  586.             header = header + "From: " + RealName + " [" + PersonalAddress + "]" + Chr$(10)
  587.         End If
  588.         header = header + "Subject: " + MailSubject + Chr$(10)
  589.         header = header + "Message-Id: <" & confirm.lpMsgID & ">" + Chr$(10)
  590.         If InReplyTo<>"" Then
  591.             header = header + "In-Reply-To: <" & InReplyTo & ">" + Chr$(10)
  592.         End If
  593.         header = header + "Content-Type: " & GetMailType(contents(0).nType) & Chr$(10)
  594.  
  595.         LastRecipientType = -1
  596.         For i = 0 To MailCount
  597.             If ExtractMailDestination(addresses, address, rname, RecipientType) Then
  598.                 If Mid$(address, 1, 9)="internet:" Then address = Mid$(user, 10)
  599.                 Select Case RecipientType
  600.                 Case EMP_PRIMARY_RECIPIENT%
  601.                     If LastRecipientType<>RecipientType Then header = header + "To:"
  602.                 Case EMP_COPY_RECIPIENT%
  603.                     If LastRecipientType<>RecipientType Then header = header + "Cc:"
  604.                 Case Else
  605.                     If LastRecipientType<>RecipientType Then header = header + "Bcc: "
  606.                 End Select
  607.                 header = header + " " + rname + " [" + address + "]" + Chr$(10)
  608.             End If
  609.         Next
  610.         For i = 1 To badcount
  611.             user = ParseString(badaddresses, Chr$(10))
  612.             If Mid$(user, 1, 9)="internet:" Then user = Mid$(user, 10)
  613.             header = header + "X-BadAddress: " + user + Chr$(10)
  614.         Next
  615.         footer = ""
  616.         For i = 1 To AttachmentCount
  617.             If ExtractMailDestination(MailAttachments, address, rname, RecipientType) Then
  618.                 footer = footer + Chr$(10) + "[Attachment " + FileUrl(rname) + " sent]"
  619.             End If
  620.         Next
  621.  
  622.         ' Create temp file, and put message in it
  623.         filename = UniqueFilename$()
  624.         On Error Goto MailTo_error
  625.         Open filename For Output Access Write Shared As #1
  626.         Print #1, "#pragma ciscontrol=yes;deleteexisting=no"
  627.         Print #1, "Memo #1 (" & Len(header) + SourceFileLen + Len(footer) & ")"
  628.         Print #1, header
  629.         Close #1
  630.         AddToFile filename, tmpFilename
  631.         Open filename For Append Access Read Write Shared As #1
  632.         Print #1, footer
  633. MailTo_error:
  634.         Close #1
  635.         result = QueueFile(Session.Service, filename, IM_DELETE)
  636.     End If
  637.     If (MailFlags And fBINARY)=0 Then DeleteFile tmpFilename
  638.     Exit Sub
  639.  
  640. SendMail_error:
  641.     ' Report error to user
  642.     LogResult id+" : SendMail Failed : Error :" & FullErrorMessage
  643.     Terminal.TransferStatus
  644. End Sub
  645.  
  646. Function ListUsers(recipient() As EMPNAMEANDADDR, erecipient() As EMPNAMEANDADDR) As String
  647.     Dim u As String, n As String, i As Integer
  648.  
  649.     On Error Resume Next
  650.     For i = 0 To Ubound(recipient)
  651.         If recipient(i).lpAddr <> "" Then
  652.             ReplaceAllInString recipient(i).lpName, ";", " "
  653.             If UCase$(Mid$(recipient(i).lpAddr, 1, 9))="INTERNET:" Then
  654.                 u = Mid$(recipient(i).lpAddr, 10)
  655.             Else
  656.                 If Mid$(recipient(i).lpAddr, 1, 1)="[" Then
  657.                     u = recipient(i).lpName+" "+recipient(i).lpAddr
  658.                 Else
  659.                     u = recipient(i).lpName+" ["+recipient(i).lpAddr+"]"
  660.                 End If
  661.             End If
  662.             If n="" Then
  663.                 n = u
  664.             Else
  665.                 n = n + Chr$(10) + " " + u
  666.             End If
  667.         End If
  668.     Next
  669.     For i = 0 To Ubound(erecipient)
  670.         If erecipient(i).lpAddr <> "" Then
  671.             ReplaceAllInString erecipient(i).lpName, ";", " "
  672.             If UCase$(Mid$(erecipient(i).lpAddr, 1, 9))="INTERNET:" Then
  673.                 u = Mid$(erecipient(i).lpAddr, 10)
  674.             Else
  675.                 If Mid$(erecipient(i).lpAddr, 1, 1)="[" Then
  676.                     u = erecipient(i).lpName+" "+erecipient(i).lpAddr
  677.                 Else
  678.                     u = erecipient(i).lpName+" ["+erecipient(i).lpAddr+"]"
  679.                 End If
  680.             End If
  681.             If n="" Then
  682.                 n = u
  683.             Else
  684.                 n = n + Chr$(10) + " " + u
  685.             End If
  686.         End If
  687.     Next
  688.     On Error Goto 0
  689.     n = Trim$(n)
  690.     If n <> "" And Right$(n, 1)=Chr$(10) Then
  691.         ListUsers = Mid$(n, 1, Len(n)-1)
  692.     Else
  693.         ListUsers = Trim$(n)
  694.     End If
  695. End Function
  696.  
  697. Function ExtractX400Name(xaddr As String) As String
  698.     Dim i As Integer, realname As String
  699.  
  700.     i = InStr(xaddr, "g=", 1)
  701.     If i<>0 Then realname = Mid$(xaddr, i+2)
  702.     i = InStr(realname, ")")
  703.     If i<>0 Then realname = Mid$(realname, 1, i-1)
  704.     i = InStr(xaddr, "s=", 1)
  705.     If i<>0 Then realname = realname + " " + Mid$(xaddr, i+2)
  706.     i = InStr(realname, ";")
  707.     If i<>0 Then realname = Mid$(realname, 1, i-1)
  708.     If realname="" Then realname = "X400 Gateway"
  709.  
  710.     ExtractX400Name = realname
  711. End Function
  712.  
  713. 'T:FetchMail (subroutine) (CompuServe)
  714. Sub FetchMail(id As String)
  715.     Dim hdr As EMPHEADER, precipient() As EMPNAMEANDADDR, b As Boolean
  716.     Dim crecipient() As EMPNAMEANDADDR, content() As EMPCONTENTS
  717.     Dim msgno As Integer, i As Integer, messagefilename As String
  718.     Dim msgtext As String, count As Long, binfname As String
  719.     Dim l As Long, lhead As long, subject As String, obinfname As String
  720.     Dim msgheader As String, searchterm(0 to 0) As EMPSEARCHTERM
  721.     Dim msg() As EMPMSGSUMMARY, userid As String, szStatus() As EMPMSGSTATUS
  722.     Dim lpMsgs() As EMPMSGDISPOSE, disp As EMPDISPOSERESPONSE
  723.     Dim crs As Integer, tmp As String, s As String, realname As String
  724.     Dim contentno As Integer, mailnum As Integer, from As String
  725.     Dim reciplist As EMPRECIPIENTSLIST, eprecipient() As EMPNAMEANDADDR
  726.     Dim ecrecipient() As EMPNAMEANDADDR, deletemail As Boolean
  727.     Dim firstblock As Boolean, badchars As String, lpCount As Integer
  728.     Dim cleanmail As Boolean
  729.  
  730.     deletemail = ReadIni$("Service "+Session.Service, "Delete Mail", Session.IniFilename)="YES"
  731.     cleanmail = ReadIni$("Service "+Session.Service, "Clean Mail", Session.IniFilename)="YES"
  732.  
  733.     ' The Content() doesn't seem to be working
  734.  
  735.     Terminal.Print "Checking for new mail..." + Basic.Eoln$
  736.  
  737.     ' Go MAIL
  738.     If Not HMIGotoMail() Then
  739.         LogResult "Collect Mail : Failed : Mail is unavailable : " + FullErrorMessage
  740.         Exit Sub
  741.     End If
  742.     If EMPconfig.wUnreadMsgs=1 Then
  743.         Terminal.Print "There is 1 unread mail message." + Basic.Eoln$
  744.     Else
  745.         Terminal.Print "There are " & LTrim(Str(EMPconfig.wUnreadMsgs)) & " unread mail messages." + Basic.Eoln$
  746.     End If
  747.  
  748.     ' Search for any mail
  749.     searchterm(0).nType = EMP_AFTERDATE%
  750.     searchterm(0).lpPattern = "800101:"
  751.     msgno = 0
  752.  
  753.     ' Start downloading
  754.     On Error Goto ReadMail_error
  755.     messagefilename = UniqueFileName$()
  756.     Capture CAPTURE_ON, messagefilename
  757.  
  758.     Do
  759.         EMPSearchMsg msg(), 10, msgno, EMP_SRC_TOTAL_SIZE%, searchterm()
  760.  
  761.         If UBound(msg)>=0 Then
  762.             ReDim lpMsgs(0 To UBound(msg))
  763.             For mailnum = 0 To UBound(msg)
  764.                 msgno = msg(mailnum).wMsgNo
  765.                 If msgno>0 Then
  766.                     count = count + 1
  767.                     If count=1 Then Terminal.CaptureStatus CAPTURE_ON
  768.                     Terminal.CaptureStatus count
  769.  
  770.                     EMPGetMsgHeader hdr, precipient(), crecipient(), content(), msgno, &HFF
  771.  
  772.                     ' Extended recipient list
  773.                     If (hdr.wComponents And EMP_MHC_EXTENDED_ENVELOPES%)<>0 Then
  774.                         EMPReadRecipients reciplist, eprecipient(), ecrecipient(), msgno, 1, 50, 1, 50
  775.                     End If
  776.                     For contentno = 0 To UBound(content)
  777.                         ' Check for empty fields
  778.                         subject = msg(mailnum).lpSubject
  779.                         If subject="" Then subject = "==== No Subject ===="
  780.                         If Mid(hdr.lpOriginatorAddr, 1, 1)="[" Then
  781.                             userid = hdr.lpOriginatorAddr
  782.                         Else
  783.                             userid = "["+hdr.lpOriginatorAddr+"]"
  784.                         End If
  785.                         from = LCase$(hdr.lpOriginatorAddr)
  786.  
  787.                         ' Get realname out of X400 mess
  788.                         If Left$(msg(mailnum).lpOriginatorName, 5)="X400:" Then
  789.                             realname = ExtractX400Name(msg(mailnum).lpOriginatorName)
  790.                         Else
  791.                             realname = msg(mailnum).lpOriginatorName
  792.                         End If
  793.                         ReplaceAllInString realname, ";", " "
  794.  
  795.                         ' If userid=realname then only use one of them
  796.                         If "["+realname+"]"=userid Then
  797.                             userid = ""
  798.                         End If
  799.  
  800.                         ' Tell the user what's happening
  801.                         Terminal.Print realname & " " & _
  802.                                        MakeDateString(hdr.tsDate) & _
  803.                                        TimeZone(EMPconfig.wtCurrentTime.tzZone) & " " & subject
  804.                         If UBound(content)>0 Then Terminal.Print ", Part" & Str(contentno+1) & " of" & Str(UBound(content)+1) & "."
  805.                         Terminal.Print Basic.Eoln$
  806.  
  807.                         If content(contentno).nType=EMP_TEXT% Or _
  808.                            content(contentno).nType=EMP_TEXT_FILE% Or _
  809.                            content(contentno).nType=EMP_TEXT_OBJECT% Then
  810.                             ' Generate the message header
  811.                             msgheader = "Date: " & MakeDateString(hdr.tsDate) & _
  812.                                                    TimeZone(EMPconfig.wtCurrentTime.tzZone) & Chr$(10) & _
  813.                                         "From: " & realname & " " & userid & Chr$(10) & _
  814.                                         "Subject: " & subject & Chr$(10) & _
  815.                                         "Message-Id: <" & hdr.lpMsgID & ">" & Chr$(10) & _
  816.                                         "Content-Type: " & GetMailType(content(contentno).nType) & Chr$(10)
  817.                             If hdr.lpInReplyTo>"" Then msgheader = msgheader + "In-Reply-To: <" + hdr.lpInReplyTo + ">" + Chr$(10)
  818.                             msgheader = msgheader + "To: " + ListUsers(precipient(), eprecipient()) + Chr$(10)
  819.                             tmp = ListUsers(crecipient(), ecrecipient())
  820.                             If tmp<>"" Then msgheader = msgheader + "Cc: " + tmp + Chr$(10)
  821.                             If hdr.moOptions.cImportance = 0 Then msgheader = msgheader + "Priority: Low" + Chr$(10)
  822.                             If hdr.moOptions.cImportance = 1 Then msgheader = msgheader + "Priority: Normal" + Chr$(10)
  823.                             If hdr.moOptions.cImportance = 2 Then msgheader = msgheader + "Priority: Urgent" + Chr$(10)
  824.  
  825.                             ' Get first block so we can check it's not CIS's
  826.                             ' dreadful automatic MIME decode junk
  827.                             l = 1
  828.                             firstblock = True
  829.                             nState = HMI_STATE_FIRST%
  830.                             Terminal.TransferStatus False, "Mail Message", 0, content(contentno).dwSize
  831.                             msgtext = EMPReceiveMsgContents(HMI_STATE_FIRST%, _
  832.                                          msgno, content(contentno).cNumber, l, _
  833.                                          BlockSize, content(contentno).nType, lpCount)
  834.  
  835.                             ' Do we need to use our own header
  836.                             If Mid$(from, 1, 9)="internet:" And _
  837.                                from<>"internet:postmaster@compuserve.com" And _
  838.                                Left$(msgtext, 7)="Sender:" Then
  839.                                 msgheader = ""
  840.                             ElseIf cleanmail And (Left$(msgtext, 9)="Contents:") Then
  841.                                 i = InStr(msgtext, "===== Begin Part 1 =====")
  842.                                 If (i<>0) And (i<150) Then
  843.                                     i = InStr(i, msgtext, Chr$(13)+Chr$(10)+Chr$(13)+Chr$(10))
  844.                                     If (i<>0) And (i<250) Then msgtext = Mid$(msgtext, i+4)
  845.                                 End If
  846.                             End If
  847.  
  848.                             ' Translate control characters?
  849.                             from = LCase$(hdr.lpOriginatorAddr)
  850.                             If Mid$(from, 1, 9)="internet:" Then
  851.                                 CaptureText Chr$(10) & "#pragma ciscontrol=no;deleteexisting=no"
  852.                             Else
  853.                                 CaptureText Chr$(10) & "#pragma ciscontrol=yes;deleteexisting=no"
  854.                             End If
  855.  
  856.                             ' Write the header + size
  857.                             lhead = content(contentno).dwSize + Len(msgheader) + 1
  858.                             CaptureText Chr$(10) & "Memo #" & LTrim(Str(msgno)) & " (" & lhead & ")" & Chr$(10)
  859.                             If msgheader<>"" Then CaptureText msgheader & Chr$(10)
  860.  
  861.                             ' Get the body text and write it out
  862.                             crs = 0
  863.                             Do
  864.                                 If Not firstblock Then
  865.                                     msgtext = ""
  866.                                     msgtext = EMPReceiveMsgContents(HMI_STATE_NEXT%, _
  867.                                                   msgno, content(contentno).cNumber, _
  868.                                                   l, BlockSize, _
  869.                                                   content(contentno).nType, lpCount)
  870.                                 End If
  871.                                 firstblock = False
  872.                                 msgtext = Left$(msgtext, lpCount)
  873.                                 l = l + Len(msgtext)
  874.                                 Terminal.TransferStatus False, "Mail Message", l-1, content(contentno).dwSize
  875.                                 crs = crs + ItemCount(msgtext, Chr$(13))
  876.                                 CaptureText msgtext
  877.                             Loop Until Len(msgtext)=0
  878.                             If l < content(contentno).dwSize Then
  879.                                 CaptureText String$(content(contentno).dwSize - l, " ")
  880.                             End If
  881.                             CaptureLine String$(crs, " ")
  882.                             Terminal.TransferStatus
  883.                         Else
  884.                             ' Try to figure out the filename
  885.                             If content(contentno).lpName="" Then
  886.                                 binfname = subject
  887.                             Else
  888.                                 binfname = Filename$(content(contentno).lpName)
  889.                             End If
  890.                             obinfname = binfname
  891.                             LogResult "Downloading binary mail:" & binfname
  892.  
  893.                             ' Support long file names in 32-bit version
  894.                             If Basic.OS = ebWin32 Then
  895.                                 badchars = "\/[]:;'""{}<>,+=*?"+Chr$(13)
  896.                             Else
  897.                                 badchars = " \/[]:;'""{}<>,+=*?"+Chr$(13)
  898.                             End If
  899.  
  900.                             ' Figure out mail filename - truncate at invalid character.
  901.                             binfname = Trim$(binfname)
  902.                             For i=1 to Len(binfname)
  903.                                 If InStr(badchars, Mid$(binfname, i, 1)) Then
  904.                                     binfname = Mid$(binfname, 1, i-1)
  905.                                     Exit For
  906.                                 End If
  907.                             Next
  908.  
  909.                             ' Make sure that whatever I have is a dos legal filename
  910.                             If InStr(binfname, ".")<>0 Then
  911.                                 If Basic.OS <> ebWin32 Then
  912.                                     binfname = Left$(Left$(binfname,InStr(binfname, ".")-1),8) & "." & Mid$(binfname, InStr(binfname, ".")+1, 3)
  913.                                 End If
  914.                                 i=InStr(".", binfname)+1
  915.                                 i=InStr(".", binfname)
  916.                                 If i<>0 Then
  917.                                     binfname = Mid$(binfname, 1, i-1)
  918.                                 End If
  919.                             ElseIf Basic.OS <> ebWin32 Then
  920.                                 binfname = Left$(binfname,8)
  921.                             End If
  922.  
  923.                             If UCase$(binfname)="RE" Then binfname = ""
  924.  
  925.                             If binfname <> obinfname Then LogResult "Name truncated to:" & binfname
  926.                             obinfname = binfname
  927.  
  928. ReadMail_TryAgain:
  929.                             ' Was it a filename?
  930.                             If FileExists(DownloadDir+binfname) Or binfname="" Then
  931.                                 ' Generate a filename
  932.                                 i = 1
  933.                                 Do
  934.                                     binfname = "mail"+Ltrim(Str(i))+".bin"
  935.                                     i = i+1
  936.                                 Loop While FileExists(DownloadDir+binfname)
  937.                             End If
  938.                             If binfname <> obinfname Then LogResult "File exists - renamed to:" & binfname
  939.  
  940.                             Open DownloadDir+binfname For Binary Access Write Shared As #1
  941.                             l = 1
  942.                             Terminal.TransferStatus False, binfname, 0, content(contentno).dwSize
  943.                             nState = HMI_STATE_FIRST%
  944.                             Do
  945.                                 msgtext = ""  ' needed to stop out of string space error
  946.                                 msgtext = EMPReceiveMsgContents(nState, msgno, _
  947.                                            content(contentno).cNumber, l, _
  948.                                            BlockSize, content(contentno).nType, _
  949.                                            lpCount)
  950.                                 nState = HMI_STATE_NEXT%
  951.  
  952.                                 If lpCount <= 0 Then Exit Do
  953.                                 Put #1, , msgtext
  954.                                 l = l + Len(msgtext)
  955.                                 Terminal.TransferStatus False, binfname, l-1, content(contentno).dwSize
  956.                             Loop
  957.                             Terminal.TransferStatus
  958.  
  959.                             ' Write a message pointing to the file
  960.                             msgheader = "Date: " & MakeDateString(hdr.tsDate) & Chr$(10) & _
  961.                                         "From: " & realname & " " & userid & Chr$(10) & _
  962.                                         "Subject: " & subject & Chr$(10) & _
  963.                                         "Message-Id: <" & hdr.lpMsgID & ">" & Chr$(10) & _
  964.                                         "Content-Type: " & GetMailType(content(contentno).nType) & Chr$(10)
  965.                             If hdr.lpInReplyTo>"" Then msgheader = msgheader + "In-Reply-To: <" + hdr.lpInReplyTo + ">" + Chr$(10)
  966.                             msgheader = msgheader + "To: " + ListUsers(precipient(), eprecipient()) + Chr$(10)
  967.                             tmp = ListUsers(crecipient(), ecrecipient())
  968.                             If tmp<>"" Then msgheader = msgheader + "Cc: " + tmp + Chr$(10)
  969.                             If hdr.moOptions.cImportance = 0 Then msgheader = msgheader + "Priority: Low" + Chr$(10)
  970.                             If hdr.moOptions.cImportance = 1 Then msgheader = msgheader + "Priority: Normal" + Chr$(10)
  971.                             If hdr.moOptions.cImportance = 2 Then msgheader = msgheader + "Priority: Urgent" + Chr$(10)
  972.                             msgheader = msgheader + Chr$(10) + "*** File Message ***" + Chr$(10) + Chr$(10)
  973.                             msgheader = msgheader + "The size of the file is" & Str(content(contentno).dwSize) & " bytes." + Chr$(10)
  974.                             msgheader = msgheader + "The file will be stored in " & FileUrl(DownloadDir + binfname) + Chr$(10) + Chr$(10)
  975.                             If content(contentno).lpSubject<>"" Then
  976.                                 msgheader = msgheader + "Additional Information:" + Chr$(10)
  977.                                 msgheader = msgheader + content(contentno).lpSubject + Chr$(10)
  978.                             End If
  979.  
  980.                             ' Write the pseudo msg
  981.                             CaptureText Chr$(10) & "#pragma ciscontrol=yes;deleteexisting=no"
  982.                             CaptureText Chr$(10) & "Memo #" & LTrim(Str(msgno)) & " (" & Len(msgheader) & ")" & Chr$(10)
  983.                             CaptureText msgheader
  984.  
  985.                             Close #1
  986.                         End If
  987.                     Next
  988.  
  989.                     ' Delete the mail we just got
  990.                     If deletemail Then
  991.                         lpMsgs(mailnum).nDisposition = EMP_DELETE_REGARDLESS%
  992.                         lpMsgs(mailnum).nMsgNo = msgno
  993.                     End If
  994.                 End If
  995.             Next
  996.             If deletemail Then EMPSendMsgDisposition disp, szStatus(), lpMsgs()
  997.         Else
  998.             msgno = 0
  999.         End If
  1000.     Loop Until msgno=0
  1001.  
  1002. ReadMail_error:
  1003.     If Err=53 Then
  1004.         binfname = ""
  1005.         Goto ReadMail_TryAgain
  1006.     ElseIf Err<>9 Then
  1007.         LogResult "Error in FetchMail : " + FullErrorMessage()
  1008.     End If
  1009.     On Error Goto 0
  1010.     Capture CAPTURE_OFF
  1011.     Terminal.CaptureStatus CAPTURE_OFF
  1012.  
  1013.     ' Import the mail
  1014.     If count > 0 Then
  1015.         b = QueueFile(Session.Service, messagefilename, IM_DELETE)
  1016.         ReportSuccess id & " :" & Str$(count) & " mail messages have been collected"
  1017.     Else
  1018.         DeleteFile messagefilename
  1019.         ReportSuccess id & " : There was no mail to collect"
  1020.     End If
  1021. End Sub
  1022.  
  1023. 'T:ExternalMailAddress (subroutine) (CompuServe)
  1024. Function ExternalMailAddress(s As String)
  1025.     Dim p As Integer, q As Integer
  1026.  
  1027.     p = InStr(s, ":")
  1028.     q = InStr(s, " ")
  1029.     If p>0 And p<q Then
  1030.         ExternalMailAddress = True
  1031.     ElseIf OldMail And InStr(s, "@") Then
  1032.         ExternalMailAddress = True
  1033.     Else
  1034.         ExternalMailAddress = False
  1035.     End If
  1036. End Function
  1037.  
  1038. 'T:AttachFile (subroutine) (CompuServe)
  1039. Sub AttachFile(id As String, filename As String, person As String, _
  1040.                eraseafter As String, codetype As String)
  1041.     Dim user As String, externalusers As String, localusers As String
  1042.     Dim cisfilename As String, fname As String, sent As String
  1043.     Dim i As Integer, maxlen As Integer, inBracket As Boolean
  1044.     Dim ch As String
  1045.  
  1046.     sent = person
  1047.     cisfilename = FileName$(filename)
  1048.     maxlen = Len(person)
  1049.     For i=1 To maxlen
  1050.         ch = Mid$(person, i, 1)
  1051.         If InBracket And ch=")" Then
  1052.             InBracket = False
  1053.             user = user + ch
  1054.         ElseIf InBracket=False And ch="(" Then
  1055.             InBracket = True
  1056.             user = user + ch
  1057.         ElseIf InBracket=False And ch=";" Then
  1058.             If ExternalMailAddress(user) Then
  1059.                 externalusers = externalusers + Chr$(10) + user
  1060.             Else
  1061.                 localusers = localusers + Chr$(10) + user
  1062.             End If
  1063.             user = ""
  1064.         Else
  1065.             user = user + ch
  1066.         End If
  1067.     Next
  1068.     If user<>"" Then
  1069.         If ExternalMailAddress(user) Then
  1070.             externalusers = externalusers + Chr$(10) + user
  1071.         Else
  1072.             localusers = localusers + Chr$(10) + user
  1073.         End If
  1074.     End If
  1075.  
  1076.     If localusers > "" Then
  1077.         localusers = Mid$(localusers, 2)    'Take off leading '\n'
  1078.  
  1079.         MailTo "Attachment", ParseString(localusers, Chr$(10)), fBINARY+fDONTCOPY, cisfilename, filename
  1080.         While localusers<>""
  1081.             MailCC ParseString(localusers, Chr$(10))
  1082.         Wend
  1083.         SendMail "Attachment"
  1084.     End If
  1085.     If externalusers > "" Then
  1086.         externalusers = Mid$(externalusers, 2)  'Take off leading '\n'
  1087.         fname = Session.ServicePath + "cis.bin"
  1088.         FileEncode filename, fname, CODE_UUENCODE
  1089.  
  1090.         MailTo "Attachment", ParseString(externalusers, Chr$(10)), fDONTCOPY, cisfilename, fname
  1091.         While externalusers<>""
  1092.             MailCC ParseString(externalusers, Chr$(10))
  1093.         Wend
  1094.         SendMail "Attachment"
  1095.         DeleteFile fname
  1096.     End If
  1097.     If MailSent Then ReportSuccess id & " : " & filename & " was sent to " & sent
  1098. End Sub
  1099.  
  1100.