Subject: bug#51733: 27.1; Detect impossible email addresses better

From: Robert Pluim <[email-masked]>
Date: Wed, 19 Jan 2022 13:49:20 +0100

>>>>> On Wed, 19 Jan 2022 13:53:59 +0200, Eli Zaretskii <[email-masked]> said:

    Eli> Here:

    Eli>   (textsec-email-suspicious-p "אבגד <[email-masked]>")
    Eli>     => (wrong-type-argument stringp nil)

    Eli> with this backtrace:

    Eli>   Debugger entered--Lisp error: (wrong-type-argument stringp nil)
    Eli>     string-search("=?" nil)
    Eli>     rfc2047-decode-string(nil)
    Eli>     mail-header-parse-address("אבגד <[email-masked]>" t)
    Eli>     textsec-email-suspicious-p("אבגד <[email-masked]>")
    Eli>     (progn (textsec-email-suspicious-p "אבגד <[email-masked]>"))
    Eli>     eval((progn (textsec-email-suspicious-p "אבגד <[email-masked]>")) t)
    Eli>     elisp--eval-last-sexp(t)
    Eli>     eval-last-sexp(t)
    Eli>     eval-print-last-sexp(nil)
    Eli>     funcall-interactively(eval-print-last-sexp nil)
    Eli>     call-interactively(eval-print-last-sexp nil nil)
    Eli>     command-execute(eval-print-last-sexp)

mail-header-parse-address assumes that the display name or the local
name starts with a (subset of) ASCII. The following doesnʼt signal an
error:

(textsec-email-suspicious-p "דגבאa <[email-masked]>")

Since itʼs now open season on display names and mailbox names, the
following might be enough. Lars?

diff --git a/lisp/mail/ietf-drums.el b/lisp/mail/ietf-drums.el
index 4a07959189..1885f958ba 100644
--- a/lisp/mail/ietf-drums.el
+++ b/lisp/mail/ietf-drums.el
@@ -217,7 +217,7 @@ ietf-drums-parse-address
 	  (push (buffer-substring
 		 (1+ (point)) (progn (forward-sexp 1) (1- (point))))
 		display-name))
-	 ((looking-at (concat "[" ietf-drums-atext-token "@" "]"))
+	 ((not (eq c ?<))
 	  (push (buffer-substring (point) (progn (forward-sexp 1) (point)))
 		display-name))
 	 ((eq c ?<)
@@ -240,7 +240,7 @@ ietf-drums-parse-address
 	    (cons
 	     (mapconcat #'identity (nreverse display-name) "")
 	     (ietf-drums-get-comment string)))
-	(cons mailbox (if decode
+	(cons mailbox (if (and decode display-string)
                           (rfc2047-decode-string display-string)
                         display-string))))))

Robert
--