Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Problems decoding and writing mail attachment

Reply
Thread Tools

Problems decoding and writing mail attachment

 
 
edwinek
Guest
Posts: n/a
 
      08-04-2003
I've written a script which I use to save attached binary files from
e-mails to disk. The core is simply:

decodedfile = bas64.decodestring(attachment)
fle = open('image.jpg','wb')
fle.write(decodedfile)
fle.close

However, the files written to disk are regularly incomplete, i.e.
jpg's having a grey bar at the bottom, gif's don't even display, pdf's
give errors.
What am I doing wrong here?

Thanks,
Edwin
 
Reply With Quote
 
 
 
 
Alex Martelli
Guest
Posts: n/a
 
      08-04-2003
edwinek wrote:

> I've written a script which I use to save attached binary files from
> e-mails to disk. The core is simply:
>
> decodedfile = bas64.decodestring(attachment)
> fle = open('image.jpg','wb')
> fle.write(decodedfile)
> fle.close
>
> However, the files written to disk are regularly incomplete, i.e.
> jpg's having a grey bar at the bottom, gif's don't even display, pdf's
> give errors.
> What am I doing wrong here?


You're not calling fle.close -- you lack parentheses after the
method, so you're just mentioning it, NOT calling it. Not sure
if that's your problem (seems unlikely), but it most definitely
IS something you're doing wrong, so I thought I'd point it out.


Alex

 
Reply With Quote
 
 
 
 
Fredrik Lundh
Guest
Posts: n/a
 
      08-04-2003
"edwinek" <(E-Mail Removed)> wrote:

> I've written a script which I use to save attached binary files from
> e-mails to disk. The core is simply:
>
> decodedfile = bas64.decodestring(attachment)
> fle = open('image.jpg','wb')
> fle.write(decodedfile)
> fle.close
>
> However, the files written to disk are regularly incomplete, i.e.
> jpg's having a grey bar at the bottom, gif's don't even display, pdf's
> give errors.


> What am I doing wrong here?


chances are that you're not closing the file before using it: try changing
the last line to

fle.close()

</F>




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problrms with decoding pdf file when iy goes as an attachment Alla Perl Misc 2 02-17-2006 02:23 PM
Any problems with writing the information into a file - Multi-users perform writing the same file at the same time ???? HNguyen ASP .Net 4 12-21-2004 01:53 PM
Decoding 'funky' e-mail subjects Jonas Galvez Python 7 06-08-2004 02:19 PM
writing a SOAP message service, how do I get the attachment from a message? rabbits77 Java 0 02-26-2004 08:52 PM
CDONTS - PDF Attachment / decoding problem Kyle Pula ASP General 2 07-28-2003 06:41 PM



Advertisments