Commit 7f53f6db authored by Guido van Rossum's avatar Guido van Rossum

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 ;-)
parent a4197776
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
# dict = f.getsequences() # dictionary of sequences in folder {name: list} # dict = f.getsequences() # dictionary of sequences in folder {name: list}
# f.putsequences(dict) # write sequences back to folder # f.putsequences(dict) # write sequences back to folder
# #
# f.createmessage(n, fp) # add message from file f as number n
# f.removemessages(list) # remove messages in list from folder # f.removemessages(list) # remove messages in list from folder
# f.refilemessages(list, tofolder) # move messages in list to other folder # f.refilemessages(list, tofolder) # move messages in list to other folder
# f.movemessage(n, tofolder, ton) # move one message to a given destination # f.movemessage(n, tofolder, ton) # move one message to a given destination
...@@ -53,7 +54,7 @@ ...@@ -53,7 +54,7 @@
# #
# XXX To do, functionality: # XXX To do, functionality:
# - annotate messages # - annotate messages
# - create, send messages # - send messages
# #
# XXX To do, organization: # XXX To do, organization:
# - move IntSet to separate file # - move IntSet to separate file
...@@ -699,7 +700,7 @@ class Message(mimetools.Message): ...@@ -699,7 +700,7 @@ class Message(mimetools.Message):
def getbodytext(self, decode = 1): def getbodytext(self, decode = 1):
self.fp.seek(self.startofbody) self.fp.seek(self.startofbody)
encoding = self.getencoding() encoding = self.getencoding()
if not decode or encoding in ('7bit', '8bit', 'binary'): if not decode or encoding in ('', '7bit', '8bit', 'binary'):
return self.fp.read() return self.fp.read()
from StringIO import StringIO from StringIO import StringIO
output = StringIO() output = StringIO()
...@@ -743,6 +744,7 @@ class SubMessage(Message): ...@@ -743,6 +744,7 @@ class SubMessage(Message):
self.body = Message.getbodyparts(self) self.body = Message.getbodyparts(self)
else: else:
self.body = Message.getbodytext(self) self.body = Message.getbodytext(self)
self.bodyencoded = Message.getbodytext(self, decode=0)
# XXX If this is big, should remember file pointers # XXX If this is big, should remember file pointers
# String representation # String representation
...@@ -750,7 +752,9 @@ class SubMessage(Message): ...@@ -750,7 +752,9 @@ class SubMessage(Message):
f, n, fp = self.folder, self.number, self.fp f, n, fp = self.folder, self.number, self.fp
return 'SubMessage(%s, %s, %s)' % (f, n, fp) return 'SubMessage(%s, %s, %s)' % (f, n, fp)
def getbodytext(self): def getbodytext(self, decode = 1):
if not decode:
return self.bodyencoded
if type(self.body) == type(''): if type(self.body) == type(''):
return self.body return self.body
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment