Parsing Email 'References' header.
J. Cliff Dyer
jcd at sdf.lonestar.org
Thu May 8 09:46:51 EDT 2008
On Thu, 2008-05-08 at 14:53 +0200, Aspersieman wrote:
> Hi
>
> I have a python script that parses email headers to extract information
> from them. I need to get the _last_ messageid in the 'References' field
> (http://cr.yp.to/immhf/thread.html) to create a threaded view of these
> emails (these messageid's are stored in a database).
>
> Now, I can easily access the 'References' field using the python 'email'
> module, but I need a regular expression to get the last messageid in the
> 'References' field.
>
> Here's what I have so far:
> <code>
> rx_lastmesgid = re.compile(r"(<.+>$)")
> lastmesgid = "".join( filter( rx_lastmesgid.match, parentid ) ) #
> parentid's value is
> eg:"<1 at mail.gmail.com><2 at mail.gmail.com><3 at mail.gmail.com><4 at mail.gmail.com><5 at mail.gmail.com>"
> lastmesgid = "".join( filter( rx_lastmesgid.match, parentid ) )
> </code>
>
> I need it to return "<5 at mail.gmail.com>"
>
> Can anyone help?
>
> Thanks
>
> Nicol
>
Forget regular expressions.
py>>> lastmesgid = '<' + parentid.split('<')[-1]
More information about the Python-list
mailing list