-1

How can I append the beginng of body to the subject of the mail using e.g. procmail? The body of new mail can be erased.

Gilles 'SO- stop being evil'
  • 92,660
  • 35
  • 189
  • 229
Marki
  • 590
  • 7
  • 21

1 Answers1

1

UPDATE extract mime text part only!!!

Could be done this way:

:0 c
* optional rules
{
    MAILSUBJ=`formail -zcxSubject:`
    MAILBODY=`/usr/local/bin/extract-mime-text.sh`
    NEWSUBJ="$MAILSUBJ $MAILBODY"

    :0 fw
    | formail -I"Subject: $NEWSUBJ"

    :0
    !sms@x.com
}

with the script in /usr/local being something along the lines of

#!/bin/bash

T=/tmp/tmpmail.$$.$RANDOM
cat /dev/stdin > $T
for i in `reformime -i < $T | grep -B1 "content-type: text/plain" | grep section | cut -d: -f2`; do
    reformime -s$i -e < $T | sed -e "s/[ \t]\+/ /g" | tr -d "\n"
done
rm $T

That way you can nicely forward messages to some pseudo email address that does SMS forwarding (beginning of text part of mail will end up in subject, as only the subject is forwarded to SMS in many cases)

Marki
  • 590
  • 7
  • 21
  • I was unfamiliar with `reformime` -- apparently it's from the Maildrop package. Funny to use a Maildrop tool with Procmail, but I'm not complaining. (-: – tripleee May 10 '12 at 08:00