Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component

Index of Chilkat Blog Posts

November 20, 2007

IMAP UID Ranges in Search Method

Question: I want to read emails between 2 UIDs or with the UIDs greater than a value.

imap.Search("UID > 83″, 1)

Is it possible?

Yes. RFC 3501 lists the details of the IMAP Search command. The Chilkat.Imap.Search method passes the search criteria directly to the IMAP server, so you may formulate a string based on the information found in RFC 3501.

In this case, I’ve found this:

      UID <sequence set>
         Messages with unique identifiers corresponding to the specified
         unique identifier set.  Sequence set ranges are permitted.

But what is a sequence set? The answer to that is found further down in the IMAP grammar:

sequence-set    = (seq-number / seq-range) *("," sequence-set)
                    ; set of seq-number values, regardless of order.
                    ; Servers MAY coalesce overlaps and/or execute the
                    ; sequence in any order.
                    ; Example: a message sequence number set of
                    ; 2,4:7,9,12:* for a mailbox with 15 messages is
                    ; equivalent to 2,4,5,6,7,9,12,13,14,15
                    ; Example: a message sequence number set of *:4,5:7
                    ; for a mailbox with 10 messages is equivalent to
                    ; 10,9,8,7,6,5,4,5,6,7 and MAY be reordered and
                    ; overlap coalesced to be 4,5,6,7,8,9,10.

Therefore, to get the set of UIDs for all messages having UIDs greater than (or equal to) 83, you do this:

imap.Search("UID 83:*", 1)

to get the set of UIDs of from UID 20 to UID 30 inclusive, do this:

imap.Search("UID 20:30″, 1)

Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.