473,796 Members | 2,632 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Extracting TIFF from emails

Hi, I'm new to Python, so this may be an easy solution. I'm having
trouble extracting TIFF files from incoming emails. Actually, I think
the root of my problem is that I'm having trouble reading the email
header. Does anyone have an easy solution? Thanks in advance.
Jul 18 '05 #1
7 1859
ry**@ryanswift. com (Ryan Swift) writes:
Hi, I'm new to Python, so this may be an easy solution. I'm having
trouble extracting TIFF files from incoming emails. Actually, I think
the root of my problem is that I'm having trouble reading the email
header. Does anyone have an easy solution? Thanks in advance.


You've found the email module, right (you probably want to use Python
2.3)?

What is the specific problem you're having?
John
Jul 18 '05 #2
On 3 Sep 2003 07:04:17 -0700, rumours say that ry**@ryanswift. com (Ryan
Swift) might have written:
Hi, I'm new to Python, so this may be an easy solution. I'm having
trouble extracting TIFF files from incoming emails. Actually, I think
the root of my problem is that I'm having trouble reading the email
header. Does anyone have an easy solution? Thanks in advance.


Check the email package. Read about the following:

* email.message_f rom_file
(Assuming you have your incoming mail in a text file)
* class email.Message, its walk method

For each part in the .walk() call, check the .get_content_ty pe() result,
and if it's an 'image/tiff', you have the image data calling
..get_payload(d ecode=True)

Roughly :)
--
TZOTZIOY, I speak England very best,
Microsoft Security Alert: the Matrix began as open source.
Jul 18 '05 #3
I have found the email module, I am using 2.2.2.

This is my code:

if __name__ == "__main__":
server = connect(mailser ver, mailuser, mailpasswd)
try:
(msgCount, msgBytes) = server.stat()
print '\nThere are', msgCount, 'mail messages, total',
msgBytes, 'bytes'
print 'Retrieving message', msgCount, '\n'
(hdr, message, octets) = server.retr(msg Count)
print 'Header:', hdr
print 'Octets:', octets
print 'Message:', message

email_file = open('email.txt ', 'w')
email_file.writ elines(message)
email_file.clos e()

for part in message.walk():
if part.get_conten t_maintype() == 'multipart':
continue
filename = part.get_filena me()
fp = open(os.path.jo in(dir, filename), 'wb')
fp.write(part.g et_payload(deco de=1))
fp.close()
finally:
server.quit()
print 'Closed connection

I can print message and see it with no problems. It also gets written
to 'email.txt' with no problems. It is a simple multi-part MIME email
with TIF attachment. However, I get this error when I try to walk
through it:

Traceback (most recent call last):
File "C:\Python22\li b\site-packages\Python win\pywin\frame work\scriptutil s.py",
line 305, in RunScript
debugger.run(co deObject, __main__.__dict __, start_stepping= 1)
File "C:\Python22\li b\site-packages\Python win\pywin\debug ger\__init__.py ",
line 60, in run
_GetCurrentDebu gger().run(cmd, globals,locals, start_stepping)
File "C:\Python22\li b\site-packages\Python win\pywin\debug ger\debugger.py ",
line 591, in run
exec cmd in globals, locals
File "C:\Python22\ma iltest.py", line 29, in ?
for part in message.walk():
AttributeError: 'list' object has no attribute 'walk'

Am I not properly using walk?

Thanks again.
Jul 18 '05 #4
ry**@ryanswift. com (Ryan Swift) writes:
I have found the email module,
I'm not 100% sure you have. My 'the email module' I meant 'the module
named "email" from the Python standard library'.
I am using 2.2.2.

This is my code:
No it's not -- where are the imports? This isn't C, we don't like to
guess these things :-)

[...] AttributeError: 'list' object has no attribute 'walk'

Am I not properly using walk?


lists have no walk method!

Presumably you thought you had something other than a list, but you don't.
John
Jul 18 '05 #5
Apparently I am getting the email as a list, but I don't know of a way
to do it otherwise. I have read through the docs on www.python.org
for the email module, but there is not much on reading mail, rather it
focuses more on creating it. Below is my *complete* code (I am fairly
sure I am importing more than I need to), is there a way to get a
message from the server in a form other than a list? I assume this
can be done with the email module but I must be too dim to find it.
Can you provide a link to information about the standard library email
module? Once again, thanks.

import poplib, os, mailconfig, email, mimetools

mailserver = mailconfig.pops ervername
mailuser = mailconfig.popu sername
mailpasswd = mailconfig.popp assword
dir = os.curdir

def connect(mailser ver, mailuser, mailpasswd):
print '\nConnecting.. .'
server = poplib.POP3(mai lserver)
server.user(mai luser)
server.pass_(ma ilpasswd)
return server
if __name__ == "__main__":
server = connect(mailser ver, mailuser, mailpasswd)
try:
(msgCount, msgBytes) = server.stat()
print '\nThere are', msgCount, 'mail messages, total',
msgBytes, 'bytes'
print 'Retrieving message', msgCount, '\n'
(hdr, msg, octets) = server.retr(msg Count)
email_file = open('email.txt ', 'w')
email_file.writ e(message)
email_file.clos e()
finally:
server.quit()
print 'Closed connection.'

fp = open('email.txt ')
filemsg = email.message_f rom_file(fp)
fp.close()

for part in filemsg.walk:
print part.get_conten t_type()
Jul 18 '05 #6
ry**@ryanswift. com (Ryan Swift) writes:
[...]
sure I am importing more than I need to), is there a way to get a
message from the server in a form other than a list? I assume this
can be done with the email module but I must be too dim to find it.
If you're getting a list, you've probably accidentally clobbered the
name that you bound to the message object.

Can you provide a link to information about the standard library email
module? Once again, thanks.
No, but http://www.python.org/ certainly can.

[...] for part in filemsg.walk:


You're missing a function call here: you want filemsg.walk(), with the
brackets.
John
Jul 18 '05 #7
On 4 Sep 2003 08:15:28 -0700, rumours say that ry**@ryanswift. com (Ryan
Swift) might have written:
Apparently I am getting the email as a list, but I don't know of a way
to do it otherwise.


I assume you didn't see my reply since yesterday?

I don't know the mailconfig module; does it return a list of strings
that end with '\n'? If yes, use

message = email.message_f rom_string(''.j oin(your_list_o f_strings))

If not, substitute '\n' for '' in the line above.
--
TZOTZIOY, I speak England very best,
Microsoft Security Alert: the Matrix began as open source.
Jul 18 '05 #8

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

Similar topics

2
1502
by: bozdog | last post by:
I have recently imported several fields from a spreadsheet(excel) and wish to update a field using an update query. The particular field is imported as a text string and defines a path for a particular graphic file. Each field is unique and there are approximately 4000 records.A typical string I wsh to edit is as follows D:\diagrams\abc_123.tiff . (one of 4000) D:\diagrams\abc_1234.tiff etc to
0
1674
by: Curtis Justus | last post by:
Hi, I am reading in a multipage TIFF image and need to manipulate each page separately. After reading the image into an Image object, I set the page by using the SelectActiveFrame method. Then, I am converting it to an individual Bitmap/Image. Here is a sample: ---------------------- FrameDimension fd = _image.SetActiveFrame(fd, 0); Bitmap bmp = new Bitmap(_image);
0
2013
by: Will Arrowsmith | last post by:
Hi All, I am trying to create a .tiff file to fax using the windows fax service FAXCOMLib. I have created an array of images (bitmaps) and converted them to 1pbb format in order to allow CCITT3/4 compression for faxing. The .Tiff file appears to be created successfully however when I try to send the file as a fax I get the error: System.Runtime.InteropServices.COMException (0x8007000D): The data is
0
1699
by: Will Arrowsmith | last post by:
Hi All, I am aiming to create a multiframe Tiff file that I can fax using the windows fax service FAXCOMLib. I have created an array of Bitmaps (pages I want in my fax doc) and succesfully converted them all to be 1bppIndexed. I then combine all bitmaps into a single multiframed Tiff file (with CCITT3 compression) before attempting to fax the file. When I call the send method of the fax routine I get the error:
5
6001
by: Shane Story | last post by:
I can seem to get the dimensions of a frame in a multiframe tiff. After selecting activeframe, the Width/Height is still really much larger than the page's actual dimensions. When I split a TIFF to several PNG files this causes a problem, becuase the resulting image is (the page to the far left and a lot of black space surrounding it and a filesize that is larger than needed. Any ideas?
6
10035
by: qysbc | last post by:
I have a web page and there is a link to open a TIFF file. The way I do it is to have the server code open a binary stream, set the content type to "image/tiff" and call Response.BinaryWrite. On the client machine, the file type TIFF is associated with Kodak Imaging Preview. This app works on most client machines. When you click on the link, Kodak Imaging Preview will open the TIFF file on the client machine. However, on some machines, the...
2
5665
by: Dave G | last post by:
I'm writing a function to look for particular emails in my Inbox and when it finds one it copies the attachment to a folder and then deletes the email. It spots the email by looking for certain text in the subject line. Here's a code fragment: Dim appOutlook As Outlook.Application Dim mpiFolder As MAPIFolder Dim msgMail As MailItem Dim strAQSPath As String Dim strSubject As String
1
3002
by: amit gupta | last post by:
Hello, I am using QuarkXPress on Macintosh to generate EPS Files with Tiff Preview embedded in it. I have written some C code to extract Tiff Preview from EPS files generated which works pretty well. I want do some image manipulation on the extracted tiff images, for which I intend to use LibTiff on Macintosh. The problem right now I am facing is that LibTiff api TIFFOpen returns
7
3794
by: Ben | last post by:
Hi We are looking for a component that offers that offers the below for Tiff files: Image clean-up (deskew, despeckle) Printing capabilities from VB The ability to add text to image, e.g. time / date Nice to have:
0
9685
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10190
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9057
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7555
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6796
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4122
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.