pop3_ssl Attachment problem

Chris cwitts at gmail.com
Thu Dec 20 03:57:45 EST 2007


On Dec 20, 9:22 am, los117 <los... at gmail.com> wrote:
> I am trying to fetch email from gmail, but what I am really interested
> is the attachment.
> I manage to access the gmail server and get the messege but the
> attachment came as text:
>
> "------=_Part_5286_15861975.1197955173158
> Content-Type: audio/mpeg; name="Dire Straits - 12 - Calling Elvis.mp3"
> Content-Transfer-Encoding: base64
> X-Attachment-Id: f_fabzd5l20
> Content-Disposition: attachment;
>  filename="Dire Straits - 12 - Calling Elvis.mp3"
>
> //
> ugbAAP8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA..."
>
> how do i manage to get the file? I google for a while now, but I am a
> bit lost of ideas. Sorry for the noobish and the english. thanks =D

the base64 string you started quoting is the attachment.
from base64 import decodestring
fout = open( filename_from_email,
'w' ).write( decodestring( string_you_parsed_from_the_email ) )

also look at the email module, there are some functions to get the
payload of the email for you.



More information about the Python-list mailing list