UI/EmailDialog.py

changeset 45
9a18f4dbb493
parent 42
23b45a742e17
child 97
c4086afea02b
equal deleted inserted replaced
44:fe5cd20cb0eb 45:9a18f4dbb493
26 ## This code is to work around a bug in the Python email ## 26 ## This code is to work around a bug in the Python email ##
27 ## package for Image and Audio mime messages. ## 27 ## package for Image and Audio mime messages. ##
28 ############################################################ 28 ############################################################
29 from base64 import b64encode as _bencode 29 from base64 import b64encode as _bencode
30 def _encode_base64(msg): 30 def _encode_base64(msg):
31 """Encode the message's payload in Base64. 31 """
32 32 Function to encode the message's payload in Base64.
33 Also, add an appropriate Content-Transfer-Encoding header. 33
34 Note: It adds an appropriate Content-Transfer-Encoding header.
35
36 @param msg reference to the message object (email.Message)
34 """ 37 """
35 orig = msg.get_payload() 38 orig = msg.get_payload()
36 encdata = str(_bencode(orig), "ASCII") 39 encdata = str(_bencode(orig), "ASCII")
37 msg.set_payload(encdata) 40 msg.set_payload(encdata)
38 msg['Content-Transfer-Encoding'] = 'base64' 41 msg['Content-Transfer-Encoding'] = 'base64'
221 maintype, subtype = itm.text(1).split('/', 1) 224 maintype, subtype = itm.text(1).split('/', 1)
222 fname = itm.text(0) 225 fname = itm.text(0)
223 name = os.path.basename(fname) 226 name = os.path.basename(fname)
224 227
225 if maintype == 'text': 228 if maintype == 'text':
226 att = MIMEText(open(fname, 'r').read(), _subtype = subtype) 229 att = MIMEText(
230 open(fname, 'r', encoding = "utf-8").read(), _subtype = subtype)
227 elif maintype == 'image': 231 elif maintype == 'image':
228 att = MIMEImage(open(fname, 'rb').read(), _subtype = subtype) 232 att = MIMEImage(open(fname, 'rb').read(), _subtype = subtype)
229 elif maintype == 'audio': 233 elif maintype == 'audio':
230 att = MIMEAudio(open(fname, 'rb').read(), _subtype = subtype) 234 att = MIMEAudio(open(fname, 'rb').read(), _subtype = subtype)
231 else: 235 else:

eric ide

mercurial