How to attach a jpeg signature message to mu4e outgoing mail?

65 views
Skip to first unread message

Richard Herbert

unread,
Aug 16, 2021, 1:38:55 AM8/16/21
to mu-discuss
Mu4e-compose-signature works well to attach a text message as a signature to outgoing mail.  However, I require sending a message signature that necessitates using a jpeg of the message signature.

I can view jpeg message signatures on incoming email.

How do I attach a jpeg message signature to outgoing email and ensure it does not become an attachment?

Richard

Tim Cross

unread,
Aug 16, 2021, 2:10:11 AM8/16/21
to mu-di...@googlegroups.com

In order to do this, I think you need to compose the message as HTML and
not plain text. This requires using another package to convert your
plain text in the compose buffer into HTML and add the necessary MIME headers.

One way to do this would be to use either org-mime or org-message.
Either of these modes can take your plain text message (possibly with
org-mode markup) and convert it into an HTML message. You would need to
reference your jpg signature as an org link i.e.

[/path/to/jpg/signature.jpg]

Richard Herbert

unread,
Aug 18, 2021, 12:27:08 PM8/18/21
to mu-discuss
Appreciated. I have seen a bit of setting up for HTML in the mu4e manual but I have not found anyone's config examples when searching. 

Can you point me to an example?

Tim Cross

unread,
Aug 18, 2021, 8:19:13 PM8/18/21
to mu-di...@googlegroups.com, Richard Herbert

For your use case, I suspect org-msg would be a better fit.
Personally, I prefer to use org-mime.

See https://github.com/jeremy-compostella/org-msg for more details on org-msg

A minimal org-msg setup would be something like the below (will need
tweaking/refinement). It will use org mode to translate your message
into HTML, so you may need to tweak your org export options for html.

Personally, I only send HTML mail when necessary because I need the
higher level formatting capability. IMO jpeg signatures are a horrible
idea - they are not accessible, require your message be HTML, many
users block images in emails by default and won't work for users who
prefer plain text messages. However, I know this is nearly an impossible
argument to win once the 'experts' in marketing get involved.

I'm sure there are other ways of doing this. I used the above setup
initially because I wanted to be able to use org-mode to compose my
messages. I've since switched to org-mime, but that takes a bit more
configuration to get working, especially in a fully automated mode.

(require 'org-msg)

(setq mail-user-agent 'mu4e-user-agent)
(setq org-msg-options "html-postamble:nil H:5 num:nil ^:{} toc:nil author:nil email:nil \\n:t"
org-msg-startup "hidestars indent inlineimages"
org-msg-greeting-fmt "\nHi %s,\n\n"
org-msg-greeting-name-limit 3
org-msg-default-alternatives '((new . (text html))
(reply-to-html . (text html))
(reply-to-text . (text html)))
org-msg-convert-citation t
org-msg-signature "

Regards,

<your name>

#+begin_signature
--
*some signature text in bold*

[/path/to/your/jpg]
#+end_signature")

(org-msg-mode)

Richard Herbert

unread,
Aug 19, 2021, 1:47:56 AM8/19/21
to mu-discuss
I appreciate your time on this. However, I also find jpeg signatures a hassle and do not open them on incoming messages unless necessary. I have used a text signature for years, but felt it was time for some colour in my emails and prepared up a jpeg signature last weekend. As you are aware, some industries look down on those who stayed away from "charmed" jpeg signatures. Your reflections on jpeg signatures reminded me why I have stayed away from them. I have saved your insight on html in a file for future use.

However, I need to get email saving to pdf up and running along with spam filtering in mu4e. Currently, I clean up my emails in a virtual machine with thunderbird and I print to pdf those that may be required for future paper trails "before" I mbsync into mu4e. However, this is adding an extra layer of work.

Do you have insight on these two topics?

Tim Cross

unread,
Aug 19, 2021, 4:06:51 AM8/19/21
to mu-di...@googlegroups.com, Richard Herbert

With respect to saving messages as PDF, it isn't a use case I have any
need for. I imagine it wouldn't be too hard. I believe mu4e supports the
ability to 'pipe' a message to another process and I expect it would be
possible to find a utility you could pipe the data to which would
generate a PDF from the input. All you would need to do is define a new
action to save the message as PDF which would trigger the piping to that
utility.

WRT spam filtering, again, not a use case I have. I find my mail service
provider does a good job at that and I just exclude the spam folder from
my mbsync download, so I never see the spam locally. In the old days, I
use to use fetchmail and pipe that through procmail, which in turn piped
it through spamassassin and then into the mailbox. Don't think such a
workflow will work with mbsync, but don't know if other 'downloaders'
will work. However, other downloaders probably won't handle syncing back
up to the server (maybe that isn't important for you). Personally, I
think the better solution is have anti-spam at the provider level as
then your not wasting bandwidth downloading garbage.

Carson Chittom

unread,
Aug 19, 2021, 11:03:31 PM8/19/21
to mu-di...@googlegroups.com
On Thu, Aug 19, 2021, at 2:51 AM, Tim Cross wrote:
>
> With respect to saving messages as PDF, it isn't a use case I have any
> need for. I imagine it wouldn't be too hard. I believe mu4e supports the
> ability to 'pipe' a message to another process and I expect it would be
> possible to find a utility you could pipe the data to which would
> generate a PDF from the input. All you would need to do is define a new
> action to save the message as PDF which would trigger the piping to that
> utility.

I haven't used it in maybe a decade, but at one point I had a need to generate PDFs from arbitrary input and used GNU a2ps[1] and ps2pdf from TeXLive for this. If I needed to do it again, that's where I'd start.

[1] https://www.gnu.org/software/a2ps/

Richard Herbert

unread,
Aug 28, 2021, 8:53:15 AM8/28/21
to mu-discuss
I discovered a simple code to add to save Mu4e emails to pdf as follows with wkhtmltopdf installed (I installed through Yast with Opensuse Tumbleweed OS).

     (defun mu4e-action-save-to-pdf (msg)
       (let* ((date (mu4e-message-field msg :date))
              (infile (mu4e~write-body-to-html msg))
             (outfile (format-time-string "%Y-%m-%d%H%M%S.pdf" date)))
        (with-temp-buffer
          (shell-command
           (format "wkhtmltopdf %s ~/Desktop/Email/%s" infile outfile) t))))
   (add-to-list 'mu4e-view-actions '("Save to PDF" . mu4e-action-save-to-pdf) t)

The drawback at this time is that headers do not include Cc: or Attachment: but other header information is there as well as the full message.

Does anyone know hoe to include Cc: and Attachment: into the header?

Richard Herbert

unread,
Aug 28, 2021, 11:10:18 AM8/28/21
to mu-discuss
I added the following into Mu4e-action.el under mu4e~write-body-to-html:

      (insert (concat "<strong>Cc</strong>: "
                      (mu4e~action-header-to-html msg :cc) "</br>"))
      (insert (concat "<strong>Attachments</strong>: "
                      (mu4e~action-header-to-html msg :attachment) "</p>"))

Cc. is working in save to pdf with a header and names. However, I have an attachment header without listing attachments.

Help?

Richard Herbert

unread,
Aug 29, 2021, 1:03:31 PM8/29/21
to mu-discuss
I have tried to invoke plist msg to get names for attachments to save to pdf:

      (insert (concat "<strong>Attachments</strong>: "
                      (mu4e-message field msg :attachment) "</p>"))

This does not work either. I am not looking to have urls asscoated with the save to pdf. have attachment names will suffice.

The relevant code from mu4e-actions.el is:

 (defun mu4e~write-body-to-html (msg)
  "Write MSG's body (either html or text) to a temporary file; return the filename."
  (let* ((html (mu4e-message-field msg :body-html))
         (txt (mu4e-message-field msg :body-txt))
         (tmpfile (mu4e-make-temp-file "html"))
         (attachments (cl-remove-if (lambda (part)
                                      (or (null (plist-get part :attachment))
                                          (null (plist-get part :cid))))
                                    (mu4e-message-field msg :parts))))
    (unless (or html txt)
      (mu4e-error "No body part for this message"))
    (with-temp-buffer
      (insert "<head><meta charset=\"UTF-8\"></head>\n")
      (insert (concat "<p><strong>From</strong>: "
                      (mu4e~action-header-to-html msg :from) "</br>"))
      (insert (concat "<strong>To</strong>: "
                      (mu4e~action-header-to-html msg :to) "</br>"))
      (insert (concat "<strong>Cc</strong>: "
                      (mu4e~action-header-to-html msg :cc) "</br>"))
      (insert (concat "<strong>Date</strong>: "
                      (format-time-string mu4e-view-date-format (mu4e-message-field msg :date)) "</br>"))
      (insert (concat "<strong>Subject</strong>: "
                      (mu4e-message-field msg :subject) "</p>"))
      (insert (concat "<strong>Attachments</strong>: "
                      (mu4e-message-field msg :attachment) "</p>"))
      (insert (or html (concat "<pre>" txt "</pre>")))
      (write-file tmpfile)
      ;; rewrite attachment urls
      (mapc (lambda (attachment)
              (goto-char (point-min))
              (while (re-search-forward (format "src=\"cid:%s\""
                                                (plist-get attachment :cid)) nil t)
                (if (plist-get attachment :temp)
                    (replace-match (format "src=\"%s\""
                                           (plist-get attachment :temp)))
                  (replace-match (format "src=\"%s%s\"" temporary-file-directory
                                         (plist-get attachment :name)))
                  (let ((tmp-attachment-name
                         (format "%s%s" temporary-file-directory
                                 (plist-get attachment :name))))
                    (mu4e~proc-extract 'save (mu4e-message-field msg :docid)
                                       (plist-get attachment :index)
                                       mu4e-decryption-policy tmp-attachment-name)
                    (mu4e-remove-file-later tmp-attachment-name)))))
            attachments)
      (save-buffer)
      tmpfile)))

Any suggestions on how to get attachment names to save with the pdf?
Reply all
Reply to author
Forward
0 new messages