473,387 Members | 1,582 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.Message.get_payload() surprising behavior

The behavior of get_payload() is different when the quoted-printable
text has \n line endings or \r\n line endings. If it's \n and the last
byte of a line in that file is 0x0D it confuses them for a \r\n line
ending and strips both bytes.

This behavior does not occur if the same file has \r\n line endings
because the confusing line will end in \r\r\n; then \r\n will be
correctly stripped, leaving a \r at the end of a line, as it should.

More graphically:

Quoted-printable encoded file with \n newlines:
'Byte number 13 is =0D\n' <--- get_payload(decode = True) will strip the
last 0x0D byte, leaving a short by 1 file.

Quoted-printable encoded file with \r\n newlines:
'Byte number 13 is =0D\r\n' <--- get_payload(decode = True) will leave
the 0x0D byte in the file.

I think this is a bug? This has bitten me in a script run from procmail;
postfix hands \n line endings and the bug happens about once in four
months, I can work around it substituting \n with \r\n ensuring that the
\r that are part of the file and happen to be in the last position of a
line will never be stripped but this is unelegant.

Thanks
Lucia
Jul 3 '06 #1
0 1065

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: David Stockwell | last post by:
snippet payload = {} try: message = email.message_from_string(message) messageHeader = dict(message._headers) addressFrom = messageHeader addressReply = messageHeader.get("Reply-To")...
4
by: Paul Schmidt | last post by:
Dear list: I am new to python, and I am trying to figure out the short answer on something. I want to open a POP3 mailbox, read the enclosed mail using the POP3 module, , and then process it...
1
by: chuck amadi | last post by:
Hi I have managed to print the output of the get_payload to screen but I need to write to a file as I only require the email body messages from the mailbox.My script using the fp.readlines()...
0
by: chuck amadi | last post by:
Hi I have managed to print the output of the get_payload to screen but I need to write to a file as I only require the email body messages from the mailbox.My script using the fp.readlines()...
1
by: Arenz, Ralph | last post by:
hi all, my problem is to get a tiff-file-attachment out of an email sent by a fax-server. When i try this with "get_payload(decode='True')" i get additional informations, looks like...
19
by: 叮叮当当 | last post by:
hi, all when a email body consist with multipart/alternative, i must know when the boundary ends to parse it, but the email lib have not provide some function to indicate the boundary end,...
7
by: erikcw | last post by:
Hi all, I'm trying to extract zip file (containing an xml file) from an email so I can process it. But I'm running up against some brick walls. I've been googling and reading all afternoon, and...
5
by: Robert Latest | last post by:
Hello, I'm new to Python but have lots of programming experience in C, C++ and Perl. Browsing through the docs, the email handling modules caught my eye because I'd always wanted to write a...
0
by: ra9ftm | last post by:
It is my first script on python. Don't know is it correctly uses modules, but it is working fine with specially with russian code pages and mime formated messages. Also quoted-printable and base64...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.