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

  1. 'T:HMIFORUM.EBS for CompuServe
  2. ' VA 4.52 release
  3. ' 20.11.97 SH  - included Taz' additions of improved Actions/Informations
  4. '                               (waiting messages listed etc.)
  5.  
  6. Declare Function ParseString(args As String, delim As String) As String
  7. Declare Function QueueFile(service As String, sfilename As String, queueflags As Long) As Boolean
  8. Declare Function StartMessageDownload(id As String, forum As String, sections As String, markunread As Boolean) As Integer
  9. Declare Sub SearchMessages(searchtype As Integer, searchstring As String, bodies As Boolean, rootsonly As Boolean, unreadonly As Boolean, lastdays As String)
  10. Declare Sub ReportSuccess(msg As String)
  11. Declare Function FullErrorMessage() As String
  12. Declare Sub ReadNumber(id As String, forum As String, number As String)
  13. Declare Sub FetchThread(id As String, forum As String, number As String)
  14. Declare Sub LogResult(result As String)
  15. Declare Function UniqueFileName$()
  16. Declare Sub AsciiListHeldMessages(id As String, forum As String, sections As String)
  17. Declare Function ParseSectionList(ByVal sect As String, ByVal validsects As Long, _
  18.                           ByRef count As Integer) As Long
  19. Declare Sub SaveMessage(hdr As FAPMSGHEADER, body As String)
  20. Declare Function MakeDateString(s As HMITIMESTAMP) As String
  21. Declare Sub StartCapturing(pseudoforum As String, title As String, formatted As Boolean)
  22. Declare Sub FinishCapturing
  23. Declare Function SectionNumber(ByVal section As String)
  24. Declare Sub FinishMessageDownload(id As String)
  25. Declare Function SysOpGotoForum(byval forum as String) as Integer
  26. Declare sub LogSysOpConfig(byval forum as String)
  27.  
  28. Const BlockSize = 2048
  29.  
  30. Const IM_DELETE = 2048        ' Delete scratchpad file afterwards?
  31. Const IM_MARKUNREAD = 131072
  32.  
  33. Const fRECEIPT = 1
  34. Const fPRIVATE = 2
  35. Const fNOFORMAT = 4
  36.  
  37. Public InAscii As Boolean
  38. Public WorkingPath As String    'added to speed up Fetch stuff online
  39. Public WhereAmI As String        'name of last forum/page etc
  40. Public Sysop As Boolean            'are we a sysop?
  41. Public Nisa As Boolean          'do we need to work round NISA "features" ?
  42. Public SetHighMessage As Boolean'True if you want a 'high;l' when leaving forum
  43.  
  44. Public MailName As String
  45. Public currentCAP As Integer
  46. Public FAPconfig As FAPCONFIG
  47. Public SectionMsgIds(32) As Integer, SectionLibIds(32) As Integer
  48. Public szMsgSection() As FAPSECTIONENTRY, szLibSection() As FAPSECTIONENTRY
  49. Public nummessages As Integer
  50. Public CurrentForum As String
  51. Public LocalHMN As Boolean
  52.  
  53. Dim LastDownMessages As String, capturefilename As String
  54. Dim messagefilename As String
  55. Dim sectionvector As Long, filterVector As Long
  56. Const ALL_HEADER_FIELDS% = &H1FF3
  57. Const FAP_FDC_FILE_TYPE% = &H4
  58. Const FAP_FDC_FILE_SIZE% = &H8
  59. Const FAP_FDC_ABSTRACT% = &H100
  60.  
  61. Const FAP_SFH_FILENAME% = 0
  62. Const FAP_SFH_USER_ID% = FAP_SFH_FILENAME + 1
  63. Const FAP_SFH_KEYWORD% = FAP_SFH_USER_ID + 1
  64. Const FAP_SFH_ACCESS_COUNT% = FAP_SFH_KEYWORD + 1
  65. Const FAP_SFH_DATE_RANGE% = FAP_SFH_ACCESS_COUNT + 1
  66. Const FAP_SFH_LAST_ACCESS_RANGE% = FAP_SFH_DATE_RANGE + 1
  67. Const FAP_SFH_FILE_ABSTRACT% = FAP_SFH_LAST_ACCESS_RANGE + 1
  68. Const FAP_SFH_FILE_BODY% = FAP_SFH_FILE_ABSTRACT + 1
  69. Const FAP_SFH_MATCH_NON_PUBLIC_ONLY% = FAP_SFH_FILE_BODY + 1
  70. Const FAP_SFH_SIZE_RANGE% = FAP_SFH_MATCH_NON_PUBLIC_ONLY + 1
  71. Const FAP_SFH_TITLE% = FAP_SFH_SIZE_RANGE + 1
  72.  
  73. Const DAP_AL_VOLATILE = &H02
  74. Const DAP_AP_SESSION_ONLY = &H01
  75. Const DAP_AP_VOLATILE = &H02
  76. Const DAP_AP_EX_HAVE_TITLE% = &H0100
  77. Const DAP_AP_HAVE_HEADER% = &H04
  78. Const DAP_AP_HAVE_TRAILER% = &H08
  79. Const HMI_DATA_SIZE% = 1024
  80. Const HMI_STATE_FIRST% = 0
  81. Const HMI_STATE_NEXT% = HMI_STATE_FIRST + 1
  82. Const FAP_USF_HIGH_MSG% = &H2
  83. Const FAP_USF_NAME% = &H4
  84. Const FAP_USR_JOIN% = &H1
  85. Const FAP_USR_PERMANENT% = &H2
  86. Const FAP_WAITING_MSGS% = &H1
  87. Const FAP_NEW_BULLETINS% = &H2
  88. Const FAP_CONFERENCE_IN_PROGRESS% = &H4
  89. Const FAP_NOT_A_MEMBER% = &H8
  90. Const FAP_IS_SYSOP% = &H10        ' user is SYSOP in this Forum
  91. Const FAP_FREE_USER% = &H20
  92. Const FAP_LOCKED_OUT% = &H40
  93. Const FAP_TRANSACTION_BILLING% = &H80
  94. Const FAP_ALLOW_MULTIPLE_SEARCH% = &H100
  95. Const FAP_NISA_FORUM% = &H200
  96.  
  97. Const FAP_MSS_ALL_MSGS% = 0
  98. Const FAP_MSS_WAITING_MSGS% = FAP_MSS_ALL_MSGS + 1
  99. Const FAP_MSS_SUBJECT_TEXT% = FAP_MSS_WAITING_MSGS + 1
  100. Const FAP_MSS_ORIGINATOR_NAME% = FAP_MSS_SUBJECT_TEXT + 1
  101. Const FAP_MSS_RECIPIENT_NAME% = FAP_MSS_ORIGINATOR_NAME + 1
  102. Const FAP_MSS_MSGS_WITHOUT_REPLIES% = FAP_MSS_RECIPIENT_NAME + 1
  103. Const FAP_MSS_HELD_MSGS% = FAP_MSS_MSGS_WITHOUT_REPLIES + 1
  104. Const FAP_MSS_PRIVATE_MSGS% = FAP_MSS_HELD_MSGS + 1        ' to the user
  105. Const FAP_MSS_MSGS_WITHOUT_SYSOP_REPLIES% = FAP_MSS_PRIVATE_MSGS + 1
  106. Const FAP_MSS_MESSAGE_BODY% = FAP_MSS_MSGS_WITHOUT_SYSOP_REPLIES + 1
  107. Const FAP_MSS_POSTING_DATE_RANGE% = FAP_MSS_MESSAGE_BODY + 1
  108. Const FAP_MSS_EXPIRATION_DATE_RANGE% = FAP_MSS_POSTING_DATE_RANGE + 1
  109. Const FAP_MSS_MESSAGES_HAS_BEEN_READ% = FAP_MSS_EXPIRATION_DATE_RANGE + 1
  110.  
  111. Const FAP_NO_MESSAGE_READ% = &H1
  112. Const FAP_NO_MESSAGE_SEND% = &H2
  113. Const FAP_NO_LIBRARY_READ% = &H4
  114. Const FAP_NO_LIBRARY_SEND% = &H8
  115. Const FAP_NO_CONFERENCE% = &H10
  116. Const FAP_NO_PRIVATE_MSGS% = &H20
  117. Const FAP_NO_MEMBERSHIP% = &H80
  118. Const FAP_PRIVATE_FORUM% = &H100
  119. Const FAP_RTC_CONFIG_SUPPORTED% = &H200
  120. Const FAP_SEARCH_LIBRARY_ABSTRACTS% = &H400   ' Full text search of file abstrats allowed
  121. Const FAP_SEARCH_LIBRARY_FILES% = &H800              ' Search text file contents
  122. Const FAP_SEARCH_MESSAGE_BODIES% = &H1000     ' Searching message bodies allowed
  123. Const FAP_LIBRARY_ONLY_FORUM% = &H2000
  124.  
  125. Const FAP_PRIVATE_MESSAGE% = &H1
  126. Const FAP_EXTENDED_MESSAGE% = &H80
  127.  
  128. Const FAP_MC_THREAD_ID% = &H1000
  129. Const FAP_MC_THREADS% = &H8000
  130.  
  131. Const FAP_MSR_PSEUDO_ROOTS% = &H80
  132.  
  133. Sub SetHighMessageNumber()
  134.     Dim b As Integer
  135.  
  136.     ' Don't set HMN if HMI error
  137.     If Err = 1009 Then
  138.         Err = 0
  139.         SetHighMessage = False
  140.     End If
  141.  
  142.     If SetHighMessage Then
  143.         If currentCAP = CAP_FORUM Then
  144.             Terminal.Print "Updating the high message number to " & FAPconfig.dwNewestMsg & " in " & CurrentForum & Basic.Eoln$
  145.             b = FAPSetUserProfile(FAP_USR_PERMANENT%, FAP_USF_HIGH_MSG%, FAPconfig.dwNewestMsg, "")
  146.             WriteIni "High Message Number", WhereAmI, LTrim$(Str$(FAPconfig.dwNewestMsg)), Session.ServicePath+"hmn.ini"
  147.         End If
  148.         SetHighMessage = False
  149.     End If
  150. End Sub
  151.  
  152. 'T:CollectSections
  153. Sub CollectSections(forum As String)
  154.     Dim sctMsg As FAPSECTIONS, sctLib As FAPSECTIONS
  155.     Dim i As Integer
  156.     Dim sNam As String
  157.     Dim bMessages As Integer, bLibraries As Integer
  158.  
  159.     ' Initialise variables
  160.     For i = 0 To 32
  161.         SectionMsgIds(i) = -1
  162.         SectionLibIds(i) = -1
  163.     Next
  164.  
  165.     ' We must be a member
  166.     If FAPconfig.wAlerts And FAP_NOT_A_MEMBER% Then
  167.         Exit Sub
  168.     End If
  169.  
  170.     Terminal.Print "Collecting section information" + Basic.Eoln$
  171.     On Error Goto CollectMsgSections_error
  172.  
  173.     ' Get the msg section names for the forum from Compuserve
  174.     FAPReadMsgSections sctMsg, szMsgSection()
  175.     For i = 0 To UBound(szMsgSection)
  176.         sectionMsgIds(szMsgSection(i).cId) = i
  177.         ReplaceAnyInString szMsgSection(i).lpTitle, " /", "_"
  178.     Next
  179.     bMessages = True
  180. CollectMsgSections_resume:
  181.  
  182.     ' Get the lib section names for the forum from Compuserve
  183.     On Error Goto CollectLibSections_error
  184.     FAPReadLibSections sctLib, szLibSection()
  185.     For i = 0 To UBound(szLibSection)
  186.         sectionLibIds(szLibSection(i).cId) = i
  187.         ReplaceAnyInString szLibSection(i).lpTitle, " /", "_"
  188.     Next
  189.     bLibraries = True
  190.  
  191. CollectLibSections_resume:
  192.     On Error Goto 0
  193.     Err = 0
  194.  
  195.     ' Cope with ZNT:<forum>
  196.     If InStr(forum, ":")<>0 Then
  197.         sNam = Mid$(forum, InStr(forum, ":")+1, 8)+".nam"
  198.     Else
  199.         sNam = Mid$(forum, 1, 8)+".nam"
  200.     End If
  201.  
  202.     ' Create the .NAM file
  203.     DeleteFile Session.ServicePath+sNam
  204.     Capture CAPTURE_ON, Session.ServicePath+sNam
  205.     If InStr(forum, ":")<>0 Then
  206.         CaptureLine "#forum " + Mid$(forum, InStr(forum, ":")+1)
  207.     Else
  208.         CaptureLine "#forum " + forum
  209.     End If
  210.  
  211.     ' Write forum info
  212.     If (FAPconfig.wAlerts And FAP_IS_SYSOP%)<>0 Then CaptureLine "SYSOP"
  213.     If (FAPconfig.wAlerts And FAP_FREE_USER%)<>0 Then CaptureLine "Free Flag"
  214.     If (FAPconfig.wAlerts And FAP_NISA_FORUM%)<>0 Then CaptureLine "NISA Forum"
  215.     If (FAPconfig.wRestrictions And FAP_NO_PRIVATE_MSGS%)<>0 Then
  216.         CaptureLine "Private Messages not allowed"
  217.     Else
  218.         CaptureLine "Private Messages are allowed"
  219.     End If
  220.     On Error Resume Next
  221.  
  222.     ' Get the message section names for the forum from Compuserve
  223.     CaptureLine "Message Sections Available:"
  224.     If bMessages Then
  225.         For i = 0 To UBound(szMsgSection)
  226.             CaptureLine Str(szMsgSection(i).cId)+" "+szMsgSection(i).lpTitle
  227.         Next
  228.     End If
  229.  
  230.     ' Get the library section names for the forum from Compuserve
  231.     CaptureLine "Libraries Available:"
  232.     If bLibraries Then
  233.         For i = 0 To UBound(szLibSection)
  234.             CaptureLine Str(szLibSection(i).cId)+" "+szLibSection(i).lpTitle
  235.         Next
  236.     End If
  237.  
  238.     ' Clear up
  239.     Capture CAPTURE_OFF
  240.     On Error Goto 0
  241.     Exit Sub
  242. CollectMsgSections_error:
  243.     Resume CollectMsgSections_resume
  244. CollectLibSections_error:
  245.     Resume CollectLibSections_resume
  246. End Sub
  247.  
  248. ' Intelligently GO forum only
  249. Function HMIGotoForum(ByVal forum As String) As Boolean
  250.     Dim filename As String, myerror As String, i As Integer
  251.     Dim fname As String, preforum As String, tmp As String
  252.     Dim forumname as String
  253.  
  254.     ' Sort out any switch between ascii/hmi
  255.     If InAscii Then
  256.         ResetForum
  257.         InAscii = False
  258.     End If
  259.  
  260.     ' Mangle the forum name a bit
  261.     forum = ParseString(forum, "/")
  262.     fname = forum
  263.     If Instr(forum, ":")=0 Then
  264.         forum = "cis:"+forum
  265.     End If
  266.  
  267.     ' Use the lookup table to auto-convert menus to forums.
  268.     ' eg. 'PCPLUS' -> 'PCPFORUM'
  269.     preforum = forum
  270.     forum = LookupForum(preforum)
  271.  
  272.     ' If we're already here then do nothing
  273.     If StrComp(WhereAmI, fname, 1)<>0 And StrComp(WhereAmI, forum, 1)<>0 _
  274.        And StrComp(WhereAmI, preforum, 1)<>0 Then
  275.         SetHighMessageNumber
  276.         If StrComp(WhereAmI, "home:mail", 1)<>0 Then
  277.             If WhereAmI<>"" Then
  278.                 Terminal.Print "Leaving " & WhereAmI & Basic.Eoln$ & Basic.Eoln$
  279.             End If
  280.         End If
  281.         Terminal.Print Basic.Eoln$+"Go " & forum & Basic.Eoln$ & Basic.Eoln$
  282.         On Error Goto GoForum_error
  283.         HMIGotoForum = False
  284.         If Not DoHMIGotoPage(forum, -1, CAP_FORUM, False) Then
  285.             If currentCAP <> CAP_ERROR Then myerror = "Not a forum"
  286.             goto GoForum_error
  287.         End If
  288.  
  289.         HMIGetFAPConfig FAPconfig
  290.         Sysop = ((FAPconfig.wAlerts And FAP_IS_SYSOP%) <> 0)
  291.         Nisa = ((FAPconfig.wAlerts And FAP_NISA_FORUM%) <> 0)
  292.  
  293.         Terminal.Print "Welcome to " & FAPconfig.lpForumName & " Forum" & Basic.Eoln$
  294.         Terminal.Print "Hello, " & FAPconfig.lpUserName
  295.         If Sysop Then Terminal.Print " (Sysop)"
  296.         If (FAPconfig.wAlerts And FAP_FREE_USER%)<>0 Then Terminal.Print " (Free)"
  297.         Terminal.Print Basic.Eoln$
  298.         If Nisa Then Terminal.Print "This is a NISA forum" & Basic.Eoln$
  299.         If FAPconfig.tsLastAccess.cYear>0 Then
  300.             Terminal.Print "Last visit: " & MakeDateString(FAPconfig.tsLastAccess) & Basic.Eoln$
  301.         Else
  302.             Terminal.Print "Last visit: Never" & Basic.Eoln$
  303.         End If
  304.         Terminal.Print "Forum messages: " & FAPconfig.dwMsgNoBase & " to " & FAPconfig.dwNewestMsg & Basic.Eoln$
  305.         Terminal.Print "Last message you've read: " & FAPconfig.dwLastMsgRead & Basic.Eoln$
  306.  
  307.         If LocalHMN Then
  308.             If Instr(fname,":")=0 then
  309.                 tmp = "cis:"+fname
  310.             Else
  311.                 tmp=fname
  312.             End If
  313.             Terminal.Print "Using local HMN for " & tmp & ": "
  314.             tmp = ReadIni$("High Message Number", tmp, Session.ServicePath+"hmn.ini")
  315.             Terminal.Print tmp & Basic.Eoln$
  316.             If Val(tmp) > 0 And Val(tmp)<>FAPconfig.dwLastMsgRead Then
  317.                 b = FAPSetUserProfile(FAP_USR_PERMANENT%, FAP_USF_HIGH_MSG%, Val(tmp), "")
  318.                 HMIGetFAPConfig FAPconfig
  319.             End If
  320.         End If
  321.  
  322.         If FAPconfig.wAlerts And FAP_WAITING_MSGS% Then
  323.             Terminal.Print Basic.Eoln$ & "You have waiting message(s)" & Basic.Eoln$
  324.         End If
  325.         Terminal.Print Basic.Eoln$
  326.  
  327.         If FAPconfig.wAlerts And FAP_LOCKED_OUT% Then
  328.             myerror = "User locked out"
  329.             goto GoForum_error
  330.         End If
  331.         If FAPconfig.wAlerts And FAP_NEW_BULLETINS% Then
  332.             Terminal.Print "Collecting updated Newsflash" + Basic.Eoln$
  333.             RecordBulletins fname, True, False, False
  334.         End If
  335.         Terminal.Status "HMIGotoForum: "+fname
  336.         On Error Goto 0
  337.  
  338.         ' It all worked
  339.         If Instr(fname, ":")=0 Then
  340.             WhereAmI = "cis:"+fname
  341.         Else
  342.             WhereAmI = fname
  343.         End If
  344.  
  345.         CollectSections WhereAmI
  346.         If Sysop And Nisa Then
  347.             i = SysOpGotoForum(Mid$(fname, InStr(fname, ":")+1))
  348.         End If
  349.     End If
  350.  
  351.     LastFailure = ""
  352.     HMIGotoForum = True
  353.     Exit Function
  354.  
  355. GoForum_error:
  356.     On Error Goto 0
  357.     If myerror = "" Then myerror = FullErrorMessage
  358.     Terminal.Print "Error: " & myerror & Basic.Eoln$
  359.     LogResult "HMIGotoForum : "+forum+" : Failed Error : "+myerror
  360.     LastFailure = forum
  361.     SetHighMessage = False
  362.  
  363.     ' If it was a PTE and HMI packet size was 2k then reduce to 1k and inform
  364.     ' the user.
  365.     If InStr(myerror, "1285:Protocol transport error", 1)<>0 And _
  366.        ReadIni$(Session.IniSection, "HMI Packet Size", Session.IniFilename)="2048" Then
  367.         WriteIni Session.IniSection, "HMI Packet Size", "1024", Session.IniFilename
  368.         LogResult "_NOTE_Reducing_HMI_packet_size_for_improved_connection_reliability_"
  369.     End If
  370.     If InStr(myerror, "1285:Protocol transport error", 1)<>0 And _
  371.        ReadIni$(Session.IniSection, "HMI Packet Size", Session.IniFilename)="4096" Then
  372.         WriteIni Session.IniSection, "HMI Packet Size", "2048", Session.IniFilename
  373.         LogResult "_NOTE_Reducing_HMI_packet_size_for_improved_connection_reliability_"
  374.     End If
  375. End Function
  376.  
  377. 'T:SetHigh (subroutine) (CompuServe)
  378. ' Set high message number
  379. Sub SetHigh(id As String, forum As String, num As String)
  380.     Dim hmn As Long, b As Integer
  381.  
  382.     If Not HMIGotoForum(forum) Then
  383.         LogResult id + " : Failed : Unable to set high message number in "+forum
  384.         Exit Sub
  385.     End If
  386.     hmn = Val(num)
  387.     If hmn < 0 Then hmn = FAPconfig.dwNewestMsg+hmn
  388.     If hmn = 0 Then hmn = FAPconfig.dwNewestMsg
  389.  
  390.     ' Set high number
  391.     Terminal.Print "Setting the high message number to" & Str(hmn) & Basic.Eoln$
  392.     b = FAPSetUserProfile(FAP_USR_PERMANENT%, FAP_USF_HIGH_MSG%, hmn, "")
  393.     WriteIni "High Message Number", WhereAmI, LTrim$(Str$(hmn)), Session.ServicePath+"hmn.ini"
  394.  
  395.     If id<>"" Then
  396.         If b=0 Then
  397.             ReportSuccess id & " : Failed to Set High Message Number to #" & hmn & " in " & forum
  398.         Else
  399.             ReportSuccess id & " : Set High Message Number to #" & hmn & " in " & forum
  400.             HMIGetFAPConfig FAPconfig
  401.         End If
  402.     Else
  403.         HMIGetFAPConfig FAPconfig
  404.     End If
  405. End Sub
  406.  
  407. Function CheckTopicBeforePosting(id As String, topic As String, _
  408.          section As Integer, subject As String, checksection As Boolean) As Boolean
  409.     Dim i As Integer
  410.  
  411.     If Not HMIGotoForum(topic) Then
  412.         LogResult id + " : Failed : Unable to post message."
  413.         Exit Function
  414.     End If
  415.  
  416.     If FAPconfig.wRestrictions And FAP_NO_MESSAGE_SEND% Then
  417.         LogResult id + " : Failed : Posting not allowed in forum " & topic
  418.         Exit Function
  419.     End If
  420.  
  421.     ' Truncate subject to 24 chars and make it valid
  422.     If Len(subject) > 24 Then subject = Left$(subject, 24)
  423.     For i = 1 To Len(subject)
  424.         If InStr(";""", Mid(subject, i, 1)) Then Mid(subject, i, 1) = " "
  425.     Next
  426.  
  427.     section = Val(SectionNumber(topic))
  428.     If checksection Then
  429.         If (FAPconfig.svMsgSections And (2 ^ section)) = 0 Then
  430.             LogResult id + " : Failed : Unknown section " & topic
  431.             Exit Function
  432.         End If
  433.     End If
  434.     CheckTopicBeforePosting = True
  435. End Function
  436.  
  437. 'T:Say (subroutine) (CompuServe)
  438. Sub Say(id As String, topic As String, pfrom As String, pto As String, flags As Integer, subject As String, filename As String)
  439.     Dim hdr As FAPMSGHEADER, body As String
  440.     Dim section As Integer, cOptions As Integer
  441.     Dim username As String, userid As String, lastname As String
  442.     Dim noformat As Integer, b As Integer
  443.  
  444.     ' Is it usenet?
  445.     If Mid(topic, 1, 7)="usenet." Then
  446.         UsenetPost id, topic, filename
  447.         Exit Sub
  448.     End If
  449.  
  450.     If Not CheckTopicBeforePosting(id, topic, section, subject, True) Then
  451.         Exit Sub
  452.     End If
  453.  
  454.     If (flags And fPRIVATE)=fPRIVATE Then
  455.         Terminal.Print "Posting private message to " + pto + " Subj: " + subject + Basic.Eoln$
  456.     Else
  457.         Terminal.Print "Posting message to " + pto + " Subj: " + subject + Basic.Eoln$
  458.     End If
  459.     AnalyseName pto, username, userid
  460.     If StrComp(userid, "all", 1)=0 Or _
  461.        StrComp(userid, "sysop", 1)=0 Or _
  462.        StrComp(userid, "*sysop", 1)=0 Then
  463.         username = userid
  464.         userid = ""
  465.     End If
  466.  
  467.     ' What posting flags ?
  468.     cOptions = 0
  469.     noformat = 0
  470.     If flags And fNOFORMAT Then noformat = 1
  471.     If (flags And fPRIVATE)=fPRIVATE Then
  472.         If (FAPconfig.wRestrictions And FAP_NO_PRIVATE_MSGS%) = 0 Then
  473.             cOptions = FAP_PRIVATE_MESSAGE%
  474.         Else
  475.             MailTo id, pto, 0, subject, filename
  476.             SendMail id
  477.             Exit Sub
  478.         End If
  479.     End If
  480.  
  481.     ' Strip off "@cs.com" and "internet:" ?
  482.     If InStr(userid, "internet:", 1)=1 And InStr(userid, "@cs.com", 1)<>0 Then
  483.         userid = Mid$(userid, 10, InStr(userid, "@cs.com")-10)
  484.     End If
  485.  
  486.     ' What's our name
  487.     If pfrom <> "" Then
  488.         On Error Resume Next
  489.         lastname = FAPconfig.lpUserName
  490.         b = FAPSetUserProfile(0, FAP_USF_NAME%, 0, pfrom)
  491.         On Error Goto 0
  492.     End If
  493.  
  494.     ' Get body text
  495.     body = ReadMessageFile(filename, 2)
  496.  
  497.     On Error Goto Say_error
  498.     On Error Resume Next    'NB Bug in CCT230B always gives error here
  499.     FAPSendMsg hdr, section, subject, username, userid, cOptions, body
  500.  
  501.     ' Change back to old name
  502.     If lastname <> "" Then
  503.         On Error Resume Next
  504.         b = FAPSetUserProfile(0, FAP_USF_NAME%, 0, lastname)
  505.         On Error Goto 0
  506.     End If
  507.  
  508.     If hdr.dwMsgNo = 0 Then
  509.         LogResult id + " : Failed : Posting Compose to " & topic
  510.     Else
  511.         ReportSuccess id & " : Posted Compose to " & pto & " as VA:" & Session.Service & ":" & topic & "#" & hdr.dwMsgNo
  512.         HMIGetFAPConfig FAPconfig
  513.     End If
  514.     Exit Sub
  515. Say_error:
  516.     LogResult id + " : Failed : Posting Compose to " & topic & " - Error:" & FullErrorMessage
  517. End Sub
  518.  
  519. 'T:UnjoinedSay (subroutine) (CompuServe)
  520. Sub UnjoinedSay(id As String, topic As String, pto As String, subject As String, filename As String)
  521.     Say id, topic, "", pto, 0, subject, filename
  522. End Sub
  523.  
  524. 'T:Comment (subroutine) (CompuServe)
  525. Sub Comment(id As String, topic As String, pfrom As String, pto As String, message As String, flags As Integer, subject As String, filename As String)
  526.     Dim hdr As FAPMSGHEADER, body As String
  527.     Dim section As Integer, cOptions As Integer
  528.     Dim username As String, userid As String, lastname As String
  529.     Dim msgno As Long, threadid As Long
  530.     Dim noformat As Integer
  531.  
  532.     ' Is it usenet?
  533.     If Mid(topic, 1, 7)="usenet." Then
  534.         UsenetPost id, topic, filename
  535.         Exit Sub
  536.     End If
  537.  
  538.     If Not CheckTopicBeforePosting(id, topic, section, subject, False) Then
  539.         Exit Sub
  540.     End If
  541.  
  542.     If (flags And fPRIVATE)=fPRIVATE Then
  543.         Terminal.Print "Replying privately to message #"+message+" Subj: "+subject+Basic.Eoln$
  544.     Else
  545.         Terminal.Print "Replying to message #"+message+" Subj: "+subject+Basic.Eoln$
  546.     End If
  547.  
  548.     ' What posting flags ?
  549.     cOptions = 0
  550.     noformat = 0
  551.     If flags And fNOFORMAT Then noformat = 1
  552.     If (flags And fPRIVATE)=fPRIVATE Then
  553.         If (FAPconfig.wRestrictions And FAP_NO_PRIVATE_MSGS%) = 0 Then
  554.             cOptions = FAP_PRIVATE_MESSAGE%
  555.         Else
  556.             MailTo id, pto, 0, "Re: "+subject, filename
  557.             SendMail id
  558.             Exit Sub
  559.         End If
  560.     End If
  561.  
  562.     ' What's our name
  563.     If pfrom <> "" Then
  564.         On Error Resume Next
  565.         lastname = FAPconfig.lpUserName
  566.         b = FAPSetUserProfile(0, FAP_USF_NAME%, 0, pfrom)
  567.         On Error Goto 0
  568.     End If
  569.  
  570.     ' Collect message text ready to send to CIS
  571.     body = ReadMessageFile(filename, 2)
  572.  
  573.     On Error Resume Next
  574.     msgno = Val(message)
  575.     FAPReadMsgHeader hdr, msgno, FAP_MC_THREAD_ID%
  576.     threadid = hdr.dwThreadID
  577.     If threadid <> 0 Then
  578.         FAPSendReply hdr, msgno, threadid, cOptions, body
  579.     Else
  580.         hdr.dwMsgNo = 0
  581.     End If
  582.     If hdr.dwMsgNo = 0 Then
  583.         AnalyseName pto, username, userid
  584.         FAPSendMsg hdr, section, "#"+message+"-"+subject, username, userid, cOptions, body
  585.         If hdr.dwMsgNo = 0 Then
  586.             LogResult id + " : Failed : Posting Reply to VA:" & Session.Service & ":" & topic & "#" & message & " - error: " & FullErrorMessage()
  587.  
  588.             ' Change back to old name
  589.             If lastname <> "" Then
  590.                 On Error Resume Next
  591.                 b = FAPSetUserProfile(0, FAP_USF_NAME%, 0, lastname)
  592.                 On Error Goto 0
  593.             End If
  594.             Exit Sub
  595.         End If
  596.     End If
  597.     ReportSuccess id & " : Posted Reply to " & message & " as VA:" & Session.Service & ":" & topic & "#" & hdr.dwMsgNo
  598.  
  599.     ' Change back to old name
  600.     If lastname <> "" Then
  601.         On Error Resume Next
  602.         b = FAPSetUserProfile(0, FAP_USF_NAME%, 0, lastname)
  603.         On Error Goto 0
  604.     End If
  605.  
  606.     HMIGetFAPConfig FAPconfig
  607.     Exit Sub
  608. End Sub
  609.  
  610. 'T:DownMessages (subroutine) (CompuServe)
  611. ' Download full message text
  612. Sub DownMessages(id As String, forum As String, sections As String)
  613.     Dim hdr As FAPMSGHEADER, sect As Long
  614.     Dim txt As String, body As String, t As String
  615.     Dim count As Integer, i As Integer, newmsgs As Long
  616.  
  617.     sections = Trim$(LTrim$(sections))
  618.  
  619.     If StartMessageDownload(id, forum, sections, False) Then
  620.         On Error Goto DownMessages_error
  621.  
  622.         sect = ParseSectionList(sections, FAPconfig.svMsgSections, count)
  623.  
  624.         If count > 0 Then
  625.             Dim lpStartWith(0 To count-1) As FAPSTARTWITH
  626.  
  627.             'Fill in the FAPSTARTWITH structures for each section
  628.             count = 0
  629.             For i = 0 To 24
  630.                 sl = 2^i
  631.                 If (sect And (2^i))<>0 Then
  632.                     lpStartWith(count).cSectionID = i
  633.                     lpStartWith(count).dwMsgNo = FAPconfig.dwLastMsgRead
  634.                     count = count + 1
  635.                 End If
  636.             Next
  637.  
  638.             'Ask HMI for all new messages after the start
  639.             FAPReadNewMsgs ALL_HEADER_FIELDS%, lpStartWith()
  640.             'Now read the actual messages
  641.             Do
  642.                 hdr.dwMsgNo = 0
  643.                 FAPReadSingleNewMsgHdr hdr
  644.                 If hdr.dwMsgNo = 0 Then Exit Do     'Finished
  645.                 body = ""
  646.                 Do
  647.                     txt = "" ' possible memory leak
  648.                     txt = FAPReadNewMessageBody(hdr)
  649.                     body = body + txt
  650.                 Loop While txt > ""
  651.                 SaveMessage hdr, body
  652.                 newmsgs = newmsgs + 1
  653.             Loop
  654.         End If
  655.         Terminal.Print "Collected " & newmsgs & " new message(s)" & Basic.Eoln$
  656.         If count>0 Then SetHighMessage = True
  657.     End If
  658.     FinishMessageDownload id
  659.     Exit Sub
  660. DownMessages_error:
  661.     LogResult "Error:" & FullErrorMessage & " collecting messages from " & forum
  662.     CaptureLine "Error:" & FullErrorMessage
  663.     FinishMessageDownload id
  664. End Sub
  665.  
  666. Dim ThreadsToFetch() As Long, MsgsToFetch() As Long, nMsgsToFetch As Integer
  667.  
  668. ' Scans the array of thread ids marked to fetch and flags this one if
  669. ' it's found
  670. Function SetFetchThreadId(threadid As Long, num As Long) As Boolean
  671.     Dim i As Integer, lin As String, file As String
  672.  
  673.     ' First call - load list of threadids marked to fetch
  674.     If threadid=0 Then
  675.         file$ = ReadIni$("Main", "Message Path", Session.IniFilename) + _
  676.                 Session.Service + "\" + _
  677.                 Mid$(WhereAmI$, InStr(WhereAmI$, ":")+1, 8) + ".tid"
  678.         i = 0
  679.         nMsgsToFetch = -1
  680.         ReDim Preserve MsgsToFetch(0 to 0)
  681.         ReDim Preserve ThreadsToFetch(0 To 0)
  682.         On Error Goto Read_Error
  683.         Open file$ For Input As #1
  684.         Do While Not EOF(1)
  685.             Line Input #1,lin$
  686.             ReDim Preserve ThreadsToFetch(0 To i)
  687.             ThreadsToFetch(i) = Val(lin$)
  688.             i = i + 1
  689.         Loop
  690. Read_error:
  691.         Close #1
  692.         SetFetchThreadId = False
  693.     Else
  694.         ' Set the fetch flag
  695.         For i=0 To UBound(ThreadsToFetch)
  696.             If ThreadsToFetch(i)=threadid Then
  697.                 nMsgsToFetch = nMsgsToFetch + 1
  698.                 ReDim Preserve MsgsToFetch(0 To nMsgsToFetch)
  699.                 MsgsToFetch(nMsgsToFetch) = num
  700.                 Terminal.Print "Need to fetch thread#"+Str$(threadid)+basic.eoln$
  701.                 SetFetchThreadId = False
  702.                 Exit Function
  703.             End If
  704.         Next
  705.         SetFetchThreadId = True
  706.     End If
  707. End Function
  708.  
  709. 'T:DownHeaders (subroutine) (CompuServe)
  710. Sub DownHeaders(id As String, forum As String, sections As String)
  711.     Dim tforum As String
  712.  
  713.     nMsgsToFetch = -1
  714.     tforum = forum
  715.     If StartMessageDownload(id, tforum, sections, False) Then
  716.         SearchMessages FAP_MSS_ALL_MSGS%, "", False, False, True, ""
  717.         If Len(Trim$(LTrim$(sections)))>0 Then SetHighMessage = True
  718.     End If
  719.     FinishMessageDownload id
  720.  
  721.     ' Now fetch any full messages that the user wanted
  722.     If nMsgsToFetch >= 0 Then
  723.         For i=0 To nMsgsToFetch
  724.             If MsgsToFetch(i) > 0 Then
  725.                 tforum = forum
  726.                 ReadNumber "", tforum, LTrim$(Str$(MsgsToFetch(i)))
  727.             End If
  728.         Next
  729.     End If
  730. End Sub
  731.  
  732. 'T:DownRoots (subroutine) (CompuServe)
  733. Sub DownRoots(id As String, forum As String, sections As String)
  734.     Dim tforum As String
  735.  
  736.     nMsgsToFetch = -1
  737.     tforum = forum
  738.     If StartMessageDownload(id, tforum, sections, False) Then
  739.         SearchMessages FAP_MSS_ALL_MSGS%, "", False, True, True, ""
  740.         If Len(Trim$(LTrim$(sections)))>0 Then SetHighMessage = True
  741.     End If
  742.     FinishMessageDownload id
  743.  
  744.     ' Now fetch any full messages that the user wanted
  745.     If nMsgsToFetch >= 0 Then
  746.         For i=0 To nMsgsToFetch
  747.             If MsgsToFetch(i) > 0 Then
  748.                 tforum = forum
  749.                 FetchThread "", tforum, LTrim$(Str$(MsgsToFetch(i)))
  750.             End If
  751.         Next
  752.     End If
  753. End Sub
  754.  
  755. 'T:SearchForMessages (subroutine) (CompuServe)
  756. Sub SearchForMessages(id As String, forum As String, sections As String, lastdays As String, searchtype As String, searchstring As String)
  757.     Dim hmn As Long
  758.  
  759.     If Not HMIGotoForum(forum) Then
  760.         LogResult id + " : Failed : Unable to collect messages from " + forum
  761.         Exit Sub
  762.     End If
  763.     If searchtype="9" And Nisa=False Then
  764.         LogResult id + " : Failed : Cannot search message body in non-NISA forum " + forum
  765.         Exit Sub
  766.     End If
  767.     hmn = FAPconfig.dwLastMsgRead
  768.     If StartMessageDownload(id, forum, sections, True) Then
  769.         If lastdays="u" Then
  770.             Terminal.Print "Searching for unread messages "
  771.         Else
  772.             Terminal.Print "Searching for messages "
  773.         End If
  774.         If searchtype="2" Then Terminal.Print "with subject: '"
  775.         If searchtype="3" Then Terminal.Print "from: '"
  776.         If searchtype="4" Then Terminal.Print "to: '"
  777.         If searchtype="9" Then Terminal.Print "containing: '"
  778.         Terminal.Print searchstring+"'"+Basic.Eoln$
  779.         If lastdays="u" Then
  780.             SearchMessages Val(searchtype), searchstring, True, False, True, ""
  781.         Else
  782.             SearchMessages Val(searchtype), searchstring, True, False, False, lastdays
  783.         End If
  784.     End If
  785.     FinishMessageDownload id
  786.  
  787.     ' Correct Compuserve's invalid assumption about HMN after remote search
  788.     b = FAPSetUserProfile(FAP_USR_PERMANENT%, FAP_USF_HIGH_MSG%, hmn, "")
  789. End Sub
  790.  
  791. 'T:ListHeldMessages (subroutine) (CompuServe)
  792. Sub ListHeldMessages(id As String, forum As String, sections As String)
  793.     Dim term(0 To 0) As FAPSEARCHTERM
  794.     Dim summary() As FAPMSGSUMMARY
  795.     Dim msgno() As Long
  796.     Dim hdr As FAPMSGHEADER
  797.     Dim i As Integer, count as Integer
  798.     Dim nmsgs As Integer
  799.     Dim cComponents As Integer
  800.     Dim dwStart As Long
  801.     Dim section As String
  802.  
  803.     If Not HMIGotoForum(forum) Then
  804.         LogResult id + " : Failed : Unable to collect messages from " + forum
  805.         Exit Sub
  806.     End If
  807.  
  808.     If Nisa Then
  809.         sectionvector = ParseSectionList(sections, FAPconfig.svMsgSections, count)
  810.         StartCapturing forum+"/Sysop_Logs", "Held_Messages", False
  811.         CaptureLine "Messages on Hold"
  812.         CaptureLine ""
  813.  
  814.         Terminal.Status "Collecting Held List ... Please Wait"
  815.  
  816.         term(0).cType = FAP_MSS_HELD_MSGS%
  817.         dwStart = FAPconfig.dwMsgNoBase
  818.         On Error Goto ListHeldMessages_end
  819.         FAPMsgSearch summary(), msgno(), HMI_STATE_FIRST%, 1, 20, _
  820.                 sectionvector, dwStart, cComponents, term()
  821.         While True
  822.             nmsgs = UBound(msgno)
  823.             On Error Goto ListHeldMessages_error
  824.             For i = 0 To UBound(msgno)
  825.                 hdr.dwMsgNo = 0
  826.                 FAPReadMsgHeader hdr, msgno(i), ALL_HEADER_FIELDS%
  827.                 If hdr.dwMsgNo = 0 Then Exit For
  828.  
  829.                 If SectionMsgIds(hdr.cSectionId) >= 0 Then
  830.                     section = szMsgSection(SectionMsgIds(hdr.cSectionId)).lpTitle
  831.                 Else
  832.                     section = "Unknown"
  833.                 End If
  834.                 CaptureText "VA:" & Session.Service & ":" & forum & "/S" & hdr.cSectionId
  835.                 CaptureLine "_" & section & "#" & hdr.dwMsgNo
  836.             Next
  837.  
  838.             On Error Goto ListHeldMessages_end
  839.             ' following will error if nothing else left
  840.             FAPMsgSearch summary(), msgno(), HMI_STATE_NEXT%, 1, 20, _
  841.                     sectionvector, dwStart, cComponents, term()
  842.         Wend
  843. ListHeldMessages_end:
  844.         FinishCapturing
  845.         ReportSuccess id & " : Held Message List for forum " & forum & " collected"
  846.         Exit Sub
  847. ListHeldMessages_error:
  848.         LogResult "SearchMessages: Error:" & FullErrorMessage
  849.     Else
  850.         AsciiListHeldMessages id, forum, sections
  851.     End If
  852. End Sub
  853.  
  854. Sub FetchMessageThread(id As String, forum As String, number As String, thr As Boolean)
  855.     Dim i As Integer, b As Integer, done As Integer
  856.     Dim tmp As String, body As String, txt As String, tforum As String
  857.     Dim hdr As FAPMSGHEADER, msgno() As Long, lasthmn As Long
  858.  
  859.     If Not HMIGotoForum(forum) Then
  860.         LogResult id + " : Failed : Unable to read messages from " + forum
  861.         Exit Sub
  862.     End If
  863.  
  864.     ' Check to see if we need to join the forum
  865.     If ((FAPconfig.wAlerts And FAP_NOT_A_MEMBER%) <> 0) Then
  866.         tforum = forum
  867.         tforum = ParseString(tforum, "/")
  868.         JoinForum "", tforum, MailName, ""
  869.     End If
  870.  
  871.     lasthmn = FAPconfig.dwLastMsgRead
  872.     CurrentForum = ParseString(forum, "/")
  873.  
  874.     ' Unique name for capture file
  875.     messagefilename = UniqueFileName$()
  876.     Capture CAPTURE_ON, messagefilename
  877.     CaptureText Basic.Eoln$+"#pragma ciscontrol=yes;markunread=yes;deleteexisting=no"+Basic.Eoln$
  878.     On Error Goto ReadMessageThread_error
  879.  
  880.     ' Read the message/thread
  881.     Redim msgno(0 To 0)
  882.     msgno(0) = number
  883.     If thr Then
  884.         FAPReadMessageHeaders ALL_HEADER_FIELDS%+FAP_MC_THREADS%, msgno()
  885.     Else
  886.         FAPReadMessageHeaders ALL_HEADER_FIELDS%, msgno()
  887.     End If
  888.     done = False
  889.     Do
  890.         FAPReadSingleMsgHdr hdr
  891.         If hdr.dwMsgNo = 0 Then Exit Do
  892.         If thr Then
  893.             Terminal.Print "Reading thread #" & LTrim(Str(hdr.dwMsgNo)) & " " & hdr.lpSubject & Basic.Eoln$
  894.         Else
  895.             Terminal.Print "Reading message #" & LTrim(Str(hdr.dwMsgNo)) & " " & hdr.lpSubject & Basic.Eoln$
  896.         End If
  897.         body = ""
  898.         Do
  899.             txt = FAPReadMessageBody(hdr)
  900.             body = body + txt
  901.         Loop While txt > ""
  902.         SaveMessage hdr, body
  903.         done = True
  904.     Loop
  905.     If done = False And thr = False Then
  906.         Terminal.Print "% Unable to read message #" & number & " from " & WhereAmI & Basic.Eoln$
  907.     End If
  908.     Capture CAPTURE_OFF
  909.     If done Then
  910.         If id<>"" Then ReportSuccess id & " : Collected message/thread #" & number & " from " & WhereAmI
  911.         b = QueueFile(Session.Service, messagefilename, IM_DELETE)
  912.     Else
  913.         If id<>"" Then ReportSuccess id & " : Didn't collect message/thread #" & number & " from " & WhereAmI
  914.         DeleteFile messagefilename
  915.     End If
  916.     i = HMIResync(CAP_FORUM)
  917.  
  918.     ' Need to set HMN because CIS messes it up
  919.     b = FAPSetUserProfile(FAP_USR_PERMANENT%, FAP_USF_HIGH_MSG%, lasthmn, "")
  920.  
  921.     Exit Sub
  922. ReadMessageThread_error:
  923.     LogResult "Error:" & FullErrorMessage & " collecting message/thread from " & forum
  924.     CaptureLine "Error:" & FullErrorMessage
  925.     i = HMIResync(CAP_FORUM)
  926.     sectionvector = 0
  927. End Sub
  928.  
  929. Sub FetchThread(id As String, forum As String, number As String)
  930.     FetchMessageThread id, forum, number, True
  931. End Sub
  932.  
  933. Function StartMessageDownload(id As String, forum As String, _
  934.               sections As String, markunread As Boolean) As Integer
  935.     Dim i As Integer, j As Integer, count As Integer
  936.     Dim tmp As String, t As String
  937.     Dim tmpVector As Long, fromyou As Boolean
  938.  
  939.     nummessages = -1
  940.     StartMessageDownload = False
  941.     If Not HMIGotoForum(forum) Then
  942.         LogResult id + " : Failed : Unable to collect messages from " + forum
  943.         Exit Function
  944.     End If
  945.  
  946.     CurrentForum = forum
  947.  
  948.     ' Unique name for capture file
  949.     Capture CAPTURE_ON, WorkingPath + "mswfetch.tmp"
  950.     CaptureText Basic.Eoln$+"#pragma ciscontrol=yes;markunread=no;deleteexisting=no"+Basic.Eoln$
  951.     Terminal.CaptureStatus CAPTURE_ON
  952.     nummessages = 0
  953.     On Error Goto StartMessageDownload_error
  954.  
  955.     ' Which sections ?
  956.     fromyou = InStr(sections, "y", 1)<>0
  957.     ReplaceAllInString sections, " y", ""
  958.     sectionvector = ParseSectionList(sections, FAPconfig.svMsgSections, count)
  959.  
  960.     ' Messages from/to you
  961.     If LastDownMessages<>WhereAmI Then
  962.         filterVector = sectionvector ' Used to filter out waiting messages
  963.         tmpVector = sectionvector
  964.         sectionvector = &HFFFFFFFF
  965.         If FAPconfig.wAlerts And FAP_WAITING_MSGS% Then
  966.             Terminal.Print "Collecting waiting messages" & Basic.Eoln$
  967.             SearchMessages FAP_MSS_WAITING_MSGS%, "", True, False, False, ""
  968.             If nummessages=1 Then
  969.                 Terminal.Print "Collected 1 waiting message" & Basic.Eoln$
  970.             Else
  971.                 Terminal.Print "Collected " & nummessages & " waiting messages" & Basic.Eoln$
  972.             End If
  973.             nummessages = 0
  974.         End If
  975.  
  976.         ' Read messages from you?
  977.         If fromyou Then
  978.             Terminal.Print "Collecting messages from you" & Basic.Eoln$
  979.             SearchMessages FAP_MSS_ORIGINATOR_NAME%, Session.LoginName, True, False, True, ""
  980.         End If
  981.         sectionvector = tmpVector
  982.     End If
  983.  
  984.     ' Start capture
  985.     Capture CAPTURE_OFF
  986.     messagefilename = UniqueFileName$()
  987.     Capture CAPTURE_ON, messagefilename
  988.     If markunread Then
  989.         CaptureText Basic.Eoln$+"#pragma ciscontrol=yes;markunread=yes;deleteexisting=no"+Basic.Eoln$
  990.     Else
  991.         CaptureText Basic.Eoln$+"#pragma ciscontrol=yes;markunread=no;deleteexisting=no"+Basic.Eoln$
  992.     End If
  993.  
  994.     ' Store the last forum we read messages from so that we don't
  995.     ' do more than one reading waiting per forum.
  996.     LastDownMessages = WhereAmI
  997.     If Not markunread Then
  998.         If sectionvector=FAPconfig.svMsgSections Then
  999.             Terminal.Print "Collecting messages from all sections" + Basic.Eoln$
  1000.         Else
  1001.             Terminal.Print "Collecting messages from sections " + Trim$(sections) + Basic.Eoln$
  1002.         End If
  1003.     End If
  1004.     StartMessageDownload = True
  1005.     Exit Function
  1006. StartMessageDownload_error:
  1007.     LogResult "Error:" & FullErrorMessage & " collecting messages from " & forum
  1008.     CaptureLine "Error:" & FullErrorMessage
  1009.     sectionvector = 0
  1010.     If nummessages > 0 Then StartMessageDownload = True
  1011. End Function
  1012.  
  1013. Sub FinishMessageDownload(id As String)
  1014.     Capture CAPTURE_OFF
  1015.     Terminal.CaptureStatus CAPTURE_OFF
  1016.     If nummessages = -1 Then Exit Sub
  1017.     If nummessages = 1 Then
  1018.         ReportSuccess id & " : Collected " & nummessages & " message from " & _
  1019.             WhereAmI & " [" & LTrim$(Str$(FAPconfig.dwLastMsgRead)) & "-" & _
  1020.             LTrim$(Str$(FAPconfig.dwNewestMsg)) & "]"
  1021.     Else
  1022.         ReportSuccess id & " : Collected " & nummessages & " messages from " & _
  1023.             WhereAmI & " [" & LTrim$(Str$(FAPconfig.dwLastMsgRead)) & "-" & _
  1024.             LTrim$(Str$(FAPconfig.dwNewestMsg)) & "]"
  1025.     End If
  1026.     If nummessages > 0 Then
  1027.         ' Add to import queue
  1028.         b = QueueFile(Session.Service, messagefilename, IM_DELETE)
  1029.     Else
  1030.         DeleteFile messagefilename
  1031.     End If
  1032. End Sub
  1033.  
  1034. Sub SearchMessages(searchtype As Integer, searchstring As String, bodies As Boolean, rootsonly As Boolean, unreadonly As Boolean, lastdays As String)
  1035.     Dim term(0 To 0) As FAPSEARCHTERM
  1036.     Dim summary() As FAPMSGSUMMARY
  1037.     Dim msgno() As Long
  1038.     Dim hdr As FAPMSGHEADER
  1039.     Dim i As Integer, txt As String, body As String
  1040.     Dim nmsgs As Integer
  1041.     Dim d As Date, tsTime As HMITIMESTAMP
  1042.     Dim cComponents As Integer
  1043.     Dim dwStart As Long
  1044.     Dim saveit As Boolean
  1045.     Dim Section as String
  1046.  
  1047.     ' Nothing to do so don't bother trying
  1048.     If unreadonly And FAPconfig.dwNewestMsg=FAPconfig.dwLastMsgRead Then
  1049.         Exit Sub
  1050.     End If
  1051.  
  1052.     term(0).cType = searchtype
  1053.     If searchstring<>"" Then term(0).lpPattern = searchstring
  1054.     If rootsonly Then
  1055.         cComponents = FAP_MSR_PSEUDO_ROOTS%
  1056.         saveit = SetFetchThreadId(0, 0)
  1057.     End If
  1058.     If lastdays<>"" Then
  1059.         d = Date() - Val(lastdays)
  1060.         tsTime.cDay = Day(d)
  1061.         tsTime.cMonth = Month(d)
  1062.         tsTime.cYear = Year(d)-1970
  1063.         dwStart = FAPSearchDate(&H00FFFFFF, tsTime)
  1064.     Else
  1065.         If unreadonly Then
  1066.             dwStart = FAPconfig.dwLastMsgRead
  1067.         Else
  1068.             dwStart = FAPconfig.dwMsgNoBase
  1069.         End If
  1070.     End If
  1071.  
  1072.     Terminal.CaptureStatus CAPTURE_ON
  1073.     On Error Goto SearchMessages_end
  1074.     FAPMsgSearch summary(), msgno(), HMI_STATE_FIRST%, 1, 1000, _
  1075.             sectionvector, dwStart, cComponents, term()
  1076.     While True
  1077.         nmsgs = UBound(msgno)
  1078.         On Error Goto SearchMessages_error
  1079.         If bodies Then
  1080.             FAPReadMessageHeaders ALL_HEADER_FIELDS%, msgno()
  1081.             Do
  1082.                 FAPReadSingleMsgHdr hdr
  1083.                 If hdr.dwMsgNo = 0 Then Exit Do
  1084.                 dwStart = hdr.dwMsgNo
  1085.                 body = ""
  1086.                 Do
  1087.                     txt = "" ' possible memory leak
  1088.                     txt = FAPReadMessageBody(hdr)
  1089.                     body = body + txt
  1090.                 Loop While txt > ""
  1091.  
  1092.                 SaveMessage hdr, body
  1093.                 If SearchType = FAP_WAITING_MSGS% Then
  1094.                     If SectionMsgIds(hdr.cSectionId) >= 0 Then
  1095.                         section = szMsgSection(SectionMsgIds(hdr.cSectionId)).lpTitle
  1096.                     Else
  1097.                         section = "Unknown"
  1098.                     End If
  1099.                     LogResult "Collected Waiting Message : VA:" & Session.Service & ":" & CurrentForum & "/S" & hdr.cSectionId & "_" & Section & "#" & hdr.dwMsgNo
  1100.                 End If
  1101.             Loop
  1102.         Else
  1103.             For i = 0 To UBound(msgno)
  1104.                 hdr.dwMsgNo = 0
  1105.                 If rootsonly Then
  1106.                     FAPReadMsgHeader hdr, msgno(i), &H1FE3
  1107.                     saveit = SetFetchThreadId(hdr.dwThreadId, hdr.dwMsgNo)
  1108.                 Else
  1109.                     FAPReadMsgHeader hdr, msgno(i), ALL_HEADER_FIELDS%
  1110.                     saveit = True
  1111.                 End If
  1112.                 If hdr.dwMsgNo = 0 Then Exit For
  1113.                 If saveit Then SaveMessage hdr, "*** Header Only ***" & Chr$(10)
  1114.             Next
  1115.         End If
  1116.         On Error Goto SearchMessages_end
  1117.         ' following will error if nothing else left
  1118.         FAPMsgSearch summary(), msgno(), HMI_STATE_NEXT%, 1, 1000, _
  1119.                 sectionvector, dwStart, cComponents, term()
  1120.     Wend
  1121. SearchMessages_end:
  1122.     filterVector = 0
  1123.     Terminal.CaptureStatus CAPTURE_OFF
  1124.     Exit Sub
  1125. SearchMessages_error:
  1126.     Terminal.CaptureStatus CAPTURE_OFF
  1127.     LogResult "SearchMessages: Error:" & FullErrorMessage
  1128.     filterVector = 0
  1129. End Sub
  1130.  
  1131. 'T:ReadNumber (subroutine) (CompuServe)
  1132. Sub ReadNumber(id As String, forum As String, number As String)
  1133.     FetchMessageThread id, forum, number, False
  1134. End Sub
  1135.  
  1136. 'T:JoinForum (subroutine) (CompuServe)
  1137. Sub JoinForum(id As String, forum As String, handle As String, newmsgs As String)
  1138.     Dim b As Integer, hmn As Long
  1139.     Dim tsTime As HMITIMESTAMP, d As Date
  1140.     Dim a As Boolean
  1141.  
  1142.     If Not HMIGotoForum(forum) Then
  1143.         LogResult "Unable to join "+forum
  1144.         Exit Sub
  1145.     End If
  1146.  
  1147.     Terminal.Print "Joining forum"+Basic.Eoln$
  1148.     On Error Goto JoinForum_error
  1149.  
  1150.     ' Set user name
  1151.     If ((FAPconfig.wAlerts And FAP_NOT_A_MEMBER%) <> 0) Then
  1152.         b = FAPSetUserProfile(FAP_USR_PERMANENT%+FAP_USR_JOIN%, FAP_USF_NAME%, 0, handle)
  1153.         FAPconfig.wAlerts = FAPconfig.wAlerts - FAP_NOT_A_MEMBER%
  1154.     Else
  1155.         On Error Resume Next
  1156.         b = FAPSetUserProfile(FAP_USR_PERMANENT%, FAP_USF_NAME%, 0, handle)
  1157.     End If
  1158.  
  1159.     ' Get list of sections/libraries
  1160.     CollectSections forum
  1161.     If (FAPconfig.wAlerts And FAP_NEW_BULLETINS)=0 Then
  1162.         Newsflash "", forum
  1163.     End If
  1164.     Announcements "", forum
  1165.  
  1166.     ' Set HMN back nnn messages
  1167.     If newmsgs <> "" Then
  1168.         hmn = FAPconfig.dwNewestMsg - Val(newmsgs)
  1169.         If hmn > 0 Then SetHigh "", forum, LTrim$(Str(hmn))
  1170.     ElseIf FAPconfig.dwLastMsgRead < FAPconfig.dwMsgNoBase Then
  1171.         SetHigh "", forum, LTrim$(Str(FAPconfig.dwMsgNoBase))
  1172.     End If
  1173.  
  1174.     ReportSuccess id & " : Joined " & forum & " successfully"
  1175.     Exit Sub
  1176. JoinForum_error:
  1177.     LogResult id + " : Failed : Unable to join " + forum + " - error:" + FullErrorMessage
  1178. End Sub
  1179.  
  1180. 'T:UserLog (subroutine) (CompuServe)
  1181. Sub UserLog(id As String, forum As String)
  1182.     If Not HMIGotoForum(forum) Then
  1183.         LogResult id + " : Failed : Unable to collect user log from "+forum
  1184.         Exit Sub
  1185.     End If
  1186.  
  1187.     If Not Nisa Then
  1188.         AsciiUserLog id, forum
  1189.         Exit Sub
  1190.     End If
  1191.  
  1192.     Terminal.Print "Collecting forum user log ... Please wait"+Basic.Eoln$
  1193.     RecordBulletins forum, False, False, True
  1194.     If id<>"" Then ReportSuccess id & " : User log collected from " & forum
  1195. End Sub
  1196.  
  1197. 'T:RecordSectionInformation (subroutine) (CompuServe)
  1198. Sub RecordSectionInformation(forum As String)
  1199.     Dim i As Integer, buf As String
  1200.  
  1201.     StartCapturing forum+"/Announcements", "CompuServe", True
  1202.     CaptureLine "Sections"
  1203.     If (FAPconfig.wAlerts And FAP_IS_SYSOP%)<>0 Then CaptureLine "SYSOP"
  1204.     If (FAPconfig.wAlerts And FAP_FREE_USER%)<>0 Then CaptureLine "Free Flag"
  1205.     If (FAPconfig.wAlerts And FAP_NISA_FORUM%)<>0 Then CaptureLine "NISA Forum"
  1206.     If (FAPconfig.wRestrictions And FAP_NO_PRIVATE_MSGS%)<>0 Then
  1207.         CaptureLine "Private Messages not allowed"
  1208.     Else
  1209.         CaptureLine "Private Messages are allowed"
  1210.     End If
  1211.     CaptureLine ""
  1212.     On Error Resume Next
  1213.  
  1214.     ' Get the message section names for the forum from Compuserve
  1215.     CaptureLine "Message Sections Available:"
  1216.     For i = 0 To UBound(szMsgSection)
  1217.         buf = Str(szMsgSection(i).cId)+" "+szMsgSection(i).lpTitle
  1218.         ReplaceAnyInString buf, "_", " "
  1219.         CaptureLine buf
  1220.     Next
  1221.     CaptureLine ""
  1222.  
  1223.     ' Get the library section names for the forum from Compuserve
  1224.     CaptureLine "Libraries Available:"
  1225.     For i = 0 To UBound(szLibSection)
  1226.         buf = Str(szLibSection(i).cId)+" "+szLibSection(i).lpTitle
  1227.         ReplaceAnyInString buf, "_", " "
  1228.         CaptureLine buf
  1229.     Next
  1230.  
  1231.     FinishCapturing
  1232. End Sub
  1233.  
  1234.