Cleaning up some more use of the old message string "content" to use "msg" email object instead.

This commit is contained in:
Joseph Ishac 2021-02-19 17:00:15 -05:00
parent 1d2478bcb6
commit 49b6c30ace
6 changed files with 11 additions and 20 deletions

View File

@ -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

View File

@ -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("(?<!\r)\n", CRLF, content)
# Get the date of the message, so we can pass it to the server.
date = self.__getmessageinternaldate(msg, rtime)
@ -689,7 +680,7 @@ class IMAPFolder(BaseFolder):
self.addmessageheader(msg, headername, headervalue)
msg_s = msg.as_string(policy=output_policy)
if len(content) > 200:
if len(msg_s) > 200:
dbg_output = "%s...%s" % (msg_s[:150], msg_s[-50:])
else:
dbg_output = msg_s

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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'" % (