Ruby IMAP “changes” since last check

后端 未结 2 2120
隐瞒了意图╮
隐瞒了意图╮ 2021-02-10 14:51

I\'m working on an IMAP client using Ruby and Rails. I can successfully import messages, mailboxes, and more... However, after the initial import, how can I detect any changes t

相关标签:
2条回答
  • 2021-02-10 14:56

    The IMAP protocol is brain dead this way, unfortunately. IDLE really should be able to return this kind of stuff while connected, for example. The FETCH FLAGS suggestion above is the only way to do it.

    One thing to be careful of, however, is that UIDs are only valid for a given session per the spec. You should not store them, even if some servers persist them.

    0 讨论(0)
  • 2021-02-10 15:21

    There is an IMAP extension for Quick Flag Changes Resynchronization (RFC-4551). With this extension it is possible to search for all messages that have been changed since the last synchronization (based on some kind of timestamp). However, as far as I know this extension is not widely supported.

    There is an informational RFC that describes how IMAP clients should do synchronization (RFC-4549, section 4.3). The text recommends issuing the following two commands:

    tag1 UID FETCH <lastseenuid+1>:* <descriptors>
    tag2 UID FETCH 1:<lastseenuid> FLAGS
    

    The first command is used to fetch the required information for all unknown mails (without knowing how many mails there are). The second command is used to synchronize the flags for the already seen mails.

    AFAIK this method is widely used. Therefore, many IMAP servers contain optimizations in order to provide this information quickly. Typically, the network bandwidth is the limiting factor.

    0 讨论(0)
提交回复
热议问题