email package and line ending

M

Manlio Perillo

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:




Manlio Perillo
 
T

Tim Roberts

Manlio Perillo said:
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:

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top