Problem with base64 mimeparts and email.*

S

seal

Hello,

I'm writing a rss2mbox program as a first python project. I'm using
feedparser,
mailbox and email.* modules. I have a problem. The produced MIME-
message (see below)
seems right, as far as I know, but the base64-encoded part isn't
decoded in the MUAs.
I've tried cone and vm. The encoded content is simply displayed 'as
text'.

Help?

Thanks
/Sebastian

Content-Type: multipart/mixed; boundary="===============2078015454=="
MIME-Version: 1.0
From: xkcd.com
Subject: Borders
Date: Wed, 15 Apr 2009 04:00:00 +0000

--===============2078015454==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

http://xkcd.com/569/

--===============2078015454==
Content-Type: text/html; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64

UEdsdFp5QnpjbU05SW1oMGRIQTZMeTlwYldkekxuaHJZMlF1WTI5dEwyTnZiV2xqY3k5aWIzSmta
WEp6TG5CdVp5SWdkR2wwYkdVOQpJa1YyWlc1MGRXRnNiSGtnWVNCVlRpQnBjeUJ6WlhRZ2RYQXVJ
Q0JCYm1RZ2RHaGxiaUJoSUd4dmJtVWdjbVZpWld3Z2NuVnVjeUJrCmIzZHVJSFJvWlNCc2FXNWxJ
RzltSUdac1lXZHpJR2x1SUdaeWIyNTBJRzltSUdsMExDQnlkVzV6SUdKaFkyc2dkRzhnYUdseklH
SmgKYzJVc0lHRnVaQ0JuWlhSeklHRWdhMkZxYVd4c2FXOXVJSEJ2YVc1MGN5NGlJR0ZzZEQwaVJY
WmxiblIxWVd4c2VTQmhJRlZPSUdsegpJSE5sZENCMWNDNGdJRUZ1WkNCMGFHVnVJR0VnYkc5dVpT
QnlaV0psYkNCeWRXNXpJR1J2ZDI0Z2RHaGxJR3hwYm1VZ2IyWWdabXhoClozTWdhVzRnWm5KdmJu
UWdiMllnYVhRc0lISjFibk1nWW1GamF5QjBieUJvYVhNZ1ltRnpaU3dnWVc1a0lHZGxkSE1nWVNC
cllXcHAKYkd4cGIyNGdjRzlwYm5SekxpSWdMejRLCg==

--===============2078015454==--

The code:

from time import strftime, gmtime
from email.header import Header
from email.charset import Charset
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import mailbox, feedparser

[...]

def entry2msg(e, title, encoding):
c = Charset(encoding)
m = MIMEMultipart()

m.attach(MIMEText(e.get('id', '') + '\n'))
print e.title
print encoding
print c.output_charset
type = minortype(e.get('summary_detail.type', 'plain'))
body = c.body_encode((e.get('summary', '') + '\n').encode
(encoding))
m.attach(MIMEText(body, type, encoding))

for i in e.get('content', []):
type = minortype(i.type)
body = c.body_encode(i.value.encode(encoding))
m.attach(MIMEText(body, type, encoding))

m['From'] = Header(title, encoding)
m['Subject'] = Header(e.get('title', 'No title'), encoding)
m['Date'] = strftime('%a, %d %b %Y %H:%M:%S +0000',
e.get('date_parsed', gmtime()))

# Won't get a valid mbox otherwise.
m.epilogue = "\n"

return mailbox.mboxMessage(m)

[...]
 

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,829
Messages
2,569,737
Members
45,525
Latest member
RosalindSa

Latest Threads

Top