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

Re: Include message attributes in print_command?



On 11Jan2009 17:44, Ed Blackman <ed@xxxxxxxxxxx> wrote:
>> That said, the following will work.  Modify accordingly for use with
>> enscript. 
>
> Thanks for the concept!  Here's what I ended up with:
[...]
> # Save message contents
> MSG="$(cat -)"
> # get Subject, striping all occurrances of 'Re: ?' and any initial spaces
> SUBJ="$(echo "$MSG" | formail -cx Subject | sed -e 's/Re: \?//g' -e 
> 's/^\s\+//')"
> # get Date, and parse into a more regular, but still human-readable format
> DATE="$(date -d "$(echo "$MSG" | formail -cx Date)" +%Y-%m-%d-%H:%M:%S)"
> # send message to print with appropriate title and all passed enscript args
> echo "$MSG" | enscript --title "$SUBJ $DATE" "$@"

Just a shell coding remark; I'd be doing this:

  #!/bin/sh
  : ${TMPDIR:=/tmp}
  tmpf=$TMPDIR/muttprint$$
  cat >"$tmpf"
  subj=$(formail ...... <"$tmpf" | sed .....)
  date=$(formail ...... <"$tmpf" | sed .....)
  enscript --title "$SUBJ $DATE" "$@" <"$tmpf"
  xit=$?
  rm "$tmpf"
  exit $xit

This is for a few reasons, but primarily because "echo" does not
reproduce its arguments exactly (on several platforms it interprets
various backslash sequences). So the 'echo "$MSG" |' can mangle the
message for bother formail and enscript.

The are other reasons like: a big message withh blow the command line
argument limit (maybe not if echo is builtin, which is usually is), and using
a temp file reduces the number of programs you spawn and the amount of data
you copy, making for a faster script. And for reasons that require a somewhat
wordy explaination, you should never use $UPPERCASE variable names for
script-local/non-exprted variables.

Cheers,
-- 
Cameron Simpson <cs@xxxxxxxxxx> DoD#743
http://www.cskk.ezoshosting.com/cs/

From the April 1996 Dr. Dobb's Journal, p.18,
DDJ:    You've mentioned Edsgar Dijkstra. What do you think of his work?
DK:     His great strength is that he is uncompromising. It would make
        him physically ill to think of programming in C++.