From 460e6a8d32b845fbebd51d0f07485ec349083abd Mon Sep 17 00:00:00 2001 From: SqrtMinusOne Date: Sat, 2 Jul 2022 14:55:58 +0300 Subject: [PATCH] feat(mail): move signature when necessary --- .emacs.d/mail.el | 38 +++++++++++++++++++++++ Mail.org | 80 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 117 insertions(+), 1 deletion(-) diff --git a/.emacs.d/mail.el b/.emacs.d/mail.el index 1d9676c..d905ea1 100644 --- a/.emacs.d/mail.el +++ b/.emacs.d/mail.el @@ -93,3 +93,41 @@ (CMS (sign) (encrypt)))) + +(setq my/message-signature-on-top '("@etu.ru")) + +(defun my/message-insert-signature-need-on-top () + (let ((parts (split-string + (string-join + (list + (message-fetch-field "to") + (message-fetch-field "cc") + (message-fetch-field "bcc")) + ", ") + ", "))) + (and + (seq-some + (lambda (rule) + (seq-some + (lambda (part) + (string-match-p rule part)) + parts)) + my/message-signature-on-top) + t))) + +(defun my/message-maybe-fix-signature (&rest _) + (when (my/message-insert-signature-need-on-top) + (save-excursion + (goto-char (point-min)) + (when (re-search-forward message-signature-separator nil t) + (move-beginning-of-line 0) + (kill-region (point) (point-max))) + (message-goto-body) + (when (re-search-forward (rx "sign=pgpmime") nil t) + (forward-line)) + (insert (current-kill 0)) + (insert "\n\n") + (set-buffer-modified-p nil)))) + +(with-eval-after-load 'notmuch-mua + (advice-add #'notmuch-mua-reply :after #'my/message-maybe-fix-signature)) diff --git a/Mail.org b/Mail.org index d70cb32..ec73c58 100644 --- a/Mail.org +++ b/Mail.org @@ -450,7 +450,8 @@ Finally the proper notmuch settings: (lambda () (display-line-numbers-mode 0)))) #+end_src -The file to which this is tangled is read in the init.el. +The file is read in =init.el=. + ** Saved filters and keybindings I want to have the saved filters available in both notmuch interface as as keybindings. So a bit more of abusing org tables. @@ -543,6 +544,83 @@ And the following does the same for my general.el definer: (sign) (encrypt)))) #+end_src +** Tuning signature +By default, =message.el= inserts the signature at the bottom of the message, like this: + +#+begin_example + + +Person writes: + +> Stuff + +-- +Yours, +me +#+end_example + +This creates issues with certain email clients. For instance, MS Exchange often just cuts the text at =Person ....=, so there's no way to see the signature from the UI. + +What's more, MS Exchange, Gmail and other such clients add the signature before the quotation block, like that: + +#+begin_example + + +-- +Yours, +me + +Person writes: + +> Stuff +#+end_example + +So here I modifiy the citation function to insert the signature like in the second example for certain cases. + +FIrst, determine whether it is necessary to do so: +#+begin_src emacs-lisp +(setq my/message-signature-on-top '("@etu.ru")) + +(defun my/message-insert-signature-need-on-top () + (let ((parts (split-string + (string-join + (list + (message-fetch-field "to") + (message-fetch-field "cc") + (message-fetch-field "bcc")) + ", ") + ", "))) + (and + (seq-some + (lambda (rule) + (seq-some + (lambda (part) + (string-match-p rule part)) + parts)) + my/message-signature-on-top) + t))) +#+end_src + +Then advice the =notmuch-mua-reply= function: +#+begin_src emacs-lisp +(defun my/message-maybe-fix-signature (&rest _) + (when (my/message-insert-signature-need-on-top) + (save-excursion + (goto-char (point-min)) + (when (re-search-forward message-signature-separator nil t) + (move-beginning-of-line 0) + (kill-region (point) (point-max))) + (message-goto-body) + (when (re-search-forward (rx "sign=pgpmime") nil t) + (forward-line)) + (insert (current-kill 0)) + (insert "\n\n") + (set-buffer-modified-p nil)))) + +(with-eval-after-load 'notmuch-mua + (advice-add #'notmuch-mua-reply :after #'my/message-maybe-fix-signature)) +#+end_src + * mailcap mailcap file is a file which defines how to read to different MIME types. Notmuch also uses it, so why not keep it here.