From 124c4ad1e5dbccb0789e96aff1c7f77957119201 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Wed, 19 Jan 2022 15:21:43 +0100 Subject: [PATCH] Split textsec-email-address-suspicious-p into two functions * lisp/international/textsec.el (textsec-email-address-suspicious-p): Made into its own function. (textsec-email-suspicious-p): Use it and adjust doc strings. --- lisp/international/textsec.el | 38 ++++++++++++++++++------ test/lisp/international/textsec-tests.el | 4 ++- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/lisp/international/textsec.el b/lisp/international/textsec.el index ab1a742e464..d861685f0b1 100644 --- a/lisp/international/textsec.el +++ b/lisp/international/textsec.el @@ -324,21 +324,41 @@ consecutive nonspacing characters." string) nil))) -(defun textsec-email-suspicious-p (email) +(defun textsec-email-address-suspicious-p (address) "Say whether EMAIL address looks suspicious. If it isn't, return nil. If it is, return a string explaining the potential problem. -An email address is considered suspicious if either of its 3 parts: -domain, local, or name -- are found to be suspicious by, respectively, -`textsec-domain-suspicious-p', `textsec-local-address-suspicious-p', -and `textsec-name-suspicious-p'." - (pcase-let* ((`(,address . ,name) (mail-header-parse-address email t)) - (`(,local ,domain) (split-string address "@"))) +An email address is considered suspicious if either of its two +parts -- the local address name or the domain -- are found to be +suspicious by, respectively, `textsec-local-address-suspicious-p' +and `textsec-domain-suspicious-p'." + (pcase-let ((`(,local ,domain) (split-string address "@"))) (or (textsec-domain-suspicious-p domain) - (textsec-local-address-suspicious-p local) - (and name (textsec-name-suspicious-p name))))) + (textsec-local-address-suspicious-p local)))) + +(defun textsec-email-suspicious-p (email) + "Say whether EMAIL looks suspicious. +If it isn't, return nil. If it is, return a string explaining the +potential problem. + +Note that EMAIL has to be a valid email specification according +to RFC2047bis -- strings that can't be parsed will be flagged as +suspicious. + +An email specification is considered suspicious if either of its +two parts -- the address or the name -- are found to be +suspicious by, respectively, `textsec-email-address-suspicious-p' +and `textsec-name-suspicious-p'." + (catch 'end + (pcase-let ((`(,address . ,name) + (condition-case nil + (mail-header-parse-address email t) + (error (throw 'end "Email address can't be parsed."))))) + (or + (textsec-email-address-suspicious-p address) + (and name (textsec-name-suspicious-p name)))))) (provide 'textsec) diff --git a/test/lisp/international/textsec-tests.el b/test/lisp/international/textsec-tests.el index 817264ec5f9..b68bce1dc70 100644 --- a/test/lisp/international/textsec-tests.el +++ b/test/lisp/international/textsec-tests.el @@ -152,6 +152,8 @@ (should (textsec-email-suspicious-p "Lars Ingebrigtsen <.larsi@gnus.org>")) (should - (textsec-email-suspicious-p "Lars Ingebrigtsen "))) + (textsec-email-suspicious-p "Lars Ingebrigtsen ")) + + (should (textsec-email-suspicious-p "דגבא "))) ;;; textsec-tests.el ends here -- 2.39.2