469,275 Members | 1,871 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

email package and line ending

Regards.

The problem is this code:
import email.Message
msg = email.Message.Message()
msg["subject"] = "email bug"
msg["from"] = "Manlio Perillo"
print repr(msg.as_string()) 'subject: email bug\nfrom: Manlio Perillo\n\n'
Why line ending is '\n' and not '\r\n' ?
RFC 2822 says that the delimiter must(?) be '\r\n'.

The same problem is presente in email.Generator and email.Header (for
multiline headers).
P.S.
email.Header has a bug:

this code causes an infinite recursion:
from email.Header import Header
h = Header('multiline header', 'iso-8859-1', maxlinelen=4)
e.encode()



Manlio Perillo
Dec 23 '05 #1
1 1055
Manlio Perillo <ma**************@SPAMlibero.it> wrote:

The problem is this code:
import email.Message
msg = email.Message.Message()
msg["subject"] = "email bug"
msg["from"] = "Manlio Perillo"
print repr(msg.as_string())'subject: email bug\nfrom: Manlio Perillo\n\n'

Why line ending is '\n' and not '\r\n' ?
RFC 2822 says that the delimiter must(?) be '\r\n'.
Because all you have there is a string. It doesn't have anything to do
with RFC 2822. \n is probably the safest cross-platform way to represent a
newline in a Python string.

Note that smtplib, which DOES have to worry abouot RFC 2822 compliance,
will replace all standalone \r and \n characters with \r\n.
email.Header has a bug:

this code causes an infinite recursion:
from email.Header import Header
h = Header('multiline header', 'iso-8859-1', maxlinelen=4)
e.encode()


I'm not sure I would call that a bug. I'd call that a usage error; you've
asked it to accomplish something that cannot be done. However, it is true
that _split has enough information to diagnose this.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Dec 27 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by andrew blah | last post: by
4 posts views Thread by Roman Suzi | last post: by
2 posts views Thread by Theodore Feldman | last post: by
55 posts views Thread by Sameer | last post: by
18 posts views Thread by Fuzzyman | last post: by
20 posts views Thread by Chris Withers | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.