代码之家  ›  专栏  ›  技术社区  ›  Dustin Getz sunsations

获取电子邮件未读内容,而不影响未读状态[重复]

  •  4
  • Dustin Getz sunsations  · 技术社区  · 16 年前

    现在它是一个gmail邮箱,但迟早我希望它能扩展。

    我想在其他地方同步实时个人邮箱(收件箱和发件箱)的副本,但我不想影响 unread

    什么类型的访问将使这变得最容易?我找不到IMAP是否会影响读取状态的任何信息,但似乎我可以手动将消息重置为未读。Pop的定义并不影响未读状态,但似乎没有人使用Pop访问他们的gmail,为什么?

    6 回复  |  直到 9 年前
        1
  •  5
  •   Tim Cooper    14 年前

    在IMAP世界中,每条消息都有标志。您可以在每条消息上设置各个标志。获取消息时,实际上可以读取消息,而无需应用\Seen标志。

    大多数邮件客户端在读取邮件时都会应用\Seen标志。因此,如果消息已在应用程序之外读取,则需要删除\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.
    
        2
  •  3
  •   Dan Goldstein    16 年前

    IMAP中的FETCH命令上有一个.PEEK选项,它不会显式设置/Seen标志。

    看看 the FETCH command in RFC 3501 然后向下滚动到第57页或搜索“BODY.PEEK”。

        3
  •  2
  •   Community Mohan Dere    9 年前

    使用BODY.PEEK时需要指定节。章节将在中进行解释 IMAP Fetch Command

    import getpass, imaplib
    
    M = imaplib.IMAP4()
    M.login(getpass.getuser(), getpass.getpass())
    M.select()
    typ, data = M.search(None, 'ALL')
    for num in data[0].split():
        typ, data = M.fetch(num, '(BODY.PEEK[])')
        print 'Message %s\n%s\n' % (num, data[0][5])
    M.close()
    M.logout()
    

    PS:我想修正给出的答案 Gene Wood 但不允许,因为编辑少于6个字符(BODY.PEEK->BODY.PEEK[])

        4
  •  1
  •   Alex Martelli    16 年前

    没有人使用POP,因为它们通常 IMAP的额外功能,例如跟踪消息状态。当这个功能只是在妨碍你,需要解决时,我认为使用POP是你最好的选择!)

        5
  •  0
  •   Dustin Getz sunsations    16 年前

    如果它对任何人都有帮助,GAE允许你 receive email as an HTTP request ,所以现在我只是在那里转发电子邮件。

        6
  •  0
  •   Community Mohan Dere    9 年前

    跟进 Dan Goldstein's answer above ,在python中,使用“.PEEK”选项的语法是调用 IMAP4.fetch 并通过它“ BODY.PEEK "

    将此应用于中的示例 python docs :

    import getpass, imaplib
    
    M = imaplib.IMAP4()
    M.login(getpass.getuser(), getpass.getpass())
    M.select()
    typ, data = M.search(None, 'ALL')
    for num in data[0].split():
        typ, data = M.fetch(num, '(BODY.PEEK)')
        print 'Message %s\n%s\n' % (num, data[0][5])
    M.close()
    M.logout()
    
    推荐文章