From e37b96432b89521871e947f322545f154547dd1b Mon Sep 17 00:00:00 2001 From: Andrew G Cohen Date: Tue, 27 Jun 2023 21:11:35 +0800 Subject: [PATCH] Fix parsing of mail address headers (bug#64296) RFC5322 specifies that an address header may be a list of both individual mailboxes and mailbox groups. This patch introduces support for parsing headers that include groups. * lisp/mail/ietf-drums.el (ietf-drums-parse-addresses): Allow message address headers to include both mailboxes and groups. --- lisp/mail/ietf-drums.el | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/lisp/mail/ietf-drums.el b/lisp/mail/ietf-drums.el index f60a3a3da28..aa714292bcc 100644 --- a/lisp/mail/ietf-drums.el +++ b/lisp/mail/ietf-drums.el @@ -272,6 +272,21 @@ a list of address strings." (while (not (eobp)) (setq c (char-after)) (cond + ((eq c ?:) + (setq beg (1+ (point))) + (skip-chars-forward "^;") + (when-let ((address + (condition-case nil + (ietf-drums-parse-addresses + (buffer-substring beg (point)) rawp) + (error nil)))) + (if (listp address) + (setq pairs (append address pairs)) + (push address pairs))) + (condition-case nil + (forward-char 1) + (error nil)) + (setq beg (point))) ((memq c '(?\" ?< ?\()) (condition-case nil (forward-sexp 1) @@ -285,10 +300,12 @@ a list of address strings." (ietf-drums-parse-address (buffer-substring beg (point))) (error nil)))) - (if address (push address pairs)) + (when (or (consp address) + (and (stringp address) (< 0 (length address)))) + (push address pairs)) (forward-char 1) (setq beg (point))) - (t + ((not (eobp)) (forward-char 1)))) (setq address (if rawp @@ -297,7 +314,9 @@ a list of address strings." (ietf-drums-parse-address (buffer-substring beg (point))) (error nil)))) - (if address (push address pairs)) + (when (or (consp address) + (and (stringp address) (< 0 (length address)))) + (push address pairs)) (nreverse pairs))))) (defun ietf-drums-unfold-fws () -- 2.39.2