[Top][All Lists]

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

Re: Strip signature on reply without standard separator

From: Satoshi Yoshida
Subject: Re: Strip signature on reply without standard separator
Date: Fri, 16 Sep 2022 08:50:56 +0900
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)

Emanuel Berg <> writes:

> Make the whole thing a function that you add to the the hook.

I see. About function name, I refered to

>> (strip-signature "^\n-- \n\\(.*\n\\)*" "")
>> (strip-signature "^\\([^[:blank:]\n<>]+>.*\\)" "> \\1")
>> (strip-signature "^\\([^\n>].+\n\n\\)\\(>[[:blank:]]+\n\\\)+" "\\1")
>> (strip-signature "^> >" ">>")
>> (strip-signature "^> -- .*\n\\(>.*\n\\)*" "")
>> (strip-signature "^\\(>[[:blank:]]+\n\\)+> \\(best\
> Here it may be a better idea to have those REs in a list and
> then iterate that (a loop) instead of calling the same
> function so many times.

I consulted members of on slack.
Many thanks for their kind help.

(setq mu-cite-prefix-format '("> "))
(setq mu-cite-cited-prefix-regexp "\\(^[^[:blank:]\n<>]+>+[[:blank:]]*\\)")
(setq mu-cite-top-format '(from " writes:\n\n"))

(defun strip-signature (regexp replacement)
  (goto-char (point-min))
  (while (re-search-forward regexp nil t)
    (replace-match replacement)))

(defun my-mu-cite-hook-function ()
    (dolist (elm '(("^\n-- \n\\(.*\n\\)*" "")
                   ("^\\([^[:blank:]\n<>]+>.*\\)" "> \\1")
                   ("^\\([^\n>].+\n\n\\)\\(>[[:blank:]]+\n\\)+" "\\1")
                   ("^> >" ">>")
                   ("^> -- .*\n\\(>.*\n\\)*" "")
                   ("^\\(>[[:blank:]]+\n\\)+> \\(best\\( regards\
\\| wishes\\)?\\|cheers\\|\\(good\\)?bye\\|good luck\\|\\(kind \\|warm\
\\(est\\)? \\)?regards\\|respectfully\\|\\(yours \\)?sincerely\\( yours\
\\)?\\|thank you\\( very much\\)?\\|\\(many \\)?thanks\\( in advance\
\\| very much\\)?\\),[[:blank:]]*\n\\(>.*\n\\)*" "")))
      (apply #'strip-signature elm))                
    (goto-char (point-min))
    (when (re-search-forward "^\"?\\([^[:blank:]\n<>]+\\)\\([^\n<>]+\\)?\"? \
<\\([^\n<>]+\\)> writes:" nil t)
      (let ((first-name (match-string 1))
            (middle-last-name (or (match-string 2) ""))
            (mail-address (match-string 3)))
        (strip-signature (apply #'format "^\\(>[[:blank:]]+\n\\)*>\
" (mapcar #'regexp-quote (list first-name middle-last-name mail-address))) "")))
    (strip-signature "^\\(>[>[:blank:]]+\n\\)+\\'" "")             
    (goto-char (point-max))
      (insert-file-contents "~/.signature")
      (insert "\n-- \n"))))

(add-hook 'mu-cite-post-cite-hook #'my-mu-cite-hook-function)

Satoshi Yoshida

reply via email to

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