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

  1. 'T:HMIBASE.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 Function FileUrl(fn As String) As String
  7. Declare Function MakeDateString(s As HMITIMESTAMP) As String
  8. Declare Sub AddToMsgFile(SourceFileName as String)
  9. Declare Function QueueFile(service As String, sfilename As String, queueflags As Long) As Boolean
  10. Declare Sub LoadAddonLibraries
  11. Declare Function MyDate$
  12. Declare Function StartMessageDownload(id As String, forum As String, sections As String) As Integer
  13. Declare Sub SearchMessages(searchtype As Integer, searchstring As String, bodies As Boolean, rootsonly As Boolean)
  14. Declare Sub ReportSuccess(msg As String)
  15. Declare Function ForumName(ByVal forum As String) As String
  16. Declare Function FullErrorMessage() As String
  17. Declare Sub FetchMail(id As String)
  18. Declare Sub SetupOptions(id As String)
  19. Declare Sub RecordBulletins(forum As String, getnews As Boolean, _
  20.                             getothers As Boolean, getuserlog As Boolean)
  21. Declare Function HMIGotoForum(ByVal forum As String) As Boolean
  22. Declare Sub RecordSectionInformation(forum As String)
  23.  
  24. 'T:iFlags for CompuServe (constant)
  25. Const IM_SPECIAL = 128        ' My special msg format
  26. Const IM_DELETE = 2048        ' Delete scratchpad file afterwards?
  27.  
  28. Const fRECEIPT = 1            'CIS mail receipt
  29. Const fPRIVATE = 2            'CIS private forum message
  30. Const fNOFORMAT = 4            'CIS unformatted message
  31.  
  32. Const DAP_DC_HAVE_MAIL% = &H0001          ' mail waiting
  33. Const DAP_DC_ACCOUNT_ATTENTION% = &H0004  ' account needs attention
  34.  
  35. Const FAP_DELETABLE% = &H1
  36. Const FAP_OWNER% = &H2
  37. Const FAP_MSG_IS_PRIVATE% = &H4
  38. Const FAP_READ_BY_RECIPIENT% = &H8
  39. Const FAP_MSG_HELD% = &H10
  40. Const FAP_MSG_FORWARDED% = &H20
  41. Const FAP_HAS_BEEN_DELETED% = &H80
  42.  
  43. Const FAP_FILE_DELETABLE% = &H1
  44. Const FAP_FILE_NON_PUBLIC% = &H2
  45. Const FAP_FILE_MARKED_FOR_DELETION% = &H4
  46. Const FAP_FILE_HAS_FEE% = &H8
  47.  
  48. Const HMI_STATE_FIRST% = 0
  49. Const HMI_STATE_NEXT% = HMI_STATE_FIRST + 1
  50.  
  51. Public DownloadDir As String    'where downloads go
  52. Public WorkingPath As String    'added to speed up Fetch stuff online
  53. Public WhereAmI As String        'name of last forum/page etc
  54. Public Sysop As Boolean            'are we a sysop?
  55. Public InAscii As Boolean
  56.  
  57. Public currentCAP As Integer
  58. Public SectionMsgIds(32) As Integer, SectionLibIds(32) As Integer
  59. Public szMsgSection() As FAPSECTIONENTRY, szLibSection() As FAPSECTIONENTRY
  60. Public nummessages As Integer
  61. Public CurrentForum As String
  62. Public MailName As String      'My name for mail purposes
  63. Public PersonalAddress As String      'My PA
  64.  
  65. Dim LastDownMessages As String
  66. Dim capturefilename As String
  67. Dim messagefilename As String
  68. Dim sectionvector As Long
  69. Dim sct As FAPSECTIONS
  70. Dim DAPconfig As DAPCONFIG
  71.  
  72. Const Months$ = "JanFebMarAprMayJunJulAugSepOctNovDec"
  73.  
  74. Dim captureStack As Integer
  75. Dim captureForum As String
  76.  
  77. Function rj(i As Integer) As String
  78.     rj = Right$(Str$(i + 100), 2)
  79. End Function
  80.  
  81. Function MakeDateString(s As HMITIMESTAMP) As String
  82.     On Error Resume Next
  83.     If s.cMonth > 0 Then
  84.         MakeDateString = rj(s.cDay) + "-" + Mid$(Months$,3 * (s.cMonth-1) + 1, 3) _
  85.                          + "-" + LTrim$(Str$(1970 + s.cYear)) + " " + _
  86.                          rj(s.cHour) + ":" + rj(s.cMinutes) + ":" + _
  87.                          rj(s.cSeconds)
  88.     Else
  89.         MakeDateString = ""
  90.     End If
  91. End Function
  92.  
  93. Function GetFileType(i As Integer) As String
  94.     Select Case i
  95.         Case 0
  96.             GetFileType = "Unknown"
  97.         Case 1
  98.             GetFileType = "Text"
  99.         Case 2
  100.             GetFileType = "Binary"
  101.         Case 3
  102.             GetFileType = "Image"
  103.         Case 4
  104.             GetFileType = "RLE"
  105.         Case 5
  106.             GetFileType = "NAPLPS"
  107.         Case 6
  108.             GetFileType = "GIF"
  109.         Case 7
  110.             GetFileType = "JPEG"
  111.         Case 8
  112.             GetFileType = "ETO"
  113.         Case 9
  114.             GetFileType = "HTML"
  115.         Case 10
  116.             GetFileType = "PNG"
  117.     End Select
  118. End Function
  119.  
  120. Function CompareTimes(d1 As HMITIMESTAMP, d2 As HMITIMESTAMP) As Integer
  121.     If d1.cYear < d2.cYear Then
  122.         CompareTimes = -1
  123.         Exit Function
  124.     End If
  125.     If d1.cYear > d2.cYear Then
  126.         CompareTimes = 1
  127.         Exit Function
  128.     End If
  129.     If d1.cMonth < d2.cMonth Then
  130.         CompareTimes = -1
  131.         Exit Function
  132.     End If
  133.     If d1.cMonth > d2.cMonth Then
  134.         CompareTimes = 1
  135.         Exit Function
  136.     End If
  137.     If d1.cDay < d2.cDay Then
  138.         CompareTimes = -1
  139.         Exit Function
  140.     End If
  141.     If d1.cDay > d2.cDay Then
  142.         CompareTimes = 1
  143.         Exit Function
  144.     End If
  145.     If d1.cHour < d2.cHour Then
  146.         CompareTimes = -1
  147.         Exit Function
  148.     End If
  149.     If d1.cHour > d2.cHour Then
  150.         CompareTimes = 1
  151.         Exit Function
  152.     End If
  153.     If d1.cMinutes < d2.cMinutes Then
  154.         CompareTimes = -1
  155.         Exit Function
  156.     End If
  157.     If d1.cMinutes > d2.cMinutes Then
  158.         CompareTimes = 1
  159.         Exit Function
  160.     End If
  161.     If d1.cSeconds < d2.cSeconds Then
  162.         CompareTimes = -1
  163.         Exit Function
  164.     End If
  165.     If d1.cSeconds > d2.cSeconds Then
  166.         CompareTimes = 1
  167.         Exit Function
  168.     End If
  169.     CompareTimes = 0
  170. End Function
  171.  
  172. Function CompareDates(d1 As HMIDATE, d2 As HMIDATE) As Integer
  173.     If d1.cYear < d2.cYear Then
  174.         CompareDates = -1
  175.         Exit Function
  176.     End If
  177.     If d1.cYear > d2.cYear Then
  178.         CompareDates = 1
  179.         Exit Function
  180.     End If
  181.     If d1.cMonth < d2.cMonth Then
  182.         CompareDates = -1
  183.         Exit Function
  184.     End If
  185.     If d1.cMonth > d2.cMonth Then
  186.         CompareDates = 1
  187.         Exit Function
  188.     End If
  189.     If d1.cDay < d2.cDay Then
  190.         CompareDates = -1
  191.         Exit Function
  192.     End If
  193.     If d1.cDay > d2.cDay Then
  194.         CompareDates = 1
  195.         Exit Function
  196.     End If
  197.     CompareDates = 0
  198. End Function
  199.  
  200. Sub CaptureLine(textline As String)
  201.     CaptureText textline + Basic.Eoln$
  202. End Sub
  203.  
  204. Sub CaptureLines(textline As String)
  205.     Dim p As Integer, q As Integer, e As Integer
  206.  
  207.     p = 1
  208.     Do
  209.         q = Instr(p, textline, Chr$(10))
  210.         If q = 0 Then
  211.             e = Len(textline) + 1
  212.             CaptureText Mid$(textline, p, e - p)
  213.         Else
  214.             e = q
  215.             If q > p Then
  216.                 If Mid$(textline, q - 1, 1) = Chr$(13) Then
  217.                     e = e - 1
  218.                 End If
  219.             End If
  220.             CaptureLine Mid$(textline, p, e - p)
  221.         End If
  222.         p = q + 1
  223.     Loop While q > 0
  224. End Sub
  225.  
  226. Sub StartCapturing(pseudoforum As String, title As String, formatted As Boolean)
  227.     captureStack = captureStack + 1
  228.     If captureStack <= 1 Then
  229.         captureStack = 1
  230.         capturefilename = UniqueFilename$()
  231.         Capture CAPTURE_ON, capturefilename
  232.         captureForum = pseudoforum
  233.     Else
  234.         CaptureText Basic.Eoln$ + "!end" + Basic.Eoln$
  235.     End If
  236.     If formatted Then
  237.         CaptureText Basic.Eoln$+"#pragma ciscontrol=yes"+Basic.Eoln$
  238.     Else
  239.         CaptureText Basic.Eoln$+"#pragma ciscontrol=no"+Basic.Eoln$
  240.     End If
  241.     CaptureText Basic.Eoln$ + "!start " + captureForum + " " + title + Basic.Eoln$
  242. End Sub
  243.  
  244. Sub FinishCapturing
  245.     Dim i As Integer
  246.  
  247.     captureStack = captureStack - 1
  248.     CaptureText Basic.Eoln$+"!end"+Basic.Eoln$
  249.     If captureStack <= 0 Then
  250.         captureStack = 0
  251.         Capture CAPTURE_OFF
  252.         ' Add to import queue
  253.         i = QueueFile(Session.Service, capturefilename, IM_SPECIAL Or IM_DELETE)
  254.     End If
  255. End Sub
  256.  
  257. Function CheckCache(pagetype As String, npage As String, pversion As Long) _
  258.         As String
  259.     Dim newpage As String
  260.     Dim tmp As String
  261.  
  262.     tmp = ReadIni$(pagetype, npage, Session.ServicePath+"cache.ini")
  263.     newpage = ParseString(tmp, " Version# ")
  264.     If newpage > "" And pversion = Val(tmp) Then
  265.         CheckCache = newpage
  266.     Else
  267.         CheckCache = ""
  268.     End If
  269. End Function
  270.  
  271. Sub UpdateCache(pagetype As String, npage As String, pversion As Long, _
  272.         newpage As String)
  273.     WriteIni pagetype, npage, newpage & " Version# " & pversion, _
  274.             Session.ServicePath+"cache.ini"
  275. End Sub
  276.  
  277. Sub RecordTerminalOutput()
  278.     On Error Goto RecordTerminal_error
  279.  
  280.     HMIResume
  281.  
  282.     Exit Sub
  283.  
  284. RecordTerminal_error:
  285.     CaptureLine "Error:" & FullErrorMessage
  286. End Sub
  287.  
  288. Sub CaptureTerminalOutput(page As String)
  289.     StartCapturing "Actions/Information", "Terminal output when going to " + page, False
  290.     page = ""
  291.     RecordTerminalOutput
  292.     FinishCapturing
  293. End Sub
  294.  
  295. Sub CaptureMenuOptions(page As String)
  296.     Dim menupage As DAPMENUPAGE
  297.     Dim selections() As DAPSELECTION
  298.     Dim p As Integer
  299.  
  300.     On Error Resume Next
  301.     StartCapturing "Actions/Information CompuServe", Basic.Eoln$+"Menu found when going to " + page, False
  302.     page = ""
  303.     HMIGetMenu menupage, selections
  304.  
  305.     If menupage.cOptions And DAP_MP_BLOB_MENU Then
  306.         CaptureLines selections(0).lpItem
  307.     Else
  308.         For p = 0 To Ubound(selections)
  309.             CaptureLine selections(p).lpItem + " " + Str(selections(p).nSvcClass)
  310.         Next
  311.     End If
  312.     FinishCapturing
  313. End Sub
  314.  
  315. Function DoHMIGotoPage(ByVal forum As String, ByVal menuoption As Integer, ByVal expectedCAP As Integer)
  316.     Dim reqforum As String
  317.  
  318.     reqforum = forum
  319.     SetHighMessageNumber
  320.     ResetForum
  321.     InAscii = False
  322.  
  323.     While forum > ""
  324.         currentCAP = HMIGoToPage(forum, menuoption)
  325.         If currentCAP = expectedCAP Then
  326.             DoHMIGotoPage = True
  327.             Exit Function
  328.         End If
  329.         Select Case currentCAP
  330.             Case DAP_ERROR
  331.                 LogResult "Go:"+forum+":HMI error"
  332.                 forum = ""
  333.             Case DAP_TERMINAL
  334.                 CaptureTerminalOutput forum
  335.                 forum = ""
  336.             Case DAP_MENU
  337.                 CaptureMenuOptions forum
  338.             Case DAP_ARTICLE
  339.                 CaptureArticleText forum
  340.             Case DAP_ALERT
  341.                 CaptureAlert reqforum, forum
  342.             Case DAP_FILE
  343.                 LogResult "Go:"+forum+":this page is a file for download"
  344.                 forum = ""
  345.             Case CAP_EMAIL
  346.                 LogResult "Go:"+forum+":this page is an Electronic Mail page"
  347.                 forum = ""
  348.             Case CAP_FORUM
  349.                 LogResult "Go:"+forum+":this page is a Forum"
  350.                 forum = ""
  351.             Case CAP_ENS
  352.                 LogResult "Go:"+forum+":this page is an Electronic News page"
  353.                 forum = ""
  354.             Case Else
  355.                 LogResult "Go:"+forum+":this page is an unexpected type (" + Trim$(Str$(currentCAP)) + ")"
  356.                 forum = ""
  357.         End Select
  358.     Wend
  359.     DoHMIGotoPage = False
  360. End Function
  361.  
  362. Function DoHMIFollowMenus(ByVal forum As String, optionlist As String, ByVal expectedDAP As Integer)
  363.     Dim p As Integer
  364.     Dim i As Integer
  365.     Dim newDAP As Integer
  366.     Dim menupage As DAPMENUPAGE
  367.     Dim selections() As DAPSELECTION
  368.  
  369.     DoHMIFollowMenus = False
  370.     newDAP = DAP_MENU
  371.     While optionlist > ""
  372.         i = Val(ParseString(optionlist, ";"))
  373.         If i <= 0 Then i = -1
  374.         If optionlist = "" Then newDAP = expectedDAP
  375.         If Not DoHMIGotoPage(forum, i, newDAP) Then Exit Function
  376.         If currentCAP = DAP_MENU Then
  377.             HMIGetMenu menupage, selections
  378.             forum = menupage.lpName
  379.         End If
  380.     Wend
  381.     DoHMIFollowMenus = True
  382. End Function
  383.  
  384.  
  385. 'T:Main - CIS (subroutine) (CompuServe) (CompuServe)
  386. 'Entry point. Does a complete blink
  387. Sub HMIMain
  388.     Dim redials As Integer, ok As Integer, i As Boolean
  389.  
  390.     Comms.AutoDownload = PROT_QUICKB
  391.  
  392.     MailName = ReadIni$("Service "+Session.Service, "Mail Name", Session.IniFilename)
  393.     PersonalAddress = ReadIni$("Service "+Session.Service, "Personal Address", Session.IniFilename)
  394.     If MailName = "" Then MailName = "Not known"
  395.  
  396.     ' Dial
  397.     If Comms.Dial("")=0 Then
  398.         LogResult "Error whilst attempting to dial modem"
  399.         Exit Sub
  400.     End If
  401.  
  402.     ' Display connection info
  403.     HMIGetDAPConfig DAPconfig
  404.     Terminal.Print "Connected to node: "+DAPconfig.lpNodeID+Basic.Eoln$
  405.  
  406.     ' Check account attention flag
  407.     If (DAPconfig.wAlerts And DAP_DC_ACCOUNT_ATTENTION%)<>0 Then
  408.         Terminal.Print Basic.Eoln$+"Your account needs attention.  Please contact CompuServe"+Basic.Eoln$
  409.         LogResult "Your account needs attention.  Please contact CompuServe"
  410.         Comms.Bitmask = True ' CIS messes up if we don't do this
  411.         On Error Resume Next
  412.         i = DoHMIGoToPage("admhmi", -1, CAP_DISPLAY)
  413.         On Error Goto 0
  414.     End If
  415.  
  416.     ' Check to see if we need to set options
  417.     If ReadIni$("Service "+Session.Service, "Set Options", Session.IniFilename)<>"YES" Then
  418.         SetupOptions ""
  419.         Script
  420.         SetHighMessageNumber
  421.         Comms.HangUp
  422.         Exit Sub
  423.     End If
  424.  
  425.     If Instr(Command$, "manual") Then
  426.         On Error Resume Next
  427.         ManualTerminal
  428.     Else
  429.         Terminal.Status "Logged in successfully"
  430.  
  431.         ' Uncomment following section if needed for VA 4.00
  432.         'If ReadIni$("Service "+Session.Service, "Fetchmail", Session.IniFilename)<>"NO" Then
  433.         '    Fetchmail "0"
  434.         'End If
  435.         Terminal.Status ""
  436.  
  437.         ' Do the REPLY.EBS script
  438.         Script
  439.  
  440.         ' Added this to process fetch file at end
  441.         QueFetches
  442.  
  443.         ' Set hmn on exit
  444.         SetHighMessageNumber
  445.         If Session.StayOnline Then
  446.             Comms.Send "go cis:top\r"
  447.             On Error Resume Next
  448.             ManualTerminal
  449.         End If
  450.     End If
  451.  
  452.     Comms.Hangup
  453. End Sub
  454.  
  455. Function ReverseInStr(search As String, find As String) As Integer
  456.     Dim i As Integer, lasti As Integer
  457.  
  458.     i = 0
  459.     Do
  460.         lasti = i
  461.         i = InStr(lasti+1, search, find)
  462.         If i>0 Then tmp = Mid$(search, i+1)
  463.     Loop Until i=0
  464.  
  465.     ReverseInStr = lasti
  466. End Function
  467.  
  468. ' Is it a special gateway address that allows space?
  469. Function GatewayAddress(pto As String) As Boolean
  470.     Dim i As Integer, j As Integer
  471.  
  472.     i = InStr(pto, ":")
  473.     j = InStr(pto, " ")
  474.     If i=0 Or j=0 Then
  475.         GatewayAddress = False
  476.     ElseIf i<j Then
  477.         GatewayAddress = True
  478.     Else
  479.         GatewayAddress = False
  480.     End If
  481. End Function
  482.  
  483. ' Parse the To: line and extract the realname and the email address
  484. Sub AnalyseName(pto As String, realname As String, email As String)
  485.     Dim buf As String, p As Integer
  486.  
  487.     ' NOTE: Must be able to split the following types of addresses.
  488.     ' "Peter Clapham 100142,2244"
  489.     ' "Peter Clapham [100142,2244]"
  490.     ' "Peter Clapham [petec]"
  491.     ' "Peter Clapham [ASHMOUNT] 100142,2244"
  492.     ' "Peter Clapham [ASHMOUNT] [petec]"
  493.     ' "Peter Clapham [ASHMOUNT] [100142,2244]"
  494.     ' "[100142,2244]"
  495.     ' "100142,2244"
  496.     ' "petec"
  497.     ' "Matthias Daum [CCMAIL:Wibble Wibble]"
  498.     ' "CCMAIL:Wibble Wibble"
  499.  
  500.     ' Init vars
  501.     buf = Trim$(pto)
  502.     realname = ""
  503.     email = ""
  504.  
  505.     ' If last char is a ']' then the start of the email address is the
  506.     ' preceeding '['
  507.     If Right$(buf,1)="]" Then
  508.         p = ReverseInStr(buf, "[")
  509.     Else
  510.         If GatewayAddress(buf) Then
  511.             p = 1
  512.         Else
  513.             p = ReverseInStr(buf, " ")
  514.         End If
  515.     End If
  516.     If p>0 Then
  517.         email = Mid$(buf, p+1)
  518.         If p>0 Then
  519.             realname = Left$(buf, p-1)
  520.         Else
  521.             realname = ""
  522.         End If
  523.     Else
  524.         email = buf
  525.     End If
  526.     ReplaceAllInString email, "[", ""
  527.     ReplaceAllInString email, "]", ""
  528.  
  529.     ' Trim off whitespace and quotes on the realname
  530.     realname = Trim$(realname)
  531.     If Left$(realname,1)=Chr$(34) Then realname = Mid$(realname, 2, Len(realname)-2)
  532.     email = Trim$(email)
  533.  
  534.     ' Remove any 'internet:' or 'mime:' prefix
  535.     If UCase$(Left$(email, 9))="INTERNET:" Then email = Mid$(email, 10)
  536.     If UCase$(Left$(email, 5))="MIME:" Then email = Mid$(email, 6)
  537.  
  538.     ' Trim off unneeded '@compuserve.com' and convert . -> ,
  539.     p = InStr(email, "@compuserve.com", 1)
  540.     If p>0 Then
  541.         email = Left$(email, p-1)
  542.         ReplaceAllInString email, ".", ","
  543.     End If
  544.  
  545.     ' @web.compuserve.com -> CSINET:
  546.     If InStr(email, "@web.compuserve.com", 1)>0 And _
  547.        UCase$(Left$(email, 7))<>"CSINET:" Then
  548.         email = "CSINET:"+email
  549.     End If
  550.  
  551.     ' Check to see if it's a gateway, if it isn't and contains a '@' then
  552.     ' then it must be an internet address
  553.     If InStr(email, ":")=0 And InStr(email, " ")=0 And _
  554.        InStr(email, "@")<>0 Then
  555.         email = "internet:"+email
  556.     End If
  557. End Sub
  558.  
  559. 'Read an entire message from a file into a string
  560. 'If noformat = 0, add @b where appropriate
  561. 'If noformat = 1, add @l to say "send as shown" instead
  562. 'If noformat = 2, don't change the data at all
  563. Function ReadMessageFile(filename As String, noformat As Integer) As String
  564.     Dim inpline As String, body As String, badded As Boolean
  565.     Dim quoted As Boolean
  566.  
  567.     ' Collect message text ready to send to CIS
  568.     On Error Goto ReadMessageFile_error
  569.     Open filename For Input Access Read Shared As #1
  570.     If noformat = 1 Then body = "@l" + Chr$(10)
  571.     While Not Eof(1)
  572.         Line Input #1, inpline
  573.         If noformat < 2 Then ReplaceAllInString inpline, "@", "@@"
  574.         If noformat = 0 Then
  575.             inpline = RTrim$(inpline)
  576.             If Left$(inpline,1)=">" Then
  577.                 If body<>"" Then body = body + "@b" + Chr$(10)
  578.                 quoted = True
  579.             ElseIf quoted Then
  580.                 body = body + "@b" + Chr$(10)
  581.                 quoted = False
  582.             ElseIf inpline="" Or inpline<=" ~" Then
  583.                 If Not badded Then
  584.                     body = body + "@b" + Chr$(10)
  585.                     badded = True
  586.                 End If
  587.             Else
  588.                 If Right$(body, 1)>" " Then
  589.                     body = body + " "
  590.                 End If
  591.             End If
  592.             If inpline > "" Then badded = False
  593.         End If
  594.         If body="" Or body="@l"+Chr$(10) Then
  595.             body = body + inpline
  596.         Else
  597.             If noformat = 0 And inpline<>"" Then
  598.                 body = body + inpline
  599.             Else
  600.                 body = body + Chr$(10) + inpline
  601.             End If
  602.         End If
  603.     Wend
  604. ReadMessageFile_error:
  605.     On Error Goto 0
  606.     Close #1
  607.     ReadMessageFile = body + Chr$(10)
  608. End Function
  609.  
  610. 'T:GetForumList (subroutine) (CompuServe)
  611. Sub GetForumList(id As String, filename As String)
  612.     Dim s As String, page As String, i As Integer, count As Long
  613.     Dim filepage As DAPFILEPAGE
  614.  
  615.     If Not DoHMIFollowMenus("cis:index", "2", DAP_FILE) Then
  616.         LogResult "Unable to refresh forum list."
  617.         Exit Sub
  618.     End If
  619.  
  620.     Terminal.Print "Collecting forum list.  Please wait..." + Basic.Eoln$
  621.     page = "CIS:IND-41"
  622.  
  623.     HMIGetFile filepage
  624.  
  625.     ' Open forum list file to write to
  626.     On Error Goto GetForumList_error
  627.     DeleteFile filename
  628.     Open filename For Binary Access Write Shared As #1
  629.  
  630.     count = 0
  631.     Terminal.TransferStatus False, "Forum list", count, filepage.dwSize
  632.     s = DAPReceiveFile(HMI_STATE_FIRST%, page, i)
  633.     Do While i>0 And s<>""
  634.         Put #1, , s
  635.         count = count + i
  636.         Terminal.TransferStatus False, "Forum list", count, filepage.dwSize
  637.         s = DAPReceiveFile(HMI_STATE_NEXT%, page, i)
  638.     Loop
  639.     Close #1
  640.     Terminal.TransferStatus
  641.  
  642.     ReportSuccess id & " : Collected new forum list"
  643.     Exit Sub
  644.  
  645. GetForumList_error:
  646.     Close #1
  647.     Terminal.TransferStatus
  648.     LogResult "Error : " + FullErrorMessage()
  649.     LogResult id & " : Failed to collect forum list"
  650.     Exit Sub
  651. End Sub
  652.  
  653. 'T:Announcements (subroutine) (CompuServe)
  654. Sub Announcements(id As String, forum As String)
  655.     If Not HMIGotoForum(forum) Then
  656.         LogResult id + " : Failed : Unable to collect announcements from "+forum
  657.         Exit Sub
  658.     End If
  659.  
  660.     Terminal.Print "Collecting forum Announcements"+Basic.Eoln$
  661.     RecordBulletins forum, False, True, False
  662.     RecordSectionInformation forum
  663.  
  664.     If id<>"" Then ReportSuccess id & " : Announcements collected from " & forum & " "
  665. End Sub
  666.  
  667. 'T:Newsflash (subroutine) (CompuServe)
  668. Sub Newsflash(id As String, forum As String)
  669.     If Not HMIGotoForum(forum) Then
  670.         LogResult id + " : Failed : Unable to collect newsflash from "+forum
  671.         Exit Sub
  672.     End If
  673.  
  674.     Terminal.Print "Collecting forum Newsflash"+Basic.Eoln$
  675.     RecordBulletins forum, True, False, False
  676.     If id<>"" Then ReportSuccess id & " : Newsflash collected from " & forum & " "
  677. End Sub
  678.  
  679. Function ParseSectionList(ByVal sect As String, ByVal validsects As Long, _
  680.                           ByRef count As Integer) As Long
  681.     Dim s As String, l As Integer, h As Integer, sl As Long, xsl As Long
  682.  
  683.     count = 0
  684.     sect = LTrim(sect)
  685.     ReplaceAllInString sect, ",", " "    ' handle comma as separator
  686.     If sect = "*" Or StrComp(sect, "ALL", 1)=0 Then
  687.         ParseSectionList = validsects
  688.         For l = 0 To 24
  689.             sl = 2^l
  690.             If (validsects And sl)=sl Then count = count + 1
  691.         Next
  692.         Exit Function
  693.     End If
  694.     s = ParseString(sect, " ")      'Numbers are separated by spaces
  695.     While s > ""
  696.         l = Instr(s, "-")           'Allowed to use range - e.g. 3-6
  697.         If l > 0 Then               'We have a range
  698.             h = Val(Mid$(s, l + 1)) 'High value of range
  699.             For l = Val(s) To h     'From low to high value
  700.                 sl = sl Or (2 ^ l)  'Set appropriate bits
  701.             Next
  702.         Else
  703.             If UCase$(s)<>"Y" Then
  704.                 l = Val(s)              'Value
  705.                 sl = sl Or (2 ^ l)      'Set appropriate bit
  706.             End If
  707.         End If
  708.         s = ParseString(sect, " ")  'Numbers are separated by spaces
  709.     Wend
  710.     xsl = sl And validsects
  711.     ParseSectionList = xsl
  712.     For l = 0 To 24
  713.         If (xsl And 2^l)=2^l Then count = count + 1
  714.     Next
  715. End Function
  716.  
  717. Sub SaveMessage(hdr As FAPMSGHEADER, body As String)
  718.     Dim section As String, n As String, l As Integer, tail As String
  719.     Dim f As String
  720.  
  721.     ' Valid message?
  722.     If hdr.lpOriginatorId="" And hdr.lpRecipientName="" Then Exit Sub
  723.  
  724.     ' Check to see if it's a fake reply
  725.     If Mid$(hdr.lpSubject, 1, 1)="#" And hdr.dwParentMsg=0 Then
  726.         tail = ""
  727.         For l = 1 To Len(hdr.lpSubject)
  728.             If InStr("1234567890", Mid$(hdr.lpSubject, l, 1)) Then
  729.                 tail = tail + Mid$(hdr.lpSubject, l, 1)
  730.             End If
  731.             If Mid$(hdr.lpSubject, l, 1)="-"  And tail<>"" Then
  732.                 hdr.dwParentMsg = Val(tail)
  733.                 hdr.lpSubject = Mid$(hdr.lpSubject, l+1, Len(hdr.lpSubject)-l)
  734.                 l = Len(hdr.lpSubject)
  735.             End If
  736.         Next
  737.         tail = ""
  738.     End If
  739.  
  740.     ' Flags
  741.     f = ""
  742.     If (hdr.cFlags And FAP_MSG_IS_PRIVATE%)<>0 Then
  743.         f = "-- PRIVATE MESSAGE --" & Chr$(10)
  744.     End If
  745.     If (hdr.cFlags And FAP_MSG_HELD%)<>0 Then
  746.         f = "-- HOLD MESSAGE --" & Chr$(10)
  747.     End If
  748.     If (hdr.cFlags And FAP_READ_BY_RECIPIENT%)<>0 Then
  749.         f = f + "Read-By-Recipient: Yes" & Chr$(10)
  750.     Else
  751.         f = f + "Read-By-Recipient: No" & Chr$(10)
  752.     End If
  753.  
  754.     l = Len(hdr.lpSubject) + Len(f) + Len(hdr.lpOriginatorName) + _
  755.         Len(hdr.lpOriginatorId) + Len(hdr.lpRecipientName) + _
  756.         Len(hdr.lpRecipientId) + 24 + Len(body)
  757.     If hdr.wNumReplies = 1 Then 
  758.         tail = "There is 1 Reply" & Chr$(10)
  759.         Else If hdr.wNumReplies > 1 Then
  760.             tail = "There are " & hdr.wNumReplies & " Replies" & Chr$(10)
  761.         End If
  762.     End If
  763.     l = l - ItemCount(body, Chr$(13)) ' Don't count both CR+LF
  764.     If tail > "" Then
  765.         l = l + Len(tail)
  766.     End If
  767.     CaptureLine ""
  768.     If SectionMsgIds(hdr.cSectionId) >= 0 Then
  769.         section = szMsgSection(SectionMsgIds(hdr.cSectionId)).lpTitle
  770.     Else
  771.         section = "Unknown"
  772.     End If
  773.     If body="*** Header Only ***" & Chr$(10) Then
  774.         n = "*header*"
  775.         body = body + Chr$(10) + "[Double-click here to mark the message for collection]"
  776.         l = l + 55
  777.     Else
  778.         n = hdr.lpOriginatorName
  779.         ReplaceAllInString n, " ", "_"
  780.     End If
  781.     ReplaceAllInString hdr.lpOriginatorName, ";", " "
  782.     ReplaceAllInString hdr.lpRecipientName, ";", " "
  783.     nummessages = nummessages + 1
  784.     Terminal.CaptureStatus nummessages
  785.     CaptureLine "=========="
  786.     CaptureText CurrentForum & "/S" & hdr.cSectionId & "_" & section & " #"
  787.     CaptureText hdr.dwMsgNo & ", from " & n
  788.     CaptureLine ", " & l & " chars, " & MakeDateString(hdr.tsDate)
  789.     If hdr.dwParentMsg Then CaptureLine "Comment to " & hdr.dwParentMsg & "."
  790.     CaptureLine "----------"
  791.     CaptureLine "Subject: " & hdr.lpSubject
  792.     If f<>"" Then CaptureText f
  793.     CaptureLine "Fm: " & hdr.lpOriginatorName & " " & hdr.lpOriginatorId
  794.     CaptureLine "To: " & hdr.lpRecipientName & " " & hdr.lpRecipientId
  795.     CaptureLine ""
  796.     CaptureText body
  797.     CaptureLine ""
  798.     If tail > "" Then 
  799.         CaptureLine tail
  800.     End If
  801. End Sub
  802.  
  803. Sub WriteLibraryMessage(forum As String, filedesc As FAPFILEDESCRIPTION, downloaded As String)
  804.     Dim l As Long, sectname As String, from As String, hdr As String
  805.     Dim d0 As String, d1 As String, d2 As String, flags As String
  806.     Dim fn As String, sectno As Integer
  807.  
  808.     from = filedesc.lpUserName
  809.     fn = filedesc.lpFilename
  810.     ReplaceAllInString from, " ", "_"
  811.     ReplaceAllInString fn, " ", "_"
  812.     d0 = MakeDateString(filedesc.tsSubmitted)
  813.     d1 = MakeDateString(filedesc.tsLastAccess)
  814.     d2 = MakeDateString(filedesc.tsReleaseDate)
  815.     If d0="" Then d0 = MyDate$
  816.  
  817.     ' RFC 822 type header
  818.     hdr = "Subject: " & filedesc.lpTitle & Chr$(10) & _
  819.           "From: " & filedesc.lpUserName & " " & filedesc.lpUserID & Chr$(10) & _
  820.           "Date-Submitted: " & d0 & Chr$(10)
  821.     If d1<>"" Then hdr = hdr & "Date-Last-Access: " & d1 & Chr$(10)
  822.     If d2<>"" Then hdr = hdr & "Date-Released: " & d2 & Chr$(10)
  823.     hdr = hdr & "Filename: " & filedesc.lpFilename & Chr$(10) & _
  824.           "File-Type: " & GetFileType(filedesc.nFileType) & Chr$(10) & _
  825.           "File-Size: " & filedesc.dwFileSize & Chr$(10) & _
  826.           "Access-Count: " & filedesc.dwAccessCount & Chr$(10) & _
  827.           "Catalog-No: " & filedesc.dwCatalogNo & Chr$(10) & _
  828.           "Keywords: " & filedesc.lpKeys & Chr$(10)
  829.     If filedesc.lpSysOpComment <> "" Then
  830.         hdr = hdr & "SysOp-Comment: " & filedesc.lpSysOpComment & Chr$(10)
  831.     End If
  832.  
  833.     sectno = filedesc.cLibSectionNo
  834.     If SectionLibIds(sectno) >= 0 Then
  835.         sectname = szLibSection(SectionLibIds(sectno)).lpTitle
  836.     Else
  837.         sectname = "Unknown"
  838.     End If
  839.  
  840.     ' For new uploads
  841.     If filedesc.cOptions And FAP_FILE_DELETABLE Then flags = flags + ",Deletable"
  842.     If filedesc.cOptions And FAP_FILE_NON_PUBLIC Then flags = flags + ",Not public"
  843.     If filedesc.cOptions And FAP_FILE_MARKED_FOR_DELETION Then flags = flags + ",Marked for deletion"
  844.     If filedesc.cOptions And FAP_FILE_HAS_FEE Then flags = flags + ",Chargeable"
  845.     If flags > "" Then hdr = hdr & "Flags: " & Mid$(flags, 2) & Chr$(10)
  846.     If filedesc.cOptions And FAP_FILE_MARKED_FOR_DELETION Then
  847.         hdr = hdr & Chr$(10) & "*New Erase*" & Chr$(10)
  848.         sectname = sectname + "_[Sysop]"
  849.     ElseIf filedesc.cOptions And FAP_FILE_NON_PUBLIC Then
  850.         hdr = hdr & Chr$(10) & "*New Upload*" & Chr$(10)
  851.         sectname = sectname + "_[Sysop]"
  852.     End If
  853.  
  854.     l = 2+Len(hdr+filedesc.lpAbstract)-ItemCount(filedesc.lpAbstract, Chr$(13))
  855.  
  856.     ' Downloaded to...
  857.     If downloaded<>"" Then
  858.         l = l+Len("[]Downloaded to "+FileUrl(downloaded))+1
  859.     End If
  860.  
  861.     ' CIX header
  862.     CaptureLine "=========="
  863.     CaptureText forum & "/L" & sectno & "_" & sectname
  864.     CaptureText " #" & LTrim(Str(filedesc.dwCatalogNo))
  865.     CaptureLine ", from " & fn & ", " & l & " chars, " & d0
  866.     CaptureLine "----------"
  867.     CaptureLines hdr
  868.     CaptureLines Chr$(10)+filedesc.lpAbstract+Chr$(10)+Chr$(10)
  869.     If downloaded<>"" Then
  870.         CaptureLine "[Downloaded to "+FileUrl(downloaded)+"]"+Chr$(10)
  871.     End If
  872. End Sub
  873.  
  874.  
  875.