email and unicode

J

janwillem

I have a script that extracts attachments from all emails in a mbox
(largely based on http://code.activestate.com/recipes/302086-strip-attachments-from-an-email-message/;
thanks ActiveState). It works fine until it encounters an attachment
with a unicode file name (Ukrainian in my case). I cannot get working
the line
msg.set_payload(replace)
which is line 39 in the activestate snippet.

How can you get the unicode file name into the replace string of line
35 of the snippet:
replace = ReplaceString % dict(content_type=ct,
filename=fn,
params=params)
without getting this nasty error message about ascii encoding?
 
S

Steven D'Aprano

How can you get the unicode file name into the replace string of line 35
of the snippet:
replace = ReplaceString % dict(content_type=ct,
filename=fn,
params=params)
without getting this nasty error message about ascii encoding?

Completely untested...

fn = fn.encode('utf-8')
replace = ReplaceString % dict(
content_type=ct, filename=fn, params=params)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,735
Latest member
HikmatRamazanov

Latest Threads

Top