all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* functions for parsing mail addresses
@ 2023-10-25  2:32 Roland Winkler
  2023-10-25  2:42 ` Emanuel Berg
  0 siblings, 1 reply; 2+ messages in thread
From: Roland Winkler @ 2023-10-25  2:32 UTC (permalink / raw)
  To: help-gnu-emacs; +Cc: Sam Steingold

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.



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: functions for parsing mail addresses
  2023-10-25  2:32 functions for parsing mail addresses Roland Winkler
@ 2023-10-25  2:42 ` Emanuel Berg
  0 siblings, 0 replies; 2+ messages in thread
From: Emanuel Berg @ 2023-10-25  2:42 UTC (permalink / raw)
  To: help-gnu-emacs

Roland Winkler wrote:

> 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.

I have something like that:

(defun citation-style-f ()
  (let*((from (mail-header-from message-reply-headers))
        (from-data (gnus-extract-address-components from))
        (name (or (car from-data)
                  ;; if the user hasn't set his name, use the
                  ;; mail username e.g. joe for joe@hacker.com
                  (car (split-string (cadr from-data) "@"))))
        (citation-string (format "%s wrote:\n\n" name)) )
    (insert citation-string) ))

Whole file:
  https://dataswamp.org/~incal/emacs-init/gnus/gnus-cite-incal.el

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-10-25  2:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-25  2:32 functions for parsing mail addresses Roland Winkler
2023-10-25  2:42 ` Emanuel Berg

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.