[Python-checkins] python/dist/src/Lib/email Generator.py,1.17.6.1,1.17.6.2

bwarsaw@users.sourceforge.net bwarsaw@users.sourceforge.net
Mon, 03 Mar 2003 08:36:28 -0800


Update of /cvsroot/python/python/dist/src/Lib/email
In directory sc8-pr-cvs1:/tmp/cvs-serv17277

Modified Files:
      Tag: folding-reimpl-branch
	Generator.py 
Log Message:
_handle_multipart(): If the preamble doesn't end in a line break, we
must add one otherwise the following boundary separator will be
broken.  Closes SF bug #682504.


Index: Generator.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/email/Generator.py,v
retrieving revision 1.17.6.1
retrieving revision 1.17.6.2
diff -C2 -d -r1.17.6.1 -r1.17.6.2
*** Generator.py	3 Mar 2003 15:48:08 -0000	1.17.6.1
--- Generator.py	3 Mar 2003 16:36:23 -0000	1.17.6.2
***************
*** 14,17 ****
--- 14,18 ----
  
  from email.Header import Header
+ from email.Parser import NLCRE
  
  try:
***************
*** 260,263 ****
--- 261,272 ----
          if msg.preamble is not None:
              self._fp.write(msg.preamble)
+             # If preamble is the empty string, the length of the split will be
+             # 1, but the last element will be the empty string.  If it's
+             # anything else but does not end in a line separator, the length
+             # will be > 1 and not end in an empty string.  We need to
+             # guarantee a newline after the preamble, but don't add too many.
+             plines = NLCRE.split(msg.preamble)
+             if plines <> [''] and plines[-1] <> '':
+                 self._fp.write('\n')
          # First boundary is a bit different; it doesn't have a leading extra
          # newline.