Index: FeedParser.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/email/FeedParser.py,v retrieving revision 1.10 diff -u -r1.10 FeedParser.py --- FeedParser.py 3 Oct 2004 03:16:18 -0000 1.10 +++ FeedParser.py 9 Oct 2004 20:29:29 -0000 @@ -394,14 +394,22 @@ self._cur.epilogue = EMPTYSTRING.join(epilogue) return # Otherwise, it's some non-multipart type, so the entire rest of the - # file contents becomes the payload. + # file contents becomes the payload. Check to see if the message + # object supports the external storage API. If so, use that, + # otherwise capture the lines ourselves. lines = [] + def default_close(): + self._cur.set_payload(EMPTYSTRING.join(lines)) + msgopen = getattr(self._cur, 'storage_open', lambda: None) + msgwrite = getattr(self._cur, 'storage_write', lines.append) + msgclose = getattr(self._cur, 'storage_close', default_close) + msgopen() for line in self._input: if line is NeedMoreData: yield NeedMoreData continue - lines.append(line) - self._cur.set_payload(EMPTYSTRING.join(lines)) + msgwrite(line) + msgclose() def _parse_headers(self, lines): # Passed a list of lines that make up the headers for the current msg Index: Generator.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/email/Generator.py,v retrieving revision 1.24 diff -u -r1.24 Generator.py --- Generator.py 3 Oct 2004 03:16:18 -0000 1.24 +++ Generator.py 9 Oct 2004 20:29:29 -0000 @@ -126,7 +126,7 @@ # Get the Content-Type: for the message, then try to dispatch to # self._handle__(). If there's no handler for the # full MIME type, then dispatch to self._handle_(). If - # that's missing too, then dispatch to self._writeBody(). + # that's missing too, then dispatch to self._write_body(). main = msg.get_content_maintype() sub = msg.get_content_subtype() specific = UNDERSCORE.join((main, sub)).replace('-', '_') @@ -135,7 +135,7 @@ generic = main.replace('-', '_') meth = getattr(self, '_handle_' + generic, None) if meth is None: - meth = self._writeBody + meth = self._write_body meth(msg) # @@ -185,7 +185,7 @@ self._fp.write(payload) # Default body handler - _writeBody = _handle_text + _write_body = _handle_text def _handle_multipart(self, msg): # The trick here is to write out each part separately, merge them all cvs diff: Diffing test Index: test/test_email.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/email/test/test_email.py,v retrieving revision 1.62 diff -u -r1.62 test_email.py --- test/test_email.py 3 Oct 2004 03:16:18 -0000 1.62 +++ test/test_email.py 9 Oct 2004 20:29:32 -0000 @@ -7,6 +7,7 @@ import time import base64 import difflib +import tempfile import unittest import warnings from cStringIO import StringIO @@ -485,6 +486,35 @@ msg.set_payload(x) self.assertEqual(msg.get_payload(decode=True), x) + def test_external_body_storage(self): + class ExternalStorageMessage(Message): + def storage_open(self): + fd, self._path = tempfile.mkstemp() + self._fp = os.fdopen(fd, 'w') + + def storage_write(self, data): + self._fp.write(data) + + def storage_close(self): + self._fp.close() + fp = open(self._path) + payload = fp.read() + self.set_payload(payload) + fp = openfile(findfile('msg_01.txt')) + try: + msg = email.message_from_file(fp, ExternalStorageMessage) + finally: + fp.close() + self.ndiffAssertEqual(msg.get_payload(), """\ + +Hi, + +Do you like this message? + +-Me +""") + + # Test the email.Encoders module