procmail
[Top] [All Lists]

Re: truncating message if size too big

2001-03-15 18:32:14
Rejo wrote,

| This is what i have:
| 
|   MAX_SIZE_NMM=10000
| 
|   :0fw
|   * $ > $MAX_SIZE_NMM
|   | head -c $MAX_SIZE_NMM
| 
| And this is what i get in the logfiles:
| 
|   procmail: Assigning "MAX_SIZE_NMM=10000"
|   procmail: Match on "> 10000"
|   procmail: Executing "head,-c,10000"
|   procmail: Error while writing to "head"
|   procmail: Rescue of unfiltered data succeeded
|   procmail: Locking "/home/rejo/mp3test.lock"

"Error while writing" means that the command didn't accept the entire input
from procmail.  And well it should not!  head exits when it has read enough
to meet its specified amount of output and then it quits.  Solution: add
procmail's `i' flag to tell procmail to ignore write errors.

| The message is not limited in size.

The `w' flag makes procmail recover the unfiltered data if the filter reports
failure.

One other thought: you wouldn't want to do that if the headers alone exceed
the maximum size, right?  Maybe you'd want to drop the message entirely, but
you wouldn't want to chop it who-knows-where in the headers.  So I'm thinking,

   :0 # measure excess over max
   * 1^1 > 1
   * $ -$MAX_SIZE_NMM^0
   { } # if not over max, skip rest of chain

   :0Efbwi # if head is less than max, reduce body by its share
   * $ $MAX_SIZE_NMM^0
   * -1^1 B ?? > 1
   | head -c $=

   :0Efbi # otherwise head >= max, so lose entire body
   | true

_______________________________________________
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>