[ python-Bugs-1645148 ] MIME renderer: wrong header line break with long subject?

SourceForge.net noreply at sourceforge.net
Sat Jun 9 07:19:10 CEST 2007


Bugs item #1645148, was opened at 2007-01-26 07:04
Message generated for change (Comment added) made by gagenellina
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1645148&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: kxroberto (kxroberto)
Assigned to: Barry A. Warsaw (bwarsaw)
Summary: MIME renderer: wrong header line break with long subject?

Initial Comment:
>>> from email.MIMEText import MIMEText
>>> o=MIMEText('hello')
>>> o['Subject']='1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4
5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 '
>>> o.as_string()
'Content-Type: text/plain; charset="us-ascii"\nMIME-Version: 1.0\nContent-Transf
er-Encoding: 7bit\nSubject: 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8
9 1 2 3 4 5 6 7 8\n\t9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 \n\
nhello'
>>>


The '6 7 8\n\t9 1 2 3'  clashes together to 6 7 89 1 2 3
without space between 89 in usual mail readers.
Is this an error and should be :

'6 7 8 \n\t9 1 2 3'


? 

as there is also the space preserved in 
'6 7 8 9 \n\nhello'


----------------------------------------------------------------------

Comment By: Gabriel Genellina (gagenellina)
Date: 2007-06-09 02:19

Message:
Logged In: YES 
user_id=479790
Originator: NO

Quoting RFC2822 section 2.2.3
<ftp://ftp.rfc-editor.org/in-notes/rfc2822.txt>: 

"""The general rule is that wherever this standard allows for folding
white space (not simply WSP characters), a CRLF may be inserted before any
WSP. For example, the header field:

           Subject: This is a test

can be represented as:

           Subject: This
            is a test

[...]Unfolding is accomplished by simply removing any CRLF that is
immediately followed by WSP."""

That is, folding is done by inserting ONLY the sequence CRLF before any
folding whitespace. When the header is interpreted, the whitespace is NOT
removed, only the CRLF. The posted Subject header should become "Subject: 1
2 3...7 8\n\r 9 1 2...'

I think this is a bug in the email.header.Header class; its __init__ says,
about the continuation_ws argument: "[it] must be RFC 2822 compliant
folding whitespace (usually either a space or a hard tab) which will be
prepended to continuation lines.". Folding does not involve *prepending*
any whitespace, just inserting CRLF right before *existing* whitespace.

Note that this is wrong even for the old RFC 822 (with slightly different
rules for line folding.)


----------------------------------------------------------------------

Comment By: kxroberto (kxroberto)
Date: 2007-06-08 09:11

Message:
Logged In: YES 
user_id=972995
Originator: YES

What would be the RFC definition for a correct auto-line break in a
(subject) mail header line?
Wouldn't it be more simple to not do any auto-line break for the subject?
or is there a requirement for the line break in the RFC. Don't think any
reader program would fail because of >79 char subject header lines.

----------------------------------------------------------------------

Comment By: Barry A. Warsaw (bwarsaw)
Date: 2007-03-11 18:17

Message:
Logged In: YES 
user_id=12800
Originator: NO

Whoops, this wasn't supposed to be a response to Tokio, but instead the
OP.

----------------------------------------------------------------------

Comment By: Barry A. Warsaw (bwarsaw)
Date: 2007-03-11 18:16

Message:
Logged In: YES 
user_id=12800
Originator: NO

Tokio, I'm not so sure about adding that extra space.  I tested all the
mail readers at my disposal on Linux and OSX.  I don't have any Windows
machines available so I couldn't test Outlook or OE.  (If you have them,
please indicate  what they do in a comment here!)  Here's what I found:

OSX:
  Mail.app 2.1.1 -- the extra space produces an extra space between the 8
and 9 both in the message summary and in the Subject header in the preview
pane.  The no extra space message looks fine.
  Thunderbird 1.5.0.10 -- The extra space message produces an extra space
in the message summary, while the no extra space message looks fine here. 
But the weird thing is that in both the extra space and non-extra space
cases, the Subject header in the preview pane both have extra spaces.  It
looks to me like the leading tab is being inserted into the Subject header
view.
  Entourage 11.3.3 -- The extra space shows up in both the summary and
preview panes but only in the message with the extra space

Linux
  Thunderbird 1.5.0.10 -- both messages get a tab between the 8 and 9 in
both the summary and preview pane.  This is for both the extra space
message and the no-extra space message; afaict, there's no difference
between the two and this is definitely a difference between the Linux
version and the OSX version of the same mail reader.
  Evolution 2.9.92 -- the extra space message produces an extra space
between the 8 and 9 in both the summary and preview panes.  The no-extra
space message looks fine.
  Sylpheed Claws 2.6.0 -- the extra space message produces an extra space
between the 8 and 9 in both the summary and preview panes.  The no-extra
space message looks file.

So anyway, afaict, the extra space is not appropriate for any of the
non-Windows mail readers.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1645148&group_id=5470


More information about the Python-bugs-list mailing list