27

I am writing an application which reacts to emails sent to a mailbox. It retrieves the emails via IMAP. It will be deployed to a number of systems where I do not control the mail server configuration.

I would like to use IMAP flags to indicate which messages have been handled. Are the system flags sufficiently widely supported that I can reasonably depend on them in my application? Are user-defined flags sufficiently widely supported?

(If the answer is "ha ha, not a chance", then I shall use folders instead.)

Thanks

-Ben

3 Answers3

24

Take a look at this collection of example IMAP server sessions. Essentially whenever you see PERMANENTFLAGS contain \*, the server will support user-defined flags.

To add to that list, here is an excerpt from a Gimap (Google Mail IMAP) session:

* OK Gimap ready for requests from 192.0.2.1 5if380490pzk.17
a login username password
* CAPABILITY IMAP4rev1 UNSELECT LITERAL+ IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE
a OK username@gmail.com authenticated (Success)
b select inbox
* FLAGS (\Answered \Flagged \Draft \Deleted \Seen)
* OK [PERMANENTFLAGS (\Answered \Flagged \Draft \Deleted \Seen \*)]
* OK [UIDVALIDITY 2]
* 1089 EXISTS
* 0 RECENT
* OK [UIDNEXT 2371]
b OK [READ-WRITE] inbox selected. (Success)
c logout
* BYE LOGOUT Requested
c OK 73 good day (Success)

And similarly, a session from Exchange 2007:

* OK Microsoft Exchange Server 2007 IMAP4 service ready
00000000 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI IDLE NAMESPACE LITERAL+
00000000 OK CAPABILITY completed.
   [...]
00000003 SELECT INBOX
* 1 EXISTS
* 0 RECENT
* FLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)
* OK [PERMANENTFLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)] Permanent flags
* OK [UIDVALIDITY 472] UIDVALIDITY value
* OK [UIDNEXT 7] The next unique identifier value
00000003 OK [READ-WRITE] SELECT completed.

I was unable to find a session from Exchange 2010.

So it's not universal -- with Exchange being the notable abstainer -- but it sure is more common than not.

fission
  • 3,506
  • 2
  • 20
  • 27
6

The main IMAP protocol document is RFC3501. Section 2.3.2 describes the standard flags every IMAP implementation must work with.

Are the system flags sufficiently widely supported that I can reasonably depend on them in my application?

Indeed, RFC3501 describes the universal system flags.

Are user-defined flags sufficiently widely supported?

There is not any RFC on the subject of user-defined flags, only proposals.

RFC 3501                         IMAPv4                       March 2003

2.3.2.  Flags Message Attribute

   A list of zero or more named tokens associated with the message.  A
   flag is set by its addition to this list, and is cleared by its
   removal.  There are two types of flags in IMAP4rev1.  A flag of
   either type can be permanent or session-only.

   A system flag is a flag name that is pre-defined in this
   specification.  All system flags begin with "\".  Certain system
   flags (\Deleted and \Seen) have special semantics described
   elsewhere.  The currently-defined system flags are:

        \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.

   A keyword is defined by the server implementation.  Keywords do not
   begin with "\".  Servers MAY permit the client to define new keywords
   in the mailbox (see the description of the PERMANENTFLAGS response
   code for more information).

   A flag can be permanent or session-only on a per-flag basis.
   Permanent flags are those which the client can add or remove from the
   message flags permanently; that is, concurrent and subsequent
   sessions will see any change in permanent flags.  Changes to session
   flags are valid only in that session.

    Note: The \Recent system flag is a special case of a
    session flag.  \Recent can not be used as an argument in a
    STORE or APPEND command, and thus can not be changed at
    all.
Ra_
  • 677
  • 4
  • 9
  • "*There is not any RFC on the subject of user-defined flags, only proposals.*" - You just disproved that. User defined flags are named keywords and you just quoted RFC 3501 which explains this feature in all detai: `A keyword is defined by the server implementation. Keywords do not begin with "\". Servers MAY permit the client to define new keywords in the mailbox (see the description of the PERMANENTFLAGS response code for more information).` – Mecki Sep 11 '20 at 16:37
5

Exchange 2010 has the same set of PERMANENTFLAGS

* OK [PERMANENTFLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)] Perman
ent flags
Jan Šotola
  • 161
  • 1
  • 5
  • 2
    Same for Office 365 `* OK [PERMANENTFLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)] Permanent flags` – Nisd Nov 18 '15 at 14:43
  • 1
    A bit off-topic, but created a user-voice suggestion for proper IMAP support in Office 365, with the hopes of them fixing proper IMAP support some time before Exchange drowns everything. – flindeberg Mar 29 '20 at 20:50