获取电子邮件未读内容,而不会影响未读状态

Dus*_*etz 4 python gmail pop3 imap imaplib

现在它是一个gmail盒子,但迟早我希望它可以扩展.

我想在其他地方同步一个实时个人邮箱(收件箱和发件箱)的副本,但我不想影响unread任何未读邮件的状态.

什么类型的访问将使这最容易?如果IMAP会影响读取状态,我找不到任何信息,但似乎我可以手动将消息重置为未读.按定义弹出不会影响未读状态,但似乎没有人使用pop访问他们的Gmail,为什么?

dav*_*nta 5

在IMAP世界中,每条消息都有标志.您可以在每条消息上设置单独的标志.当您获取消息时,实际上可以读取消息,而不应用\ Seen标志.

大多数邮件客户端将在读取邮件时应用\ Seen标志.因此,如果在您的应用程序之外已经读取了该消息,那么您将需要删除\ Seen标志.

就像fyi ...这里是关于RFC的标志的相关部分:

系统标志是在本规范中预定义的标志名称.所有系统标志都以"\"开头.某些系统标志(\ Deleted和\ Seen)具有其他地方描述的特殊语义.当前定义的系统标志是:

    \Seen
       Message has been read

    \Answered
       Message has been answered

    \Flagged
       Message is "flagged" for urgent/special attention

    \Deleted
       Message is "deleted" for removal by later EXPUNGE

    \Draft
       Message has not completed composition (marked as a draft).

    \Recent
       Message is "recently" arrived in this mailbox.  This session
       is the first session to have been notified about this
       message; if the session is read-write, subsequent sessions
       will not see \Recent set for this message.  This flag can not
       be altered by the client.

       If it is not possible to determine whether or not this
       session is the first session to be notified about a message,
       then that message SHOULD be considered recent.

       If multiple connections have the same mailbox selected
       simultaneously, it is undefined which of these connections
       will see newly-arrived messages with \Recent set and which
       will see it without \Recent set.
Run Code Online (Sandbox Code Playgroud)