docker-offlineimap/offlineimap/folder
Nicolas Sebrecht be285e522d IMAP: don't take junk data for valid mail content
OfflineIMAP frequently delivers mail files to the Maildir consisting exclusively
of a single ASCII digit in IDLE mode. IMAPFolder.getmessage expects 'data' to be
of the form

  [(fetch-info, message-body)]

However, the imapobj.uid call in getmessage returns a list of *all* pending
untagged FETCH responses.  If any message flags were changed in the selected
IMAP folder since the last command (by another client or another thread in
OfflineIMAP itself), the IMAP server will issue unsolicited FETCH responses
indicating these flag changes (RFC3501, section 7).  When this happens, 'data'
will look like, for example

  ['1231 (FLAGS (\\Seen) UID 5300)',
   '1238 (FLAGS (\\Seen) UID 5318)',
   ('1242 (UID 5325 BODY[] {7976}', message-body)]

Unfortunately, getmessage retrieves the message body as data[0][1], which in
this example is just the string "2", and this is what gets stored in the mail
file.

Multi-threaded OfflineIMAP with IDLE or holdconnectionopen is particularly
susceptible to this problem because flag changes synced back to the IMAP server
on one thread will appear as unsolicited FETCH responses on another thread if it
happens to have the same folder selected.  This can also happen without IDLE or
holdconnectionopen or even in single-threaded OfflineIMAP with concurrent access
from other IMAP clients (webmail clients, etc.), though the window for the bug
is much smaller.

Ideally, either imaplib2 or getmessage would parse the fetch responses to find
the response for the requested UID.  However, since IMAP only specifies
unilateral FETCH responses for flag changes, it's almost certainly safe to
simply find the element of 'data' that is a tuple (perhaps aborting if there is
more than one tuple) and use that.

Github-fix: https://github.com/OfflineIMAP/offlineimap/issues/162
Based-on-patch-by: Austin Clements <amdragon@MIT.EDU>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-07-28 07:18:23 +02:00
..
__init__.py IMAP/IMAP: fix import issue about UIDMaps 2016-07-25 05:26:57 +02:00
Base.py remove dead code: the description of the passes is never used 2016-07-18 18:41:41 +02:00
Gmail.py remove dead code: the description of the passes is never used 2016-07-18 18:41:41 +02:00
GmailMaildir.py GmailMaildir: don't add a tuple to syncmessagesto_passes 2016-07-27 16:29:34 +02:00
IMAP.py IMAP: don't take junk data for valid mail content 2016-07-28 07:18:23 +02:00
LocalStatus.py local status: deletemessagelist: remove broken code 2016-07-25 15:06:39 +02:00
LocalStatusSQLite.py Remove double import of "six" 2016-07-27 03:19:14 +02:00
Maildir.py Maildir: OfflineImapError is missing the severity argument 2016-07-16 18:02:01 +02:00
UIDMaps.py UIDMaps: correctly protect from concurrent writes 2016-07-03 20:00:21 +02:00