Search The ForumSearch   RegisterRegister  LoginLogin

MailBee.NET POP3

 AfterLogic Forum : MailBee.NET POP3
Subject Topic: Question about IndexOnServer and position Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
HPS
Newbie
Newbie


Joined: 06 August 2013
Location: Germany
Online Status: Offline
Posts: 8
Posted: 14 August 2019 at 4:52am | IP Logged Quote HPS

Hello,

we need to download "new" mails from a pop3 e-mail account. After downloading these mails, we can't delete them, because it must be possible to read them with other devices.
We want to use the method "Pop3.DownloadMessageHeaders Method (startIndex , count)" to get the headers of the "last" 20 mails in the account.
Then we want to check the messageId and date of each header and compare it with our internaly stored messageId and date combinations.
If all 20 messageId/date combination are "unkown", the next 20 headers must be checked.
The first "known" combination of messageId/date would be the "latest" mail we have downloaded and all before checked mails would be "new" mails.

Now to the question:
Are new mails always be appended to the last position of enumeration of mail on the mailserver?
Is it guaranteed that the position of new mails are the "last" in the enumeration, which we get from Pop3.DownloadMessageHeaders?
Or could it be that new mails are somewhere in between and mixed with older ones?


Greetings
Hans-Peter
Back to Top View HPS's Profile Search for other posts by HPS
 
Alex
AfterLogic Support
AfterLogic Support
Avatar

Joined: 19 November 2003
Online Status: Offline
Posts: 2116
Posted: 14 August 2019 at 8:04am | IP Logged Quote Alex

Hi,

Don't use headers and Message-ID. Use UID values instead.

storedUids = db.GetUidsForAccount(accountID);
actualUids = pop.GetMessageUids;
foreach (actualUid in actualUids)
{
if (!storedUids.IndexOf(actualUid))
{
    newUids.Add(actualUid); // This UID was not in the mailbox before
}
}

now you can download the messages denoted by newUids

foreach (newUid in newUids)
{
int msgIndex = pop.GetMessageIndexFromUid(newUid);
MailMessage msg = pop.DownloadEntireMessage(msgIndex);
...
}

now update database (you'll need to implement 'db' methods on your own):

db.ClearUidsForAccount(accountID); // remove all existing entries
db.SaveUidsForAccount(accountID, actualUids);

or you can avoid overwriting all stored UIDs each time:

db.SaveUidsForAccount(accountID, newUids);

The latter will only add new UIDs but it won't remove entries which are no longer on the POP3 server. Assuming that mails are rarely deleted, these redundant entries won't take up much space. Anyway, you can remove them too, if you wish:

foreach (storedUid in storedUids)
{
if (!actualUids.IndexOf(storedUid))
{
    nonExistentUids.Add(storedUid); // This UID is no longer in the mailbox
}
}

db.RemoveUidsFromAccount(accountID, nonExistentUids);

Regards,
Alex
Back to Top View Alex's Profile Search for other posts by Alex
 
HPS
Newbie
Newbie


Joined: 06 August 2013
Location: Germany
Online Status: Offline
Posts: 8
Posted: 14 August 2019 at 10:12pm | IP Logged Quote HPS

Hi Alex,

I can't use UID because the mailserver, we must support, doesn't support UID. The UID of a message is nothing. We can not store a UID. We store the messageId and date of each received message. That's not the fastest way, but we can identify each mail we've already received.

So we need another way to reduce the message-headers we must download to identify new messages and the only way I can see is to rely on IndexOnServer.
That's the cause for my question.

I new messages are not appended at the end of the "index", this alternative wouldn't work well.

In your sample https://afterlogic.com/mailbee/docs/#KB_ReceivingNewMessagesPOP3_VB1.htm Part 2,
there is a comment "Another important fact is that new messages are always appended to the end of the mailbox. ". It seems to me, that IndexOnServer could work instead of UID - but I'm not shure if this works.

So - Is it guaranteed that the position of new mails are the "last" in the enumeration, which we get from Pop3.DownloadMessageHeaders?




Greetings
Hans-Peter
Back to Top View HPS's Profile Search for other posts by HPS
 
Alex
AfterLogic Support
AfterLogic Support
Avatar

Joined: 19 November 2003
Online Status: Offline
Posts: 2116
Posted: 15 August 2019 at 1:52am | IP Logged Quote Alex

Hi Hans-Peter,

Oh. Never faced POP3 server without UID support before.

Well, you can indeed rely on the fact that new messages are always appended to the end of the mailbox. So if you download, let's say, last 20 headers and then iterate from the last one to the first one, you can check if you already have the message-id in your db. Once you got the match, you can assume that older messages are already in sync. If all 20 messages are new, then you download the previous 20 headers, and so on.

Once you reached the last old message (so that the first new message is +1 to it), you can start downloading them entirely, and save them in db (now in ascending order, not descending).

Regards,
Alex
Back to Top View Alex's Profile Search for other posts by Alex
 
HPS
Newbie
Newbie


Joined: 06 August 2013
Location: Germany
Online Status: Offline
Posts: 8
Posted: 15 August 2019 at 10:29pm | IP Logged Quote HPS

Thank you Alex - that helps.
Back to Top View HPS's Profile Search for other posts by HPS
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump

Powered by Web Wiz Forums version 7.9
Copyright ©2001-2004 Web Wiz Guide