This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: email/Generator.py: Incorrect header output
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: barry Nosy List: barry, bbaetz, mjepronk
Priority: normal Keywords:

Created on 2003-10-20 10:23 by mjepronk, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg18691 - (view) Author: Matthias Pronk (mjepronk) Date: 2003-10-20 10:23
I've found a small bug when using the email/Parser.py
classes. When there is a long "Subject" header, it will
be wrapped to multiple lines, which are preceded by a
tab. This is undesired behaviour, because e-mail
clients show this tab in the subject. Especially,
Mozilla for Windows shows a strange square symbol. The
following code in email/Generator.py (line 180)
resolves the problem:

            else:
                # Header's got lots of smarts, so use it.
                if h.lower() == 'subject':
                    cont_ws = ' ' 
                else:
                    cont_ws = '\t'
                print >> self._fp, Header(
                    v, maxlinelen=self.__maxheaderlen,
                    header_name=h,
continuation_ws=cont_ws).encode()

For more information you can e-mail me: matthias -at-
rubberbiscuit.nl
msg18692 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2003-11-21 18:38
Logged In: YES 
user_id=12800

RFC 2822 specifies when and how long headers are supposed to
be wrapped, and the default Generator behavior is to be
compliant with this standard.  I consider it a bug in your
mail reader that such long headers are displayed incorrectly
(other mail readers display long wrapped headers correctly).

Having said this, you have options.  You can disable
wrapping altogether by passing maxheaderlen=0 to the
Generator constructor, or you can create a Generator
subclass which overrides the _write_headers() method and
passes a different value for continuation_ws.
msg18693 - (view) Author: Bradley Baetz (bbaetz) Date: 2006-03-30 07:52
Logged In: YES 
user_id=495627

I disagree that this follows RFC2822. The RFC says:

   The process of moving from this folded multiple-line
representation
   of a header field to its single line representation is called
   "unfolding". Unfolding is accomplished by simply removing
any CRLF
   that is immediately followed by WSP.  Each header field
should be
   treated in its unfolded form for further syntactic and
semantic
   evaluation.

This means that if python takes a header:

Subject: This is a long string

and wraps it to:

Subject: This is a\r\n\tlong string

then when the MUA "simply remov[es] any CRLF" the
whitespace, and we end up with:

Subject: This is a\tlong string

with a tab rather than a space, which doesn't look too good.
Some MUAs condense any following WSP into a single space,
but thats technically breaking the RFC.

(This affects mailman -
http://mail.python.org/pipermail/mailman-developers/2005-December/018410.html)
History
Date User Action Args
2022-04-11 14:56:00adminsetgithub: 39431
2003-10-20 10:23:42mjepronkcreate