home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD115101192000.psc / ModData.bas < prev   
Encoding:
BASIC Source File  |  2000-10-06  |  38.0 KB  |  902 lines

  1. Attribute VB_Name = "Module"
  2. ''''''''''''''''''''''''''''' Hotmail Check Message ''''''''''''''''''''''''''''
  3. '                                                                              '
  4. '    This code uses the http/1.1 protocol to connect to the hotmail server     '
  5. '    and retrieve the mail box (note: when i use the term mailbox 'data'       '
  6. '    I am actually referring to the SOURCE CODE of the mailbox, which of       '
  7. '    course is sent in html format). This program does not use any special     '
  8. '    mail features, nor does it implement POP mail, it simply uses http        '
  9. '    commands to get the mailbox. Because it is so confusing, I tried the      '
  10. '    best i could to comment anywhere that there may be confusion, but         '
  11. '    if you are not familiar with socket programming or the http protocol,     '
  12. '    you will most likely have a difficult time understanding it.              '
  13. '    And although the only piece of data you see as a result of this program   '
  14. '    is how many new messages you have, once you understand how the program    '
  15. '    works, retrieving any other information about your hotmail account is     '
  16. '    a piece of cake. If you have any questions or comments, you can contact   '
  17. '    me at:  nmjblue@hotmail.com                                               '
  18. '                                                                              '
  19. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  20.  
  21. Public NextPage As String, CurrentPage As String, FolderURL As String, msgURL As String
  22. Public msgIDX As Long
  23. Public ShowDlgs As Boolean, Interval As Integer, lastmsg As Long
  24. Public StrLogin As String, StrPass As String ' holds login and password
  25. Public NewHost As String, NewUrl As String ' new server and url after redirection (see below)
  26. Public BatchNumber As Integer ' holds the current batch number we need to send
  27. Public Cookies(6) As String ' stores cookies received, required for receiving mailbox (contains encrypted information read by server)
  28. Public CurrentCookie As Integer ' stores current cookie number, as there are numerous different ones
  29. Public MailData As String ' once we begin to receive data about mailbox, this is the string that stores it so we can retrieve the information
  30. Public ReadBox As Boolean, BoxBatch As Integer ' boolean for whether or not we are receiving the mailbox data, and batch number of the data we are receiving
  31. Public loggedin As Boolean
  32. Public GotMail As Boolean, composeString As String
  33. Public composeurl As String, newmessages As String
  34. Public newmail As Long, msgfolder As String
  35.  
  36.  
  37. Public msghdrid As String, sendURL As String
  38.  
  39. ' Socket Values
  40. Public Const AF_INET = 2
  41. Public Const SOCK_STREAM = 1
  42. Public Const IPPROTO_IP = 0
  43. Public Const SOCKET_CONNECT = 2
  44. Public Const SOCKET_CANCEL = 5
  45. Public Const SOCKET_FLUSH = 6
  46. Public Const SOCKET_DISCONNECT = 7
  47.  
  48. Public Type HotmailMsg
  49.     subject As String
  50.     sender As String
  51.     email As String
  52.     indate As String
  53.     newmail As Boolean
  54.     msgURL As String
  55.     attach As Boolean
  56.     attachURL As String
  57.     size As Long
  58.     index As Long
  59.     cached As Boolean
  60.     ' Indicates whether the message is still online
  61.     isonline As Boolean
  62.     ' Indicates whether the message is new as far as the program is concerned
  63.     isnew As Boolean
  64. End Type
  65.  
  66. Public Type HotmailFolder
  67.     fname As String
  68.     id As String
  69.     url As String
  70.     size As Long
  71.     msgs As Long
  72.     newmsgs As Long
  73. End Type
  74.  
  75. Public Type HotmailAddress
  76.     fullname As String * 128
  77.     email As String * 128
  78. End Type
  79.  
  80. Public Type HotmailAccount
  81.     username As String * 64
  82.     loginname As String * 64
  83.     ' This will have to be encrypted someday
  84.     password As String * 12
  85. End Type
  86.  
  87. Public Type upVersion
  88.     major As Integer
  89.     minor As Integer
  90.     rev As Integer
  91. End Type
  92.  
  93. 'Public NewMessages As Integer
  94.  
  95. Public Folders() As HotmailFolder
  96. Public FolderCount As Long
  97.  
  98. Public Messages() As HotmailMsg
  99. Public MsgCount As Long
  100.  
  101. Public Addresses() As HotmailAddress
  102. Public addcount As Long
  103.  
  104. Public Accounts() As HotmailAccount
  105. Public AccCount As Long
  106.  
  107. Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
  108. Private Declare Function sndPlaySound Lib "winmm" Alias "sndPlaySoundA" (ByVal lpSound As String, ByVal flag As Long) As Long
  109.  
  110. Public Function AddMessage(ByVal subject As String, ByVal sender As String, ByVal email As String, Optional ByVal indate As String, Optional newmsg As Boolean, Optional ByVal url As String) As Long
  111.     Dim i As Long
  112.     Dim lastnum As Long
  113.     ' Make sure the message is not already loaded
  114.     For i = 0 To MsgCount - 1
  115.         If InStr(1, Messages(i).subject, Left(subject, Len(subject) - 3)) = 1 And Messages(i).indate = indate And Messages(i).email = email Then
  116.             Messages(i).isonline = True
  117.             Messages(i).newmail = newmsg
  118.             If Not Messages(i).cached Then
  119.                 Messages(i).isnew = True
  120.             End If
  121.             AddMessage = i
  122.             Exit Function
  123.         End If
  124.         
  125.         If Messages(i).index > lastnum Then
  126.             lastnum = Messages(i).index
  127.         End If
  128.     Next
  129.         
  130.     newmail = newmail + 1
  131.         
  132.     ReDim Preserve Messages(MsgCount) As HotmailMsg
  133.     Messages(MsgCount).isonline = True
  134.     With Messages(MsgCount)
  135.         .subject = subject
  136.         .sender = sender
  137.         .email = email
  138.         .indate = indate
  139.         .newmail = newmsg
  140.         .isnew = True
  141.         .msgURL = url
  142.         .index = lastnum + 1
  143.     End With
  144.     AddMessage = MsgCount
  145.     MsgCount = MsgCount + 1
  146. End Function
  147.  
  148. Public Function MakeSendString(ByVal tomail As String, ByVal subject As String, ByVal body As String, Optional ByVal cc As String, Optional ByVal bcc As String, Optional ByVal signature As String)
  149.     Dim content As String
  150.     Dim strdata As String ' for temporary storage of data to send
  151.     Dim feed As String
  152.     feed = (Chr(13) & Chr(10))
  153.     
  154.     ' We have to first take out all the spaces and replace them with plus signs
  155.     Dim tt1 As Long
  156.     Dim part1 As String, part2 As String
  157.     Dim last As Long
  158.     
  159.     body = body & vbCrLf & signature
  160.     
  161.     tt1 = InStr(1, body, " ")
  162.     Do Until tt1 = 0
  163.         part1 = Mid(body, 1, tt1 - 1)
  164.         part2 = Mid(body, tt1 + 1, Len(body) - tt1)
  165.             
  166.         body = part1 & "+" & part2
  167.         
  168.         last = tt1 + 1
  169.         tt1 = InStr(1, body, " ")
  170.     Loop
  171.     
  172.     If frmhotmail.chkSaveSent.Value = 1 Then
  173.         content$ = "login=" & StrLogin & "&wcid=&msg=&start=&len=&attfile=&type=&src=&subaction=&wysiwyg=&ref=&sigflag=y&newmail=new&msghdrid=" & msghdrid & "&col_name=Name&col_size=Size&col_type=Type&col_mod=Modified&col_path=Path&dlog_choosefile=Choose+File&dlog_progress=Attachment+Upload+Progress&dlog_delete=Attachments+on+the+server+can+not+be+removed.&dlog_zerok=Cannot+send+a+zero+length+attachment.&dlog_sizeexceeded=The+total+size+of+attachments+cannot+exceed+1000k.&dlog_filenotfound1=The+file+&dlog_filenotfound2=+could+not+be+found.+Continue%3F&dlog_badserver=The+target+server+is+not+a+valid+Hotmail+server.&to=" & tomail & "&subject=" & subject & "&cc=" & cc & "&bcc=" & bcc & "&outgoing=on&Send.x=Send&body=" & body & "&TMP_outgoing=on"
  174.     Else
  175.         content$ = "login=" & StrLogin & "&wcid=&msg=&start=&len=&attfile=&type=&src=&subaction=&wysiwyg=&ref=&sigflag=y&newmail=new&msghdrid=" & msghdrid & "&col_name=Name&col_size=Size&col_type=Type&col_mod=Modified&col_path=Path&dlog_choosefile=Choose+File&dlog_progress=Attachment+Upload+Progress&dlog_delete=Attachments+on+the+server+can+not+be+removed.&dlog_zerok=Cannot+send+a+zero+length+attachment.&dlog_sizeexceeded=The+total+size+of+attachments+cannot+exceed+1000k.&dlog_filenotfound1=The+file+&dlog_filenotfound2=+could+not+be+found.+Continue%3F&dlog_badserver=The+target+server+is+not+a+valid+Hotmail+server.&to=" & tomail & "&subject=" & subject & "&cc=" & cc & "&bcc=" & bcc & "&body=" & body & "&Send.x=Send"
  176.     End If
  177.     strdata = "POST " & sendURL & " HTTP/1.1" & feed & "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*" & feed
  178.     strdata = strdata & "Accept -Language: en -us" & feed
  179.     strdata = strdata & "Referer: http://" & NewHost & "/cgi-bin/compose?a=b" & feed
  180.     strdata = strdata & "Accept -Encoding: gzip , deflate" & feed & "User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)" & feed
  181.     strdata = strdata & "Content-Type: application/x-www-form-urlencoded" & feed
  182.     strdata = strdata & "Host: " & NewHost & feed
  183.     strdata = strdata & "Content-Length: " & Len(content$) & feed & "Connection: Keep -Alive" & feed
  184.     strdata = strdata & "Cookie: HMP1=1; " & Cookies(4) & "; " & Cookies(1) & "; " & Cookies(2) & feed & feed
  185.     strdata = strdata & content$ & feed & feed
  186.     MakeSendString = strdata
  187. End Function
  188.  
  189. Public Function MakeString(Connection As Long, Optional ByVal url As String) As String
  190.     Dim strdata As String ' for temporary storage of data to send
  191.     Dim feed As String
  192.     feed = (Chr(13) & Chr(10)) ' carriage return & linefeed
  193.     
  194.     Select Case Connection
  195.         Case 0 'first batch of data sent, contains login information
  196.             Dim content As String
  197.             content$ = "login=" & StrLogin$ & "&domain=hotmail.com&passwd=" & StrPass$ & "&enter=Sign+in&sec=no&curmbox=ACTIVE&js=yes&_lang=&beta=&ishotmail=1&id=2&ct=963865176"
  198.             strdata = "POST /cgi-bin/dologin HTTP/1.1" & feed & "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*" & feed
  199.             strdata = strdata & "Accept -Language: en -us" & feed & "Content-Type: application/x-www-form-urlencoded" & feed
  200.             strdata = strdata & "Accept -Encoding: gzip , deflate" & feed & "User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)" & feed
  201.             strdata = strdata & "Host: lc5.law5.hotmail.passport.com" & feed
  202.             strdata = strdata & "Content-Length: " & Len(content$) & feed & "Connection: Keep -Alive" & feed & feed
  203.             strdata = strdata & content$ & feed & feed
  204.             MakeString = strdata
  205.         Case 1 'we get relocated to a new hotmail server (NewHost) containing the mailbox. here we request a new page, because contained in the url of the page (NewUrl) is our encrypted login and password
  206.             strdata = "GET /" & NewUrl$ & " HTTP/1.1" & feed
  207.             strdata = strdata & "User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)" & feed
  208.             strdata = strdata & "Host: " & NewHost$ & feed
  209.             strdata = strdata & "Cookie: MC1=V=2&GUID=B8E9C518070C49B18A9884F543033C33; mh=ENCA; MSPDom=; MSPAuth=; MSPProf=; MSPVis=; LO=; HMSC0899=; HMP1=1; HMSC0899="
  210.             strdata = strdata & feed & feed
  211.              '& feed
  212.             MakeString = strdata
  213.         Case 2 'finally, we request the mailbox on the new server, by sending the cookies we received with all the encrypted information needed
  214.             strdata = "GET " & NewUrl$ & " HTTP/1.1" & feed
  215.             strdata = strdata & "User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)" & feed
  216.             strdata = strdata & "Host: " & NewHost$ & feed
  217.             strdata = strdata & "Connection: Keep-Alive" & feed
  218.             strdata = strdata & "Cookie: HMP1=1; " & Cookies(4) & "; MSPDom=; " & Cookies(1) & "; " & Cookies(2) & "; MSPVis=1; LO=;" & feed & feed
  219.             MakeString = strdata
  220.         Case 3
  221.             ' Get Next Page of Messages
  222.             strdata = "GET " & url & " HTTP/1.1" & feed & "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*" & feed
  223.             'If LastPage <> "" Then
  224.             strdata = strdata & "Referer: http://" & NewHost & CurrentPage & feed
  225.             'End If
  226.             strdata = strdata & "Accept-Language: en-us" & feed '& "Content-Type: application/x-www-form-urlencoded" & feed
  227.             strdata = strdata & "Accept-Encoding: gzip, deflate" & feed
  228.             strdata = strdata & "User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)" & feed
  229.             strdata = strdata & "Host: " & NewHost$ & feed
  230.             strdata = strdata & "Connection: Keep-Alive" & feed
  231.             strdata = strdata & "Cookie: HMP1=1; " & Cookies(4) & "; " & Cookies(1) & "; " & Cookies(2) & feed & feed
  232.             MakeString = strdata
  233.         Case 4
  234.             ' Get Folder List
  235.             strdata = "GET /cgi-bin/" & FolderURL & " HTTP/1.1" & feed & "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*" & feed
  236.             strdata = strdata & "Referer: http://" & NewHost & NextPage & feed
  237.             strdata = strdata & "Accept-Language: en-us" & feed '& "Content-Type: application/x-www-form-urlencoded" & feed
  238.             strdata = strdata & "Accept-Encoding: gzip, deflate" & feed
  239.             strdata = strdata & "User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)" & feed
  240.             strdata = strdata & "Host: " & NewHost$ & feed
  241.             strdata = strdata & "Connection: Keep-Alive" & feed
  242.             strdata = strdata & "Cookie: HMP1=1; " & Cookies(4) & "; " & Cookies(1) & "; " & Cookies(2) & feed & feed
  243.             MakeString = strdata
  244.         Case 5
  245.             ' Get Message Body
  246.             strdata = "GET /cgi-bin/" & url & " HTTP/1.1" & feed
  247.             strdata = strdata & "Referer: http://" & NewHost & NextPage & feed
  248.             strdata = strdata & "User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)" & feed
  249.             strdata = strdata & "Host: " & NewHost$ & feed
  250.             strdata = strdata & "Connection: Keep-Alive" & feed
  251.             strdata = strdata & "Cookie: HMP1=1; " & Cookies(4) & "; MSPDom=; " & Cookies(1) & "; " & Cookies(2) & "; MSPVis=1; LO=;" & feed & feed
  252.             MakeString = strdata
  253.         Case 6
  254.             ' Delete Message
  255.             content = "tobox=&js=&_HMaction=delete&foo=inbox&page=&" & url & "=on&nullbox="
  256.             strdata = strdata & "POST /cgi-bin/HoTMaiL HTTP/1.1" & feed & "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*" & feed
  257.             strdata = strdata & "Referer: http://" & NewHost & NextPage & feed
  258.             strdata = strdata & "Accept-Language: en-us" & feed & "Content-Type: application/x-www-form-urlencoded" & feed
  259.             strdata = strdata & "Accept-Encoding: gzip, deflate" & feed
  260.             strdata = strdata & "User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)" & feed
  261.             strdata = strdata & "Host: " & NewHost$ & feed
  262.             strdata = strdata & "Content-Length: " & Len(content$) & feed & "Connection: Keep-Alive" & feed
  263.             strdata = strdata & "Cookie: HMP1=1; " & Cookies(4) & "; MSPDom=; " & Cookies(1) & "; " & Cookies(2) & "; MSPVis=1; LO=;" & feed & feed
  264.             strdata = strdata & content & feed & feed
  265.             MakeString = strdata
  266.     End Select
  267. End Function
  268.  
  269. Public Sub PlayWave(sFileName As String)
  270.     On Error GoTo Play_Err
  271.     
  272.     Dim iReturn As Integer
  273.     
  274.     If frmhotmail.chkNoSounds.Value = 0 Then
  275.         'Make sure something was passed to the Play Function
  276.         If sFileName > "" Then
  277.             'Make sure a WAV filename was passed
  278.             If UCase$(Right$(sFileName, 3)) = "WAV" Then
  279.                 'Make sure the file exists
  280.                 If Dir(sFileName) > "" Then
  281.                     iReturn = sndPlaySound(sFileName, 0)
  282.                 End If
  283.             End If
  284.         End If
  285.     End If
  286.     
  287.     'Wav file play successful
  288.     Exit Sub
  289.  
  290. Play_Err:
  291.     'If there was an error then exit without playing
  292.     Exit Sub
  293. End Sub
  294.  
  295. Public Function FindNextMessage(ByVal start As Long, ByVal text As String) As String
  296.     Dim pos1 As Long, pos2 As Long, pos3 As Long
  297.     Dim epos1 As Long
  298.     Dim temp As String
  299.     Dim sender As String, email As String
  300.     Dim newmail As Boolean
  301.     Dim msgURL As String
  302.     Dim mDate As String
  303.     Dim newmsg As Long, size As String
  304.     
  305.     ' 1. First, we find the next HREF tag that starts with "msg=MSG".  This denotes a Message
  306.     pos1 = InStr(start, text, "msg=MSG")
  307.     If pos1 <> 0 Then
  308.         
  309.         ' GET THE SENDER OF THE MESSAGE
  310.         ' The sender's name is embedded in an HREF tag that is just after the msg=MSG...
  311.         ' So, we should first look for the next ">" and then find the next "<"
  312.         ' and get the part in between.
  313.         
  314.                 ' Find the next ">"
  315.                 pos2 = InStr(pos1, text, ">")
  316.                 If pos2 <> 0 Then
  317.                     ' Find the next "<"
  318.                     pos3 = InStr(pos2, text, "<")
  319.                     If pos3 <> 0 Then
  320.                         ' Extract the sender's name (it's sometimes truncated)
  321.                         sender = RemoveNBSPs(Mid(text, pos2 + 1, (pos3 - pos2) - 1), True)
  322.                     End If
  323.                 End If
  324.                 
  325.         ' Let's say we want their e-mail address
  326.         ' that information is embedded in a name tag just before the sender's name
  327.         ' we have to be careful about which one we grab though.  It has to be following
  328.         ' a name tag that starts with "MSG"
  329.         epos1 = InStr(start, text, "name=" & Chr(34) & "MSG")
  330.         If epos1 <> 0 Then
  331.             ' Now it should be the next name tag
  332.             pos2 = InStr(epos1 + Len("name=" & Chr(34) & "MSG"), text, "name=")
  333.             If pos2 <> 0 Then
  334.                 ' and we'll find the ">"
  335.                 pos3 = InStr(pos2, text, ">")
  336.                 If pos3 <> 0 Then
  337.                     pos2 = pos2 + Len("name=")
  338.                     email = Mid(text, pos2 + 1, (pos3 - pos2) - 1)
  339.                     ' And take the quotes off the ends
  340.                     email = Left(email, Len(email) - 1)
  341.                     'email = Mid(email, 1, Len(email) - 1)
  342.                 End If
  343.             End If
  344.         End If
  345.         
  346.         ' We can also check if the message is new by looking for "newmail.gif"
  347.         ' just so we don't mark the wrong message as new, we have to make sure it
  348.         ' is positioned before the email address we just got
  349.         pos2 = InStr(start, text, "alt='New'")
  350.         If pos2 <> 0 Then
  351.             If pos2 < pos3 And pos2 > epos1 Then
  352.                 newmail = True
  353.                 'lastmsg = pos2 + 1
  354.             End If
  355.         End If
  356.         
  357.         ' We also want the message URL so we can download the message
  358.         pos2 = InStr(start, text, "getmsg?")
  359.         If pos2 <> 0 Then
  360.             ' find the ending ">"
  361.             pos3 = InStr(pos2, text, ">")
  362.             If pos3 <> 0 Then
  363.                 ' extract the url
  364.                 msgURL = Mid(text, pos2, (pos3 - 1) - pos2)
  365.             End If
  366.         End If
  367.         
  368.         ' 2. Now, we look for the first <TD> after that
  369.         pos2 = InStr(pos1, text, "<td>")
  370.         If pos2 <> 0 Then
  371.             ' 3. Now we get the </TD> that goes with it
  372.             pos3 = InStr(pos2, text, "</td>")
  373.             If pos3 <> 0 Then
  374.                 ' 4. Extract the stuff in between
  375.                 pos2 = pos2 + Len("<td>")
  376.                 temp = Mid(text, pos2 + 1, pos3 - pos2)
  377.                 ' 5. Take 6 characters off of each end.  These are " " tags
  378.                 temp = Mid(temp, 6, Len(temp) - 7)
  379.                 temp = Left(temp, Len(temp) - 5)
  380.                 
  381.                 lastmsg = pos3 + 1
  382.                 FindNextMessage = temp & " from " & sender & " (" & email & ")"
  383.             End If
  384.         End If
  385.         
  386.         ' The date for the message is embedded in the next <TD>
  387.         pos1 = InStr(pos3 + 1, text, "<td>")
  388.         If pos1 <> 0 Then
  389.             pos2 = InStr(pos1 + 1, text, "</td>")
  390.             If pos2 <> 0 Then
  391.                 pos1 = pos1 + Len("<td>")
  392.                 mDate = Mid(text, pos1, pos2 - pos1)
  393.                 ' We'll have to clean out the  s
  394.                 mDate = RemoveNBSPs(mDate)
  395.             End If
  396.         End If
  397.         
  398.         ' The size of the message would be useful when downloading them
  399.         pos1 = InStr(pos2 + Len("</td>") + 1, text, ">")
  400.         If pos1 <> 0 Then
  401.             pos3 = InStr(pos1, text, "</td>")
  402.             If pos3 <> 0 Then
  403.                 size = RemoveNBSPs(Mid(text, pos1 + 1, pos3 - pos1), True)
  404.                 size = Left(size, Len(size) - 2)
  405.             End If
  406.         End If
  407.                        
  408.         newmsg = AddMessage(temp, sender, email, mDate, newmail, msgURL)
  409.         Messages(newmsg).size = CLng(size)
  410.     End If
  411. End Function
  412.  
  413. Private Function RemoveNBSPs(ByVal text As String, Optional sp As Boolean) As String
  414.     Dim p1 As Long, p2 As Long
  415.     Dim part1 As String, part2 As String
  416.     
  417.     p1 = InStr(1, text, " ")
  418.     Do Until p1 = 0
  419.         part1 = Mid(text, 1, p1 - 1)
  420.         part2 = Mid(text, p1 + Len(" "), Len(text) - p1)
  421.         
  422.         If sp Then
  423.             text = part1 & "" & part2
  424.         Else
  425.             text = part1 & " " & part2
  426.         End If
  427.         'last = tt1 + 1
  428.         p1 = InStr(1, text, " ")
  429.     Loop
  430.     RemoveNBSPs = Trim(text)
  431. End Function
  432.  
  433. Public Function GetFolderURL(ByVal text As String) As String
  434.     Dim p1 As Long, p2 As Long
  435.     Dim temp As String
  436.     
  437.     ' Look for folders?a=
  438.     p1 = InStr(1, text, "folders?")
  439.     If p1 <> 0 Then
  440.         ' find the next "
  441.         p2 = InStr(p1, text, Chr(34))
  442.         If p2 <> 0 Then
  443.             temp = Mid(text, p1, p2 - p1)
  444.             GetFolderURL = temp
  445.         End If
  446.     End If
  447. End Function
  448.  
  449. Public Function ResizeMessageArray()
  450.     ' This function will remove any messages that have been deleted
  451.     ' and update the message count so we don't have wierd things going on
  452.     Dim tempar() As HotmailMsg
  453.     Dim count As Long, i As Long
  454.     
  455.     For i = 0 To MsgCount - 1
  456.         If Messages(i).msgURL <> "" And Messages(i).isonline = True Then
  457.             ReDim Preserve tempar(count) As HotmailMsg
  458.             tempar(count) = Messages(i)
  459.             'tempar(count).index = count
  460.             count = count + 1
  461.         End If
  462.     Next
  463.     
  464.     MsgCount = count
  465.     ReDim Messages(count - 1) As HotmailMsg
  466.     Messages = tempar
  467. End Function
  468.  
  469. Public Function ProcessFolders(ByVal text As String)
  470.     Dim id1 As Long, id2 As Long
  471.     Dim nm1 As Long
  472.     Dim temp As String
  473.     Dim fname As String
  474.     Dim msgs As Long
  475.     Dim newmsgs As Long
  476.     Dim size As Long
  477.     
  478.     id1 = InStr(1, text, "<tbody>")
  479.     If id1 <> 0 Then
  480.     
  481.         ' Find the first ID tag
  482.         id1 = InStr(id1 + 1, text, "/cgi-bin/HoTMaiL?")
  483.         Do Until id1 = 0
  484.         'If id1 <> 0 Then
  485.             ' Now, find the corresponding "
  486.             id2 = InStr(id1, text, Chr(34))
  487.             If id2 <> 0 Then
  488.                 ' Extract the ID
  489.                 temp = Mid(text, id1, id2 - id1)
  490.                 
  491.                 ' Now, we might want the name of the folder as well
  492.                 ' to get this, we have to look for a carriage return after the ">"
  493.                 nm1 = InStr(id2, text, "<")
  494.                 If nm1 <> 0 Then
  495.                     fname = Mid(text, id2 + 2, (nm1 - id2) - 2)
  496.                     If fname <> "" Then
  497.                         ' Now we can get the number of messages
  498.                         ' by looking for the following "center>"
  499.                         id1 = InStr(nm1, text, "center>")
  500.                         If id1 <> 0 Then
  501.                             id2 = InStr(id1 + 1, text, "</")
  502.                             If id2 <> 0 Then
  503.                                 id1 = id1 + Len("center>")
  504.                                 msgs = CInt(Mid(text, id1, id2 - id1))
  505.                             End If
  506.                         End If
  507.                         ' Make sure we have a starting point if we didn't find
  508.                         ' the number of messages
  509.                         If id2 = 0 Then id2 = nm1
  510.                         ' Do the same for the number of new messages
  511.                         id1 = InStr(id2 + 1, text, "center>")
  512.                         If id1 <> 0 Then
  513.                             id2 = InStr(id1 + 1, text, "</")
  514.                             If id2 <> 0 Then
  515.                                 id1 = id1 + Len("center>")
  516.                                 If Mid(text, id1, 3) = "<b>" Then
  517.                                     id1 = id1 + 3
  518.                                 End If
  519.                                 newmsgs = CInt(Mid(text, id1, id2 - id1))
  520.                             End If
  521.                         End If
  522.                         ' And now we do the same for the size of the folder
  523.                         If id2 = 0 Then id2 = nm1
  524.                         id1 = InStr(id2 + 1, text, "right>")
  525.                         If id1 <> 0 Then
  526.                             id2 = InStr(id1 + 1, text, "</")
  527.                             If id2 <> 0 Then
  528.                                 id1 = id1 + Len("right>")
  529.                                 id2 = id2 - 1
  530.                                 size = CLng(Mid(text, id1, id2 - id1))
  531.                             End If
  532.                         End If
  533.                         
  534.                         ReDim Preserve Folders(FolderCount) As HotmailFolder
  535.                         With Folders(FolderCount)
  536.                             .fname = fname
  537.                             .id = temp
  538.                             .url = temp
  539.                             .size = size
  540.                             .newmsgs = newmsgs
  541.                             .msgs = msgs
  542.                         End With
  543.                         FolderCount = FolderCount + 1
  544.                     End If
  545.                 End If
  546.             End If
  547.             id1 = InStr(id1 + 1, text, "/cgi-bin/HoTMaiL?")
  548.         'End If
  549.         Loop
  550.     End If
  551. End Function
  552.  
  553. Public Function IsNextPage(ByVal text As String) As String
  554.     Dim ref1 As Long, ref2 As Long
  555.     Dim t1 As Long
  556.     Dim temp As String
  557.     
  558.     ' The NEXT PAGE text is embedded in an HREF tag that looks like this
  559.     ' <a href="/cgi-bin/HoTMaiL?a=b&page=2">Next Page</a>
  560.     ' So, we will first find the "HoTMaiL?a=b&page=" section
  561.     
  562.     ref1 = InStr(1, text, "/cgi-bin/HoTMaiL?")
  563.     Do Until ref1 = 0
  564. '    If ref1 <> 0 Then
  565.         ' Now we check for the "<"
  566.         ref2 = InStr(ref1, text, "<")
  567.         If ref2 <> 0 Then
  568.             ' Now we will get the ">" before the NEXT PAGE
  569.             t1 = InStr(ref1, text, ">")
  570.             If t1 <> 0 Then
  571.                 ' Finally, extract what is in between and check if it says NEXT PAGE
  572.                 temp = Mid(text, t1 + 1, (ref2 - t1) - 1)
  573.                 If temp = "Next Page" Then
  574.                     ' We'll want the URL for the page now too
  575.                     temp = Mid(text, ref1, (t1 - ref1) - 1)
  576.                     IsNextPage = temp
  577.                     'Debug.Print temp
  578.                 End If
  579.             End If
  580.         End If
  581.         ref1 = InStr(ref1 + 1, text, "/cgi-bin/HoTMaiL?")
  582. '    End If
  583.     Loop
  584. End Function
  585.  
  586. Sub PS_MvFrm(frm As Form)
  587.     'ReleaseCapture
  588.     'Call SendMessage(frm.hwnd, &HA1, 2, 0&)
  589. End Sub
  590.  
  591. Sub GetMessage(ByVal url As String)
  592.     With frmhotmail
  593.         msgURL = url
  594.         .Socket.Action = SOCKET_DISCONNECT
  595.         BatchNumber = 5
  596.         .Socket.Action = 2
  597.     End With
  598. End Sub
  599.  
  600. Public Function ProcessMessage(ByVal text As String) As String
  601.     ' We are now going to extract the body of a message from an HTML document
  602.     ' The body of Hotmail messages are usually between <TT></TT> or <PRE></PRE> tags
  603.     ' That makes this a whole lot simpler.
  604.     
  605.     Dim tt1 As Long, tt2 As Long
  606.     Dim pre1 As Long, pre2 As Long
  607.     Dim last As Long
  608.     
  609.     Dim msg As String
  610.     Dim part1 As String, part2 As String
  611.     Dim temp As String
  612.     
  613.     ' First, check for the <TT> tag
  614.     tt1 = InStr(1, text, "<tt>")
  615.     If tt1 <> 0 Then
  616.         ' Now, find the </TT>
  617.         tt2 = InStr(tt1, text, "</tt>")
  618.         If tt2 <> 0 Then
  619.             ' Finally, extract the message
  620.             tt1 = tt1 + 4
  621.             msg = Mid(text, tt1, tt2 - tt1)
  622.             msg = "<HTML><HEAD><TITLE></TITLE></HEAD><BODY><FONT FACE='Courier New' SIZE=2>" & msg
  623.             'msg = ProcessReturns(msg)
  624.         End If
  625.     Else
  626.         ' There must be a <DIV> instead
  627.         pre1 = InStr(1, text, "<div>", vbTextCompare)
  628.         If pre1 <> 0 Then
  629.             pre2 = InStr(pre1, text, "</div>")
  630.             If pre2 <> 0 Then
  631.                 pre1 = pre1 + 5
  632.                 ' Before we cut it up, let's look for a <p> following the div.
  633.                 ' this would indicate an image or embedded attachment of sorts
  634.                 msg = RemoveCrap(Mid(text, pre1, pre2 - pre1))
  635.                 tt1 = InStr(pre1 - 2, text, "<p>")
  636.                 If tt1 <> 0 Then
  637.                     ' Find the corresponding </p>
  638.                     tt2 = InStr(tt1, text, "</p>")
  639.                     If tt2 <> 0 Then
  640.                         tt1 = tt1 + 3
  641.                         If Left(Mid(text, tt1, tt2 - tt1), 4) = "<img" Then
  642.                             temp = Mid(text, tt1, tt2 - tt1)
  643.                             ' Extract the URL
  644.                             tt1 = InStr(1, temp, Chr(34))
  645.                             tt2 = InStr(tt1 + 1, temp, Chr(34))
  646.                             tt1 = tt1 + 1
  647.                             msg = msg & "<b><a href=" & Chr(34) & Mid(temp, tt1, tt2 - tt1) & Chr(34) & ">View Image</a></b>"
  648.                             Messages(msgIDX).attach = True
  649.                             Messages(msgIDX).attachURL = Mid(temp, tt1, tt2 - tt1)
  650.                         End If
  651.                     End If
  652.                 End If
  653.                 msg = "<HTML><HEAD><TITLE></TITLE></HEAD><BODY><FONT FACE='Courier New' SIZE=3>" & msg
  654.             End If
  655.         Else
  656.             ' There must be a <PRE> instead
  657.             pre1 = InStr(1, text, "<pre>")
  658.             If pre1 <> 0 Then
  659.                 pre2 = InStr(pre1, text, "</pre>")
  660.                 If pre2 <> 0 Then
  661.                     pre1 = pre1 + 5
  662.                     msg = ProcessReturns(Mid(text, pre1, pre2 - pre1))
  663.                     msg = "<HTML><HEAD><TITLE></TITLE></HEAD><BODY><FONT FACE='Courier New' SIZE=3>" & msg
  664.                 End If
  665.             End If
  666.         End If
  667.     End If
  668.     
  669.     ' We can also check to see if there is an attachment with this message
  670.     pre1 = InStr(1, text, "icon_clip.gif")
  671.     If pre1 <> 0 Then
  672.         pre2 = InStr(pre1, text, "<a")
  673.         If pre2 <> 0 Then
  674.             pre2 = pre2 + Len("<a href=") + 1
  675.             tt1 = InStr(pre2, text, Chr(34))
  676.             If tt1 <> 0 Then
  677.                 'tt1 = tt1 + Len("</a>")
  678.                 temp = Mid(text, pre2, tt1 - pre2)
  679.                 
  680.                 Messages(msgIDX).attach = True
  681.                 Messages(msgIDX).attachURL = temp
  682.                 
  683.                 msg = msg & "<P><B><a href=" & Chr(34) & "http://" & NewHost & temp & Chr(34) & ">View Attachment</a></B>"
  684.             End If
  685.         End If
  686.     End If
  687.     
  688.     msg = msg & "</FONT></BODY></HTML>"
  689.             
  690.     ProcessMessage = msg
  691. End Function
  692.  
  693. Public Function ProcessReturns(ByVal msg As String) As String
  694.     Dim tt1 As Long
  695.     Dim part1 As String, part2 As String
  696.     Dim last As Long
  697.     ' Now, we have to go through and replace carriage returns with <BR>
  698.     tt1 = InStr(1, msg, Chr(10))
  699.     Do Until tt1 = 0
  700.         If tt1 <> last + Len("<BR>") Then
  701.             part1 = Mid(msg, 1, tt1 - 1)
  702.             part2 = Mid(msg, tt1 + 1, Len(msg) - tt1)
  703.         
  704.             msg = part1 & "<BR>" & part2
  705.         Else
  706.             part1 = Mid(msg, 1, tt1 - 1)
  707.             part2 = Mid(msg, tt1 + 1, Len(msg) - tt1)
  708.             
  709.             msg = part1 & part2
  710.         End If
  711.         last = tt1 + 1
  712.         tt1 = InStr(1, msg, Chr(10))
  713.     Loop
  714.     
  715.     ProcessReturns = msg
  716. End Function
  717.  
  718. Public Function RemoveCrap(ByVal msg As String) As String
  719.     Dim tt1 As Long
  720.     Dim part1 As String, part2 As String
  721.     Dim last As Long
  722.     ' Remove Crap Like these damn things: 
  723.     tt1 = InStr(1, msg, Chr(11))
  724.     Do Until tt1 = 0
  725.         part1 = Mid(msg, 1, tt1 - 1)
  726.         part2 = Mid(msg, tt1 + 1, Len(msg) - tt1)
  727.             
  728.         msg = part1 & part2
  729.         
  730.         last = tt1 + 1
  731.         tt1 = InStr(1, msg, Chr(11))
  732.     Loop
  733.     RemoveCrap = msg
  734. End Function
  735.  
  736. Public Function GetComposeURL(ByVal text As String) As String
  737.     Dim c1 As Long, c2 As Long
  738.     Dim temp As String
  739.     
  740.     ' The compose URL is hidden amongst the other functions found
  741.     ' on the top bar on the hotmail page.  It's beside inbox and addresses
  742.     ' We're going to look for part of the url, which won't ever change
  743.     ' that's the key in all of this.  The part we want is "/cgi-bin/compose?a"
  744.     
  745.     c1 = InStr(1, text, "/cgi-bin/compose?")
  746.     If c1 <> 0 Then
  747.         ' Now we'll look for the ending quote
  748.         c2 = InStr(c1, text, Chr(34))
  749.         If c2 <> 0 Then
  750.             ' and get what's between
  751.             temp = Mid(text, c1, c2 - c1)
  752.             GetComposeURL = temp
  753.         End If
  754.     End If
  755. End Function
  756.  
  757. Public Sub ProcessComposePage(ByVal text As String)
  758.     Dim c1 As Long, c2 As Long
  759.     Dim b1 As Long, b2 As Long
  760.     
  761.     ' The two pieces of information we want are the URL that we
  762.     ' post to, and the MsgHDrid.  What that is, I don't know.
  763.     ' These two things are pretty simple to find.  The first, is
  764.     ' right next to "action=" in a form.  The second is next to a
  765.     ' "value=" in an hidden input box.  To be sure we get the URL,
  766.     ' we're going to just look for "premail" and get the Id that follows
  767.     
  768.     ' Find the ID
  769.     c1 = InStr(1, text, "premail/")
  770.     If c1 <> 0 Then
  771.         ' find the following quote
  772.         c2 = InStr(c1, text, Chr(34))
  773.         If c2 <> 0 Then
  774.             ' Get the id
  775.             sendURL = "/cgi-bin/" & Mid(text, c1, c2 - c1)
  776.         End If
  777.     End If
  778.     
  779.     ' Find the msghdrid
  780.     c1 = InStr(1, text, "name=" & Chr(34) & "msghdrid" & Chr(34))
  781.     If c1 <> 0 Then
  782.         b1 = InStr(c1, text, "value=")
  783.         If b1 <> 0 Then
  784.             b1 = b1 + Len("value=") + 1
  785.             b2 = InStr(b1, text, Chr(34))
  786.             If b2 <> 0 Then
  787.                 msghdrid = Mid(text, b1, b2 - b1)
  788.             End If
  789.         End If
  790.     End If
  791. End Sub
  792.  
  793. Public Sub LoadAccounts()
  794.     Dim filename As String
  795.     Dim tAccount As HotmailAccount
  796.     Dim fnum As Integer
  797.     Dim recNum As Long
  798.     filename = App.Path & "\Accounts.idx"
  799.     If Dir(filename) <> "" Then
  800.         addcount = 0
  801.         ReDim Accounts(AccCount) As HotmailAccount
  802.         recNum = 1
  803.         ' Get the next availble file number
  804.         fnum = FreeFile
  805.         Open filename For Random Access Read As #fnum Len = Len(tAccount)
  806.         Do Until EOF(fnum)
  807.             ' Seek to the current record number
  808.             Seek #fnum, recNum
  809.             ' Get the address record from the file
  810.             Get #fnum, , tAccount
  811.             recNum = recNum + 1
  812.             ' Make sure it's not a dud
  813.             If tAccount.username <> "" And Left(tAccount.username, 1) <> Chr(0) Then
  814.                 ' Copy the information into the address array
  815.                 ReDim Preserve Accounts(AccCount) As HotmailAccount
  816.                 Accounts(AccCount) = tAccount
  817.                 AccCount = AccCount + 1
  818.             End If
  819.             
  820.             If recNum * Len(tAccount) > LOF(fnum) Then
  821.                 Exit Do
  822.             End If
  823.         Loop
  824.         Close #fnum
  825.     End If
  826. End Sub
  827. Public Sub SaveAccounts()
  828.     Dim filename As String
  829.     Dim tAccount As HotmailAccount
  830.     Dim fnum As Integer
  831.     filename = App.Path & "\Accounts.idx"
  832.     If Dir(filename) <> "" Then Kill (filename)
  833.         ' Get the next availble file number
  834.         fnum = FreeFile
  835.         Open filename For Random Access Write As #fnum Len = Len(tAccount)
  836.         For i = 0 To AccCount - 1
  837.             ' Put the address to the file
  838.             If RTrim(Accounts(i).username) <> "" Then
  839.                 Put #fnum, , Accounts(i)
  840.             End If
  841.         Next
  842.         Close #fnum
  843. End Sub
  844. Public Sub AddAccount(ByVal username As String, ByVal loginname As String, ByVal password As String)
  845.     ReDim Preserve Accounts(AccCount) As HotmailAccount
  846.     With Accounts(AccCount)
  847.         .loginname = loginname
  848.         .username = username
  849.         ' Encrypt this
  850.         .password = password
  851.     End With
  852.     AccCount = AccCount + 1
  853. End Sub
  854.  
  855. Function CheckVersion(ByVal newversion As String, ByVal oldversion As String) As Boolean
  856.     Dim tNewVer As upVersion, tOldVer As upVersion
  857.     Dim newer As Boolean
  858.     
  859.     ' Convert the string versions to structures
  860.     tNewVer = ConvertToVersion(newversion)
  861.     tOldVer = ConvertToVersion(oldversion)
  862.     
  863.     ' Compare the two structures
  864.     If tNewVer.major > tOldVer.major Then
  865.         newer = True
  866.     ElseIf tNewVer.major = tOldVer.major Then
  867.         ' Check the minor version
  868.         If tNewVer.minor > tOldVer.minor Then
  869.             newer = True
  870.         Else
  871.             ' Check the revision
  872.             If tNewVer.rev > tOldVer.rev Then
  873.                 newer = True
  874.             End If
  875.         End If
  876.     End If
  877.     CheckVersion = newer
  878. End Function
  879.  
  880. Function ConvertToVersion(ByVal ver As String) As upVersion
  881.     Dim maj As Integer, min As Integer, rev As Integer
  882.     Dim tVer As upVersion
  883.     If ver <> "" Then
  884.         ' Find first DOT
  885.         min = InStr(1, ver, ".")
  886.         If min Then
  887.             tVer.major = Left(ver, min - 1)
  888.             ' Find the next DOT
  889.             rev = InStr(min + 1, ver, ".")
  890.             If rev Then
  891.                 tVer.minor = Mid(ver, min + 1, (rev - 1) - min)
  892.                 tVer.rev = Mid(ver, rev + 1, Len(ver) - rev)
  893.             Else
  894.                 tVer.minor = Mid(ver, min + 1, Len(ver) - min)
  895.             End If
  896.         Else
  897.             tVer.major = ver
  898.         End If
  899.     End If
  900.     ConvertToVersion = tVer
  901. End Function
  902.