13

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
1

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

4
  • That is good to hear. The page you linked said the support for sending multipart/alternative is rudimentary but I'll give it a try some time soon. Thanks for pointing it out. – tremby Apr 4 '19 at 23:28
  • Neomutt is supposed to be a drop-in replacement for regular ol' mutt. The other nice thing is that its apparently got pretty large active development. – Davey Apr 5 '19 at 12:17
  • Looks like the feature was added just a year ago: github.com/neomutt/neomutt/pull/734 – tremby Apr 5 '19 at 18:30
  • It works great. I made a macro similar to the one suggested in the docs you posted at neomutt.org/guide/… -- I still have to press enter after using the macro, and I'm not yet sure what will happen if I want to make changes after generating the alternative but before sending, but I'll figure all that out in due course. Note the first version to support multipart/alternative is the 2018-05-12 release, which is not yet in my distro. I compiled from source with --gnutls --prefix/usr/local --tokyocabinet. – tremby Apr 5 '19 at 23:27
-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
10
  • You appear to be answering the question "is it possible to use different signatures per 'from' email address", which is not at all the question I asked. I don't see how this helps with sending multipart/alternative email. – tremby Apr 4 '19 at 17:19
  • I see you've edited your answer. OK so this checks which email addresses you're sending from and to (doesn't look like you do anything with "from") and possibly adds some headers. But I still don't see how this helps with sending multipart/alternative email. – tremby Apr 4 '19 at 18:57
  • You are probably gonna need to adjust this for your own needs, so I probably can't spell out everything for you. But the general solution is that you set your editor to a script that calls on your editor then parses the draft file. – Davey Apr 4 '19 at 19:08
  • Which specific edit to the draft file will allow mutt to send multipart/alternative? Where are the two versions of the file, HTML and plain text? – tremby Apr 4 '19 at 20:01
  • You seem to have a way to convert with commonmark. Replace that with the someMultipartScript line. $1 at that point will be plaintext. Send it through your conversion tool there and pipe it to the same filename $1. When this script terminates, it sends a signal to the calling program (mutt), that your editor is closed, at which point it should be ready to send. – Davey Apr 4 '19 at 20:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.