]> git.eshelyaron.com Git - emacs.git/commitdiff
Split textsec-email-address-suspicious-p into two functions
authorLars Ingebrigtsen <larsi@gnus.org>
Wed, 19 Jan 2022 14:21:43 +0000 (15:21 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Wed, 19 Jan 2022 14:21:50 +0000 (15:21 +0100)
* 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
test/lisp/international/textsec-tests.el

index ab1a742e4648d13b117531eb15b0085e99883227..d861685f0b1322eee219e2a8cc30e93410222a96 100644 (file)
@@ -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)
 
index 817264ec5f91fa33037f788454699648be6828f5..b68bce1dc70f9d7e3e6eb9dcb8f5ca507700e9bb 100644 (file)
   (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