Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > email library

Reply
Thread Tools

email library

 
 
peterob
Guest
Posts: n/a
 
      03-15-2011
Hi,

Im completely confused from email library. When you parse email from
file it creates object Message.

f = open(emailFile, 'r')
msg = email.message_from_file(f)
f.close()


How can I access RAW header of email represented by object msg? I dont
wanna access each header field by hand.

Im doing another parsing, searching for attachments and so on, with
email, but i need write raw data of email too. Do I have to allocate
another memory for that emailFile? (by mmap or f=open(rawemail).



Thanks


Best,
Peter






 
Reply With Quote
 
 
 
 
Ethan Furman
Guest
Posts: n/a
 
      03-18-2011
peterob wrote:
> Im completely confinvalided from email library. When you parse email from
> file it creates object Message.
>
> f = open(emailFile, 'r')
> msg = email.message_from_file(f)
> f.close()
>
>
> How can I access RAW header of email represented by object msg? I dont
> wanna access each header field by hand.
>
> Im doing another parsing, searching for attachments and so on, with
> email, but i need write raw data of email too. Do I have to allocate
> another memory for that emailFile? (by mmap or f=open(rawemail).


For the ultimate in raw, open the email file and parse it manually.

Your other option is use msg.walk() and msg.items() and walk through the
returned (header, value) pairs.

8<-----------------------------
--> import email
--> msg = email.message_from_file(open(r'c:\temp2\latest_dbf .eml'))
--> from pprint import pprint as pp
--> for sub in msg.walk():
.... pp(sub.items())
....
[('Return-path', '<(E-Mail Removed)>'),
('Envelope-to', '(E-Mail Removed)'),
('Delivery-date', 'Mon, 07 Mar 2011 18:32:18 -0600'),
('Received',
'from [72.11.125.166] (port=2728 helo=[192.168.10.136])\n\tby
gator410.hostgator.com with esmtpa (Exim 4.69)\n\t(envelope-from
<(E-Mail Removed)>)\n\tid
1PwkqN-0001eV-54\n\tfor http://www.velocityreviews.com/forums/(E-Mail Removed)d; Mon, 07 Mar 2011
18:32:16 -0600'),
('Message-ID', '<(E-Mail Removed)>'),
('Date', 'Mon, 07 Mar 2011 16:42:40 -0800'),
('From', 'First Last <(E-Mail Removed)>'),
('User-Agent', 'Thunderbird 1.5.0.10 (Windows/20070221)'),
('MIME-Version', '1.0'),
('To', 'First Last <(E-Mail Removed)>'),
('Subject', 'latest dbf'),
('Content-Type',
'multipart/mixed;\n boundary="------------010408020108000602070901"')]

[('Content-Type', 'text/plain; charset=ISO-8859-1; format=flowed'),
('Content-Transfer-Encoding', '7bit')]

[('Content-Type', 'text/plain;\n name="tables.py"'),
('Content-Transfer-Encoding', '7bit'),
('Content-Disposition', 'inline;\n filename="tables.py"')]

[('Content-Type', 'application/x-zip-compressed;\n name="dbf-0.88.18.zip"'),
('Content-Transfer-Encoding', 'base64'),
('Content-Disposition', 'inline;\n filename="dbf-0.88.18.zip"')]
8<-----------------------------

Hope this helps!

~Ethan~
 
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
Static library Vs. Dynamic library iceColdFire C++ 3 05-17-2005 06:16 AM
Dynamic Library or Static Library under Linux gouqizi.lvcha@gmail.com C++ 6 05-10-2005 03:16 PM
Re: Difference between Web Control Library and Class Library Alan Ferrandiz [MCT] ASP .Net 0 09-11-2004 01:51 PM
Re: Difference between Web Control Library and Class Library Mythran ASP .Net 0 08-24-2004 05:53 PM
Library in library... Sweep C++ 1 12-09-2003 04:12 AM



Advertisments