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
标题: email module does not complay with RFC 2046: CRLF issue
类型: behavior Stage: resolved
Components: Library (Lib) Versions:
process
状态: closed Resolution: duplicate
Dependencies: 后续: email.Generator does not separate headers with "\r\n"
View: 1349106
分配给: barry 抄送列表: andrzejl, barry, dmeranda
优先级: normal 关键字:

Created on 2006-10-06 01:30 by andrzejl, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg30173 - (view) Author: Andy Leszczynski (andrzejl) 日期: 2006-10-06 01:30
According to rfc2046, line breaks in MIME are CRLF.
However python just
uses LF like in the following example:

from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText

msg = MIMEMultipart()
msg['Subject'] = 'Our family reunion'
msg['From'] = '...@a.b'
msg['To'] = '...@x.y'
msg.epilogue = ''

msg.attach(MIMEText('aaaaaaaaaaaaaaaaaaaaaaaa'))

print `msg.as_string()`

gives:
'Content-Type: multipart/mixed;
boundary="===============1018679223=="\nMIME-Version:
1.0\nSubject: Our
family reunion\nFrom: a...@a.b\nTo:
c...@x.y\n\n--===============1018679223==\nContent-Type:
text/plain;
charset="us-ascii"\nMIME-Version:
1.0\nContent-Transfer-Encoding:
7bit\n\naaaaaaaaaaaaaaaaaaaaaaaa\n--===============1018679223==--\n'


Found in version 2.3 and 2.4 
msg68642 - (view) Author: Deron Meranda (dmeranda) 日期: 2008-06-23 17:44
Still an issue in 2.5.

This lack of conformance to the RFC is can also cause problems when
trying to use encrypted or signed email, as those activities may depend
on "canonical" line endings.  An LF rather than CR+LF can cause the
crypto to break in some cases.

This appears to be caused by the email package writing to an internal
StringIO file using the print statement, where it relies on print
outputting the end-of-line character (which will always output a LF). 
The module should instead write the eol character(s) explicitly.

To maintain backwards compatibility, it may be best if the preferred eol
character be settable on a per-message basis; which would default to the
current non-conforming behavior of LF, but which could be set to CR+LF
if strict MIME behavior is desired.
历史
日期 用户 动作 参数
2022-04-11 14:56:20admin修改github: 44089
2010-01-13 15:18:54r.david.murray修改状态: open -> closed
2010-01-12 02:07:17r.david.murray修改resolution: duplicate
后续: email.Generator does not separate headers with "\r\n"
stage: resolved
2008-06-23 17:44:54dmeranda修改抄送: + dmeranda
type: behavior
消息: + msg68642
2006-10-06 01:30:57andrzejl创建