Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The canonical way to detect new messages in IMAP is via <code>UIDNEXT</code>. Issuing</p> <pre><code>A001 STATUS "foldername" (UIDVALIDITY UIDNEXT) </code></pre> <p>on <em>each</em> folder that you care about will give you the expected next UID for that folder. <a href="http://tools.ietf.org/html/rfc3501#section-2.3.1.1" rel="nofollow">Here's what the RFC has to say</a>:</p> <blockquote> <p>Unique identifiers are assigned in a strictly ascending fashion in the mailbox; as each message is added to the mailbox it is assigned a higher UID than the message(s) which were added previously. Unlike message sequence numbers, unique identifiers are not necessarily contiguous.</p> <p>The next unique identifier value is the predicted value that will be assigned to a new message in the mailbox. Unless the unique identifier validity also changes (see below), the next unique identifier value MUST have the following two characteristics. First, the next unique identifier value MUST NOT change unless new messages are added to the mailbox; and second, the next unique identifier value MUST change whenever new messages are added to the mailbox, even if those new messages are subsequently expunged.</p> </blockquote> <p>So just keep track of the each folder's expected next UID and UID validity value. If a <code>STATUS</code> command results in either <code>UIDNEXT</code> or <code>UIDVALIDITY</code> changing from your cached value, you know you need to check for new mail (if the former) or resync (if the latter).</p> <p><a href="http://www.ruby-doc.org/stdlib/libdoc/net/imap/rdoc/classes/Net/IMAP.html#M001437" rel="nofollow">Something like this</a>:</p> <pre><code>imap.status("foldername", ["UIDNEXT", "UIDVALIDITY"]) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload