Author |
|
prasad Challa Guest Group
Joined: 10 November 2003
Online Status: Online Posts: 262
|
Posted: 24 May 2004 at 5:41pm | IP Logged
|
|
|
Hello,
I am using Mailbee's pop3 object, how do i restrict my RetrieveMessages method to pnly new messages.
Thanks
prasad challa
|
Back to Top |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 25 May 2004 at 5:24am | IP Logged
|
|
|
Basically, the POP3 protocol has no features to determine whether a message is new or not.
However, the POP3 protocol allows you to get list of Unique-ID's of all messages in the mailbox.
The procedure is as follows:
On every connection to POP3 server, get list of Unique-ID's of all messages in the mailbox.
Then, check which of these ID's are already in database. Those ID's which already in database, correspond to old messages. If particular ID is not in database, it is a new message: download it completely!
Once all new messages are retrieved, update database with recent version of Unique-ID's list.
Thus, on very first connection the database is empty (and all messages are new). Next times the procedure will retrieve only new messages.
To get list of Unique-ID's, use Search method of POP3 object.
Sample code below shows MailBee part of the procedure discussed above. IsNewMessage function is empty, in your code it should actually lookup passed Unique-ID value in the database.
' This is main function. It retrieves new messages from
' the POP3 server and shows "Subject:" field of each
' retrieved message.
Sub RetrieveNewMessages()
Dim objPOP3, objMsg, I
' Array of Unique-IDs (taken from the POP3 server)
Dim arrIDs
' Create POP3 object
Set objPOP3 = CreateObject("MailBee.POP3")
' Unlock POP3 object
objPOP3.LicenseKey = "put your license key here"
' Set POP3 server name
objPOP3.ServerName = "mail.server.com"
' Set user credentials
objPOP3.UserName = "username"
objPOP3.Password = "password"
' Connect to the server and log in the mailbox
If objPOP3.Connect Then
' Get Unique-IDs for all messages in the mailbox
arrIDs = objPOP3.Search
' Iterate through all messages in the mailbox
For I = 1 To objPOP3.MessageCount
' Search Unique-ID of the message in the database
If IsNewMessage(arrIDs(I)) Then
' Download new message entirely
Set objMsg = objPOP3.RetrieveSingleMessage(I)
' Display the message's Subject
MsgBox objMsg.Subject
End If
Next
' Close the connection
objPOP3.Disconnect
Else
' Display error information
MsgBox "Error #" & objPOP3.ErrCode
MsgBox "Server response: " & objPOP3.ServerResponse
End If
End Sub
' This helper function should lookup the ID in the
' database, and then return True if the ID does not
' exist in the list of already downloaded messages.
Function IsNewMessage(ID)
' For demo purposes, the function always returns True.
IsNewMessage = True
End Function
|
Back to Top |
|
|
21323 Guest Group
Joined: 10 November 2003
Online Status: Online Posts: 262
|
Posted: 14 September 2004 at 8:55pm | IP Logged
|
|
|
|
Back to Top |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 15 September 2004 at 6:01am | IP Logged
|
|
|
Could you describe in more detail what did you mean?
Regards,
Alex
|
Back to Top |
|
|
juris Groupie
Joined: 27 June 2011 Location: Italy
Online Status: Offline Posts: 72
|
Posted: 06 February 2017 at 3:01pm | IP Logged
|
|
|
Alex wrote:
Basically, the POP3 protocol has no features to determine whether a message is new or not.
However, the POP3 protocol allows you to get list of Unique-ID's of all messages in the mailbox.
The procedure is as follows:
On every connection to POP3 server, get list of Unique-ID's of all messages in the mailbox.
Then, check which of these ID's are already in database. Those ID's which already in database, correspond to old messages. If particular ID is not in database, it is a new message: download it completely!
Once all new messages are retrieved, update database with recent version of Unique-ID's list.
Thus, on very first connection the database is empty (and all messages are new). Next times the procedure will retrieve only new messages.
To get list of Unique-ID's, use Search method of POP3 object.
Sample code below shows MailBee part of the procedure discussed above. IsNewMessage function is empty, in your code it should actually lookup passed Unique-ID value in the database.
' This is main function. It retrieves new messages from
' the POP3 server and shows "Subject:" field of each
' retrieved message.
Sub RetrieveNewMessages()
Dim objPOP3, objMsg, I
' Array of Unique-IDs (taken from the POP3 server)
Dim arrIDs
' Create POP3 object
Set objPOP3 = CreateObject("MailBee.POP3")
' Unlock POP3 object
objPOP3.LicenseKey = "put your license key here"
' Set POP3 server name
objPOP3.ServerName = "mail.server.com"
' Set user credentials
objPOP3.UserName = "username"
objPOP3.Password = "password"
' Connect to the server and log in the mailbox
If objPOP3.Connect Then
' Get Unique-IDs for all messages in the mailbox
arrIDs = objPOP3.Search
' Iterate through all messages in the mailbox
For I = 1 To objPOP3.MessageCount
' Search Unique-ID of the message in the database
If IsNewMessage(arrIDs(I)) Then
' Download new message entirely
Set objMsg = objPOP3.RetrieveSingleMessage(I)
' Display the message's Subject
MsgBox objMsg.Subject
End If
Next
' Close the connection
objPOP3.Disconnect
Else
' Display error information
MsgBox "Error #" & objPOP3.ErrCode
MsgBox "Server response: " & objPOP3.ServerResponse
End If
End Sub
' This helper function should lookup the ID in the
' database, and then return True if the ID does not
' exist in the list of already downloaded messages.
Function IsNewMessage(ID)
' For demo purposes, the function always returns True.
IsNewMessage = True
End Function |
|
|
Hello Alex,
This method is not safe because some email servers change Uids after new configuration. Any other ideas?
|
Back to Top |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 07 February 2017 at 12:16am | IP Logged
|
|
|
The purpose of UIDs is to keep persistent. If they change, this defeats the whole idea of them. All email will be considered new again. This sometimes happens with mail migrations - someone moves email to a new server and then Outlook (or any other POP3 client) reads all mail from the new server again thinking it's all new. That's why it's so important to keep UIDs untouched when mail migrations occur. If the server still does it - yes, all mail will be considered new. There is no workaround for that.
Regards,
Alex
|
Back to Top |
|
|
juris Groupie
Joined: 27 June 2011 Location: Italy
Online Status: Offline Posts: 72
|
Posted: 07 February 2017 at 12:38am | IP Logged
|
|
|
Hello Alex,
The solution is to not use Uids.
I prefer to download all the headers from the server.
Then I search in my database to see if there is already an email with the same date of receipt and with the same messageID.
This method is a little slower but it is much safer.
Get MyUniqueIDs for all messages in the mailbox
Code:
private Regex RegularFileNameExpression = new Regex(string.Format("[{0}]", Regex.Escape(new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars()))));
string MyUniqueIDs = RegularFileNameExpression.Replace(msg.Date.ToString("yyyyMMddHHmmssfff") + "_" + msg.MessageID + ".eml", "");
|
|
|
What do you think about it?
Regards, Lello
|
Back to Top |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 07 February 2017 at 12:41pm | IP Logged
|
|
|
As I said earlier, UID-based method is the only one which was ever tested and found to be working. If you found another method which suits your needs, that's fine then.
Regards,
Alex
|
Back to Top |
|
|
juris Groupie
Joined: 27 June 2011 Location: Italy
Online Status: Offline Posts: 72
|
Posted: 11 February 2017 at 3:13am | IP Logged
|
|
|
Hello Alex
Server POP3 and server IMAP have different Uids for the same email.
Using Uids I risk of downloading twice the same email
Better to create a different identifier (eg: the date of receipt + MessageID)
Lello
|
Back to Top |
|
|