Author |
|
HugoDrx Newbie
Joined: 13 February 2009 Location: Canada
Online Status: Offline Posts: 6
|
Posted: 18 February 2009 at 10:15am | IP Logged
|
|
|
Hi All,
I am using MailBee .NET Version: 4.0.2.105.
I am attempting to only download emails from a POP server that fit a certain criteria, so I get the last checked message UID and store it locally. Then when I check the POP server again, I start from that message UID and find all messages with UIDs greater (assuming that UIDs are incremented) than the stored one, like so:
if (aPopMailer.GetMessageUidFromIndex(msgLooper) > savedUID) then
{
DownloadNewMessage();
}
else
{
//ignore the message and continue the loop through the Inbox count.
}
I find this works fine with GMail, but it appears I have problems with UIDs from MS Exchange Server as I have multiple messages newer than the last UID saved, but my UID comparison doesn't determine that the newer emails UIDs are greater than the stored one.
Can anyone shed any light on this? For example, do MS Exhange Server message UIDs increment? Is there a better way to manage my email checks? Is there a maximum length to a UID in the MailBee .NET Pop3Mail.Pop3.GetMessageUids() method?
Here are example UIDs:
GMail: GmailId11f6fcd6739379a4
Exchange Svr: AAA2EQAAAAQpscOw3RsXdaESwXiiS70T
Thanks,
HugoDrx
|
Back to Top |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 18 February 2009 at 10:39am | IP Logged
|
|
|
POP3 UIDs are not guaranteed to increment in any way, the only requirement is that they all must be unique. If you need to somehow detect if particular UID is newer than another way, the only reliable way is using IMAP (which is supported by both Exchange and GMail).
IMAP UIDs are positive incrementing integers.
Regards,
Alex
|
Back to Top |
|
|
HugoDrx Newbie
Joined: 13 February 2009 Location: Canada
Online Status: Offline Posts: 6
|
Posted: 18 February 2009 at 1:29pm | IP Logged
|
|
|
Thanks Alex,
I was afraid of that. I would prefer to be using IMAP but the boss says to stick with POP3.
Just one more question, I understand that UIDs can be re-used which might give me some headaches later on, but when the POP server sends the UID list, how does it sort them. Could I for instance, keep a list locally and go backwards through the retrieved UID list until I find the first one that matches one in my local list? Or is the retrieved list just sorted by the location in the POP database? I didn't see anything about it in the POP3RFC.
Thanks again for your assistance. The MailBee .NET tools are great!
HugoDrx
|
Back to Top |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 19 February 2009 at 7:21am | IP Logged
|
|
|
POP3 server may or may not sort the UID list. Anyway, even if it doesn't, MailBee.NET returns you the list already sorted (newer messages last).
If you had a snapshot of the UID list of the previous session, you can compare it with the current UID list to find new entries. Once you synchronized the state, you overwrite the UID list snapshot with the newer one.
It's not engough to just reverse-iterate through the list until you find a match. This might not work in the case if certain messages has been deleted and you need to reflect this fact in your local database.
Regards,
Alex
|
Back to Top |
|
|
HugoDrx Newbie
Joined: 13 February 2009 Location: Canada
Online Status: Offline Posts: 6
|
Posted: 20 February 2009 at 7:22am | IP Logged
|
|
|
Hi Alex,
Just curious,
If "POP3 server may or may not sort the UID list. Anyway, even if it doesn't, MailBee.NET returns you the list already sorted (newer messages last). " and the UID list on the server may or may not be incremental (just unique) how can MailBee be sure its sorted by the newer messages last?
I worry about a situation where I have 100,000 new messages and 100,000 old messages and comparing the two lists could take a great deal of time.
Thanks for all your help,
HugoDrx
|
Back to Top |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 20 February 2009 at 7:58am | IP Logged
|
|
|
Quote:
how can MailBee be sure its sorted by the newer messages las |
|
|
For each UID, the server also returns the ordinal message number. Thus, usually the list looks like:
1 sd74gvad
2 9wqwerhh
3 8sfdhl38
but may look like
3 8sfdhl38
1 sd74gvad
2 9wqwerhh
In this case, MailBee resorts it to make ordinal message numbers increment.
Regards,
Alex
|
Back to Top |
|
|
HugoDrx Newbie
Joined: 13 February 2009 Location: Canada
Online Status: Offline Posts: 6
|
Posted: 20 February 2009 at 9:12am | IP Logged
|
|
|
Hi Alex,
Just to clarify what we have been talking about here:
The highest ordinal number always represents the newest message in the POP server database and the lowest represents the oldest.
If I go backwards through the UID list from the server comparing against my saved UID list, I can be sure that the first UID found in my list is the last email from the previous session and all others in the downloaded list have already been read.
Am I right in this?
I'm trying to avoid comparing all items from both lists every time I check the mailbox.
Thanks again,
HugoDrx
|
Back to Top |
|
|
Andrew AfterLogic Support
Joined: 28 April 2006 Location: United States
Online Status: Offline Posts: 1189
|
Posted: 23 February 2009 at 8:50am | IP Logged
|
|
|
Quote:
The highest ordinal number always represents the newest message in the POP server database and the lowest represents the oldest. |
|
|
Although this is correct in the most cases, we faced POP3 servers which have different behavior.
Quote:
Am I right in this?
I'm trying to avoid comparing all items from both lists every time I check the mailbox. |
|
|
Comparing all the items is the only 100%-reliable way. However, the approach you described will work for POP3 servers which assign message indexes in chronological order (99% POP3 servers nowadays).
Best regards,
Andrew
|
Back to Top |
|
|