Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add to different signatures, one for text and one for html #160

Open
hokreb opened this issue Dec 23, 2022 · 2 comments
Open

How to add to different signatures, one for text and one for html #160

hokreb opened this issue Dec 23, 2022 · 2 comments

Comments

@hokreb
Copy link

hokreb commented Dec 23, 2022

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?

@gajama
Copy link
Contributor

gajama commented Jan 31, 2023

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

@benthamite
Copy link

benthamite commented Jan 25, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants