Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old August 21st, 2003, 03:18 PM
Swifty Swifty is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 5 Swifty User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to Swifty
Question Multipart email returning 0 for "is_multipart()"

I'm trying to parse a multi-part email but regardless of what I try, I cannot get my code to recognize any emails as multipart MIME messages.

The code is basically:
Code:
fp = open('C:\Python22\email.txt')
msg = email.message_from_file(fp)
fp.close()

for part in msg.walk():
    if part.is_multipart():
        print part.is_multipart()
    else:
        print part.is_multipart()


As a result I cannot seem to do anything to extract the attached .tif file, or even strip off the headers using either the rfc822 or email modules.

I'd love any help, I'm getting desparate.

The email I tried last is simple text email with a .tif attachment:
Quote:
Received: by usamcms4.mc.usa.xerox.com id <01C3681F.57295FB0@usamcms4.mc.usa.xerox.com>; Thu, 21 Aug 2003 16:03:51 -0400Message-ID: <052106A55179D611B34300096BB02E3FCB30CE@usamcms4.mc.usa.xerox.com>From: "Swift, Ryan" <Ryan.Swift@usa.xerox.com>To: "Swift, Ryan" <Ryan.Swift@usa.xerox.com>Subject: Attach this!Date: Thu, 21 Aug 2003 16:03:49 -0400MIME-Version: 1.0Content-Type: multipart/mixed; boundary="----_=_NextPart_000_01C3681F.1A9B6F98"This message is in MIME format. Since your mail reader does not understandthis format, some or all of this message may not be legible.------_=_NextPart_000_01C3681F.1A9B6F98Content-Type: text/plain; charset="iso-8859-1"Test test 1 2 3-------------------------------------------------------------Ryan SwiftImage Science Engineering & Technologyryan.swift@usa.xerox.com(585) 442-6392MS 111-30N-------------------------------------------------------------- <<tifemail.tif>> ------_=_NextPart_000_01C3681F.1A9B6F98Content-Type: application/octet-stream; name="tifemail.tif"Content-Transfer-Encoding: base64Content-Disposition: attachment; filename="tifemail.tif"SUkqAAgAAAAQAP4ABAABAAAAAAAAAAABAwABAAAACgAAAAEBAwABAAAACgAAAAIBAwABAAAACAAAAAMBAwABAAAAAQAAAAYBAwAB AAAAAQAAAA4BAgAPAAAAzgAAABEBBAABAAAAjgUAABUBAwABAAAAAQAAABYBAwABAAAACgAAABcBBAABAAAAZAAAABoBBQABAAAA 3gAAABsBBQABAAAA5gAAACgBAwABAAAAAgAAALuDBAAHAAAA7gAAAEmGAQCEBAAACgEAAAAAAABEb2N1SW1hZ2UgNjIwcwAAAAk9 ABAnAAAACT0AECcAABwCAAACAAIcAngADkRvY3VJbWFnZSA2MjBzAAA4QklNBAQAAAAAABocAgAAAgACHAJ4AA5Eb2N1SW1hZ2Ug NjIwczhCSU0D7QAAAAAAEAGQAAAAAQABAZAAAAABAAE4QklNBA0AAAAAAAQAAAAeOEJJTQQZAAAAAAAEAAAAHjhCSU0D8wAAAAAA CQAAAAAAAAAAAQA4QklNBAoAAAAAAAEAADhCSU0nEAAAAAAACgABAAAAAAAAAAI4QklNA/QAAAAAABIANQAAAAEALQAAAAYAAAAAAAE4QklNA/cAAAAAABwAAP////////////////////////////8D6AAAOEJJTQQIAAAAAAAQAAAAAQAAAkAAAAJAAAAAADhCSU0EHgAAAAAABAAAAAA4QklNBBoAAAAAAHEAAAAGAAAAAAAAAAAAAA AKAAAACgAAAAgAdABpAGYAZQBtAGEAaQBsAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAKAAAACgAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4QklNBBEAAAA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2Xn5WdqqRrlK2ebpW3r36OoJ56oautjp2KlqGgiZ+jqoaWrqt3lbGvfpeonw==------_=_NextPart_000_01C3681F.1A9B6F98--


To my eyes it's clearly a multi-part MIME message with a .tif attachment, what am I missing?

Reply With Quote
  #2  
Old August 21st, 2003, 07:00 PM
sissy sissy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 29 sissy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m 25 sec
Reputation Power: 0
try this

part.get_maintype() == 'multipart'

-----------
m.get_maintype(default=None)


Returns m's main content type, a string 'maintype' taken from header Content-Type converted to lowercase. When m has no header Content-Type, get_maintype returns default.
-----------

Reply With Quote
  #3  
Old August 21st, 2003, 07:15 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
I'm just looking at your code and i have to say I'm a little unsure of what your doing with the if statment, even if multipart is false you still go and print the same data as if it were true, do yourself a favour and just print part.is_multipart()

Code:
fp = open('C:\Python22\email.txt')
msg = email.message_from_file(fp)
fp.close()

for part in msg.walk():
    print part.is_multipart()


You'll get the same result and use less code. less code == less for python to do == better preformance (in theory)

Mark.

Last edited by netytan : August 21st, 2003 at 07:28 PM.

Reply With Quote
  #4  
Old August 22nd, 2003, 06:55 AM
Swifty Swifty is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 5 Swifty User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to Swifty
Quote:
Originally posted by netytan
I'm just looking at your code and i have to say I'm a little unsure of what your doing with the if statment, even if multipart is false you still go and print the same data as if it were true, do yourself a favour and just print part.is_multipart()

Code:
fp = open('C:\Python22\email.txt')
msg = email.message_from_file(fp)
fp.close()

for part in msg.walk():
    print part.is_multipart()


You'll get the same result and use less code. less code == less for python to do == better preformance (in theory)

Mark.


Actually, I had some other stuff in the if/else statements that I removed for clarity's sake when posting. Otherwise I'd agree.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Multipart email returning 0 for "is_multipart()"


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway