14

I'd like the option for certain emails and/or recipients to have a script run before sending (whether automatically or by pressing a keybinding) which takes my text/plain, runs a script over it, and then attaches the output of that script with the text/html type, setting the whole message to multipart/alternative.

Side ramble: It might be nice if this happened automatically immediately before sending but only if the body type was currently set to text/markdown, as this would mean the pending email is never in a state where I edit the source again but forget to regenerate the HTML, and I still have the option to send only text/plain. Then I'd have another binding to set the content type of the body to text/markdown, so that this would be picked up. But then I also have the issue that a lot of mail clients (Gmail included) refuse to render text/markdown (even as plain text), instead offering it as a download, so I'd need to have the content type of the source part switched back to text/plain.

Is such a thing possible with mutt?

Sadly as far as I can tell mutt doesn't support sending multipart/alternative messages, refusing to send anything but multipart/mixed, but I'd love to be shown I'm wrong.

The best solution I've been able to come up with is this macro:

macro compose M "<filter-entry>commonmark<return>y<edit-type><kill-line>text/html<return>" "convert message to HTML with Commonmark"

There are a few issues with this:

  • It entirely replaces the original plain text, so it's then much harder to edit
  • I don't like that there's the y in the macro to say yes to the dialog asking whether it's okay to overwrite the file
  • I have to press return after this runs
  • And of course the main thing: it doesn't send the plain text alternative

Is there a better solution?

I'm potentially open to another text-mode mail client, as long as it

  • is usable with Google Apps, and syncs flags etc in both directions
  • supports GPG
  • has vim-like bindings, or I can configure them
  • lets me use vim as a message editor
  • has a threaded message view
  • allows me to filter/search mail in a somewhat sophisticated way (sender, recipient, presence of attachments, subject and body text search)
  • handles attachment types a bit like mutt, i.e. mailcap or equivalent so I can run incoming HTML mail through lynx, or press something to open it in the graphical browser if need be, I can launch image viewers at a button press, and so on
tremby
  • 542

2 Answers2

1

I forgot about NeoMutt supports multipart. https://neomutt.org/guide/mimesupport.

Davey
  • 595
-1
    #!/bin/bash

    cp $1 $1.tmp
    ##CHANGE OVERALL TYPE IN HEADER TO MULTIPART

    #HANDLE CONTENT-TYPE LINE IN HEADER
    if grep -q "Content-Type:" $1; then
            sed -i -e 's/Content-Type:.*?;/Content-Type: multipart\/alternative; boundary=boundary42/' $1.tmp
    else
            sed -i '1iContent-Type: multipart/alternative; boundary=boundary42' $1.tmp
    fi

    #EXTRACT HEADER AND BODY
    header="$(sed '/^$/q' $1.tmp)"
    body="$(sed -n -e '/^$/,$p' $1.tmp | tail -n +2)"

    #CREATE HTML VERSION
    HTMLbody="$(echo "$body" | commonmark)"

    #ADD HEADER
    echo "$header" > $1

    #START PLAIN TEXT
    echo -e "\n--boundary42\n" >> $1
    echo -e "Content-Type: text/plain; charset=us-ascii\n" >> $1
    echo "$body" >> $1

    #START HTML
    echo -e "\n--boundary42\n" >> $1
    echo "Content-Type: text/html; charset=UTF-8" >> $1
    echo "Content-Transfer-Encoding: quoted-printable\n" >> $1
    echo "$HTMLbody" >> $1

    echo -e "\n--boundary42--" >> $1

    msmtp $1
Davey
  • 595