| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 
 | ;;; textsec-check.el --- Check for suspicious texts  -*- lexical-binding: t; -*-
;; Copyright (C) 2022-2025 Free Software Foundation, Inc.
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; Code:
(defgroup textsec nil
  "Suspicious text identification."
  :group 'security
  :version "29.1")
(defcustom textsec-check t
  "If non-nil, perform some security-related checks on text objects.
If nil, these checks are disabled."
  :type 'boolean
  :version "29.1")
(defface textsec-suspicious
  '((t (:weight bold :background "red" :foreground "white")))
  "Face used to highlight suspicious strings.")
;;;###autoload
(defun textsec-suspicious-p (object type)
  "Say whether OBJECT is suspicious for use as TYPE.
If OBJECT is suspicious, return a string explaining the reason
for considering it suspicious, otherwise return nil.
Available values of TYPE and corresponding OBJECTs are:
 `url'                   -- a URL; OBJECT should be a URL string.
 `link'                 -- an HTML link; OBJECT should be a cons cell
                           of the form (URL . LINK-TEXT).
 `domain'               -- a Web domain; OBJECT should be a string.
 `local-address'        -- the local part of an email address; OBJECT
                           should be a string.
 `name'                 -- the \"display name\" part of an email address;
                           OBJECT should be a string.
`email-address'         -- a full email address; OBJECT should be a string.
 `email-address-header' -- a raw email address header in RFC 2822 format;
                           OBJECT should be a string.
If the user option `textsec-check' is nil, these checks are
disabled, and this function always returns nil."
  (if (not textsec-check)
      nil
    (require 'textsec)
    (let ((func (intern (format "textsec-%s-suspicious-p" type))))
      (unless (fboundp func)
        (error "%s is not a valid function" func))
      (funcall func object))))
(provide 'textsec-check)
;;; textsec-check.el ends here
 |