Private Sub ws_DataArrival(ByVal bytesTotal As Long)
Dim myData As String
ws.GetData myData
Select Case pStat
Case Is = pop_Connect
'this is still in connection state
showprint myData
If Left(myData, 1) = "+" Then
'we got a +OK message, now for user authentication
pStat = pop_User
sSend "user " & myServer.srv_User
ElseIf Left(myData, 1) = "-" Then
'oops we got a -ERR message means we have an error of some sorts
mError = 1
End If
Case Is = pop_User
showprint myData
'we are now in user authentication stage
If Left(myData, 1) = "+" Then
'we got a +OK message, now for password authentication
pStat = pop_Password
sSend "pass " & myServer.srv_Password
ElseIf Left(myData, 1) = "-" Then
'oops we got a -ERR message means we have an error of some sorts
mError = 2
End If
Case Is = pop_Password
'we are now in password authentication stage
showprint myData
If Left(myData, 1) = "+" Then
'we got a +OK message, now for checking number of emails in the server
pStat = pop_Stat
sSend "stat"
ElseIf Left(myData, 1) = "-" Then
'oops we got a -ERR message means we have an error of some sorts
mError = 3
End If
Case Is = pop_Stat
'we are now checking for number of messages
showprint myData
If Left(myData, 1) = "+" Then
'we got a +OK message, now for checking individual messages
myServer.srv_Messages = getMsgNum(myData) 'we got the number of messages in the server
If myServer.srv_Messages > 0 Then
'we have messages
curMsg = 1
pStat = pop_List
sSend "list " & curMsg
Else
'we have no messages just quit
pStat = pop_Quit
sSend "quit"
End If
ElseIf Left(myData, 1) = "-" Then
'oops we got a -ERR message means we have an error of some sorts
mError = 4
End If
Case Is = pop_List
'we are checking individual messages
showprint myData
If Left(myData, 1) = "+" Then
If curMsg > 0 And curMsg <= myServer.srv_Messages Then
'we are ready to recieve messages
ReDim Preserve myMsg(curMsg) As MSG_STATS
With myMsg(curMsg)
.msg_Body = ""
.msg_File = getMsgFile(curMsg)
.msg_Len = thisMsgLen(myData)
.msg_ThisLen = 0
End With
'send command to recieve the particular message
pStat = pop_Retr
sSend "retr " & curMsg
ElseIf curMsg > myServer.srv_Messages Then
'all messages have been downloaded
pStat = pop_Quit
sSend "quit"
End If
ElseIf Left(myData, 1) = "-" Then
'oops we got a -ERR message means we have an error of some sorts
mError = 5
End If
Case Is = pop_Retr
'we recieve the actual message here
showprint myData
If Left(myData, 1) = "+" Then
'straight write to file
Open_And_Write_File myMsg(curMsg).msg_File, myData
'calculate the size recieved
With myMsg(curMsg)
.msg_ThisLen = bytesTotal + .msg_ThisLen
End With
If Mid(myData, Len(myData) - 2, 1) = "." Then
Close_And_Save_File
pStat = pop_Delete
sSend "dele " & curMsg
Else
pStat = pop_CRetr
End If
ElseIf Left(myData, 1) = "-" Then
'oops we got a -ERR message means we have an error of some sorts
mError = 6
End If
Case Is = pop_CRetr
Just_Write_To_File myData
showprint myData
With myMsg(curMsg)
.msg_ThisLen = bytesTotal + .msg_ThisLen
End With
If Mid(myData, Len(myData) - 2, 1) = "." Then
Close_And_Save_File
pStat = pop_Delete
sSend "dele " & curMsg
End If
Case Is = pop_Delete
'we just recieved the delete command's reply
showprint myData
If Left(myData, 1) = "+" Then
If CheckForMore(curMsg) = True Then
pStat = pop_List
curMsg = curMsg + 1
sSend "list " & curMsg
Else
pStat = pop_Quit
sSend "quit"
End If
ElseIf Left(myData, 1) = "-" Then
'oops we got a -ERR message means we have an error of some sorts
mError = 7
End If
Case Is = pop_Quit
showprint myData
If Left(myData, 1) = "-" Then
mError = 8
End If
End Select
End Sub