procmail
[Top] [All Lists]

Re: body -> subject

1999-08-26 01:52:26
On Wed, 25 Aug 1999 22:55:34 +0200, Volford Andras
<volfi(_at_)PHYNDI(_dot_)FKE(_dot_)BME(_dot_)HU> wrote:
TEXT=`formail -I ""` 
:0 c 
| formail -I"To:" -A"To:volfi(_at_)phyndi(_dot_)fke(_dot_)bme(_dot_)hu" \
-I Subject: -A "Subject:$TEXT" \
| $SENDMAIL  -t

This should indeed capture the body of the message, but it might not
be the best way to do it. And anyway, unless you are sure every line
except the first has one or more leading whitespace characters, this
will wreak extreme havoc with the headers. If you have a message like
this (indented for readability):

    Received: (here is an uninteresting header I assume you don't want)
    From: me
    To: you
    Subject: testing

    This is a test.
    The message has two body lines.

    No, make that four.

then your present script would turn it into

    Received: (here is an uninteresting header I assume you don't want)
    To:volfi(_at_)phyndi(_dot_)fke(_dot_)bme(_dot_)hu
    Subject: This is a test.
    The message has two body lines.  <<< This is an invalid header line!
                                << And this now becomes start of body
    No, make that four.         << which is also probably not what you want

    This is a test.
    The message has two body lines.

    No, make that four.

Also, the -ISubject: and -ITo: options before -A are not useful, it's
enough to just say -I "Header: value".

For a variation, try the following recipe instead. It does things
fairly differently but is probably closer to what you +want+ to be
doing. The main change, apart from arranging things rather
differently, is that any body lines after the first one are indented
by a tab if there is not already a leading whitespace character
(whereby we turn them into a valid continued Subject: header).

    :0bc
    | sed -e 's/^$/     /' -e '1s/^[    ]*/Subject: /' \
          -e '2,$s/^[^  ]/      &/' \
      | formail -I "To: volfi(_at_)phyndi(_dot_)fke(_dot_)bme(_dot_)hu" \
      | $SENDMAIL $SENDMAILFLAGS -t

This should result in a message like this:

    Subject: This is a test.
        The message has two body lines.
        << (there is a tab here)
        No, make that four.
    To: volfi(_at_)phyndi(_dot_)fke(_dot_)bme(_dot_)hu

without any body at all. (This is permissible.)

Do notice that all the original headers are thrown away, all that
remains is a To: header and the Subject:. (In transport, some
Received: headers and probably a Message-Id: and Date: header will be
added.) I'm guessing you are probably trying to forward this to a
pager or something, in which case those missing (and additional)
headers probably won't matter at all anyway. (There will probably also
be at least one empty line after the headers.)

I tried also:
-I Subject -A "subject:`echo $TEXT`" \
not working :-(

(This is obviously just a Useless Use of Echo.
See <http://www.iki.fi/era/unix/award.html#echo> for a discussion.)

In most cases, you'll get a lot more help if you can be more
specific about what "it doesn't work" means (for example,
some logfile messages).
I checked the \var\log\maillog but the only information I could see that
the message size becomes 0.
No signs for error.
Probably another log file exist somewhere else not in the /var/log/?

You want to set LOGFILE=$HOME/Mail/procmail.log and then examine that
file for warning and error messages from Procmail. Add VERBOSE=yes to
get detailed, line-by-line logging.

It's also a good idea to try scripts from the command line, and then
when you see that they work in interactive use, plug them into your
Procmail recipe.

(It's also useful to make your recipes send their output somewhere
where you can examine it while you are still debugging them. In the
above example, you might replace the pipe to Sendmail with a
redirection to a temporary file, like

    :0bc
    * Subject: I am only testing this now
    | sed -blah -blah >/tmp/output

This will obviously overwrite /tmp/output every time you get a new
test message. You will want the test condition to be fairly specific;
replace that too when you are confident that your tests are working.)

Hope this helps,

/* era */

-- 
 Too much to say to fit into this .signature anyway: <http://www.iki.fi/era/>
  Fight spam in Europe: <http://www.euro.cauce.org/> * Sign the EU petition

<Prev in Thread] Current Thread [Next in Thread>