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

  1. 'T:HMIFORUM.EBS for CompuServe
  2. ' VA 4.01 release
  3.  
  4. Declare Function ParseString(args As String, delim As String) As String
  5. Declare Function FileName$(fullpath As String)
  6. Declare Sub AddToMsgFile(SourceFileName as String)
  7. Declare Function QueueFile(service As String, sfilename As String, queueflags As Long) As Boolean
  8. Declare Function MyDate$
  9. Declare Function StartMessageDownload(id As String, forum As String, sections As String, markunread As Boolean) As Integer
  10. Declare Sub SearchMessages(searchtype As Integer, searchstring As String, bodies As Boolean, rootsonly As Boolean, unreadonly As Boolean, lastdays As String)
  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 Sub ReadNumber(id As String, forum As String, number As String)
  15. Declare Sub LogResult(result As String)
  16. Declare Sub RecordFileDownload(topic As String, fname As String)
  17. Declare Function UniqueFileName$()
  18. Declare Function FileUrl(fn As String) As String
  19. Declare Sub AsciiListHeldMessages(id As String, forum As String, sections As String)
  20. Declare Function ParseSectionList(ByVal sect As String, ByVal validsects As Long, _
  21.                           ByRef count As Integer) As Long
  22. Declare Sub SaveMessage(hdr As FAPMSGHEADER, body As String)
  23. Declare Sub WriteLibraryMessage(forum As String, filedesc As FAPFILEDESCRIPTION, downloaded As String)
  24. Declare Function MakeDateString(s As HMITIMESTAMP) As String
  25. Declare Function GetFileType(i As Integer) As String
  26. Declare Function CheckCache(pagetype As String, npage As String, pversion As Long) As String
  27. Declare Sub UpdateCache(pagetype As String, npage As String, pversion As Long, newpage As String)
  28. Declare Function CompareDates(d1 As HMIDATE, d2 As HMIDATE) As Integer
  29. Declare Sub StartCapturing(pseudoforum As String, title As String, formatted As Boolean)
  30. Declare Sub FinishCapturing
  31. Declare Function SectionNumber(ByVal section As String)
  32. Declare Sub AsciiUserLog(id As String, forum As String)
  33. Declare Sub FinishMessageDownload(id As String)
  34. Declare Sub NewSearchLibrary(id As String, forum As String, catalog As String, _
  35.                   ssections As String, filename As String, uploadby As String, _
  36.                   age As String, accesscount As String, keywords As String, _
  37.                   title As String, description As String, full As String, _
  38.                   replace As String)
  39.  
  40. Const BlockSize = 2048
  41.  
  42. Const IM_DELETE = 2048        ' Delete scratchpad file afterwards?
  43. Const IM_MARKUNREAD = 131072
  44.  
  45. Const fRECEIPT = 1
  46. Const fPRIVATE = 2
  47. Const fNOFORMAT = 4
  48.  
  49. Public InAscii As Boolean
  50. Public DownloadDir As String    'where downloads go
  51. Public WorkingPath As String    'added to speed up Fetch stuff online
  52. Public WhereAmI As String        'name of last forum/page etc
  53. Public Sysop As Boolean            'are we a sysop?
  54. Public Nisa As Boolean          'do we need to work round NISA "features" ?
  55. Public SetHighMessage As Boolean'True if you want a 'high;l' when leaving forum
  56.  
  57. Public currentCAP As Integer
  58. Public FAPconfig As FAPCONFIG
  59. Public SectionMsgIds(32) As Integer, SectionLibIds(32) As Integer
  60. Public szMsgSection() As FAPSECTIONENTRY, szLibSection() As FAPSECTIONENTRY
  61. Public nummessages As Integer
  62. Public CurrentForum As String
  63.  
  64. Dim LastDownMessages As String
  65. Dim capturefilename As String
  66. Dim messagefilename As String
  67. Dim sectionvector As Long, filterVector As Long
  68.  
  69. Const ALL_HEADER_FIELDS% = &HFF3
  70. Const FAP_FDC_FILE_TYPE% = &H4
  71. Const FAP_FDC_FILE_SIZE% = &H8
  72. Const FAP_FDC_ABSTRACT% = &H100
  73.  
  74. Const FAP_SFH_FILENAME% = 0
  75. Const FAP_SFH_USER_ID% = FAP_SFH_FILENAME + 1
  76. Const FAP_SFH_KEYWORD% = FAP_SFH_USER_ID + 1
  77. Const FAP_SFH_ACCESS_COUNT% = FAP_SFH_KEYWORD + 1
  78. Const FAP_SFH_DATE_RANGE% = FAP_SFH_ACCESS_COUNT + 1
  79. Const FAP_SFH_LAST_ACCESS_RANGE% = FAP_SFH_DATE_RANGE + 1
  80. Const FAP_SFH_FILE_ABSTRACT% = FAP_SFH_LAST_ACCESS_RANGE + 1
  81. Const FAP_SFH_FILE_BODY% = FAP_SFH_FILE_ABSTRACT + 1
  82. Const FAP_SFH_MATCH_NON_PUBLIC_ONLY% = FAP_SFH_FILE_BODY + 1
  83. Const FAP_SFH_SIZE_RANGE% = FAP_SFH_MATCH_NON_PUBLIC_ONLY + 1
  84. Const FAP_SFH_TITLE% = FAP_SFH_SIZE_RANGE + 1
  85.  
  86. Const DAP_AL_VOLATILE = &H02
  87. Const DAP_AP_SESSION_ONLY = &H01
  88. Const DAP_AP_VOLATILE = &H02
  89. Const DAP_AP_EX_HAVE_TITLE% = &H0100
  90. Const DAP_AP_HAVE_HEADER% = &H04
  91. Const DAP_AP_HAVE_TRAILER% = &H08
  92. Const HMI_DATA_SIZE% = 1024
  93. Const HMI_STATE_FIRST% = 0
  94. Const HMI_STATE_NEXT% = HMI_STATE_FIRST + 1
  95. Const FAP_USF_HIGH_MSG% = &H2
  96. Const FAP_USF_NAME% = &H4
  97. Const FAP_USR_JOIN% = &H1
  98. Const FAP_USR_PERMANENT% = &H2
  99. Const FAP_WAITING_MSGS% = &H1
  100. Const FAP_NEW_BULLETINS% = &H2
  101. Const FAP_CONFERENCE_IN_PROGRESS% = &H4
  102. Const FAP_NOT_A_MEMBER% = &H8
  103. Const FAP_IS_SYSOP% = &H10        ' user is SYSOP in this Forum
  104. Const FAP_FREE_USER% = &H20
  105. Const FAP_LOCKED_OUT% = &H40
  106. Const FAP_TRANSACTION_BILLING% = &H80
  107. Const FAP_ALLOW_MULTIPLE_SEARCH% = &H100
  108. Const FAP_NISA_FORUM% = &H200
  109.  
  110. Const FAP_MSS_ALL_MSGS% = 0
  111. Const FAP_MSS_WAITING_MSGS% = FAP_MSS_ALL_MSGS + 1
  112. Const FAP_MSS_SUBJECT_TEXT% = FAP_MSS_WAITING_MSGS + 1
  113. Const FAP_MSS_ORIGINATOR_NAME% = FAP_MSS_SUBJECT_TEXT + 1
  114. Const FAP_MSS_RECIPIENT_NAME% = FAP_MSS_ORIGINATOR_NAME + 1
  115. Const FAP_MSS_MSGS_WITHOUT_REPLIES% = FAP_MSS_RECIPIENT_NAME + 1
  116. Const FAP_MSS_HELD_MSGS% = FAP_MSS_MSGS_WITHOUT_REPLIES + 1
  117. Const FAP_MSS_PRIVATE_MSGS% = FAP_MSS_HELD_MSGS + 1        ' to the user
  118. Const FAP_MSS_MSGS_WITHOUT_SYSOP_REPLIES% = FAP_MSS_PRIVATE_MSGS + 1
  119. Const FAP_MSS_MESSAGE_BODY% = FAP_MSS_MSGS_WITHOUT_SYSOP_REPLIES + 1
  120. Const FAP_MSS_POSTING_DATE_RANGE% = FAP_MSS_MESSAGE_BODY + 1
  121. Const FAP_MSS_EXPIRATION_DATE_RANGE% = FAP_MSS_POSTING_DATE_RANGE + 1
  122. Const FAP_MSS_MESSAGES_HAS_BEEN_READ% = FAP_MSS_EXPIRATION_DATE_RANGE + 1
  123.  
  124. Const FAP_NO_MESSAGE_READ% = &H1
  125. Const FAP_NO_MESSAGE_SEND% = &H2
  126. Const FAP_NO_LIBRARY_READ% = &H4
  127. Const FAP_NO_LIBRARY_SEND% = &H8
  128. Const FAP_NO_CONFERENCE% = &H10
  129. Const FAP_NO_PRIVATE_MSGS% = &H20
  130. Const FAP_NO_MEMBERSHIP% = &H80
  131. Const FAP_PRIVATE_FORUM% = &H100
  132. Const FAP_RTC_CONFIG_SUPPORTED% = &H200
  133. Const FAP_SEARCH_LIBRARY_ABSTRACTS% = &H400   ' Full text search of file abstrats allowed
  134. Const FAP_SEARCH_LIBRARY_FILES% = &H800              ' Search text file contents
  135. Const FAP_SEARCH_MESSAGE_BODIES% = &H1000     ' Searching message bodies allowed
  136. Const FAP_LIBRARY_ONLY_FORUM% = &H2000
  137.  
  138. Const FAP_PRIVATE_MESSAGE% = &H1
  139. Const FAP_EXTENDED_MESSAGE% = &H80
  140.  
  141. Const FAP_MC_THREAD_ID% = &H1000
  142. Const FAP_MC_THREADS% = &H8000
  143.  
  144. Const FAP_MSR_PSEUDO_ROOTS% = &H80
  145.  
  146. Sub RecordAlert(alert As DAPALERTPAGE)
  147.     Dim nextpage As String
  148.     
  149.     On Error Resume Next
  150.     CaptureLine alert.lpHeader
  151.     CaptureLines alert.lpBody
  152.     CaptureLine alert.lpTrailer
  153. End Sub
  154.  
  155. Sub CaptureAlert(forum As String, page As String)
  156.     Dim alert As DAPALERTPAGE
  157.     Dim nextpage As String
  158.     
  159.     On Error Resume Next
  160.     HMIGetAlert alert
  161.     If (alert.cOptions And DAP_AL_VOLATILE) = 0 Then
  162.         nextpage = CheckCache("Alerts", nextpage, 0)
  163.         If nextpage > "" Then 
  164.             page = nextpage
  165.             Exit Sub
  166.         End If
  167.         UpdateCache "Alerts", page, 0, alert.lpNextPage
  168.     End If
  169.     page = alert.lpNextPage
  170.     If StrComp(Mid$(forum, 1, 4), "CIS:", 1)=0 Then
  171.         StartCapturing Mid$(forum, 5)+"/Alerts", "Alert recieved going to " + page, False
  172.     Else
  173.         StartCapturing forum+"/Alerts", "Alert recieved going to " + page, False
  174.     End If
  175.     RecordAlert alert
  176.     FinishCapturing
  177. End Sub
  178.  
  179. Sub RecordArticleText(article As DAPARTICLEPAGE)
  180.     Dim textbuf As String
  181.     Dim state As Integer
  182.  
  183.     On Error Resume Next
  184.     If article.wExtendedOptions And DAP_AP_EX_HAVE_TITLE Then CaptureLine article.lpTitle
  185.     If article.cOptions And DAP_AP_HAVE_HEADER Then CaptureLine article.lpHeader
  186.     If article.cOptions And DAP_AP_HAVE_TRAILER Then CaptureLine article.lpTrailer
  187.     state = HMI_STATE_FIRST%
  188.     Do While DAPArticleRead(state, page, 1, HMI_DATA_SIZE, textbuf)
  189.         CaptureLines textbuf
  190.         If textbuf = "" Then Exit Do
  191.         state = HMI_STATE_NEXT%
  192.     Loop
  193. End Sub
  194.  
  195. Sub CaptureArticleText(nextpage As String)
  196.     Dim article As DAPARTICLEPAGE
  197.  
  198.     On Error Resume Next
  199.     HMIGetArticle article
  200.     If (article.cOptions And (DAP_AP_SESSION_ONLY Or DAP_AP_VOLATILE)) = 0 Then
  201.         nextpage = CheckCache("Articles", article.lpName, article.pvVersion)
  202.         If nextpage > "" Then Exit Sub
  203.         UpdateCache "Articles", article.lpName, article.pvVersion, article.lpNextPage
  204.     End If
  205.     nextpage = article.lpNextPage
  206.     StartCapturing "Actions/Articles", Basic.Eoln$ + "Article recieved when going to " + page, False
  207.     RecordArticleText article
  208.     FinishCapturing
  209. End Sub
  210.  
  211. Sub RecordBulletins(forum As String, getnews As Boolean, _
  212.                     getothers As Boolean, getuserlog As Boolean)
  213.     Dim bulletins As FAPBULLETINCONFIG
  214.     Dim entry() as FAPBULLETINENTRY
  215.     Dim i As Integer
  216.     Dim textbuf As String
  217.  
  218.     ' We must be a member
  219.     If FAPconfig.wAlerts And FAP_NOT_A_MEMBER% Then
  220.         Exit Sub
  221.     End If
  222.  
  223.     FAPGetBulletinConfig bulletins, entry()
  224.     For i = 0 To UBound(entry)
  225.         ' Are we interested in this one ?
  226.         If ((getnews And (entry(i).lpTitle="News Flash" Or _
  227.                           entry(i).lpTitle="Newsflash" Or _
  228.                           entry(i).lpTitle="Aktuelles")) Or _
  229.             (getuserlog And entry(i).lpTitle="User Log") Or _
  230.             (getothers And entry(i).lpTitle<>"News Flash" And _
  231.                            entry(i).lpTitle<>"User Log" And _
  232.                            entry(i).lpTitle<>"Newsflash")) Then
  233.             If entry(i).lpTitle="News Flash" Or _
  234.                entry(i).lpTitle="Aktuelles" Or _ 
  235.                entry(i).lpTitle="Newsflash" Then
  236.                 StartCapturing forum+"/Newsflash", "CompuServe", True
  237.             Else
  238.                 If entry(i).lpTitle="User Log" Then
  239.                     StartCapturing forum+"/Sysop_Logs", "User_Log", True
  240.                 Else
  241.                     StartCapturing forum+"/Announcements", "CompuServe", True
  242.                 End If
  243.             End If
  244.             CaptureLine entry(i).lpTitle
  245.             textbuf = FAPBulletinRead(HMI_STATE_FIRST%, entry(i).nId, 1, HMI_DATA_SIZE)
  246.             While textbuf > ""
  247.                 CaptureLines textbuf
  248.                 textbuf = FAPBulletinRead(HMI_STATE_NEXT%, entry(i).nId, 1, HMI_DATA_SIZE)
  249.             Wend
  250.             FinishCapturing
  251.         End If
  252.     Next
  253. End Sub
  254.  
  255. Sub SetHighMessageNumber()
  256.     Dim b As Integer
  257.  
  258.     ' Don't set HMN if HMI error
  259.     If Err = 1009 Then
  260.         Err = 0
  261.         SetHighMessage = False
  262.     End If
  263.  
  264.     If SetHighMessage Then
  265.         If currentCAP = CAP_FORUM Then
  266.             Terminal.Print "Updating the high message number to " & FAPconfig.dwNewestMsg & " in " & CurrentForum & Basic.Eoln$
  267.             b = FAPSetUserProfile(FAP_USR_PERMANENT%, FAP_USF_HIGH_MSG%, FAPconfig.dwNewestMsg, "")
  268.         End If
  269.         SetHighMessage = False
  270.     End If
  271. End Sub
  272.  
  273. 'T:CollectSections
  274. Sub CollectSections(forum As String)
  275.     Dim sctMsg As FAPSECTIONS, sctLib As FAPSECTIONS
  276.     Dim i As Integer
  277.     Dim sNam As String
  278.     Dim bMessages As Integer, bLibraries As Integer
  279.  
  280.     ' Initialise variables
  281.     For i = 0 To 32
  282.         SectionMsgIds(i) = -1
  283.         SectionLibIds(i) = -1
  284.     Next
  285.  
  286.     ' We must be a member
  287.     If FAPconfig.wAlerts And FAP_NOT_A_MEMBER% Then
  288.         Exit Sub
  289.     End If
  290.  
  291.     Terminal.Print "Collecting section information" + Basic.Eoln$
  292.     On Error Goto CollectMsgSections_error
  293.  
  294.     ' Get the msg section names for the forum from Compuserve
  295.     FAPReadMsgSections sctMsg, szMsgSection()
  296.     For i = 0 To UBound(szMsgSection)
  297.         sectionMsgIds(szMsgSection(i).cId) = i
  298.         ReplaceAnyInString szMsgSection(i).lpTitle, " /", "_"
  299.     Next
  300.     bMessages = True
  301. CollectMsgSections_resume:
  302.  
  303.     ' Get the lib section names for the forum from Compuserve
  304.     On Error Goto CollectLibSections_error
  305.     FAPReadLibSections sctLib, szLibSection()
  306.     For i = 0 To UBound(szLibSection)
  307.         sectionLibIds(szLibSection(i).cId) = i
  308.         ReplaceAnyInString szLibSection(i).lpTitle, " /", "_"
  309.     Next
  310.     bLibraries = True
  311.  
  312. CollectLibSections_resume:
  313.     On Error Goto 0
  314.     Err = 0
  315.  
  316.     ' Cope with ZNT:<forum>
  317.     If InStr(forum, ":")<>0 Then
  318.         sNam = Mid$(forum, InStr(forum, ":")+1, 8)+".nam"
  319.     Else
  320.         sNam = Mid$(forum, 1, 8)+".nam"
  321.     End If
  322.  
  323.     ' Create the .NAM file
  324.     DeleteFile Session.ServicePath+sNam
  325.     Capture CAPTURE_ON, Session.ServicePath+sNam
  326.     If InStr(forum, ":")<>0 Then
  327.         CaptureLine "#forum " + Mid$(forum, InStr(forum, ":")+1)
  328.     Else
  329.         CaptureLine "#forum " + forum
  330.     End If
  331.  
  332.     ' Write forum info
  333.     If (FAPconfig.wAlerts And FAP_IS_SYSOP%)<>0 Then CaptureLine "SYSOP"
  334.     If (FAPconfig.wAlerts And FAP_FREE_USER%)<>0 Then CaptureLine "Free Flag"
  335.     If (FAPconfig.wAlerts And FAP_NISA_FORUM%)<>0 Then CaptureLine "NISA Forum"
  336.     If (FAPconfig.wRestrictions And FAP_NO_PRIVATE_MSGS%)<>0 Then
  337.         CaptureLine "Private Messages not allowed"
  338.     Else
  339.         CaptureLine "Private Messages are allowed"
  340.     End If
  341.     On Error Resume Next
  342.  
  343.     ' Get the message section names for the forum from Compuserve
  344.     CaptureLine "Message Sections Available:"
  345.     If bMessages Then
  346.         For i = 0 To UBound(szMsgSection)
  347.             CaptureLine Str(szMsgSection(i).cId)+" "+szMsgSection(i).lpTitle
  348.         Next
  349.     End If
  350.  
  351.     ' Get the library section names for the forum from Compuserve
  352.     CaptureLine "Libraries Available:"
  353.     If bLibraries Then
  354.         For i = 0 To UBound(szLibSection)
  355.             CaptureLine Str(szLibSection(i).cId)+" "+szLibSection(i).lpTitle
  356.         Next
  357.     End If
  358.  
  359.     ' Clear up
  360.     Capture CAPTURE_OFF
  361.     On Error Goto 0
  362.     Exit Sub
  363. CollectMsgSections_error:
  364.     Resume CollectMsgSections_resume
  365. CollectLibSections_error:
  366.     Resume CollectLibSections_resume
  367. End Sub
  368.  
  369. ' Intelligently GO forum only
  370. Function HMIGotoForum(ByVal forum As String) As Boolean
  371.     Dim filename As String, myerror As String, i As Integer
  372.     Dim fname As String, preforum As String, tmp As String
  373.  
  374.     ' Sort out any switch between ascii/hmi
  375.     If InAscii Then
  376.         ResetForum
  377.         InAscii = False
  378.     End If
  379.  
  380.     ' Mangle the forum name a bit
  381.     forum = ParseString(forum, "/")
  382.     fname = forum
  383.     If Instr(forum, ":")=0 Then
  384.         forum = "cis:"+forum
  385.     End If
  386.  
  387.     ' Use the lookup table to auto-convert menus to forums.
  388.     ' eg. 'PCPLUS' -> 'PCPFORUM'
  389.     preforum = forum
  390.     forum = LookupForum(preforum)
  391.  
  392.     ' If we're already here then do nothing
  393.     If StrComp(WhereAmI, fname, 1)<>0 And StrComp(WhereAmI, forum, 1)<>0 _
  394.        And StrComp(WhereAmI, preforum, 1)<>0 Then
  395.         SetHighMessageNumber
  396.         If StrComp(WhereAmI, "cis:mail", 1)<>0 Then
  397.             If WhereAmI<>"" Then
  398.                 Terminal.Print "Leaving " & WhereAmI & Basic.Eoln$ & Basic.Eoln$
  399.             End If
  400.         End If
  401.         Terminal.Print Basic.Eoln$+"Go " & forum & Basic.Eoln$ & Basic.Eoln$
  402.         On Error Goto GoForum_error
  403.         HMIGotoForum = False
  404.         If Not DoHMIGoToPage(forum, -1, CAP_FORUM) Then
  405.             If currentCAP <> CAP_ERROR Then myerror = "Not a forum"
  406.             goto GoForum_error
  407.         End If
  408.  
  409.         HMIGetFAPConfig FAPconfig
  410.         Sysop = ((FAPconfig.wAlerts And FAP_IS_SYSOP%) <> 0)
  411.         Nisa = ((FAPconfig.wAlerts And FAP_NISA_FORUM%) <> 0)
  412.  
  413.         Terminal.Print "Welcome to " & FAPconfig.lpForumName & " Forum" & Basic.Eoln$
  414.         Terminal.Print "Hello, " & FAPconfig.lpUserName
  415.         If Sysop Then Terminal.Print " (Sysop)"
  416.         If (FAPconfig.wAlerts And FAP_FREE_USER%)<>0 Then Terminal.Print " (Free)"
  417.         Terminal.Print Basic.Eoln$
  418.         If Nisa Then Terminal.Print "This is a NISA forum" & Basic.Eoln$
  419.         If FAPconfig.tsLastAccess.cYear>0 Then
  420.             Terminal.Print "Last visit: " & MakeDateString(FAPconfig.tsLastAccess) & Basic.Eoln$
  421.         Else
  422.             Terminal.Print "Last visit: Never" & Basic.Eoln$
  423.         End If
  424.         Terminal.Print "Forum messages: " & FAPconfig.dwMsgNoBase & " to " & FAPconfig.dwNewestMsg & Basic.Eoln$
  425.         Terminal.Print "Last message you've read: " & FAPconfig.dwLastMsgRead & Basic.Eoln$
  426.         If FAPconfig.wAlerts And FAP_WAITING_MSGS% Then
  427.             Terminal.Print Basic.Eoln$ & "You have waiting message(s)" & Basic.Eoln$
  428.         End If
  429.         Terminal.Print Basic.Eoln$
  430.  
  431.         If FAPconfig.wAlerts And FAP_LOCKED_OUT% Then
  432.             myerror = "User locked out"
  433.             goto GoForum_error
  434.         End If
  435.         If FAPconfig.wAlerts And FAP_NEW_BULLETINS% Then
  436.             Terminal.Print "Collecting updated Newsflash" + Basic.Eoln$
  437.             RecordBulletins fname, True, False, False
  438.         End If
  439.         Terminal.Status "HMIGotoForum: "+fname
  440.         On Error Goto 0
  441.  
  442.         ' It all worked
  443.         If Instr(fname, ":")=0 Then
  444.             WhereAmI = "cis:"+fname
  445.         Else
  446.             WhereAmI = fname
  447.         End If
  448.  
  449.         CollectSections WhereAmI
  450.     End If
  451.  
  452.     LastFailure = ""
  453.     HMIGotoForum = True
  454.     Exit Function
  455.  
  456. GoForum_error:
  457.     On Error Goto 0
  458.     If myerror = "" Then myerror = FullErrorMessage
  459.     Terminal.Print "Error: " & myerror & Basic.Eoln$
  460.     LogResult "HMIGotoForum : "+forum+" : Failed Error : "+myerror
  461.     LastFailure = forum
  462.     SetHighMessage = False
  463.  
  464.     ' If it was a PTE and HMI packet size was 2k then reduce to 1k and inform
  465.     ' the user.
  466.     If InStr(myerror, "1285:Protocol transport error", 1)<>0 And _
  467.        ReadIni$(Session.IniSection, "HMI Packet Size", Session.IniFilename)="2048" Then
  468.         WriteIni Session.IniSection, "HMI Packet Size", "1024", Session.IniFilename
  469.          LogResult "_NOTE_Reducing_HMI_packet_size_for_improved_connection_reliability_"
  470.     End If
  471. End Function
  472.  
  473. 'T:SetHigh (subroutine) (CompuServe)
  474. ' Set high message number
  475. Sub SetHigh(id As String, forum As String, num As String)
  476.     Dim hmn As Long, b As Integer
  477.  
  478.     If Not HMIGotoForum(forum) Then
  479.         LogResult id + " : Failed : Unable to set high message number in "+forum
  480.         Exit Sub
  481.     End If
  482.     hmn = Val(num)
  483.     If hmn < 0 Then hmn = FAPconfig.dwNewestMsg+hmn
  484.     If hmn = 0 Then hmn = FAPconfig.dwNewestMsg
  485.  
  486.     ' Set high number
  487.     Terminal.Print "Setting the high message number to" & Str(hmn) & Basic.Eoln$
  488.     b = FAPSetUserProfile(FAP_USR_PERMANENT%, FAP_USF_HIGH_MSG%, hmn, "")
  489.  
  490.     If id<>"" Then
  491.         If b=0 Then
  492.             ReportSuccess id & " : Failed to Set High Message Number to #" & hmn & " in " & forum
  493.         Else
  494.             ReportSuccess id & " : Set High Message Number to #" & hmn & " in " & forum
  495.             HMIGetFAPConfig FAPconfig
  496.         End If
  497.     Else
  498.         HMIGetFAPConfig FAPconfig
  499.     End If
  500. End Sub
  501.  
  502. Function CheckTopicBeforePosting(id As String, topic As String, _
  503.          section As Integer, subject As String, checksection As Boolean) As Boolean
  504.     Dim i As Integer
  505.  
  506.     If Not HMIGotoForum(topic) Then
  507.         LogResult id + " : Failed : Unable to post message."
  508.         Exit Function
  509.     End If
  510.  
  511.     If FAPconfig.wRestrictions And FAP_NO_MESSAGE_SEND% Then
  512.         LogResult id + " : Failed : Posting not allowed in forum " & topic
  513.         Exit Function
  514.     End If
  515.  
  516.     ' Truncate subject to 24 chars and make it valid
  517.     If Len(subject) > 24 Then subject = Left$(subject, 24)
  518.     For i = 1 To Len(subject)
  519.         If InStr(";""", Mid(subject, i, 1)) Then Mid(subject, i, 1) = " "
  520.     Next
  521.  
  522.     section = Val(SectionNumber(topic))
  523.     If checksection Then
  524.         If (FAPconfig.svMsgSections And (2 ^ section)) = 0 Then
  525.             LogResult id + " : Failed : Unknown section " & topic
  526.             Exit Function
  527.         End If
  528.     End If
  529.     CheckTopicBeforePosting = True
  530. End Function
  531.  
  532. 'T:Say (subroutine) (CompuServe)
  533. Sub Say(id As String, topic As String, pfrom As String, pto As String, flags As Integer, subject As String, filename As String)
  534.     Dim hdr As FAPMSGHEADER, body As String
  535.     Dim section As Integer, cOptions As Integer
  536.     Dim username As String, userid As String, lastname As String
  537.     Dim noformat As Integer, b As Integer
  538.  
  539.     ' Is it usenet?
  540.     If Mid(topic, 1, 7)="usenet." Then
  541.         UsenetPost id, topic, filename
  542.         Exit Sub
  543.     End If
  544.  
  545.     If Not CheckTopicBeforePosting(id, topic, section, subject, True) Then
  546.         Exit Sub
  547.     End If
  548.  
  549.     If (flags And fPRIVATE) <> 0 Then
  550.         Terminal.Print "Posting private message to " + pto + " Subj: " + subject + Basic.Eoln$
  551.     Else
  552.         Terminal.Print "Posting message to " + pto + " Subj: " + subject + Basic.Eoln$
  553.     End If
  554.     AnalyseName pto, username, userid
  555.     If StrComp(userid, "all", 1)=0 Or _
  556.        StrComp(userid, "sysop", 1)=0 Or _
  557.        StrComp(userid, "*sysop", 1)=0 Then
  558.         username = userid
  559.         userid = ""
  560.         userid=userid
  561.     ElseIf Not IsNumeric(Mid$(userid, 1, 1)) Then
  562.         username = username + " " + userid
  563.         userid = ""
  564.     End If
  565.  
  566.     ' What posting flags ?
  567.     If flags And fNOFORMAT Then noformat = 1
  568.     If (flags And fPRIVATE) <> 0 Then
  569.         If (FAPconfig.wRestrictions And FAP_NO_PRIVATE_MSGS%) = 0 Then
  570.             cOptions = FAP_PRIVATE_MESSAGE%
  571.         Else
  572.             MailTo id, pto, 0, subject, filename
  573.             SendMail id
  574.             Exit Sub
  575.         End If
  576.     End If
  577.  
  578.     ' What's our name
  579.     If pfrom <> "" Then
  580.         On Error Resume Next
  581.         lastname = FAPconfig.lpUserName
  582.         b = FAPSetUserProfile(0, FAP_USF_NAME%, 0, pfrom)
  583.         On Error Goto 0
  584.     End If
  585.  
  586.     ' Get body text
  587.     body = ReadMessageFile(filename, noformat)
  588.  
  589.     On Error Goto Say_error
  590.     On Error Resume Next    'NB Bug in CCT230B always gives error here
  591.     FAPSendMsg hdr, section, subject, username, userid, cOptions, body
  592.  
  593.     ' Change back to old name
  594.     If lastname <> "" Then
  595.         On Error Resume Next
  596.         b = FAPSetUserProfile(0, FAP_USF_NAME%, 0, lastname)
  597.         On Error Goto 0
  598.     End If
  599.  
  600.     If hdr.dwMsgNo = 0 Then
  601.         LogResult id + " : Failed : Posting Compose to " & topic
  602.     Else
  603.         ReportSuccess id & " : Posted Compose to " & pto & " in " & topic & " As #" & hdr.dwMsgNo
  604.         HMIGetFAPConfig FAPconfig
  605.     End If
  606.     Exit Sub
  607. Say_error:
  608.     LogResult id + " : Failed : Posting Compose to " & topic & " - Error:" & FullErrorMessage
  609. End Sub
  610.  
  611. 'T:UnjoinedSay (subroutine) (CompuServe)
  612. Sub UnjoinedSay(id As String, topic As String, pto As String, subject As String, filename As String)
  613.     Say id, topic, "", pto, 0, subject, filename
  614. End Sub
  615.  
  616. 'T:Comment (subroutine) (CompuServe)
  617. 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)
  618.     Dim hdr As FAPMSGHEADER, body As String
  619.     Dim section As Integer, cOptions As Integer
  620.     Dim username As String, userid As String, lastname As String
  621.     Dim msgno As Long, threadid As Long
  622.     Dim noformat As Integer
  623.  
  624.     ' Is it usenet?
  625.     If Mid(topic, 1, 7)="usenet." Then
  626.         UsenetPost id, topic, filename
  627.         Exit Sub
  628.     End If
  629.  
  630.     If Not CheckTopicBeforePosting(id, topic, section, subject, False) Then
  631.         Exit Sub
  632.     End If
  633.  
  634.     If (flags And fPRIVATE) <> 0 Then
  635.         Terminal.Print "Replying privately to message #"+message+" Subj: "+subject+Basic.Eoln$
  636.     Else
  637.         Terminal.Print "Replying to message #"+message+" Subj: "+subject+Basic.Eoln$
  638.     End If
  639.  
  640.     ' What posting flags ?
  641.     If flags And fNOFORMAT Then noformat = 1
  642.     If (flags And fPRIVATE) <> 0 Then
  643.         If (FAPconfig.wRestrictions And FAP_NO_PRIVATE_MSGS%) = 0 Then
  644.             cOptions = FAP_PRIVATE_MESSAGE%
  645.         Else
  646.             MailTo id, pto, 0, "Re: "+subject, filename
  647.             SendMail id
  648.             Exit Sub
  649.         End If
  650.     End If
  651.  
  652.     ' What's our name
  653.     If pfrom <> "" Then
  654.         On Error Resume Next
  655.         lastname = FAPconfig.lpUserName
  656.         b = FAPSetUserProfile(0, FAP_USF_NAME%, 0, pfrom)
  657.         On Error Goto 0
  658.     End If
  659.  
  660.     ' Collect message text ready to send to CIS
  661.     body = ReadMessageFile(filename, noformat)
  662.  
  663.     On Error Resume Next
  664.     msgno = Val(message)
  665.     FAPReadMsgHeader hdr, msgno, FAP_MC_THREAD_ID%
  666.     threadid = hdr.dwThreadID
  667.     If threadid <> 0 Then
  668.         FAPSendReply hdr, msgno, threadid, cOptions, body
  669.     Else
  670.         hdr.dwMsgNo = 0
  671.     End If
  672.     If hdr.dwMsgNo = 0 Then
  673.         AnalyseName pto, username, userid
  674.         FAPSendMsg hdr, section, "#"+message+"-"+subject, username, userid, cOptions, body
  675.         If hdr.dwMsgNo = 0 Then
  676.             LogResult id + " : Failed : Posting Reply to " & message & " in " & topic & " - error: " & FullErrorMessage()
  677.  
  678.             ' Change back to old name
  679.             If lastname <> "" Then
  680.                 On Error Resume Next
  681.                 b = FAPSetUserProfile(0, FAP_USF_NAME%, 0, lastname)
  682.                 On Error Goto 0
  683.             End If
  684.             Exit Sub
  685.         End If
  686.     End If
  687.     ReportSuccess id & " : Posted Reply to " & message & " in " & topic & " As #" & hdr.dwMsgNo
  688.  
  689.     ' Change back to old name
  690.     If lastname <> "" Then
  691.         On Error Resume Next
  692.         b = FAPSetUserProfile(0, FAP_USF_NAME%, 0, lastname)
  693.         On Error Goto 0
  694.     End If
  695.  
  696.     HMIGetFAPConfig FAPconfig
  697.     Exit Sub
  698. End Sub
  699.  
  700. 'T:DownMessages (subroutine) (CompuServe)
  701. ' Download full message text
  702. Sub DownMessages(id As String, forum As String, sections As String)
  703.     Dim hdr As FAPMSGHEADER, sect As Long
  704.     Dim txt As String, body As String, t As String
  705.     Dim count As Integer, i As Integer, newmsgs As Long
  706.  
  707.     sections = Trim$(LTrim$(sections))
  708.  
  709.     If StartMessageDownload(id, forum, sections, False) Then
  710.         On Error Goto DownMessages_error
  711.  
  712.         sect = ParseSectionList(sections, FAPconfig.svMsgSections, count)
  713.  
  714.         If count > 0 Then
  715.             Dim lpStartWith(0 To count-1) As FAPSTARTWITH
  716.  
  717.             'Fill in the FAPSTARTWITH structures for each section
  718.             count = 0
  719.             For i = 0 To 24
  720.                 sl = 2^i
  721.                 If (sect And (2^i))<>0 Then
  722.                     lpStartWith(count).cSectionID = i
  723.                     lpStartWith(count).dwMsgNo = FAPconfig.dwLastMsgRead
  724.                     count = count + 1
  725.                 End If
  726.             Next
  727.  
  728.             'Ask HMI for all new messages after the start
  729.             FAPReadNewMsgs ALL_HEADER_FIELDS, lpStartWith()
  730.             'Now read the actual messages
  731.             Do
  732.                 hdr.dwMsgNo = 0
  733.                 FAPReadSingleNewMsgHdr hdr
  734.                 If hdr.dwMsgNo = 0 Then Exit Do        'Finished
  735.                 body = ""
  736.                 Do
  737.                     txt = "" ' possible memory leak
  738.                     txt = FAPReadNewMessageBody(hdr)
  739.                     body = body + txt
  740.                 Loop While txt > ""
  741.                 SaveMessage hdr, body
  742.                 newmsgs = newmsgs + 1
  743.             Loop
  744.         End If
  745.         Terminal.Print "Collected " & newmsgs & " new message(s)" & Basic.Eoln$
  746.         If count>0 Then SetHighMessage = True
  747.     End If
  748.     FinishMessageDownload id
  749.     Exit Sub
  750. DownMessages_error:
  751.     LogResult "Error:" & FullErrorMessage & " collecting messages from " & forum
  752.     CaptureLine "Error:" & FullErrorMessage
  753.     FinishMessageDownload id
  754. End Sub
  755.  
  756. 'T:DownHeaders (subroutine) (CompuServe)
  757. Sub DownHeaders(id As String, forum As String, sections As String)
  758.     If StartMessageDownload(id, forum, sections, False) Then
  759.         SearchMessages FAP_MSS_ALL_MSGS%, "", False, False, True, ""
  760.         If Len(Trim$(LTrim$(sections)))>0 Then SetHighMessage = True
  761.     End If
  762.     FinishMessageDownload id
  763. End Sub
  764.  
  765. 'T:DownRoots (subroutine) (CompuServe)
  766. Sub DownRoots(id As String, forum As String, sections As String)
  767.     If StartMessageDownload(id, forum, sections, False) Then
  768.         SearchMessages FAP_MSS_ALL_MSGS%, "", False, True, True, ""
  769.         If Len(Trim$(LTrim$(sections)))>0 Then SetHighMessage = True
  770.     End If
  771.     FinishMessageDownload id
  772. End Sub
  773.  
  774. 'T:SearchForMessages (subroutine) (CompuServe)
  775. Sub SearchForMessages(id As String, forum As String, sections As String, lastdays As String, searchtype As String, searchstring As String)
  776.     Dim hmn As Long
  777.  
  778.     If Not HMIGotoForum(forum) Then
  779.         LogResult id + " : Failed : Unable to collect messages from " + forum
  780.         Exit Sub
  781.     End If
  782.     If searchtype="9" And Nisa=False Then
  783.         LogResult id + " : Failed : Cannot search message body in non-NISA forum " + forum
  784.         Exit Sub
  785.     End If
  786.     hmn = FAPconfig.dwLastMsgRead
  787.     If StartMessageDownload(id, forum, sections, True) Then
  788.         If lastdays="u" Then
  789.             Terminal.Print "Searching for unread messages "
  790.         Else
  791.             Terminal.Print "Searching for messages "
  792.         End If
  793.         If searchtype="2" Then Terminal.Print "with subject: '"
  794.         If searchtype="3" Then Terminal.Print "from: '"
  795.         If searchtype="4" Then Terminal.Print "to: '"
  796.         If searchtype="9" Then Terminal.Print "containing: '"
  797.         Terminal.Print searchstring+"'"+Basic.Eoln$
  798.         If lastdays="u" Then
  799.             SearchMessages Val(searchtype), searchstring, True, False, True, ""
  800.         Else
  801.             SearchMessages Val(searchtype), searchstring, True, False, False, lastdays
  802.         End If
  803.     End If
  804.     FinishMessageDownload id
  805.  
  806.     ' Correct Compuserve's invalid assumption about HMN after remote search
  807.     b = FAPSetUserProfile(FAP_USR_PERMANENT%, FAP_USF_HIGH_MSG%, hmn, "")
  808. End Sub
  809.  
  810. 'T:ListHeldMessages (subroutine) (CompuServe)
  811. Sub ListHeldMessages(id As String, forum As String, sections As String)
  812.     Dim term(0 To 0) As FAPSEARCHTERM
  813.     Dim summary() As FAPMSGSUMMARY
  814.     Dim msgno() As Long
  815.     Dim hdr As FAPMSGHEADER
  816.     Dim i As Integer, count as Integer
  817.     Dim nmsgs As Integer
  818.     Dim cComponents As Integer
  819.     Dim dwStart As Long
  820.     Dim section As String
  821.  
  822.     If Not HMIGotoForum(forum) Then
  823.         LogResult id + " : Failed : Unable to collect messages from " + forum
  824.         Exit Sub
  825.     End If
  826.  
  827.     If Nisa Then
  828.         sectionvector = ParseSectionList(sections, FAPconfig.svMsgSections, count)
  829.         StartCapturing forum+"/Sysop_Logs", "Held_Messages", False
  830.         CaptureLine "Messages on Hold"
  831.         CaptureLine ""
  832.  
  833.         Terminal.Status "Collecting Held List ... Please Wait"
  834.  
  835.         term(0).cType = FAP_MSS_HELD_MSGS%
  836.         dwStart = FAPconfig.dwMsgNoBase
  837.         On Error Goto ListHeldMessages_end
  838.         FAPMsgSearch summary(), msgno(), HMI_STATE_FIRST%, 1, 20, _
  839.                 sectionvector, dwStart, cComponents, term()
  840.         While True
  841.             nmsgs = UBound(msgno)
  842.             On Error Goto ListHeldMessages_error
  843.             For i = 0 To UBound(msgno)
  844.                 hdr.dwMsgNo = 0
  845.                 FAPReadMsgHeader hdr, msgno(i), ALL_HEADER_FIELDS
  846.                 If hdr.dwMsgNo = 0 Then Exit For
  847.  
  848.                 If SectionMsgIds(hdr.cSectionId) >= 0 Then
  849.                     section = szMsgSection(SectionMsgIds(hdr.cSectionId)).lpTitle
  850.                 Else
  851.                     section = "Unknown"
  852.                 End If
  853.                 CaptureText "VA:Cis:" & forum & "/S" & hdr.cSectionId
  854.                 CaptureLine "_" & section & "#" & hdr.dwMsgNo
  855.             Next
  856.  
  857.             On Error Goto ListHeldMessages_end
  858.             ' following will error if nothing else left
  859.             FAPMsgSearch summary(), msgno(), HMI_STATE_NEXT%, 1, 20, _
  860.                     sectionvector, dwStart, cComponents, term()
  861.         Wend
  862. ListHeldMessages_end:
  863.         FinishCapturing
  864.         ReportSuccess id & " : Held Message List for forum " & forum & " collected"
  865.         Exit Sub
  866. ListHeldMessages_error:
  867.         LogResult "SearchMessages: Error:" & FullErrorMessage
  868.     Else
  869.         AsciiListHeldMessages id, forum, sections
  870.     End If
  871. End Sub
  872.  
  873. Sub FetchMessageThread(id As String, forum As String, number As String, thr As Boolean)
  874.     Dim i As Integer, b As Integer, done As Integer
  875.     Dim tmp As String, body As String, txt As String
  876.     Dim hdr As FAPMSGHEADER, msgno() As Long, lasthmn As Long
  877.  
  878.     If Not HMIGotoForum(forum) Then
  879.         LogResult id + " : Failed : Unable to read messages from " + forum
  880.         Exit Sub
  881.     End If
  882.  
  883.     lasthmn = FAPconfig.dwLastMsgRead
  884.     CurrentForum = ParseString(forum, "/")
  885.  
  886.     ' Unique name for capture file
  887.     messagefilename = UniqueFileName$()
  888.     Capture CAPTURE_ON, messagefilename
  889.     CaptureText Basic.Eoln$+"#pragma ciscontrol=yes;markunread=yes"+Basic.Eoln$
  890.     On Error Goto ReadMessageThread_error
  891.  
  892.     ' Read the message/thread
  893.     Redim msgno(0 To 0)
  894.     msgno(0) = number
  895.     If thr Then
  896.         FAPReadMessageHeaders ALL_HEADER_FIELDS+FAP_MC_THREADS%, msgno()
  897.     Else
  898.         FAPReadMessageHeaders ALL_HEADER_FIELDS, msgno()
  899.     End If
  900.     done = False
  901.     Do
  902.         FAPReadSingleMsgHdr hdr
  903.         If hdr.dwMsgNo = 0 Then Exit Do
  904.         Terminal.Print "Reading message/thread #" & LTrim(Str(hdr.dwMsgNo)) & " " & hdr.lpSubject & Basic.Eoln$
  905.         body = ""
  906.         Do
  907.             txt = FAPReadMessageBody(hdr)
  908.             body = body + txt
  909.         Loop While txt > ""
  910.         SaveMessage hdr, body
  911.         done = True
  912.     Loop
  913.     If done = False And thr = False Then
  914.         Terminal.Print "% Unable to read message #" & number & " from " & WhereAmI & Basic.Eoln$
  915.     End If
  916.     Capture CAPTURE_OFF
  917.     If done Then
  918.         If id<>"" Then ReportSuccess id & " : Collected message/thread #" & number & " from " & WhereAmI
  919.         b = QueueFile(Session.Service, messagefilename, IM_DELETE)
  920.     Else
  921.         If id<>"" Then ReportSuccess id & " : Didn't collect message/thread #" & number & " from " & WhereAmI
  922.         DeleteFile messagefilename
  923.     End If
  924.     i = HMIResync(CAP_FORUM)
  925.  
  926.     ' Need to set HMN because CIS messes it up
  927.     b = FAPSetUserProfile(FAP_USR_PERMANENT%, FAP_USF_HIGH_MSG%, lasthmn, "")
  928.  
  929.     Exit Sub
  930. ReadMessageThread_error:
  931.     LogResult "Error:" & FullErrorMessage & " collecting message/thread from " & forum
  932.     CaptureLine "Error:" & FullErrorMessage
  933.     i = HMIResync(CAP_FORUM)
  934.     sectionvector = 0
  935. End Sub
  936.  
  937. Sub FetchThread(id As String, forum As String, number As String)
  938.     FetchMessageThread id, forum, number, True
  939. End Sub
  940.  
  941. Function StartMessageDownload(id As String, forum As String, _
  942.               sections As String, markunread As Boolean) As Integer
  943.     Dim i As Integer, j As Integer, count As Integer
  944.     Dim tmp As String, t As String
  945.     Dim tmpVector As Long, fromyou As Boolean
  946.  
  947.     nummessages = -1
  948.     StartMessageDownload = False
  949.     If Not HMIGotoForum(forum) Then
  950.         LogResult id + " : Failed : Unable to collect messages from " + forum
  951.         Exit Function
  952.     End If
  953.  
  954.     CurrentForum = forum
  955.  
  956.     ' Unique name for capture file
  957.     Capture CAPTURE_ON, WorkingPath + "mswfetch.tmp"
  958.     CaptureText Basic.Eoln$+"#pragma ciscontrol=yes;markunread=no"+Basic.Eoln$
  959.     Terminal.CaptureStatus CAPTURE_ON
  960.     nummessages = 0
  961.     On Error Goto StartMessageDownload_error
  962.  
  963.     ' Which sections ?
  964.     fromyou = InStr(sections, "y", 1)<>0
  965.     ReplaceAllInString sections, " y", ""
  966.     sectionvector = ParseSectionList(sections, FAPconfig.svMsgSections, count)
  967.  
  968.     ' Messages from/to you
  969.     If LastDownMessages<>WhereAmI Then
  970.         filterVector = sectionvector ' Used to filter out waiting messages
  971.         tmpVector = sectionvector
  972.         sectionvector = &HFFFFFFFF
  973.         If FAPconfig.wAlerts And FAP_WAITING_MSGS% Then
  974.             Terminal.Print "Collecting waiting messages" & Basic.Eoln$
  975.             SearchMessages FAP_MSS_WAITING_MSGS%, "", True, False, False, ""
  976.             If nummessages=1 Then
  977.                 Terminal.Print "Collected 1 waiting message" & Basic.Eoln$
  978.             Else
  979.                 Terminal.Print "Collected " & nummessages & " waiting messages" & Basic.Eoln$
  980.             End If
  981.             nummessages = 0
  982.         End If
  983.  
  984.         ' Read messages from you?
  985.         If fromyou Then
  986.             Terminal.Print "Collecting messages from you" & Basic.Eoln$
  987.             SearchMessages FAP_MSS_ORIGINATOR_NAME%, Session.LoginName, True, False, True, ""
  988.         End If
  989.         sectionvector = tmpVector
  990.     End If
  991.  
  992.     ' Start capture
  993.     Capture CAPTURE_OFF
  994.     messagefilename = UniqueFileName$()
  995.     Capture CAPTURE_ON, messagefilename
  996.     If markunread Then
  997.         CaptureText Basic.Eoln$+"#pragma ciscontrol=yes;markunread=yes"+Basic.Eoln$
  998.     Else
  999.         CaptureText Basic.Eoln$+"#pragma ciscontrol=yes;markunread=no"+Basic.Eoln$
  1000.     End If
  1001.  
  1002.     ' Store the last forum we read messages from so that we don't
  1003.     ' do more than one reading waiting per forum.
  1004.     LastDownMessages = WhereAmI
  1005.     If Not markunread Then
  1006.         If sectionvector=FAPconfig.svMsgSections Then
  1007.             Terminal.Print "Collecting messages from all sections" + Basic.Eoln$
  1008.         Else
  1009.             Terminal.Print "Collecting messages from sections " + Trim$(sections) + Basic.Eoln$
  1010.         End If
  1011.     End If
  1012.     StartMessageDownload = True
  1013.     Exit Function
  1014. StartMessageDownload_error:
  1015.     LogResult "Error:" & FullErrorMessage & " collecting messages from " & forum
  1016.     CaptureLine "Error:" & FullErrorMessage
  1017.     sectionvector = 0
  1018.     If nummessages > 0 Then StartMessageDownload = True
  1019. End Function
  1020.  
  1021. Sub FinishMessageDownload(id As String)
  1022.     Capture CAPTURE_OFF
  1023.     Terminal.CaptureStatus CAPTURE_OFF
  1024.     If nummessages = -1 Then Exit Sub
  1025.     If nummessages = 1 Then
  1026.         ReportSuccess id & " : Collected " & nummessages & " message from " & WhereAmI
  1027.     Else
  1028.         ReportSuccess id & " : Collected " & nummessages & " messages from " & WhereAmI
  1029.     End If
  1030.     If nummessages > 0 Then
  1031.         ' Add to import queue
  1032.         b = QueueFile(Session.Service, messagefilename, IM_DELETE)
  1033.     Else
  1034.         DeleteFile messagefilename
  1035.     End If
  1036. End Sub
  1037.  
  1038. Sub SearchMessages (searchtype As Integer, searchstring As String, bodies As Boolean, rootsonly As Boolean, unreadonly As Boolean, lastdays As String)
  1039.     Dim term(0 To 0) As FAPSEARCHTERM
  1040.     Dim summary() As FAPMSGSUMMARY
  1041.     Dim msgno() As Long
  1042.     Dim hdr As FAPMSGHEADER
  1043.     Dim i As Integer, txt As String, body As String
  1044.     Dim nmsgs As Integer
  1045.     Dim d As Date, tsTime As HMITIMESTAMP
  1046.     Dim cComponents As Integer
  1047.     Dim dwStart As Long
  1048.  
  1049.     ' Nothing to do so don't bother trying
  1050.     If unreadonly And FAPconfig.dwNewestMsg=FAPconfig.dwLastMsgRead Then
  1051.         Exit Sub
  1052.     End If
  1053.  
  1054.     term(0).cType = searchtype
  1055.     If searchstring<>"" Then term(0).lpPattern = searchstring
  1056.     If rootsonly Then cComponents = FAP_MSR_PSEUDO_ROOTS%
  1057.     If lastdays<>"" Then
  1058.         d = Date() - Val(lastdays)
  1059.         tsTime.cDay = Day(d)
  1060.         tsTime.cMonth = Month(d)
  1061.         tsTime.cYear = Year(d)-1970
  1062.         dwStart = FAPSearchDate(&H00FFFFFF, tsTime)
  1063.     Else
  1064.         If unreadonly Then
  1065.             dwStart = FAPconfig.dwLastMsgRead
  1066.         Else
  1067.             dwStart = FAPconfig.dwMsgNoBase
  1068.         End If
  1069.     End If
  1070.  
  1071.     On Error Goto SearchMessages_end
  1072.     FAPMsgSearch summary(), msgno(), HMI_STATE_FIRST%, 1, 1000, _
  1073.             sectionvector, dwStart, cComponents, term()
  1074.     While True
  1075.         nmsgs = UBound(msgno)
  1076.         On Error Goto SearchMessages_error
  1077.         If bodies Then
  1078.             FAPReadMessageHeaders ALL_HEADER_FIELDS, msgno()
  1079.             Do
  1080.                 FAPReadSingleMsgHdr hdr
  1081.                 If hdr.dwMsgNo = 0 Then Exit Do
  1082.                 dwStart = hdr.dwMsgNo
  1083.                 body = ""
  1084.                 Do
  1085.                     txt = "" ' possible memory leak
  1086.                     txt = FAPReadMessageBody(hdr)
  1087.                     body = body + txt
  1088.                 Loop While txt > ""
  1089.  
  1090.                 SaveMessage hdr, body
  1091.                 ' Don't import waiting messages if the message is
  1092.                 ' collected by DownMessages()
  1093.                 'If searchtype<>FAP_MSS_WAITING_MSGS% Or _
  1094.                 '   ((2^hdr.cSectionId) And filterVector)=0 Then
  1095.                 '    SaveMessage hdr, body
  1096.                 'Else
  1097.                 '    nummessages = nummessages + 1
  1098.                 '    Terminal.Print "(Filtering out message #" & hdr.dwMsgNo & " - importing once only)" & Basic.Eoln$
  1099.                 'End If
  1100.             Loop
  1101.         Else
  1102.             For i = 0 To UBound(msgno)
  1103.                 hdr.dwMsgNo = 0
  1104.                 FAPReadMsgHeader hdr, msgno(i), ALL_HEADER_FIELDS
  1105.                 If hdr.dwMsgNo = 0 Then Exit For
  1106.                 SaveMessage hdr, "*** Header Only ***" & Chr$(10)
  1107.             Next
  1108.         End If
  1109.         On Error Goto SearchMessages_end
  1110.         ' following will error if nothing else left
  1111.         FAPMsgSearch summary(), msgno(), HMI_STATE_NEXT%, 1, 1000, _
  1112.                 sectionvector, dwStart, cComponents, term()
  1113.     Wend
  1114. SearchMessages_end:
  1115.     filterVector = 0
  1116.     Exit Sub
  1117. SearchMessages_error:
  1118.     LogResult "SearchMessages: Error:" & FullErrorMessage
  1119.     filterVector = 0
  1120. End Sub
  1121.  
  1122. 'T:DeleteMessage (subroutine) (CompuServe)
  1123. Sub DeleteMessage(id As String, forum As String, dummy As String, number As String)
  1124.     If Not HMIGotoForum(forum) Then
  1125.         LogResult id + " : Failed : Unable to delete messages in " + forum
  1126.         Exit Sub
  1127.     End If
  1128.  
  1129.     Terminal.Print "Deleting message #" + number + Basic.Eoln$
  1130.  
  1131.     ' Delete the message
  1132.     On Error Goto DeleteMessage_error
  1133.     If FAPDeleteMsg_(number)<>0 Then
  1134.         ReportSuccess id & " : Deleted message #" & number & " from " & forum
  1135.     End If
  1136.     Exit Sub
  1137. DeleteMessage_error:
  1138.     ReportSuccess id & " : Unable to delete message #" & number & " from " & forum
  1139. End Sub
  1140.  
  1141. 'T:ReadNumber (subroutine) (CompuServe)
  1142. Sub ReadNumber(id As String, forum As String, number As String)
  1143.     FetchMessageThread id, forum, number, False
  1144. End Sub
  1145.  
  1146. 'T:NewJoinForum (subroutine) (CompuServe)
  1147. Sub NewJoinForum(id As String, forum As String, handle As String, ndays As String, sect As String)
  1148.     Dim b As Integer, hmn As Long
  1149.     Dim tsTime As HMITIMESTAMP, d As Date
  1150.     Dim a As Boolean
  1151.  
  1152.     If Not HMIGotoForum(forum) Then
  1153.         LogResult "Unable to join "+forum
  1154.         Exit Sub
  1155.     End If
  1156.  
  1157.     Terminal.Print "Joining forum"+Basic.Eoln$
  1158.     On Error Goto JoinForum_error
  1159.  
  1160.     ' Set user name
  1161.     If ((FAPconfig.wAlerts And FAP_NOT_A_MEMBER%) <> 0) Then
  1162.         b = FAPSetUserProfile(FAP_USR_PERMANENT%+FAP_USR_JOIN%, FAP_USF_NAME%, 0, handle)
  1163.         FAPconfig.wAlerts = FAPconfig.wAlerts - FAP_NOT_A_MEMBER%
  1164.     Else
  1165.         On Error Resume Next
  1166.         b = FAPSetUserProfile(FAP_USR_PERMANENT%, FAP_USF_NAME%, 0, handle)
  1167.     End If
  1168.  
  1169.     ' Get list of sections/libraries
  1170.     CollectSections forum
  1171.     If (FAPconfig.wAlerts And FAP_NEW_BULLETINS)=0 Then
  1172.         Newsflash "", forum
  1173.     End If
  1174.     Announcements "", forum
  1175.  
  1176.     ' Set HMN back nnn days
  1177.     If ndays <> "" Then
  1178.         d = Date() - Val(ndays)
  1179.         tsTime.cDay = Day(d)
  1180.         tsTime.cMonth = Month(d)
  1181.         tsTime.cYear = Year(d)-1970
  1182.         hmn = FAPSearchDate(FAPconfig.svMsgSections, tsTime)
  1183.         If hmn > 0 Then SetHigh "", forum, LTrim$(Str(hmn))
  1184.     ElseIf FAPconfig.dwLastMsgRead < FAPconfig.dwMsgNoBase Then
  1185.         SetHigh "", forum, LTrim$(Str(FAPconfig.dwMsgNoBase))
  1186.     End If
  1187.  
  1188.     ReportSuccess id & " : Joined " & forum & " successfully"
  1189.  
  1190.     DownMessages id, forum, sect
  1191.     Exit Sub
  1192. JoinForum_error:
  1193.     LogResult id + " : Failed : Unable to join " + forum + " - error:" + FullErrorMessage
  1194. End Sub
  1195.  
  1196. 'T:NewDownloadFile (subroutine) (CompuServe)
  1197. Sub NewDownloadFile(id As String, forum As String, filename As String, pubavail As Boolean)
  1198.     Dim section As Integer, sections As Long, ftype As Integer, i As Integer
  1199.     Dim catalog As Long, filesize As Long, l As Long
  1200.     Dim tforum As String, s As String, count As Long
  1201.     Dim b As Integer, fname As String, pterm(0 to 0) As FAPSEARCHTERM
  1202.     Dim fdesc() As FAPFILEDESCRIPTION, fterm(0 to 1) As FAPSEARCHTERM
  1203.  
  1204.     tforum = forum
  1205.     If Not HMIGotoForum(tforum) Then
  1206.         LogResult "Unable to download file "+filename+" from "+forum
  1207.         Exit Sub
  1208.     End If
  1209.  
  1210.     ' Extract the section number
  1211.     section = Val(SectionNumber(forum))
  1212.     sections = 2 ^ section
  1213.     If (FAPconfig.svLibSections And sections) = 0 Then
  1214.         LogResult id + " : Failed : Unknown library section " & forum
  1215.         Exit Sub
  1216.     End If
  1217.  
  1218.     ' Scan library for the file
  1219.     On Error Goto NotFound_error
  1220.     If pubavail Then
  1221.         Terminal.Print "Downloading file " + filename + Basic.Eoln$
  1222.  
  1223.         pterm(0).cType = FAP_SFH_FILENAME
  1224.         pterm(0).lpPattern = filename
  1225.         FAPSearchFile fdesc(), HMI_STATE_FIRST%, 1, 1, sections, _
  1226.             FAP_FDC_FILE_TYPE% + FAP_FDC_FILE_SIZE%, pterm()
  1227.     Else
  1228.         Terminal.Print "Downloading unreleased file " + filename + Basic.Eoln$
  1229.  
  1230.         fterm(0).cType = FAP_SFH_FILENAME
  1231.         fterm(0).lpPattern = filename
  1232.         fterm(1).cType = FAP_SFH_MATCH_NON_PUBLIC_ONLY
  1233.         FAPSearchFile fdesc(), HMI_STATE_FIRST%, 1, 1, sections, _
  1234.             FAP_FDC_FILE_TYPE% + FAP_FDC_FILE_SIZE%, fterm()
  1235.     End If
  1236.  
  1237.     catalog = fdesc(0).dwCatalogNo
  1238.     filesize = fdesc(0).dwFileSize
  1239.     ftype = fdesc(0).nFileType
  1240.  
  1241.     If filesize = 0 Then
  1242.         Terminal.Print "File not found." + Basic.Eoln$
  1243.         LogResult "Unable to find "+filename+" in library "+forum
  1244.         Exit Sub
  1245.     End If
  1246.  
  1247.     On Error Goto DownloadFile_error
  1248.     Terminal.TransferStatus False, filename, 0, filesize
  1249.  
  1250.     ' Open file to write to
  1251.     If FileExists(DownloadDir+filename) Then
  1252.         count = FileLen(DownloadDir+filename) ' Resume file download
  1253.     Else
  1254.         count = 0
  1255.     End If
  1256.     Open DownloadDir+filename For Binary Access Write Shared As #1
  1257.     If count>0 Then
  1258.         Terminal.Print "Resuming file download at " & count & Basic.Eoln$
  1259.         Seek #1, count+1
  1260.     End If
  1261.  
  1262.     s = FAPReceiveFileOffset(HMI_STATE_FIRST%, catalog, ftype, 0, i, count+1)
  1263.     Do While s > ""
  1264.         Put #1, , s
  1265.         count = count + i
  1266.         Terminal.TransferStatus False, filename, count, filesize
  1267.         s = FAPReceiveFileOffset(HMI_STATE_NEXT%, catalog, ftype, 0, i, count+1)
  1268.     Loop
  1269.     If count < filesize Then 
  1270.         Terminal.TransferStatus False, filename, count, count
  1271.         LogResult id & " : Possible incomplete download of "+filename+" from "+forum
  1272.         LogResult id & " : Reported size " & filesize & " actual size " & count
  1273.     End If
  1274.     Close #1
  1275.     Terminal.TransferStatus
  1276.  
  1277.     ' Write comment to catalog entry and import into messagebase
  1278.     tforum = ParseString(tforum, "/")+"/L"+LTrim(Str(section))
  1279.     RecordFileDownload tforum, LTrim$(Str$(catalog))
  1280.     If SectionLibIds(section) >= 0 Then
  1281.         tforum = tforum +"_" + szLibSection(SectionLibIds(section)).lpTitle
  1282.     Else
  1283.         tforum = tforum + "_Unknown"
  1284.     End If
  1285.     
  1286.     If pubavail Then
  1287.         ReportSuccess id & " : Downloaded "+FileUrl(DownloadDir+filename)+" from forum "+forum
  1288.         NewSearchLibrary "", tforum, LTrim$(Str(catalog)), "", DownloadDir+filename, _
  1289.                          "", "", "", "", "", "", "y", "n"
  1290.     Else
  1291.         ReportSuccess id & " : Downloaded unreleased "+FileUrl(DownloadDir+filename)+" from forum "+forum
  1292.     End If
  1293.     Exit Sub
  1294.  
  1295. NotFound_error:
  1296.     LogResult "Unable to find "+filename+" in library "+forum
  1297.     Exit Sub
  1298.  
  1299. DownloadFile_error:
  1300.     Close #1
  1301.     Terminal.TransferStatus
  1302.     LogResult id & " : Failed to download "+filename+" from "+forum+" error : " + FullErrorMessage()
  1303. End Sub
  1304.  
  1305. 'T:DownloadFile (subroutine) (CompuServe)
  1306. Sub DownloadFile(id As String, forum As String, filename As String)
  1307.     NewDownloadFile id, forum, filename, True
  1308. End Sub
  1309.  
  1310. 'T:DownloadFileFinder (subroutine) (CompuServe)
  1311. Sub DownloadFileFinder(id As String, forum As String, filename As String, handle As String)
  1312.     If Not HMIGotoForum(forum) Then
  1313.         LogResult "Unable to download file "+filename+" from "+forum
  1314.         Exit Sub
  1315.     End If
  1316.  
  1317.     ' Check to see if we need to join the forum
  1318.     If ((FAPconfig.wAlerts And FAP_NOT_A_MEMBER%) <> 0) Then
  1319.         JoinForum "", forum, handle, ""
  1320.     End If
  1321.  
  1322.     ' Download the file
  1323.     NewDownloadFile id, forum, filename, True
  1324. End Sub
  1325.  
  1326. Sub NextSearchTerm(ByRef searchterm() As FAPSEARCHTERM, ByRef i As Integer, sfh As Integer, pat As String)
  1327.     If pat="" Then Exit Sub
  1328.     ReDim Preserve searchterm(0 To i)
  1329.     searchterm(i).cType = sfh
  1330.     searchterm(i).lpPattern = pat
  1331.     i = i + 1
  1332. End Sub
  1333.  
  1334. 'T:NewSearchLibrary (subroutine) (CompuServe)
  1335. Sub NewSearchLibrary(id As String, forum As String, catalog As String, _
  1336.                   ssections As String, filename As String, uploadby As String, _
  1337.                   age As String, accesscount As String, keywords As String, _
  1338.                   title As String, description As String, full As String, _
  1339.                   replace As String)
  1340.     Dim fname As String, i As Integer, t As Long
  1341.     Dim section As Integer, tforum As String, count As Long
  1342.     Dim filedesc() As FAPFILEDESCRIPTION, tmpdesc As FAPFILEDESCRIPTION
  1343.     Dim searchterm() As FAPSEARCHTERM, errmsg As String
  1344.     Dim searchflags As Long, catno As Long, ok As Boolean
  1345.  
  1346.     tforum = forum
  1347.     catno = Val(catalog)
  1348.     If Not HMIGotoForum(tforum) Then
  1349.         LogResult "Unable to refresh library list from "+forum
  1350.         Exit Sub
  1351.     End If
  1352.  
  1353.     tforum = ParseString(tforum, "/")
  1354.  
  1355.     ' Set which bits of info we want
  1356.     searchflags = &H6FF
  1357.     If UCase(full)="Y" Then searchflags = searchflags + FAP_FDC_ABSTRACT%
  1358.     If UCase(replace)="Y" Then
  1359.         replace = "yes"
  1360.     Else
  1361.         replace = "no"
  1362.     End If
  1363.     ok = True
  1364.  
  1365.     ' Scan library for the files
  1366.     fname = UniqueFilename$()
  1367.     count = 0
  1368.     Capture CAPTURE_ON, fname
  1369.     CaptureText Basic.Eoln$+"#pragma ciscontrol=yes;markunread=yes;deleteexisting="+replace+Basic.Eoln$
  1370.     If catno > 0 Then
  1371.         Terminal.Print "Collecting library #" + LTrim$(Str(catno)) + Basic.Eoln$
  1372.  
  1373.         ' We know which catalog we want - get it
  1374.         On Error Goto EndOfLibrary_error
  1375.         i = FAPReadFileDescription(catno, searchflags, tmpdesc)
  1376.         If tmpdesc.lpFilename <> "" Then
  1377.             tmpdesc.dwCatalogNo = catno
  1378.             WriteLibraryMessage tforum, tmpdesc, filename
  1379.             count = 1
  1380.         End If
  1381.     Else
  1382.         Terminal.Print "Collecting libraries from sections " + LTrim$(ssections) + Basic.Eoln$
  1383.  
  1384.         If filename="" Then filename = "*.*"
  1385.  
  1386.         ' Set search terms
  1387.         i = 0
  1388.         NextSearchTerm searchterm(), i, FAP_SFH_FILENAME%, filename
  1389.         NextSearchTerm searchterm(), i, FAP_SFH_USER_ID%, uploadby
  1390.         NextSearchTerm searchterm(), i, FAP_SFH_TITLE%, title
  1391.         NextSearchTerm searchterm(), i, FAP_SFH_DATE_RANGE%, age
  1392.         NextSearchTerm searchterm(), i, FAP_SFH_ACCESS_COUNT%, accesscount
  1393.         NextSearchTerm searchterm(), i, FAP_SFH_KEYWORD%, keywords
  1394.         NextSearchTerm searchterm(), i, FAP_SFH_FILE_ABSTRACT%, description
  1395.  
  1396.         ' Select sections to search
  1397.         sectionvector = ParseSectionList(ssections, FAPconfig.svLibSections, i)
  1398.         t = 1
  1399.         For i = 0 to 24
  1400.             If sectionvector And t Then SetLastUpdated tforum & "/L" & i
  1401.             t = t + t
  1402.         Next
  1403.  
  1404.         Terminal.CaptureStatus CAPTURE_ON
  1405.         On Error Goto EndOfLibrary_error
  1406.         FAPSearchFile filedesc(), HMI_STATE_FIRST%, 1, 4, sectionvector, searchflags, searchterm()
  1407.         Do While filedesc(0).dwCatalogNo > 0
  1408.             For i = 0 To UBound(filedesc)
  1409.                 If filedesc(i).dwCatalogNo > 0 Then
  1410.                     count = count + 1
  1411.                     Terminal.CaptureStatus count, "Receiving Library Message"
  1412.                     WriteLibraryMessage tforum, filedesc(i), ""
  1413.                 End If
  1414.             Next
  1415.  
  1416.             FAPSearchFile filedesc(), HMI_STATE_NEXT%, 1, 4, sectionvector, searchflags, searchterm()
  1417.         Loop
  1418.         Terminal.Print "Collected "+LTrim$(Str(count))+" library entries" + Basic.Eoln$
  1419.     End If
  1420. EndOfLibrary_ok:
  1421.     On Error Goto 0
  1422.     Terminal.CaptureStatus CAPTURE_OFF
  1423.     Capture CAPTURE_OFF
  1424.  
  1425.     ' Add to import queue
  1426.     If count > 0 Then
  1427.         b = QueueFile(Session.Service, fname, IM_DELETE Or IM_MARKUNREAD)
  1428.     Else
  1429.         DeleteFile fname
  1430.     End If
  1431.  
  1432.     If ok And id<>"" Then ReportSuccess id & " : Downloaded library list(s) for " & forum & " " & LTrim$(ssections)
  1433.     Exit Sub
  1434. EndOfLibrary_error:
  1435.     If Err<>9 Then
  1436.         errmsg = FullErrorMessage()
  1437.         If InStr(errmsg, "No library sections specified in request")>0 Then
  1438.             LogResult "Error while downloading library from "+forum+" - no valid library section(s) selected"
  1439.         Else
  1440.             LogResult "Error while downloading library from "+forum+" error : " + errmsg
  1441.         End If
  1442.         ok = False
  1443.     End If
  1444.     Resume EndOfLibrary_ok
  1445. End Sub
  1446.  
  1447. 'T:SearchLibrary (subroutine) (CompuServe)
  1448. Sub SearchLibrary(id As String, forum As String, catalog As String, _
  1449.                   ssections As String, filename As String, uploadby As String, _
  1450.                   age As String, accesscount As String, keywords As String, _
  1451.                   title As String, description As String, full As String)
  1452.     NewSearchLibrary id, forum, catalog, ssections, filename, uploadby, _
  1453.                         age, accesscount, keywords, title, description, _
  1454.                         full, "n"
  1455. End Sub
  1456.  
  1457. Function CheckLibraryBeforePosting(id As String, topic As String, section As Integer) As Boolean
  1458.     Dim i As Integer
  1459.  
  1460.     If Not HMIGotoForum(topic) Then
  1461.         LogResult id + " : Failed : Unable to upload file."
  1462.         Exit Function
  1463.     End If
  1464.  
  1465.     If FAPconfig.wRestrictions And FAP_NO_LIBRARY_SEND Then
  1466.         LogResult id + " : Failed : Uploading not allowed in forum " & topic
  1467.         Exit Function
  1468.     End If
  1469.  
  1470.     section = Val(SectionNumber(topic))
  1471.     If (FAPconfig.svLibSections And (2 ^ section)) = 0 Then
  1472.         LogResult id + " : Failed : Unknown section " & topic
  1473.         Exit Function
  1474.     End If
  1475.     CheckLibraryBeforePosting = True
  1476. End Function
  1477.  
  1478. 'T:UploadFile (subroutine) (CompuServe)
  1479. Sub UploadFile(id As String, forum As String, filename As String, _
  1480.                ftype As String, keywords As String, title As String, _
  1481.                msgfile As String)
  1482.     Dim path As String, sname As String, body As String, nState As Integer
  1483.     Dim section As Integer, SourceFileNum as Integer, SourceFileAt as Long
  1484.     Dim SourceFileLen as Long, TheData as String, BytesToRead as Long
  1485.     Dim i As Integer, iType As Integer
  1486.  
  1487.     If Not CheckLibraryBeforePosting(id, forum, section) Then
  1488.         Exit Sub
  1489.     End If
  1490.  
  1491.     Terminal.Print "Uploading file " + filename + Basic.Eoln$
  1492.  
  1493.     ' Does the file exist ?
  1494.     If Not FileExists(filename) Then
  1495.         LogResult "File doesn't exist"
  1496.         Exit Sub
  1497.     End If
  1498.     SourceFileLen = FileLen(filename)
  1499.     If SourceFileLen <= 0 Then
  1500.         LogResult "Can't upload file"
  1501.         Exit Sub
  1502.     End If
  1503.     SplitPath filename, path, sname
  1504.     iType = Val(ftype)
  1505.  
  1506.     ' Overwrite and reset file download counts
  1507.     If FAPSendFileInfo(section, SourceFileLen, iType, 3, sname, title, keywords)=0 Then
  1508.         LogResult "Failed sending file info"
  1509.         Exit Sub
  1510.     End If
  1511.  
  1512.     ' Send the abstract
  1513.     body = ReadMessageFile(msgfile, 0)
  1514.     If FAPSendFileAbstract(body, 3, "", Session.LoginName)=0 Then
  1515.         LogResult "Failed sending file abstract"
  1516.         Exit Sub
  1517.     End If
  1518.  
  1519.     ' Send the file
  1520.     On Error Goto UploadFile_error
  1521.     BytesToRead = SourceFileLen
  1522.     SourceFileNum = FreeFile()
  1523.     Open filename for Binary Access Read Shared as #SourceFileNum
  1524.     SourceFileAt = 1        'read point
  1525.  
  1526.     TheData = String$(BlockSize, " ")
  1527.     nState = 0
  1528.     
  1529.     ' Operate on blocks of BlockSize at a time
  1530.     Do While BytesToRead > BlockSize
  1531.         Terminal.TransferStatus True, filename, SourceFileAt-1, SourceFileLen
  1532.         Get #SourceFileNum, SourceFileAt, TheData
  1533.         i = FAPSendFileData(iType, TheData, nState)
  1534.         BytesToRead = BytesToRead - BlockSize
  1535.         SourceFileAt = SourceFileAt + BlockSize
  1536.         nState = 1
  1537.     Loop
  1538.  
  1539.     ' Now do the last block of less than BlockSize
  1540.     If BytesToRead > 0 then
  1541.         TheData = String$(BytesToRead, " ")
  1542.         Get #SourceFileNum, SourceFileAt, TheData
  1543.         i = FAPSendFileData(iType, TheData, nState)
  1544.     End If
  1545.     Terminal.TransferStatus True, filename, SourceFileLen, SourceFileLen
  1546.     i = FAPSendFileData(iType, "", nState)
  1547.     
  1548.     Close #SourceFileNum
  1549.     Terminal.TransferStatus
  1550.     ReportSuccess id & " : " & filename & " was uploaded to " & forum
  1551.     Exit Sub
  1552.  
  1553. UploadFile_error:
  1554.     Terminal.TransferStatus
  1555.     LogResult "Error in UploadFile : " + FullErrorMessage()
  1556.     Close #SourceFileNum
  1557.     Exit Sub
  1558. End Sub
  1559.  
  1560. Sub UpdateLibrary(id As String, forum As String, sdate As String)
  1561.     Dim sect As String
  1562.  
  1563.     sect = SectionNumber(forum)
  1564.     forum = ParseString(forum, "/")
  1565.     SearchLibrary id, forum, "", sect, "", "", sdate, "", "", "", "", "y"
  1566. End Sub
  1567.  
  1568. 'T:UserLog (subroutine) (CompuServe)
  1569. Sub UserLog(id As String, forum As String)
  1570.     If Not HMIGotoForum(forum) Then
  1571.         LogResult id + " : Failed : Unable to collect user log from "+forum
  1572.         Exit Sub
  1573.     End If
  1574.  
  1575.     If Not Nisa Then
  1576.         AsciiUserLog id, forum
  1577.         Exit Sub
  1578.     End If
  1579.  
  1580.     Terminal.Print "Collecting forum user log ... Please wait"+Basic.Eoln$
  1581.     RecordBulletins forum, False, False, True
  1582.     If id<>"" Then ReportSuccess id & " : User log collected from " & forum
  1583. End Sub
  1584.  
  1585. 'T:RecordSectionInformation (subroutine) (CompuServe)
  1586. Sub RecordSectionInformation(forum As String)
  1587.     Dim i As Integer, buf As String
  1588.  
  1589.     StartCapturing forum+"/Announcements", "CompuServe", True
  1590.     CaptureLine "Sections"
  1591.     If (FAPconfig.wAlerts And FAP_IS_SYSOP%)<>0 Then CaptureLine "SYSOP"
  1592.     If (FAPconfig.wAlerts And FAP_FREE_USER%)<>0 Then CaptureLine "Free Flag"
  1593.     If (FAPconfig.wAlerts And FAP_NISA_FORUM%)<>0 Then CaptureLine "NISA Forum"
  1594.     If (FAPconfig.wRestrictions And FAP_NO_PRIVATE_MSGS%)<>0 Then
  1595.         CaptureLine "Private Messages not allowed"
  1596.     Else
  1597.         CaptureLine "Private Messages are allowed"
  1598.     End If
  1599.     CaptureLine ""
  1600.     On Error Resume Next
  1601.  
  1602.     ' Get the message section names for the forum from Compuserve
  1603.     CaptureLine "Message Sections Available:"
  1604.     For i = 0 To UBound(szMsgSection)
  1605.         buf = Str(szMsgSection(i).cId)+" "+szMsgSection(i).lpTitle
  1606.         ReplaceAnyInString buf, "_", " "
  1607.         CaptureLine buf
  1608.     Next
  1609.     CaptureLine ""
  1610.  
  1611.     ' Get the library section names for the forum from Compuserve
  1612.     CaptureLine "Libraries Available:"
  1613.     For i = 0 To UBound(szLibSection)
  1614.         buf = Str(szLibSection(i).cId)+" "+szLibSection(i).lpTitle
  1615.         ReplaceAnyInString buf, "_", " "
  1616.         CaptureLine buf
  1617.     Next
  1618.  
  1619.     FinishCapturing
  1620. End Sub
  1621.  
  1622.