From 49b6c30aceea7fbef6b6a454a0bd5c113a89fd69 Mon Sep 17 00:00:00 2001 From: Joseph Ishac Date: Fri, 19 Feb 2021 17:00:15 -0500 Subject: [PATCH] Cleaning up some more use of the old message string "content" to use "msg" email object instead. --- offlineimap/folder/Base.py | 2 +- offlineimap/folder/IMAP.py | 15 +++------------ offlineimap/folder/LocalStatus.py | 2 +- offlineimap/folder/LocalStatusSQLite.py | 2 +- offlineimap/folder/Maildir.py | 4 ++-- offlineimap/folder/UIDMaps.py | 6 +++--- 6 files changed, 11 insertions(+), 20 deletions(-) diff --git a/offlineimap/folder/Base.py b/offlineimap/folder/Base.py index 929f515..5e562ad 100644 --- a/offlineimap/folder/Base.py +++ b/offlineimap/folder/Base.py @@ -370,7 +370,7 @@ class BaseFolder: return len(self.getmessagelist()) def getmessage(self, uid): - """Returns the content of the specified message.""" + """Returns and email message object.""" raise NotImplementedError diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py index 658b20b..49d4c1b 100644 --- a/offlineimap/folder/IMAP.py +++ b/offlineimap/folder/IMAP.py @@ -30,13 +30,6 @@ CRLF = '\r\n' MSGCOPY_NAMESPACE = 'MSGCOPY_' -# NB: message returned from getmessage() will have '\n' all over the place, -# NB: there will be no CRLFs. Just before the sending stage of savemessage() -# NB: '\n' will be transformed back to CRLF. So, for the most parts of the -# NB: code the stored content will be clean of CRLF and one can rely that -# NB: line endings will be pure '\n'. - - class IMAPFolder(BaseFolder): def __init__(self, imapserver, name, repository, decode=True): # decode the folder name from IMAP4_utf_7 to utf_8 if @@ -400,7 +393,7 @@ class IMAPFolder(BaseFolder): # mails with identical content, the randomness requirements are # not extremly critial though. - # Compute unsigned crc32 of 'content' as unique hash. + # Compute unsigned crc32 of 'msg' (as bytes) into a unique hash. # NB: crc32 returns unsigned only starting with python 3.0. headervalue = '{}-{}'.format( (binascii.crc32(msg.as_bytes(policy=output_policy)) & 0xffffffff), @@ -654,10 +647,8 @@ class IMAPFolder(BaseFolder): # Filter user requested headers before uploading to the IMAP server self.deletemessageheaders(msg, self.filterheaders) - # Should just be able to set the policy + # Should just be able to set the policy, to use CRLF in msg output output_policy = self.policy['8bit-RFC'] - # # Use proper CRLF all over the message. - # content = re.sub("(? 200: + if len(msg_s) > 200: dbg_output = "%s...%s" % (msg_s[:150], msg_s[-50:]) else: dbg_output = msg_s diff --git a/offlineimap/folder/LocalStatus.py b/offlineimap/folder/LocalStatus.py index 4f8d42d..035f9e0 100644 --- a/offlineimap/folder/LocalStatus.py +++ b/offlineimap/folder/LocalStatus.py @@ -190,7 +190,7 @@ class LocalStatusFolder(BaseFolder): os.close(fd) # Interface from BaseFolder - def savemessage(self, uid, content, flags, rtime, mtime=0, labels=None): + def savemessage(self, uid, msg, flags, rtime, mtime=0, labels=None): """Writes a new message, with the specified uid. See folder/Base for detail. Note that savemessage() does not diff --git a/offlineimap/folder/LocalStatusSQLite.py b/offlineimap/folder/LocalStatusSQLite.py index 27a9a81..a576b9c 100644 --- a/offlineimap/folder/LocalStatusSQLite.py +++ b/offlineimap/folder/LocalStatusSQLite.py @@ -323,7 +323,7 @@ class LocalStatusSQLiteFolder(BaseFolder): # assert False,"getmessageflags() called on non-existing message" # Interface from BaseFolder - def savemessage(self, uid, content, flags, rtime, mtime=0, labels=None): + def savemessage(self, uid, msg, flags, rtime, mtime=0, labels=None): """Writes a new message, with the specified uid. See folder/Base for detail. Note that savemessage() does not diff --git a/offlineimap/folder/Maildir.py b/offlineimap/folder/Maildir.py index 42e2f0c..bfa8234 100644 --- a/offlineimap/folder/Maildir.py +++ b/offlineimap/folder/Maildir.py @@ -254,7 +254,7 @@ class MaildirFolder(BaseFolder): # Interface from BaseFolder def getmessage(self, uid): - """Return the content of the message.""" + """Returns and email message object.""" filename = self.messagelist[uid]['filename'] filepath = os.path.join(self.getfullname(), filename) @@ -287,7 +287,7 @@ class MaildirFolder(BaseFolder): return uniq_name.replace(os.path.sep, self.sep_subst) def save_to_tmp_file(self, filename, msg, policy=None): - """Saves given content to the named temporary file in the + """Saves given message to the named temporary file in the 'tmp' subdirectory of $CWD. Arguments: diff --git a/offlineimap/folder/UIDMaps.py b/offlineimap/folder/UIDMaps.py index fd495d4..740cdbb 100644 --- a/offlineimap/folder/UIDMaps.py +++ b/offlineimap/folder/UIDMaps.py @@ -236,11 +236,11 @@ class MappedIMAPFolder(IMAPFolder): # Interface from BaseFolder def getmessage(self, uid): - """Returns the content of the specified message.""" + """Returns the specified message.""" return self._mb.getmessage(self.r2l[uid]) # Interface from BaseFolder - def savemessage(self, uid, content, flags, rtime): + def savemessage(self, uid, msg, flags, rtime): """Writes a new message, with the specified uid. The UIDMaps class will not return a newly assigned uid, as it @@ -271,7 +271,7 @@ class MappedIMAPFolder(IMAPFolder): self.savemessageflags(uid, flags) return uid - newluid = self._mb.savemessage(-1, content, flags, rtime) + newluid = self._mb.savemessage(-1, msg, flags, rtime) if newluid < 1: raise OfflineImapError("server of repository '%s' did not return " "a valid UID (got '%s') for UID '%s' from '%s'" % (