procmail
[Top] [All Lists]

Re: Restricting mail size to under 10K

1998-02-25 20:25:17
At 03:14 PM 2/25/98 -1000, Daryl Ching wrote:

I wish to restrict the size of all e-mail sent to a particular domain to 
under 10K.

You are aware that by the time Procmail has recieved the message, you've
already taken the bandwidth hit for the message?  I think sendmail has some
facility for limiting message sizes - I'm too lazy to dig up the answer at
the moment (and my batbook is where my servers are, which isn't where I'm at).

# To set 10K max message size:
O MaxMessageSize=10240

(this is an option you'd set in the sendmail.cf)

If an incoming message exceeds this threshold, the message should be
rejected with a result code of 552:

        "552 Message exceeds maximum fixed size (10240)"


When a message larger than 10K is received, I want to reject 
the message back to the sender with an attachment message explaining why 
the e-mail was rejected.

To tweak the text, you could either modify sendmail to include such a
message, or you could do this in procmail (there are addressing issues
though - reply-to vs. sender vs. from, vs. forged, etc).

Anyone know how to extract the sender's address 
and relay the back the original message.

You'd use 'formail -r' for this.


To achieve this in procmail, the following would probably work (NOT TESTED
- that's up to you to do):

:0
* > 10240
* !^FROM_DAEMON
* !^From:.*YOUR-ADDRESS
* !^X-Loop:[    ]*YOUR-UNIQUE-LOOP-IDENTIFIER-HERE
| ( formail -rk -A "Precedence: junk" \
-A "X-Loop: YOUR-UNIQUE-LOOP-IDENTIFIER" \
| $MYBIN/insertdoc -v file=$AUTOREPLY/msgtoolarge ) | $SENDMAIL -t -oi -oe


the insertdoc script:
#! /usr/bin/gawk -f
/^[ \t]*$/ && !INSERTED { print; system("cat " file ); INSERTED=1}
1

Set AUTOREPLY to be the path to your autoreply texts, $SENDMAIL to your
sendmail executable, $MYBIN to whereever the shell script is.  Edit the
msgtoolarge text, send yourself a message FROM a different address (I
intentionally make this recipe NOT mangle mail coming from you, so if you
carboncopy yourself, you don't get whacked).

The insertdoc and original basis for the reply recipe came from The Linux
Gazette, June 1997.

This is easier if you don't need to send back the original body:

:0
* > 10240
* !^FROM_DAEMON
* !^From:.*YOUR-ADDRESS
* !^X-Loop:[    ]*YOUR-UNIQUE-LOOP-IDENTIFIER-HERE
| (formail -r -A "Precedence: junk" \
-A "X-Loop: YOUR-UNIQUE-LOOP-IDENTIFIER" ; \
cat $AUTOREPLY/msgtoolarge ) | $SENDMAIL -t -oi -oe


Notably, no external shell app is needed (just use cat - and you aren't
PIPING formail output to it either), and you don't use the 'k'eep body
option with formail.  This method would be considerably more bandwidth
friendly.

---
 Please DO NOT carbon me on list replies.  I'll get my copy from the list.

 Sean B. Straw / Professional Software Engineering
 Post Box 2395 / San Rafael, CA  94912-2395

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