RFC header to plain address(es)
This has got to be one of the most stupid questions I've ever asked online ...
I have a need of a "helper function" that takes a string someone would "want to send an e-mail to", i.e., something like an RFC 5322 "address" token, as used in a "To:" header, and extract just the actual e-mail address(es) from it. (The capability to deal with lists of *several* recipients is likely optional.)
I found a certain number of *libraries* for various programming languages that offer such a functionality¹, but I would prefer an executable from some run-of-the-mill Linux/UNIX package to be called by shell command. Considering that pretty much every MTA and MUA must contain such functionality (to construct an SMTP envelope for a mail to be sent), and then some (I looked into, e.g., procmail), I'm surprised that apparently none of them *expose* it. (I seem to remember that the original "sendmail -bt" came somewhat close at least ...)
Does anyone have an idea what tool I could (ab)use for that purpose?
¹ Namely: -- parseaddr() for python https://documentation.help/Python-PEP/module-email.Utils.html -- maildrop for C https://www.courier-mta.org/maildrop/rfc822.html -- mail_parser for Rust https://docs.rs/mail-parser/latest/mail_parser/ -- address-rfc2822 for JavaScript https://www.npmjs.com/package/address-rfc2822 -- mailparse-rfc822-parse-addresses for PHP https://www.php.net/manual/en/function.mailparse-rfc822-parse-addresses.php -- mail-header-parse-address for LISP https://www.gnu.org/software/emacs/manual/html_node/emacs-mime/Interface-Fun... -- and I suppose you could try to stuff the syntax definition into some parser code generator, too https://www.rfc-editor.org/rfc/rfc5322#section-3.4
Thanks in advance,
Jochen Bern Systemingenieur
Binect GmbH
- Jochen Bern via dovecot:
I have a need of a "helper function" that takes a string someone would "want to send an e-mail to", i.e., something like an RFC 5322 "address" token, as used in a "To:" header, and extract just the actual e-mail address(es) from it.
Just to be sure: Do you mean extracting the "addr-spec" part as per https://datatracker.ietf.org/doc/html/rfc5322#section-3.4 from a string?
I found a certain number of *libraries* for various programming languages that offer such a functionality¹, but I would prefer an executable from some run-of-the-mill Linux/UNIX package to be called by shell command.
Anything capable of handling regular expressions immediately comes to mind, like "sed" or "awk". Minimal Perl or Python snippets will also do, but that's overkill if I understand your requirements correctly.
-Ralph
participants (2)
-
Jochen Bern
-
Ralph Seichter