Pretty print mails from mutt?

There is also Muttprint. It does support UTF-8 and its output looks decent by default. Muttprint uses LaTeX and provides hooks for customization.

Since I am printing mails from different environments I can't use a default printer. Thus I have set it up (via ~/.muttrc) to use a PDF viewer where I can dynamically select a printer:

set print_command='set -e; f=`mktemp`; \
        muttprint -P A4 -p TO_FILE:"$f"; evince "$f"; rm "$f"'

Mktemp uses /tmp, by default. For using a custom cache directory:

set print_command='set -e; f=`mktemp -p "$HOME"/.cache/mutt`; \
        muttprint -P A4 -p TO_FILE:"$f"; evince "$f"; rm "$f"'

Btw, you can set print_decode inside muttrc to configure if the print_command is able to decode MIME, encodings etc. on its own. By default it is set to yes which is the right setting for commands like muttprint, enscript etc.

Regarding the UTF-8 issues of a2ps, enscript and mp one can just conclude that they should be considered obsolete. Indeed, looking at the project pages they don't seem to be maintained (e.g. last news item of the mp page is from 2002 and it mentions a mailing list located at Sun).


You might also consider using paps, which reads a UTF-8 encoded file and generates a PostScript language rendering of the file. The rendering is done by creating outline curves through the pango ft2 backend.


More secure and using less paper, create a wrapper:

There is my print command for .muttrc:

set print_command="$HOME/bin/print_preview-wrapper.sh"

And there is the content of "$HOME/bin/print_preview-wrapper.sh"

#!/bin/bash

read tmpdir < <(mktemp -d /tmp/print_preview-$USER-XXXXXXXX)
cd $tmpdir || exit 1

trap "cd && rm -fR $tmpdir;exit" 0 1 2 3 6 9 15

cat >file.eml
muttprint -P A4 -p TO_FILE:file.ps <file.eml 

read numPages < <(sed '/^%%Pages/{s/%%Pages: //;q;};d' file.ps)
(( numPages > 1 )) &&
    muttprint -2 -P A4 -p TO_FILE:file.ps <file.eml 

gv file.ps

This will

  • securely create temporary dir to store current printing mail,
  • convert them to postscript, but
    • if there's more than 1 page,
    • convert them again, but putting 2 pages by sheet.
  • run gv because I like it, but you could run any other tool.
  • delete temporary directory on exit.

Tags:

Printing

Mutt