classification
Title: get_payload(decode=True) eats last newline
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.2, Python 3.1, Python 3.0, Python 2.7, Python 2.6, Python 2.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: athomas, esam (2)
Priority: Keywords

Created on 2009-10-15 18:06 by athomas, last changed 2009-10-16 06:47 by esam.

Files
File name Uploaded Description Edit Remove
test.eml athomas, 2009-10-15 18:06 Sample email
Messages (1)
msg94100 - (view) Author: Andreas Thomas (athomas) Date: 2009-10-15 18:06
The attachment of my sample email contains '123\n', but get_payload
(decode=True) returns '123'.
The source of this error is the function _bdecode from the email.utils 
module, which gets called for decoding base64 encoded payloads. Here 
the last \n gets stripped away, because (comment in the function):

# We can't quite use base64.encodestring() since it tacks on a "courtesy
# newline".  Blech!

I don't think that's true. At least not for Python 2.5.4 and upwards. 
Also note the "encodestring" instead of "decodestring".
In fact calling

base64.decodestring(part.get_payload())

returns the correct value, so I propose to remove this function 
completely and just use the standard decoding method.
Please note that base64.encodestring really tacks on a \n.
History
Date User Action Args
2009-10-16 06:47:02esamsetnosy: + esam
2009-10-15 18:06:47athomascreate