]> git.eshelyaron.com Git - emacs.git/commitdiff
Teach gnus/message about international Re: variants
authorRobert Pluim <rpluim@gmail.com>
Thu, 22 Aug 2024 16:49:12 +0000 (18:49 +0200)
committerEshel Yaron <me@eshelyaron.com>
Fri, 14 Feb 2025 11:43:13 +0000 (12:43 +0100)
* lisp/mail/mail-utils.el (mail-re-regexps): New defcustom,
contains the components used to construct 'rmail-re-abbrevs' and
'message-subject-re-regexp'.
* lisp/gnus/message.el (message-subject-re-regexp): Derive from
'mail-re-regexps'.
(message-strip-subject-re): Make the match case-insensitive.
* lisp/mail/rmail.el (rmail-re-abbrevs): Derive from
'mail-re-regexps'.  Update 'rmail-reply-regexp' when it changes.
(rmail-reply-regexp): Set to nil, 'rmail-re-abbrevs' will set
it.

* doc/emacs/rmail.texi (Rmail Reply): Describe
'mail-re-regexps'.
* doc/misc/message.texi (Message Headers): Describe
'mail-re-regexps'.

(Bug#72442)

(cherry picked from commit 315519fa7c8e5e142b6abca7b78a47ad3c0cbe37)

doc/emacs/rmail.texi
doc/misc/message.texi
lisp/gnus/message.el
lisp/mail/mail-utils.el
lisp/mail/rmail.el

index 402386684ae5c82559d7688a9cc83a2b64401b02..7a2ef9be16eb88997b06dd64911a77d124c21864 100644 (file)
@@ -776,6 +776,14 @@ to.  The @samp{To} field starts out as the address of the person who
 sent the message you received, and the @samp{CC} field starts out with
 all the other recipients of that message.
 
+@vindex rmail-re-abbrevs
+@vindex rmail-reply-prefix
+@vindex mail-re-regexps
+The @samp{Subject} header field may contain one or more instances of
+@samp{Re:} or localized variants thereof.  These are removed if they
+match @code{rmail-re-abbrevs} (which is initialized from
+@code{mail-re-regexps}), and @code{rmail-reply-prefix} is prepended.
+
 @vindex mail-dont-reply-to-names
   You can exclude certain recipients from being included automatically
 in replies, using the variable @code{mail-dont-reply-to-names}.  Its
index c6afbcd3731433cf09b7c9666ac42cb7a914a057..f84186233806f3d7288cdb6d77c6aeec9e74ca37 100644 (file)
@@ -1688,13 +1688,14 @@ result is inserted.
 
 @item message-subject-re-regexp
 @vindex message-subject-re-regexp
+@vindex mail-re-regexps
 @cindex Aw
 @cindex Sv
 @cindex Re
 Responses to messages have subjects that start with @samp{Re: }.  This
 is @emph{not} an abbreviation of the English word ``response'', but it
 comes from the Latin ``res'', and means ``in the matter of''.  Some
-illiterate nincompoops have failed to grasp this fact, and have
+standards-challenged companies have failed to grasp this fact, and have
 ``internationalized'' their software to use abominations like
 @samp{Aw: } (``antwort'') or @samp{Sv: } (``svar'') instead, which is
 meaningless and evil.  However, you may have to deal with users that
@@ -1726,6 +1727,16 @@ responding to a message:
        ))
 @end lisp
 
+You shouldn't need to do this, since the default value of
+@code{message-subject-re-regexp} is initialized based on
+@code{mail-re-regexps}, which covers most known cases of such
+internationalization, and is a lot easier to customize.  Customizing
+@code{mail-re-regexps} updates @code{message-subject-re-regexp} to
+match.
+
+Note that the regexp is matched case-insensitively against the
+@samp{Subject} header contents.
+
 @item message-subject-trailing-was-query
 @vindex message-subject-trailing-was-query
 @vindex message-subject-trailing-was-ask-regexp
index 411c9afd32396f2616ef514de7b11ca0e566fdde..d9537fca589ae3f5df41859c2e4c5e5bb55df59b 100644 (file)
@@ -312,11 +312,20 @@ any confusion."
                 regexp))
 
 (defcustom message-subject-re-regexp
-  "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)* ?:[ \t]*\\)*[ \t]*"
-  "Regexp matching \"Re: \" in the subject line."
+  (mail--wrap-re-regexp
+   (concat
+    "\\("
+    (string-join mail-re-regexps "\\|")
+    "\\)"))
+  "Regexp matching \"Re: \" in the subject line.
+Matching is done case-insensitively.
+Initialized from the value of `mail-re-regexps', which is easier to
+customize."
   :group 'message-various
   :link '(custom-manual "(message)Message Headers")
-  :type 'regexp)
+  :type 'regexp
+  :set-after '(mail-re-regexps)
+  :version "31.1")
 
 (defcustom message-screenshot-command '("import" "png:-")
   "Command to take a screenshot.
@@ -2254,10 +2263,12 @@ see `message-narrow-to-headers-or-head'."
       subject)))
 
 (defun message-strip-subject-re (subject)
-  "Remove \"Re:\" from subject lines in string SUBJECT."
-  (if (string-match message-subject-re-regexp subject)
-      (substring subject (match-end 0))
-    subject))
+  "Remove \"Re:\" from subject lines in string SUBJECT.
+This uses `mail-re-regexps', matching is done case-insensitively."
+  (let ((case-fold-search t))
+    (if (string-match message-subject-re-regexp subject)
+        (substring subject (match-end 0))
+      subject)))
 
 (defcustom message-replacement-char "."
   "Replacement character used instead of unprintable or not decodable chars."
index f8474da8f6d380b42a2b008c85beeb4978dbc4fd..5ddcb4b7686e8300549e5d718e3400ab8d81a2b9 100644 (file)
@@ -46,6 +46,37 @@ also the To field, unless this would leave an empty To field."
   :type '(choice regexp (const :tag "Your Name" nil))
   :group 'mail)
 
+(defun mail--wrap-re-regexp (re)
+  (concat "\\`[ \t]*"
+          "\\("
+          re
+          ; Re(1) or Re[1] or Re^1
+          "\\(([0-9]+)\\|\\[[0-9]+\\]\\|\\^[0-9]+\\)?"
+          ; SPC/NBSP followed by colon and TAB/SPC
+          " ?\u00a0*[::][ \t]*"
+          ; Handle repetition, eg "Re[1]: Re[2]:"
+          "\\)*"
+          "[ \t]*"))
+
+;;;###autoload
+(defcustom mail-re-regexps
+  '("RE" "R\u00c9\\.?" "FWD?" "رد" "回复" "回覆" "SV" "Antw\\.?"
+  "VS" "REF" "AW" "ΑΠ" "ΣΧΕΤ" "השב" "Vá" "R" "RIF" "BLS" "RES"
+  "Odp" "YNT" "ATB")
+  "List of localized \"Re:\" abbreviations in various languages.
+Each component can be a regular expression or a simple string.  Matching
+is done case-insensitively.  Used to initialize the legacy
+`rmail-re-abbrevs' and `message-subject-re-regexp' user options."
+  :type '(repeat regexp)
+  :set (lambda (sym val)
+         (custom-set-default sym val)
+         (dolist (sym '(rmail-re-abbrevs
+                        message-subject-re-regexp))
+           (when (get sym 'standard-value)
+             (custom-reevaluate-setting sym))))
+  :group 'mail
+  :version "31.1")
+
 (defvar epa-inhibit)
 ;; Returns t if file FILE is an Rmail file.
 ;;;###autoload
index 44b49293d08357f2e778478d78cc05bb291dc117..4b93f379c72361f79494fb717fccd77a8ca12968 100644 (file)
@@ -525,22 +525,27 @@ Examples:
 (defvar rmail-reply-prefix "Re: "
   "String to prepend to Subject line when replying to a message.")
 
-;; Note: this is matched with case-fold-search bound to t.
-(defcustom rmail-re-abbrevs
-  "\\(RE\\|رد\\|回复\\|回覆\\|SV\\|Antw\\|VS\\|REF\\|AW\\|ΑΠ\\|ΣΧΕΤ\\|השב\\|Vá\\|R\\|RIF\\|BLS\\|RES\\|Odp\\|YNT\\|ATB\\)"
-  "Regexp with localized \"Re:\" abbreviations in various languages."
-  :version "28.1"
-  :type 'regexp)
+(defvar rmail-reply-regexp nil ;; set by `rmail-re-abbrevs
+  "Regexp to delete from Subject line before inserting `rmail-reply-prefix'.")
 
 ;; Some mailers use "Re(2):" or "Re^2:" or "Re: Re:" or "Re[2]:".
 ;; This pattern should catch all the common variants.
 ;; rms: I deleted the change to delete tags in square brackets
 ;; because they mess up RT tags.
-(defvar rmail-reply-regexp
-  (concat "\\`\\("
-          rmail-re-abbrevs
-          "\\(([0-9]+)\\|\\[[0-9]+\\]\\|\\^[0-9]+\\)?\u00a0*[::] *\\)*")
-  "Regexp to delete from Subject line before inserting `rmail-reply-prefix'.")
+;; Note: this is matched with case-fold-search bound to t.
+(defcustom rmail-re-abbrevs
+  (concat "\\("
+          (string-join mail-re-regexps "\\|")
+          "\\)")
+  "Regexp with localized \"Re:\" abbreviations in various languages.
+Matching is done case-insensitively.
+Initialized from `mail-re-regexps', which is easier to customize."
+  :set-after '(mail-re-regexps)
+  :set (lambda (sym val)
+         (custom-set-default sym val)
+         (setq rmail-reply-regexp (mail--wrap-re-regexp val)))
+  :type 'regexp
+  :version "31.1")
 
 (defcustom rmail-display-summary nil
   "If non-nil, Rmail always displays the summary buffer."