Package: offlineimap
Version: 4.0.9
Severity: important
Tags: patch
Cryrus IMAPD rejects mails with a NUL characters in them,
and offlineimap 4.0.9 crashes in the error from IMAP:
EEKF9 NO Message contains NUL characters
... place of the crash:
offlineimap/folder/IMAP.py:savemessage():
assert(imapobj.append(self.getfullname(),
imaputil.flagsmaildir2imap(flags),
date, content)[0] == 'OK')
Longer description and fix:
As it so happens, my mail server, which puts mail into my
maildir folder happily passes mail with NULL characters
but Cyrus IMAP, where I want to sync the mail to, does
not. Because this could happen anytime again because
of spam for example, I need to fix the crash in offlineimap
instead of working around it - I need to have it working
for unattended operation and my email is critical.
Therefore I looked at a place to fix the crash and did my
change here:
offlineimap/folder/IMAP.py:
ui.debug('imap', 'savemessage: using date ' + str(date))
- content = re.sub("(?<!\r)\n", "\r\n", content)
+ content = re.sub("(?<!\r)\n", "\r\n", content.replace("\0", "=00"))
ui.debug('imap', 'savemessage: initial content is: ' + repr(content))
works fine - you can choose to replace \0 with also with nothing,
I choose =00 because it's the quoted-printable sequence for \0,
so this does not fix something but clearly shows me that this
message had a replaced \0 character, that's all.
-- System Information:
Debian Release: 3.1
APT prefers testing
APT policy: (500, 'testing')
Architecture: i386 (i686)
Kernel: Linux 2.4.27
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Versions of packages offlineimap depends on:
ii python2.3 2.3.5-1 An interactive high-level object-o
-- no debconf information
PS: Thanks for offlineimap, works great now!
--- offlineimap/folder/IMAP.py
+++ offlineimap/folder/IMAP.py
@@ -207,7 +207,7 @@
date = imaplib.Time2Internaldate(time.localtime())
ui.debug('imap', 'savemessage: using date ' + str(date))
- content = re.sub("(?<!\r)\n", "\r\n", content)
+ content = re.sub("(?<!\r)\n", "\r\n", content.replace("\0", "=00"))
ui.debug('imap', 'savemessage: initial content is: ' +
repr(content))
(headername, headervalue) = self.savemessage_getnewheader(content)