Sub POP_DownloadCompleted (Success As Boolean, MessageId As Int, MessageText As String)
' Log("Download: " & Success & ", " & MessageId)
Dim SearchForDeviceName As String
If Success Then
'If the download is a success then parse the mail to a message format and save it to the device
m = MailParser.ParseMail(MessageText, File.DirDefaultExternal)
SearchForDeviceName = m.Subject
'Searches for the device name within the subject
If SearchForDeviceName.Contains(DeviceName) Then
'A mail can only be deleted before it is downloaded so I use a second POP3 that downloads and
'deletes the messages based on their MessageID
Delete = MessageId
' POPDelete.ListMessages
Else
Return
End If
'The desktop application will send emails in this format
If m.Subject = DeviceName & "DataVersion" Then
'Write body of email containg the version of the data being sent to the device to the device
File.WriteString(File.Dirdefaultexternal, "DataVersion", m.Body)
'Counts how many files the device has recieved to check it has recieved the correct amount
FilesRecieved = FilesRecieved + 1
'Exit the sub to save time by not executing the rest of the code within the sub
Return
End If
'The following for loops are used to check what data is being sent
'15 users
For x = 1 To 15
'DeviceName is chosen by the user and allows the user to send data to more than one device
If m.Subject = DeviceName & "UserName" & x Then
'Write body of the email (contains the data) to the device
File.WriteString(File.DirDefaultExternal, "UserName" & x & ".txt", m.Body)
FilesRecieved = FilesRecieved + 1
Return
End If
If m.Subject = DeviceName & "UserNumber" & x Then
File.WriteString(File.DirDefaultExternal, "UserNumber" & x & ".txt", m.Body)
FilesRecieved = FilesRecieved + 1
Return
End If
If m.Subject = DeviceName & "UserAdmin" & x Then
File.WriteString(File.DirDefaultExternal, "UserAdmin" & x & ".txt", m.Body)
FilesRecieved = FilesRecieved + 1
Return
End If
Next
'60 Products
For x = 1 To 60
If m.Subject = DeviceName & "ProductName" & x Then
File.WriteString(File.DirDefaultExternal, "ProductName" & x & ".txt", m.Body)
FilesRecieved = FilesRecieved + 1
Return
End If
If m.Subject = DeviceName & "ProductPrice" & x Then
File.WriteString(File.DirDefaultExternal, "ProductPrice" & x & ".txt", m.Body)
FilesRecieved = FilesRecieved + 1
Return
End If
Next
Else 'Success not true
Return
End If
End Sub