unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Roland Winkler <winkler@gnu.org>
To: help-gnu-emacs@gnu.org
Cc: Sam Steingold <sds@gnu.org>
Subject: functions for parsing mail addresses
Date: Tue, 24 Oct 2023 21:32:25 -0500	[thread overview]
Message-ID: <87sf5z1lfq.fsf@gnu.org> (raw)

I am looking at functions in the Emacs code base for parsing mail
addresses, trying to figure out their differences.  But this appears to
be somewhat messy.

The docstring of the user variable `gnus-extract-address-components' says
that two pre-defined function exist: ‘gnus-extract-address-components’,
which is the default, quite fast, and too simplistic solution, and
‘mail-extract-address-components’, which works much better, but is
slower.  But it seems to me that calls of the function
`gnus-extract-address-components' are as often hard-coded as the user
variable `gnus-extract-address-components' is used.

Well, `mail-extract-address-components' uses strange heuristics.  And
the docstring of `mail-extract-address-components' says that often
‘mail-header-parse-address’ may be better.  But there is also the less
strict version ‘mail-header-parse-address-lax’.

What's the difference between the functions
‘gnus-extract-address-components’ and ‘mail-header-parse-address-lax’?
Do these two functions supposedly do the same thing?  That's what their
code suggests to me.

One important difference between ‘mail-header-parse-address’ and
functions like ‘mail-header-parse-address-lax’ seems to be that
‘mail-header-parse-address’ expects undecoded addresses.  But for the
example of an already-decoded address given in the docstring of
‘mail-header-parse-address’, this function works just fine.

Also, for multiple addresses, ‘mail-header-parse-addresses-lax’ first
calls

  (ignore-errors (mail-header-parse-address elem))

before calling  ‘mail-header-parse-address-lax’.

But unless I am misreading the code of ‘mail-header-parse-address’, this
function does not throw errors that are not caught by a condition-case.
So is there a real-world example when ‘mail-header-parse-address’ fails
for an already-decoded address?

It seems to me that all this could benefit from some cleaning up.

I looked into this because Sam Steingold (CC'ed) suggested that BBDB
should use ‘mail-header-parse-address’ instead of
`mail-extract-address-components'.

A solution for BBDB should preferably also be backward-compatible.  It
seems that ‘mail-header-parse-address-lax’ and
‘mail-header-parse-addresses-lax’ were only introduced in Emacs 28.



             reply	other threads:[~2023-10-25  2:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-25  2:32 Roland Winkler [this message]
2023-10-25  2:42 ` functions for parsing mail addresses Emanuel Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sf5z1lfq.fsf@gnu.org \
    --to=winkler@gnu.org \
    --cc=help-gnu-emacs@gnu.org \
    --cc=sds@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).