Open hokreb opened 1 year ago
The code in the README didn't work for me*, but I can share how I've set this up.
My org-msg-signature defaults to some html wrapped in export_begin html
and end_export
tags, that I keep in a file:
(setq org-msg-signature (with-current-buffer (find-file-noselect (expand-file-name ".html-signature" org-roam-directory) t) (buffer-string))))
Then I used the example code in the README to come up with the following:
(defun gjm/org-msg-signature-switch (orig-fun &rest args)
"No signature for replies. Text signature for new plain text emails."
(let ((res (apply orig-fun args))
(is-reply (not (equal (car args) 'new)))
(is-text (equal (last (cadr args)) '(text)))
(text-sig "\n\n--\nGav Massingham\nTechnology Development Officer\nCarers' Resource"))
(if is-reply (setf (alist-get 'signature res) "")
(if is-text (setf (alist-get 'signature res) text-sig)))
res))
(advice-add 'org-msg-composition-parameters
:around #'gjm/org-msg-signature-switch)
First, I set a couple of local convenience variables for whether it's a reply email, whether it's a plain text email, and to hold a basic signature for plain text emails. Then there are a couple of nested if
statements. The first check if it's a reply email, and set the signature to be empty if so, as I don't want a signature on replies. The second checks if we're sending a plain text email and sets the signature to the variable created earlier, if so.
This works for setting the signature of the message being edited.
What doesn't seem to happen is for separate text and HTML signatures to be added to the relevant parts of the message if there are both HTML and text versions (at least it doesn't for me using mu4e with org-msg). I don't know if this is the expected behaviour, or a bug. A quick scan of the code suggests the signature is only inserted once, into the buffer for editing the message. It would be good to have both versions of the signature included in emails that send both text and HTML parts, so I'll look into this further.
*because args
was set to '(new (text))
at the time, and (cadr args)
is nil
if args
is a list with a single element
If you use mu4e
, you can also do this with the “contexts” function; here’s the key part from my config:
(defun mu4e-extras-set-contexts ()
"Set `mu4e-contexts'."
(setq mu4e-contexts
`(,(make-mu4e-context
:name "Personal HTML"
:match-func #'mu4e-extras-msg-is-personal-and-html-p
:vars `((user-mail-address . ,(getenv "PERSONAL_GMAIL"))
(org-msg-signature . ,org-msg-extras-personal-html-signature)))
,(make-mu4e-context
:name "Personal plain text"
:match-func #'mu4e-extras-msg-is-personal-and-plain-text-p
:vars `((user-mail-address . ,(getenv "PERSONAL_GMAIL"))
(org-msg-signature . ,org-msg-extras-personal-plain-text-signature)))
,(make-mu4e-context
:name "Work HTML"
:match-func #'mu4e-extras-msg-is-work-and-html-p
:vars `((user-mail-address . ,(getenv "WORK_EMAIL"))
(org-msg-signature . ,org-msg-extras-work-html-signature)))
,(make-mu4e-context
:name "Work plain text"
:match-func #'mu4e-extras-msg-is-work-and-plain-text-p
:vars `((user-mail-address . ,(getenv "WORK_EMAIL"))
(org-msg-signature . ,org-msg-extras-work-plain-text-signature))))))
(defun org-msg-extras-msg-is-html-p ()
"Return t iff the current message is an HTML message."
(not (null (condition-case nil
(org-msg-mua-call 'article-htmlp)
(error nil)))))
The other relevant functions are defined here.
I really like this project, as so I can send html emails, which is demanded by my company.
But what I miss, is a way to provide two signatures, one for text messages, and one for html messages, which are just placed at the end.
I am not sure, if this is possible by the org-msg-get-alternatives oder org-msg-composition-parameters function. I tried to use the sample provided in the README.org, but it seems, that this function can be used to manipulate the text, which will be converted to html later. What I would like to achieve, is to manipulate the text after the conversion to html, so I can inject the full html signature with all formatting. For the text version I like to insert the signature as plain text, without any org-mode special #+ instructions, which looks not so nice in the text context.
Is there a way to achive this?