Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4fe6caa

Browse files
committed
Patch by Lars Wirzenius:
o the initial comment is wrong: creating messages is already implemented o Message.getbodytext: if the mail or it's part contains an empty content-transfer-encoding header, the code used to break; the change below treats an empty encoding value the same as the other types that do not need decoding o SubMessage.getbodytext was missing the decode argument; the change below adds it; I also made it unconditionally return the raw text if decoding was not desired, because my own routines needed that (and it was easier than rewriting my own routines ;-)
1 parent 72b715d commit 4fe6caa

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

Lib/mhlib.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
# dict = f.getsequences() # dictionary of sequences in folder {name: list}
4040
# f.putsequences(dict) # write sequences back to folder
4141
#
42+
# f.createmessage(n, fp) # add message from file f as number n
4243
# f.removemessages(list) # remove messages in list from folder
4344
# f.refilemessages(list, tofolder) # move messages in list to other folder
4445
# f.movemessage(n, tofolder, ton) # move one message to a given destination
@@ -53,7 +54,7 @@
5354
#
5455
# XXX To do, functionality:
5556
# - annotate messages
56-
# - create, send messages
57+
# - send messages
5758
#
5859
# XXX To do, organization:
5960
# - move IntSet to separate file
@@ -699,7 +700,7 @@ def getheadertext(self, pred = None):
699700
def getbodytext(self, decode = 1):
700701
self.fp.seek(self.startofbody)
701702
encoding = self.getencoding()
702-
if not decode or encoding in ('7bit', '8bit', 'binary'):
703+
if not decode or encoding in ('', '7bit', '8bit', 'binary'):
703704
return self.fp.read()
704705
from StringIO import StringIO
705706
output = StringIO()
@@ -743,14 +744,17 @@ def __init__(self, f, n, fp):
743744
self.body = Message.getbodyparts(self)
744745
else:
745746
self.body = Message.getbodytext(self)
747+
self.bodyencoded = Message.getbodytext(self, decode=0)
746748
# XXX If this is big, should remember file pointers
747749

748750
# String representation
749751
def __repr__(self):
750752
f, n, fp = self.folder, self.number, self.fp
751753
return 'SubMessage(%s, %s, %s)' % (f, n, fp)
752754

753-
def getbodytext(self):
755+
def getbodytext(self, decode = 1):
756+
if not decode:
757+
return self.bodyencoded
754758
if type(self.body) == type(''):
755759
return self.body
756760

0 commit comments

Comments
 (0)