<<< Date Index >>>     <<< Thread Index >>>

how to print (was: extracting sender's name for use in a script?)



I had been wondering about a strategy for printing an
occasional mutt email message.  Rather than just sending a
raw message directly to my printer, I like to format using
two-up enscript to create a PostScript file, then display
that file using gv as a preview to printing.  (Sometimes I
do not want to print every page, and this facilitates that.)

I also wanted to put the name of the sender in the enscript
header, and so wondered how to extract the sender's name
(typically displayed in mutt using the "@" key).  Kyle Wheeler
suggested using Daniel Bernstein's "mess822" package,
available, for example, from http://cr.yp.to/mess822.html, and
using a mutt macro like this:

macro pager P \
 '<enter-command>set pipe_decode<enter><pipe-message>myscript<enter>'

(The "set pipe_decode" will weed out the header material,
which I usually do not want to print.  It will also cause mutt
to attempt to PGP/MIME decode the messages first, which may
not be what is wanted in case an email arrives in some format
other than text/plain, for example, only html.  In that case,
however, what I make happen (with auto_view text/html) is to
display the html in my browser window.  In this situation, the
message may be printed from the browser, so setting
pipe_decode is not a problem.)

Then "myscript" (which i call "print_msg") looks like this:

#!/bin/sh
# to be used with a mutt macro to preview email prior to
# printing.
#
message="`cat -`"
sender="`echo "$message" | 822field From`"
echo "$message" | enscript -2Gr --header="from $sender" --output tmp.ps
gv tmp.ps
/bin/rm tmp.ps

My OS is FC5 with an AMD 64x2 3800+ cpu, and at first I had
trouble getting the "mess822" functions (like "822field") to
work.  An rpm I found installed without a hitch, but then the
mess822 functions stopped working when "prelink" ran on a daily
cron job.  Then I discovered that the mess822 source would not
compile, bombing with this error message:

===========================================================
./load iftocc mess822.a getln.a strerr.a substdio.a \
stralloc.a alloc.a error.a env.a str.a case.a fs.a open.a
/usr/bin/ld: errno: TLS definition in /lib64/libc.so.6 section
.tbss mismatches non-TLS reference in strerr.a(strerr_sys.o)
/lib64/libc.so.6: could not read symbols: Bad value
collect2: ld returned 1 exit status
make: *** [iftocc] Error 1
===========================================================

Eventually I saw on a mail list this comment:

==============================================
This is "errno.h" problem!
Please edit
conf-cc
like follows.

gcc -O2 -include /usr/include/errno.h

This will be used to compile .c files.
==============================================

And this solved the problem: I compiled mess822 from the
source and installed it, and the mutt macro and my "print_msg"
script work exactly the way I want them to.

I now see that Michelle Konzack suggested using "formail -cx"
in place of "822field", which also works well for this
purpose, especially since I do use procmail.  I should have
thought of that.  But the mess822 puzzle was interesting to
solve.

(Another list reader suggested that I check out "muttprint",
but that did not compile for me at all.)

    -- Peter