hello there,
i am having a bit o trouble being able to read a base64 encoded email attachement.

here is the script.

import email
import poplib
import base64
import os

email_folder = 'emails/'
mime = "application/octet-stream"

def WriteAttachment(msg):
    for part in msg.walk():
        print part
        if part.get_content_type() == mime:
            name = part.get_filename()
            data = "">             email_folder = 'emails/'           
            f = file('%s%s'%(email_folder,name),'wb')
            f.write(data)
            f.close()

ms = poplib.POP3('my.mailserver.net')
ms.user('me')
ms.pass_('pass')

msgcount = len(ms.list()[1])
ii = 0
for i in range(msgcount):
    ii+=1
    if ii > 1: break
    response, msg_as_list, size = ms.retr(i+1)
    msg = email.message_from_string('\r\n'.join(msg_as_list))
    WriteAttachment(msg)
   
dumped_files = os.listdir(email_folder)
i = 0
for d_file in dumped_files:
    i+=1         
    base64.decode(open("%s%s" % (email_folder,d_file)), open("out.txt", "w"))

the issue is when it gets to the part of decoding. The traceback says
binascii.Error: Incorrect Padding.
but i am certain that the info as it is being sent is good.

anyone see where i may be missing it here ?

thanks.

-shawn
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to