home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 3_2004-2005.ISO / Data / Zips / VB_API_cod1852392132005.psc / clsPOP.cls < prev    next >
Encoding:
Visual Basic class definition  |  2004-06-01  |  9.2 KB  |  268 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "clsPOP"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15.  
  16.  
  17.  
  18.  
  19. Event POPconnected()
  20. Event POPmsgsWaiting(NumMsgs As Integer)
  21. Event POPstatechange(currState As enumPOPstate, POPserverCommunication As String, _
  22.                                                 POPclientCommunication As String)
  23.  
  24. Public Enum enumPOPstate
  25.         POP_CONNECTED = 0
  26.         POP_USEROK = 1
  27.         POP_PASSOK = 2
  28.         POP_MAILSTAT = 3
  29.         POP_TOP = 4
  30. End Enum
  31.  
  32.  
  33. Private iMsgCount                   As Integer
  34. Private m_POPaddress                As String
  35. Private m_POPusername               As String
  36. Private m_POPpassword               As String
  37. Private m_POPserverCommunication    As String
  38. Private m_POPclientCommunication    As String
  39. Private m_popState                  As enumPOPstate
  40. Public WithEvents YourPopSock       As Winsock
  41. Attribute YourPopSock.VB_VarHelpID = -1
  42.  
  43.  
  44. ' _ __      . _   .    . _     .  '    .     . _   .    .
  45. '| '_ \_   _ | |__  _   (_) ___   ' _ _'_   _ | |__  _ _'
  46. '| |_)  | | ||  _ \| |  | |/ __|  '/ __| | | ||  _ \/ __|
  47. '| .__/ |_| || |_) | |_ | | (__   '\__ \ |_| || |_) \__ \
  48. '|_|   \__,_||_.__/|___||_|\___|  '|___/\__,_||_.__/|___/
  49.  
  50.  
  51.  
  52. '----------------------------------------------------------------------
  53. '   INPUTS: |
  54. '  RETURNS: |
  55. ' COMMENTS: |CONNECT WITH THE MAIL SERVER
  56. '----------------------------------------------------------------------
  57. Sub ConnectMailServer()
  58.  
  59.        YourPopSock.Close
  60.        YourPopSock.Connect POPaddress, 110
  61. End Sub
  62. '----------------------------------------------------------------------
  63. '   INPUTS: |
  64. '  RETURNS: |
  65. ' COMMENTS: |SEND TERMINATE COMMUNICATION NOTICE TO SERVER AND CLOSE SOCKET
  66. '----------------------------------------------------------------------
  67. Sub CloseMailServer()
  68.  
  69.       If YourPopSock.State = 2 Then
  70.           YourPopSock.SendData "QUIT" & vbCrLf
  71.           DoEvents
  72.           YourPopSock.Close
  73.       Else
  74.           YourPopSock.Close
  75.       End If
  76. End Sub
  77. Private Sub YourPopSock_Connect()
  78.       
  79.       RaiseEvent POPconnected
  80. End Sub
  81.  
  82. Private Sub YourPopSock_DataArrival(ByVal bytesTotal As Long)
  83.  Dim sData               As String
  84.  
  85.     With YourPopSock
  86.           .GetData sData
  87.           POPserverCommunication = sData
  88.           
  89.           'we must first make sure has sent an OK reply b4 proceeding
  90.           If LCase(Left(Trim(sData), 3)) = "+ok" Then
  91.                 'send mail server the username
  92.                 If m_popState = POP_CONNECTED Then
  93.                     POPclientCommunication = "USER " & POPusername & vbCrLf
  94.                     .SendData POPclientCommunication
  95.                     m_popState = POP_USEROK
  96.                     '
  97.                     RaiseEvent POPstatechange(POP_USEROK, _
  98.                                                POPserverCommunication, _
  99.                                                POPclientCommunication)
  100.                     
  101.                 'send mail server the password
  102.                 ElseIf m_popState = POP_USEROK Then
  103.                     POPclientCommunication = "PASS " & POPpassword & vbCrLf
  104.                     .SendData POPclientCommunication
  105.                     m_popState = POP_PASSOK
  106.                     '
  107.                     RaiseEvent POPstatechange(POP_PASSOK, _
  108.                                               POPserverCommunication, _
  109.                                               POPclientCommunication)
  110.                                               
  111.                 'ask mail server how many messages and how big they are
  112.                 ElseIf m_popState = POP_PASSOK Then
  113.                      POPclientCommunication = "STAT " & vbCrLf
  114.                      .SendData POPclientCommunication
  115.                      m_popState = POP_MAILSTAT
  116.                      '
  117.                      RaiseEvent POPstatechange(POP_MAILSTAT, _
  118.                                               POPserverCommunication, _
  119.                                               POPclientCommunication)
  120.                     
  121.                 'at this point we will get a response like so...
  122.                 ' +OK 5 23990 which means 5 message are waiting
  123.                 'that are 23,990 byes in size total
  124.                 'we will split this by the spaces..and
  125.                 'this middle value is number of msgs
  126.                 'which will will place in integer so we
  127.                 'can use in loop to deal with each indiv msg
  128.                 ElseIf m_popState = POP_MAILSTAT Then
  129.                       iMsgCount = funcMsgCount(POPserverCommunication)
  130.                       RaiseEvent POPmsgsWaiting(iMsgCount)
  131.                       RaiseEvent POPstatechange(POP_TOP, _
  132.                                               POPserverCommunication, _
  133.                                               POPclientCommunication)
  134.                                          
  135.                 End If
  136.                
  137.           'we didnt recieve an ok response from the server
  138.            Else
  139.                  ERR.Raise 43434, "clsPOP", "Mail server returned error code"
  140.            End If
  141.           
  142.      End With
  143. End Sub
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152. ' _ __     .    . _ __     .    .     . _     .    .
  153. '| '_ \ _ _  ___ | '_ \ ___  _ _ _____ (_) ___  _ _'
  154. '| |_) | '_\/ _ \| |_) / _ \| '_\_   _|| |/ _ \/ __|
  155. '| .__/| |   (_) | .__/  __/| |   | |  | |  __/\__ \
  156. '|_|   |_|  \___/|_|   \___||_|   |_|  |_|\___||___/
  157.  
  158.  
  159.  
  160. '----------------------------------------------------------------------
  161. '   INPUTS: |
  162. '  RETURNS: | THE USERNAME FOR THE POP EMAIL ACCOUNT
  163. ' COMMENTS: |
  164. '----------------------------------------------------------------------
  165. Public Property Get POPusername() As String
  166.         
  167.         POPusername = m_POPusername
  168. End Property
  169. Public Property Let POPusername(ByVal vNewValue As String)
  170.  
  171.         m_POPusername = vNewValue
  172. End Property
  173. '----------------------------------------------------------------------
  174. '   INPUTS: |
  175. '  RETURNS: | THE PASSWORD FOR THE POP EMAIL ACCOUNT
  176. ' COMMENTS: |
  177. '----------------------------------------------------------------------
  178. Public Property Get POPpassword() As String
  179.  
  180.        POPpassword = m_POPpassword
  181. End Property
  182. Public Property Let POPpassword(ByVal vNewValue As String)
  183.  
  184.         m_POPpassword = vNewValue
  185. End Property
  186. '----------------------------------------------------------------------
  187. '   INPUTS: |
  188. '  RETURNS: | THE NET ADDRESS FOR THE POP EMAIL ACCOUNT
  189. ' COMMENTS: |
  190. '----------------------------------------------------------------------
  191. Public Property Get POPaddress() As String
  192.  
  193.         POPaddress = m_POPaddress
  194. End Property
  195. Public Property Let POPaddress(ByVal vNewValue As String)
  196.  
  197.         m_POPaddress = vNewValue
  198. End Property
  199.  
  200. '----------------------------------------------------------------------
  201. '   INPUTS: |
  202. '  RETURNS: | THE DATA/COMMUNICATION THE POP SERVER IS SENDING TO US
  203. ' COMMENTS: | ALLOWS USER OF CLASS TO SEE THE COMMUNICATION AS WELL
  204. '----------------------------------------------------------------------
  205. Public Property Get POPserverCommunication() As String
  206.  
  207.         POPserverCommunication = m_POPserverCommunication
  208. End Property
  209. Private Property Let POPserverCommunication(ByVal vNewValue As String)
  210.  
  211.         m_POPserverCommunication = vNewValue
  212. End Property
  213. '----------------------------------------------------------------------
  214. '   INPUTS: |
  215. '  RETURNS: | THE DATA/COMMUNICATION THAT WERE SENDING POP SERVER
  216. ' COMMENTS: | ALLOWS USER OF CLASS TO SEE THE COMMUNICATION AS WELL
  217. '----------------------------------------------------------------------
  218. Public Property Get POPclientCommunication() As String
  219.  
  220.         POPclientCommunication = m_POPclientCommunication
  221. End Property
  222. Private Property Let POPclientCommunication(ByVal vNewValue As String)
  223.  
  224.         m_POPclientCommunication = vNewValue
  225. End Property
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233. ' _ __     . _      .     .     .    .  '    .     . _   .    .
  234. '| '_ \ _ _ (_)_   __ __ _ _____  ___   ' _ _'_   _ | |__  _ _'
  235. '| |_) | '_\| | \ / // _` |_   _|/ _ \  '/ __| | | ||  _ \/ __|
  236. '| .__/| |  | |\ V /  (_| | | |    __/  '\__ \ |_| || |_) \__ \
  237. '|_|   |_|  |_| \_/  \__,_| |_|  \___|  '|___/\__,_||_.__/|___/
  238. ''  _      .      .    .     . _     .      .    .
  239. ' / _|_   _  _ __   ___ _____ (_) ___  _ __   _ _'
  240. '| |_  | | || '_ ` / __|_   _|| |/ _ \| '_ ` / __|
  241. '|  _| |_| || | | | (__  | |  | | (_) | | | |\__ \
  242. '|_|  \__,_||_| |_|\___| |_|  |_|\___/|_| |_||___/
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252. '----------------------------------------------------------------------
  253. '   INPUTS: |THE MAIL SERVER RESPONSE TO "STAT" WHICH GIVES US
  254. '            THE EXAMPLE STRING   +OK 5 23990, WE NEED TO PARSE OUT THE 5
  255. '  RETURNS: |NUMBER OF MESSAGES WAITING ON THE SERVER
  256. ' COMMENTS: |
  257. '----------------------------------------------------------------------
  258. Private Function funcMsgCount(strToParse) As Integer
  259.  Dim sParts()           As String
  260.  Dim i                  As Integer
  261.  
  262.         sParts = Split(strToParse, " ")
  263.         funcMsgCount = Trim(sParts(1))
  264.         
  265. End Function
  266.  
  267.  
  268.