On 2025-01-04 19:07:57 +0000, Chris Green via Python-list wrote:
> Stefan Ram <r...@zedat.fu-berlin.de> wrote:
> > Chris Green <c...@isbd.net> wrote or quoted:
> > >From: =?utf-8?B?U8OpYmFzdGllbiBDcmlnbm9u?= <sebastien.crig...@amvs.fr>
> > 
> Is there a simple[r] way to extract just the 'real' address between
> the <>, that's all I actually need.  I think it has the be the last
> chunk of the From: doesn't it?

No,
    From: <sebastien.crig...@amvs.fr> (Sébastien Crignon)
would also be permissible (properly encoded, of course), and even
    From: < sebastien (Sébastien) . crignon (Crignon) @ amvs . fr >
(although I think the latter is deprecated).

And also, there can be more than one address in a From header.

To properly extract email addresses from a header, use
email.utils.getaddresses(). You don't have to decode the header first.
The MIME-encoding is supposed to not interfere with parsing headers for
machine-readable information like addresses or message ids.

        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | h...@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Attachment: signature.asc
Description: PGP signature

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to