From 442c88d838d9116d297b0fa9345158dd5b9a2c40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolfo=20Garc=C3=ADa=20Pe=C3=B1as=20=28kix=29?= Date: Sun, 25 Oct 2020 20:36:07 +0100 Subject: [PATCH] imaplib expect bytes in the append imaplib2 is doing this code for strings: if isinstance(message, str): message = bytes(message, 'ASCII') But our message is already encoded using 'utf-8'. Then, we can set the message as bytes, encoded using 'utf-8' in offlineimap and imaplib2 won't change our message. This patch solves this problem: WARNING:OfflineImap: Traceback: File "/home/kix/src/offlineimap3/offlineimap/folder/Base.py", line 1127, in syncmessagesto action(dstfolder, statusfolder) File "/home/kix/src/offlineimap3/offlineimap/folder/Base.py", line 955, in __syncmessagesto_copy self.copymessageto(uid, dstfolder, statusfolder, register=0) File "/home/kix/src/offlineimap3/offlineimap/folder/Base.py", line 855, in copymessageto new_uid = dstfolder.savemessage(uid, message, flags, rtime) File "/home/kix/src/offlineimap3/offlineimap/folder/IMAP.py", line 668, in savemessage (typ, dat) = imapobj.append(self.getfullIMAPname(), File "/usr/lib/python3/dist-packages/imaplib2.py", line 660, in append message = bytes(message, 'ASCII') --- offlineimap/folder/IMAP.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py index c7febea..ef39892 100644 --- a/offlineimap/folder/IMAP.py +++ b/offlineimap/folder/IMAP.py @@ -666,7 +666,7 @@ class IMAPFolder(BaseFolder): # Do the APPEND. try: (typ, dat) = imapobj.append(self.getfullIMAPname(), - imaputil.flagsmaildir2imap(flags), date, content) + imaputil.flagsmaildir2imap(flags), date, bytes(content, 'utf-8')) # This should only catch 'NO' responses since append() # will raise an exception for 'BAD' responses: if typ != 'OK':