2

I'm trying to use enscript to print PDFs from Mutt, and hitting character encoding issues with curly quotes. So that an email with text like this:

“very dirty”    
we’re 

Comes out as:

â\200\234very dirtyâ\200\235
weâ\200\231re

My print script currently reads like this:

#!/usr/bin/env sh
INPUT="$1" PDIR="$HOME/Desktop" OPEN_PDF=evince



tmpfile="`mktemp $PDIR/mutt_XXXXXXXX.pdf`"
enscript --font=Courier8 $INPUT -2r --word-wrap --fancy-header=mutt -p - 2>/dev/null | ps2pdf - $tmpfile
$OPEN_PDF $tmpfile >/dev/null 2>&1 &
sleep 1
rm $tmpfile

Is there a way to replace the curly quotes before I send it to enscript? Or a character encoding I can use that will handle the quotes?

If there's another (better?) way to print to PDF from Mutt, I'm all ears. I just need to ensure that my quotes aren't getting fouled up.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Amanda
  • 1,709
  • 2
  • 13
  • 26
  • FWIW, the hack I settled on for this particular case (printing from Mutt, primarily concerned with curly quotes) was to create a series of sed filters I could call from `.muttrc` with `set display_filter="sed -f /path/to/file"` – Amanda Nov 20 '16 at 20:39

1 Answers1

1

Apparently, enscript doesn't support UTF-8 files.

What you may want to do is use sed to change the quotes before they go into enscript.

This will change the fancy quotes to the standard " and '. You won't be able to get them back after they're converted. To do this, you can insert a line like the following, just above the enscript line:

sed -i "s/[”“]/\"/g; s/[‘’]/'/g" $tmpfile

You may also be able to use iconv to convert the text to some other encoding, but I don't know much about that program. May be worth looking into.

apricot boy
  • 1,153
  • 7
  • 11
  • I wish! I tried that first and hit walls. http://stackoverflow.com/questions/40698444/how-do-i-use-sed-to-alter-a-variable-in-a-bash-script (And I'm fine with losing the fancy quotes for good -- that's definitely preferable to `â\200\234` – Amanda Nov 20 '16 at 06:36
  • That SO exchange doesn't include trying to run `sed` using `$tmpfile` as the input but I tried that and I'm getting the same result. – Amanda Nov 20 '16 at 06:46