$AppType GUI
$TypeCheck ON
$Include "RapidQ.inc"

Declare Sub FormExit
Declare Sub ButtonClick

Const PortNum = 80  'Standard HTTP port.
Const TimeOut = 5  '5 seconds
Const WM_SOCK = 10000  'Make sure it's > 1024, whatever you want
Const WM_CLOSE = &H10

DefStr CRLF = Chr$(13) + Chr$(10)

Dim Sock As Integer
Dim Connected As Long

Sub FormWndProc (Hwnd&, uMsg&, wParam&, lParam&)
    If uMsg& = WM_SOCK Then Connected = 1
    If uMsg& = WM_CLOSE Then FormExit
End Sub

Create Form As QForm
  DelBorderIcons(biMaximize)
  Width = 640
  Height = 480
  Center
  Caption = "RapidQ Message Archive Retriever"
  OnClose = FormExit
  Create Socket As QSocket
    WMessage = WM_SOCK
  End Create
  Create URLLabel As QLabel
    Left = 8
    Top = 12
    Caption = "URL: "
  End Create
  Create Edit As QEdit
    Left = 45
    Top = 8
    Width = 230
    Text = "http://www.yahoo.com/"
  End Create
  Create Button As QButton
    Left = 300
    Top = 6
    Width = 80
    Caption = "Get it now!"
    OnClick = ButtonClick
  End Create
  Create RichEdit As QRichEdit
    Top = 45
    Width = Form.ClientWidth
    Height = 386
    PlainText = True
    WordWrap = False
    ScrollBars = ssBoth
    Text = "Warning!"+CRLF+"This will take a very long time to run."+CRLF+"And it will use up alot of disk space."+CRLF+"Only click on [Get it now!] when you're sure you can."
  End Create
  Create StatusBar As QStatusBar
    AddPanels "",""
    Panel(0).Width = 130
    Panel(0).Caption = ""
  End Create
  WndProc = FormWndProc
  ShowModal
End Create

Sub FormExit
    If Connected = 1 Then Socket.Close(Sock)
    Application.Terminate
End Sub

Sub ButtonClick
    Dim Text As String
    Dim Bytes As Long
    Dim Server As String, PathToFile As String
    Dim I As Integer
    Dim T# As Double
    Dim Count As Integer
    PathToFile = ""
    For Count = 1 To 29400 Step 30
     
Server="groups.yahoo.com/group/rapidq/messages/"+Str$(count)+"?xm=1&m=e&l=1"
      Edit.Text="http://"+Server
      I = InStr(Server, "/")
      If I Then
        PathToFile = Mid$(Server, I, Len(Server)+1-I)
        Server = Left$(Server, I-1)
      End If
      Sock = Socket.Connect(Server, PortNum)
      Connected = 0
      T# = Timer
      Do
        DoEvents
      Loop Until Connected Or Timer - T# >= TimeOut
      If Connected = 0 Then
        ShowMessage "Could not make connection!"
        RichEdit.SaveToFile("yahoo-rapidq.html")
        Exit Sub
      Else
        Sock = Socket.MySocket
      End If
      StatusBar.Panel(1).Caption = "Getting "+PathToFile+" from "+Server
      Socket.WriteLine(Sock, "GET "+PathToFile+" HTTP/1.0")
      Socket.WriteLine(Sock, "HOST "+Server+":"+Str$(PortNum))
      Socket.WriteLine(Sock, "")
      Text = ""
      Bytes = 0
      Do
        DoEvents
        If Socket.IsServerReady(Sock) Then
          Text = Text + Socket.Read(Sock, 32000)
          Bytes = Bytes + Socket.Transferred
          StatusBar.Panel(0).Caption = "Bytes Read: "+ Str$(Bytes)
        End If
      Loop Until Socket.Transferred = 0
      RichEdit.Clear
      RichEdit.Text = Right$(Text, Len(Text)-(InStr(Text,"<!")-1))
      StatusBar.Panel(1).Caption="Saving messages "+Str$(Count)+" to "+Str$(Count+30)+"."
      RichEdit.SaveToFile("RQ Msg Archives - "+Str$(Count)+" to "+Str$(Count+29)+".html")
      Socket.Close(Sock)
    Next Count
End Sub
'End Of code


