procmail
[Top] [All Lists]

Re: Cutting the body to a certain amount of characters

2001-02-07 09:51:17
Andreas Tindlund wants to send a truncated copy of certain mail
messages to his cell phone. He tried a suggestion from Matt Dunford with
the following result:

| [...]
|
| | procmail: Assigning "LASTFOLDER= (formail -r -iFrom: -iSubject: ; cat
| body.tmp) | \
|                         perl -aF// -ne 'while ($c = shift @F) { exit if
| ++$i > 160; "
| procmail: Assigning "print"
| procmail: Skipped "$c; }' | \"
| procmail: Skipped "$SENDMAIL -oi xx(_at_)xx(_dot_)xx(_dot_)xx"
| procmail: Executing " cat - >body.tmp"
| (...)
| procmail: Locking "/home/homee/ti/tindlund/mail/INBOX.lock"
| procmail: Executing " (formail -r -iFrom: -iSubject: ; cat body.tmp) | \
|                         perl -aF// -ne 'while ($c = shift @F) { exit if
| ++$i > 160; "
| /bin/bash: -c: line 2: unexpected EOF while looking for matching `''
| /bin/bash: -c: line 3: syntax error: unexpected end of file
| 
| [...]

It looks like you're missing the single quote to close the perl
one-liner. You'll have to check that because Matt's code has it, but you
didn't include the recipe you actually implemented. You may have made
changes or copied and pasted incorrectly, but it looks like that final
quote is missing.

You might also be able to simplify the whole thing a bit (untested):

:0
* your conditions
| formail -rbk -iFrom: -iSubject: |dd bs=160 count=1 \
  |$SENDMAIL -oi phone(_at_)email(_dot_)com 2>/dev/null

That obviously requires you have the program dd on your system. The
trailing redirection of stderr is to eliminate the block count from dd
which I think would end up in the procmail log (but not cause any other
problems). If you don't have dd and/or want to stick with perl, a
simpler incantation might be:

:0
* your conditions
| formail -rbk -iFrom: -iSubject: \
  |perl -e'undef$/;print substr(<>,0,160)' \
  |$SENDMAIL -oi phone(_at_)email(_dot_)com

Someone else will have to correct me if that'll cause problems with
LINEBUF on large messages since it's slurping the whole thing.

There was a discussion on this not long ago, and I'd be willing to bet
that there was at least one "pure" procmail solution to this also that
can be found in the archives.

Don Hammond


_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

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