Title: Issue with imaplib and append messages passing a tuple with flags
Type: Stage: needs patch
Components: Documentation Versions: Python 3.4, Python 3.5, Python 2.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Pilessio, docs@python, eric.smith, r.david.murray
Priority: normal Keywords:

Created on 2015-01-26 12:41 by Pilessio, last changed 2015-01-26 14:04 by r.david.murray.

Messages (3)
msg234738 - (view) Author: Alessio (Pilessio) Date: 2015-01-26 12:41
In example when appending a message with more than one flag in a tuple with imaplib:

print flags
('\\Answered', '\\Seen')

connection.append('INBOX', flags, date, msg)

TypeError                                 Traceback (most recent call last)
<ipython-input-42-832414ffe4b5> in <module>()
----> 1 connection.append('INBOX', flags, date, msg[1][0][1])

/usr/lib/python2.7/ in append(self, mailbox, flags, date_time, message)
    326         if flags:
    327             if (flags[0],flags[-1]) != ('(',')'):
--> 328                 flags = '(%s)' % flags
    329         else:
    330             flags = None

TypeError: not all arguments converted during string formatting

When I have only one flag to append:

print flags
Out[70]: ('\\Answered',)

connection.append('INBOX', flags, date, msg)
Out[74]: ('OK', ['[APPENDUID 1 1012] APPEND completed'])

Any ideas?

msg234739 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2015-01-26 13:04
flags is supposed to be a string. This is not well documented, like much of the module.

flags = r'(\Answered \Seen)'
msg234743 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-01-26 14:04
Indeed, as with much of the early email related code in the stdlib, the documentation assumes way too much familiarity with the relevant RFC...which is really hard to read.  We should add a few more details to the docs (like FLAGS being a string) even if we don't have the resources to do a full overhaul.
Date User Action Args
2015-01-26 14:04:31r.david.murraysetassignee: docs@python
components: + Documentation, - Library (Lib)
versions: + Python 3.4, Python 3.5
nosy: + docs@python, r.david.murray

messages: + msg234743
stage: needs patch
2015-01-26 13:04:22eric.smithsetnosy: + eric.smith
messages: + msg234739
2015-01-26 12:41:03Pilessiocreate