使用IMAP邮寄:如何检测邮件已从一个文件夹移到另一个文件夹? [英] Mailing with IMAP: How to detect that a message has been moved from one folder to another?

查看:156
本文介绍了使用IMAP邮寄:如何检测邮件已从一个文件夹移到另一个文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用JavaMail API和IMAP,我想了解一条消息已从文件夹a移到了b.我如何在不添加侦听器的情况下做到这一点?我的意思是我想在登录帐户并打开文件夹后发现邮件的更改.

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.

问题是,如果您在文件夹a中有3条消息,其ID为1 2和3,并将您将ID 3的消息移至文件夹B,该消息的ID发生了变化,而我们在文件夹B中存在一条ID为1的消息

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));

或通过

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:

两个月前已阅读的邮件已移至另一个文件夹.

我的想法是

由于uid更改,我无法将其用于识别邮件. 我想我必须使用邮件信息(例如主题发件人接收日期),建立它们的哈希值并在每次登录时比较消息的哈希值.但这会导致性能问题.

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.

推荐答案

您不能在IMAP中执行此操作.跟踪Message-Id标头可能会让您半途而废,但是您将必须对各种极端情况进行各种检查,例如重复的消息ID(是的,它们是假定是唯一的)等.另外请记住,基线IMAP为您提供的是单个邮箱的同步视图,而不是组合后的一组邮箱的原子视图.这意味着,即使用户在文件夹A和B之间移动"了一条消息,对于较长时间的脚本,它也很可能同时在A和B中可见.

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.

某些IMAP服务器添加了非标准字段,您可以FETCH包含消息有效负载的加密哈希.但是,这些仍然是非标准的.

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.

这篇关于使用IMAP邮寄:如何检测邮件已从一个文件夹移到另一个文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆