emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 124c4ad1e5: Split textsec-email-address-suspicious-p into two fun


From: Lars Ingebrigtsen
Subject: master 124c4ad1e5: Split textsec-email-address-suspicious-p into two functions
Date: Wed, 19 Jan 2022 09:21:58 -0500 (EST)

branch: master
commit 124c4ad1e5dbccb0789e96aff1c7f77957119201
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    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 ab1a742e46..d861685f0b 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 817264ec5f..b68bce1dc7 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 <larsi@gn\N{LEFT-TO-RIGHT 
ISOLATE}us.org>")))
+   (textsec-email-suspicious-p "Lars Ingebrigtsen <larsi@gn\N{LEFT-TO-RIGHT 
ISOLATE}us.org>"))
+
+  (should (textsec-email-suspicious-p "דגבא <foo@bar.com>")))
 
 ;;; textsec-tests.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]