imaplib.IMAP4: Bug in implementation

Tony Meyer t-meyer at
Wed Mar 17 22:41:10 CET 2004

[Oliver Kurz]
> I call the uid like this
> uid("STORE",uid,"+FLAGS(\SEEN)")

[Donn Cave]
> Have you tried uid("STORE", uid, "+FLAGS", "(\SEEN)")?

I was bitten by this just the other day.  Donn is correct, adding the
surrounding parentheses fixes the problem.

The documentation does mention this in section 11.10.1: "If you want to
avoid having an argument string quoted (eg: the flags argument to "STORE")
then enclose the string in parentheses (eg: r'(\Deleted)')."  It's also
necessary in other situations, for example, doing uid("FETCH", uid,

IMO, this is not desirable behaviour, since not using the parentheses is
valid IMAP4, and this catches people familiar with IMAP, but not familiar
with imaplib.  The _checkquote function could be smarter and only quote when
the RFC says it's meant to.  OTOH, given the multitude of ways that IMAP
servers choose to ignore the RFC, it's possible this could break some code
with non-standard IMAP servers.

IAC, I opened a bug report: 

[ 917120 ] imaplib: incorrect quoting in commands

If you agree it should be fixed, then adding to the tracker would be a good
idea.  At some point TPTB will look at it and give it a verdict.  For the
moment, the parantheses hack works.

=Tony Meyer

More information about the Python-list mailing list