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 message parser doesn't handle \r\n correctly
Type: Stage:
Components: None Versions:
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: barry Nosy List: anadelonbrin, barry, sjoerd
Priority: normal Keywords:

Created on 2004-08-03 08:32 by sjoerd, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg21921 - (view) Author: Sjoerd Mullender (sjoerd) * (Python committer) Date: 2004-08-03 08:32
Header lines that end in \r\n only get the \n stripped,
not the \r (unless it's the last header which does get
the \r stripped):

>>> import email.Parser
>>> m = 'Header: text\r\nNext-Header: more
text\r\n\r\nBody\r\n\r\n'
>>> msg = email.Parser.Parser().parsestr(m)
>>> msg.get('header')
'text\r'
>>> msg.get('next-header')
'more text'
>>>

This bug showed itself in my SpamBayes setup using
sb_imapfilter.py where base64-encoded text/html
messages were not decoded in Message.get_payload
because the call to get('content-transfer-encoding')
returned the string 'base64\r' instead of 'base64'.
msg21922 - (view) Author: Tony Meyer (anadelonbrin) Date: 2004-08-05 01:28
Logged In: YES 
user_id=552329

A patch to fix this is in:

[ 1003693 ] Fix for 1002475 (Feedparser not handling \r\n
correctly)
http://sourceforge.net/tracker/index.php?func=detail&aid=1003693&group_id=5470&atid=305470

I'll try to write a test for it, too, and also attach that.
msg21923 - (view) Author: Sjoerd Mullender (sjoerd) * (Python committer) Date: 2004-08-06 06:40
Logged In: YES 
user_id=43607

The patch seems to work well.  +1 for checking it in.
msg21924 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2004-08-07 15:58
Logged In: YES 
user_id=12800

Patch looks good to me.  Accepted and checked in.

test_email.py 1.59
FeedParser.py 1.9
History
Date User Action Args
2022-04-11 14:56:06adminsetgithub: 40679
2004-08-03 08:32:50sjoerdcreate