473,545 Members | 2,663 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems decoding and writing mail attachment

I've written a script which I use to save attached binary files from
e-mails to disk. The core is simply:

decodedfile = bas64.decodestr ing(attachment)
fle = open('image.jpg ','wb')
fle.write(decod edfile)
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
Jul 18 '05 #1
2 1849
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.decodestr ing(attachment)
fle = open('image.jpg ','wb')
fle.write(decod edfile)
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

Jul 18 '05 #2
"edwinek" <ed***@mindless .com> 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.decodestr ing(attachment)
fle = open('image.jpg ','wb')
fle.write(decod edfile)
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>


Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4242
by: Bjorn Jensen | last post by:
Hello! My resulting image har nearly same size of original (but not exact) and the nu.jpg can be shown, but it is modified so much, that it look totally different.... why? what to do? Greetings Bjorn! ============================ use strict; use Net::POP3;
7
9528
by: Stingray | last post by:
Are there any know problems with using a MemoryStream as a backing store for a CryptoStream? I'm trying to simply encrypt and decrypt text in memory. I'd like to create some simple methods to encrypt text before writing to a database and decrypt it when reading it back. I figured I'd use a MemoryStream that I can either store as a blob or...
5
4968
by: Kelli | last post by:
Hi there, I'm wondering if someone can have a quick look at my code and see if there's anything that I've done wrong. This silly script is driving me crazy! <% DIM File, Upload, Count, Ext DIM Mail, strMsgHeader
27
15000
by: gRizwan | last post by:
Hello all, We have a problem on a webpage. That page is sent some email data in base64 format. what we need to do is, decode the base64 data back to original shape and extract attached image from it. Any help will be highly appriciated. Thanks
9
1844
by: Russell Stevens | last post by:
I generate pdf files on my server and allow users to access them via a browser and also email them. Most files work fine whether the user uses his browser or gets an email with a pdf attachment which he can then open with Acrobat. All my pdf files work fine via a browser, but some are corrupted by one byte when sent as an email attachment....
0
2501
by: mubx2000 | last post by:
Hi , I'm looking for code (Symbian C++) that can do the following things: 1-Analyzing the (MIME) types (Content-typemContent-transfere-encoding,Mime Version,Conent Description). 2-Download attached files from the (MMS/Email). 3-Uploading to email or (MMS) . 4-Dealing with Multi-Part Messages. Here Is A Methods That Can HelP In...
1
2415
by: William Connery | last post by:
Hi, I have a small python program with e-mail capabilities that I have pieced together from code snippets found on the internet. The program uses the smtplib module to successfully send an e-mail with an attachment. I want to give users an indication of the percentage of the e-mail that has already been sent so as to avoid frustration...
3
6896
by: olafmol | last post by:
Hello, i want to write a PHP4 script that reads POP3 or IMAP mail and can decode the possible attachments in the email. I've looked around for some classes to do this, and found a few, but most of them seem to be very lowlevel or lacking in functionality. Is there a good script, class or example for decoding email attachments? I have used...
0
1331
by: shilpab | last post by:
My query is regarding the decoding classes available in Exchange 2007. I am working on a problem where I want to decode a TNEF encoded MIME message. I am using the class Base64Decode in Microsoft.Exchange.data.Mime namespace and I am also able to decode the message if it doesn't contain an attachment . But , for a TNEF encoded message without...
0
7490
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7935
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7449
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7780
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6009
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5069
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3479
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3465
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.