This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: email.encoders.encode_base64 create a single long line
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 3.3
process
Status: closed Resolution: duplicate
Dependencies: Superseder: binary email attachment issue with base64 encoding
View: 9298
Assigned To: Nosy List: r.david.murray, yves@zioup.com
Priority: normal Keywords:

Created on 2011-02-09 02:09 by yves@zioup.com, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg128202 - (view) Author: Yves Dorfsman (yves@zioup.com) Date: 2011-02-09 02:09
email.encoders.encode_base64 returns a str of a single long line instead of breaking it up into 76 chars line as per RFC 2045, and as implemented by email.base64mime.

Solution:
In /usr/lib/python3.1/email/encoders.py, use encodebytes instead of b64encode:

--- encoders.py 2011-02-08 09:37:21.025030051 -0700
+++ encoders.py.yves    2011-02-08 09:38:04.945608365 -0700
@@ -12,7 +12,7 @@
     ]
 
 
-from base64 import b64encode as _bencode
+from base64 import encodebytes as _bencode
 from quopri import encodestring as _encode
msg128213 - (view) Author: Yves Dorfsman (yves@zioup.com) Date: 2011-02-09 14:37
In case this does not get fixed for a long time, here is a work around (re-implement the encoder yourself):


.
.
.
def myencoder(msg):
  from base64 import encodebytes as _bencode

  orig = msg.get_payload()
  encdata = str(_bencode(orig), 'ascii')
  msg.set_payload(encdata)
  msg['Content-Transfer-Encoding'] = 'base64'
.
.
.
# here is an example of how to use it
fp = open('/usr/share/openclipart/png/animals/mammals/happy_monkey_benji_park_01.png', 'rb')

bindata = fp.read()

x = email.mime.image.MIMEImage(bindata, _subtype='png', _encoder=myencoder)

y = x.get_payload()
print (y)
.
.
.
msg128219 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-02-09 16:19
This appears to be a duplicate of issue 9298.  Yves, if you disagree let me know what's different.
History
Date User Action Args
2022-04-11 14:57:12adminsetgithub: 55365
2011-02-09 16:20:38r.david.murraysetsuperseder: binary email attachment issue with base64 encoding
2011-02-09 16:19:03r.david.murraysetstatus: open -> closed

type: behavior
versions: + Python 3.2, Python 3.3
nosy: + r.david.murray

messages: + msg128219
resolution: duplicate
stage: resolved
2011-02-09 14:37:16yves@zioup.comsetmessages: + msg128213
2011-02-09 02:09:59yves@zioup.comcreate