473,574 Members | 2,687 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

email package and line ending

Regards.

The problem is this code:
import email.Message
msg = email.Message.M essage()
msg["subject"] = "email bug"
msg["from"] = "Manlio Perillo"
print repr(msg.as_str ing()) '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('multili ne header', 'iso-8859-1', maxlinelen=4)
e.encode()



Manlio Perillo
Dec 23 '05 #1
1 1169
Manlio Perillo <ma************ **@SPAMlibero.i t> wrote:

The problem is this code:
import email.Message
msg = email.Message.M essage()
msg["subject"] = "email bug"
msg["from"] = "Manlio Perillo"
print repr(msg.as_str ing())'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('multili ne 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
6136
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 text of the body - every character from the new line after the headers until the end of the message.
4
1386
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 00:12:27 2005 a: 123
2
7276
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 when you copy the package to a new environment; otherwise your packages in multiple environments will all reference the same INI file. If there are...
55
25441
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
9502
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 letting Python handle the line endings. Is the following safe and sane : text = open('test.txt', 'rb').read()
20
2896
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 = MIMEText( u'Some text with chars that need encoding: \xa3',
1
2157
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 line, and ending line). On invoking this function, I want to scroll the page to a) make the text within starting-line / ending-line visible (well,...
6
1974
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 example, Python recognizes that the statement obviously must continue. I've noticed, however, that the same rule does not apply when a line ends with...
7
2179
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 it complains that I am attempting a relative import in a non-package. eg ~/python/testpackage$ ls config.py importer.py __init__.py
0
7732
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7822
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8101
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5626
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5302
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3754
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2249
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1347
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.