473,387 Members | 1,611 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 1153
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: andrew blah | last post by:
Hello, I need to get the text of the body (the payload) of an email. As I understand it, an email has headers at the top, then a blank line, then the body of the message. I want to get the...
4
by: Roman Suzi | last post by:
I was playing with email package and discovrered this strange kind of behaviour: >>> import email.Message >>> m = email.Message.Message() >>> m = '123' >>> print m >From nobody Mon Feb 21...
2
by: Theodore Feldman | last post by:
If connection properties and global variables are set from an INI file, how can a DTS package be made truly portable? If the INI file pathname is hard-coded in the package, it must be edited...
55
by: Sameer | last post by:
Hi, when i compile my C programs (even 2 line progs) give the warning, no new line at end of file. What does this mean ? -Regards, Sameer
18
by: Fuzzyman | last post by:
Hello all, I'm trying to detect line endings used in text files. I *might* be decoding the files into unicode first (which may be encoded using multi-byte encodings) - which is why I'm not...
20
by: Chris Withers | last post by:
Hi All, The following piece of code is giving me issues: from email.Charset import Charset,QP from email.MIMEText import MIMEText charset = Charset('utf-8') charset.body_encoding = QP msg =...
1
by: navisingh | last post by:
I have a HTML page with a block of text encased in <code> </code>. This text is unwrapped (because of the code block). I want to write a javascript function that takes two arguments(starting...
6
by: Russ P. | last post by:
I've always appreciated Python's lack of requirement for a semi-colon at the end of each line. I also appreciate its rules for automatic line continuation. If a statement ends with a "+", for...
7
by: alito | last post by:
Hi all, I am new to using packages to group my modules. I can't figure out how to run a module that uses relative imports without writing a wrapper that imports that module. Everything I try...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.