473,728 Members | 2,114 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 1856
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
1500
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
1663
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
2012
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
1697
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
5992
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
10034
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
5663
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
2999
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
3789
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
8759
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9425
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9278
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9199
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
9138
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8136
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
6718
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
4524
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4794
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.