Using JavaMail API and IMAP, i want to learn that a message has been moved from folder a to b. how can i do that without adding listeners? i mean i want to discover the changes of messages when i login to the account and open the folder.
The problem is if you have 3 messages in folder a with ids 1 2 and 3 and you move the message with id 3 to the folder B, the id of the message changes and we have a message with id 1 in folder B.
My goal is synchronizing the message structure in mail server with my own local server. I have to keep all message information, flags etc on my own. So on each login, i have to discover all the changes made to the messages stored in mail server.
I can get new or unread mails by:
Message messages[] = inbox.search(new FlagTerm(new Flags(Flag.RECENT), true));
or by
Message messages[] = inbox.search(new FlagTerm(new Flags(Flag.SEEN), false));
but i am not interested only to new mails, i also want to know the changes made to the old mails for example i want to get informed about that:
a mail which has been read 2 months ago, has been moved to another folder.
my idea is,
because the uids change, i can not use that for identifying mails. i think i have to use mail infos such as subject sender receive date, build an hashvalue of them and compare the hash values of messages on each login. but it will cause performance problems.
You cannot do that in IMAP. Tracking the Message-Id
header might get you half way there, but you will have to add all sorts of checks for corner cases like duplicate message IDs (yes, they are supposed to be unique) etc. Also keep in mind that what baseline IMAP gives you is a well-synchronized view to a single mailbox, not an atomic view on a set of mailboxes when combined. This means that even though a user has "moved" a message between folder A and B, it could very well be visible in both A and B for your script for a longer time period.
Some IMAP servers have added non-standard fields that you can FETCH
which contain a cryptographic hash of the message payload. These are still non-standard, though.
you can try using the rfc822-header information it contains a message-id like blablabla@mail.gmail.com which should not change when mails are moved into folders. but you will have to crawl all the mail-headers of the user to sync this, at least i don't know of a way to retrieve moved messages
来源:https://stackoverflow.com/questions/16265703/mailing-with-imap-how-to-detect-that-a-message-has-been-moved-from-one-folder-t