parsing emails
Riccardo Galli
riccardo_cut-me at cut.me.sideralis.net
Sat Mar 20 13:35:15 EST 2004
On Sat, 20 Mar 2004 00:29:40 -0800, Michele Simionato wrote:
> I use Mozilla or Netscape, so my emails are stored in the nsmail
> directory
> or the Mozilla's equivalent. What's the simplest way to look at them
> and
> extract the mails with a given subject? In principle I could use a
> regular expression, but I bet there are better solutions already
> available.
> Second question: are Mozilla and Netscape compatible, i.e. are the
> emails stored with the same format and can I use the same extraction
> method on both?
>
> TIA,
>
>
> Michele Simionato
Ciao Michele,
maybe you could use something like that
"""code not tested"""
import email
import mailbox
fp=file('fileName','r')
mbox = mailbox.UnixMailbox(fp, email.message_from_file)
msg_list=[]
for msg in mbox.next():
if msg['Subject']=="the subject you're searching for":
msg_list.append(msg)
fp.close()
for msg in msg_list:
print msg
Dunno about Mozilla/Netscape compatibility, but I think they'll use the
same mail format.
Ciao,
Riccardo
--
-=Riccardo Galli=-
_,e.
s~ ``
~@. ideralis Programs
. ol
`**~ http://www.sideralis.net
More information about the Python-list
mailing list