procmail
[Top] [All Lists]

Re: help with maximum message size rules

1999-06-23 19:21:39
John Coy (the John Coy I knew on line in the 80s?  couldn't be) wrote,

| What I am trying to do is configure procmail to reject
| incoming messages based on the size of the message (done).  If
| the message is above a certain size, then I want to bounce
| the message back with a generic error (done) and INCLUDE THE ORIGINAL
| HEADERS in the response (not done).  It's that "include the
| headers" part that I'm having trouble with!

Classic way to get the head copied into the body:

 :0fwh
 | sed -e H -e '$g'

assuming the head fits into sed's hold space, which it will unless it is a
badly multiply carboned spam.

| What I want to know is how I can store a good copy of the
| message headers in a variable or something which can then
| be used in my auto-reply?  I've tried storing the headers
| in a variable but the carriage returns are lost (and there's
| a finite limit to the length of headers that can be stored
| in a variable).

The newlines wouldn't be lost unless you tried to echo it without quoting
the variable.

| Here's my recipie so far.  If there's a better way to do
| what I want please let me know!  I'm still learning...

| -- cut here --
| 
| SHELL=/bin/sh
| PATH=/usr/local/bin:/bin:/usr/bin
| LOGFILE=/tmp/log.amsinternal
| VERBOSE=yes
| MAXMSGSIZE=10000
| MAX_INBOX_SIZE=200000
| 
| #
| # Bounce messages which exceed the MAXMSGSIZE variable
| #
| :0
| * > ${MAXMSGSIZE}
| {
|     #
|     # Get the subject line of the offending piece of mail
|     #
|     :0 h
|     SUBJECT=|formail -x "Subject:"
| 
|     #
|     # Generate the auto-reply
|     #
|     :0 h
|     * !^FROM_DAEMON
|     * !^X-Loop: X-BOUNCE-FILE-SIZE
|     | (formail -rt \
|        -I"Subject: Returned Mail: ${SUBJECT}" \
|        -I"From: MAILER-DAEMON(_at_)${HOST}" \
|        -A"X-Max-Message-Size: ${MAXMSGSIZE} bytes" \
|        -A"X-Bounced-Reason: Maximum Message Size Exceeded" \
|        -A"X-Loop: X-BOUNCE-FILE-SIZE" ; \
|        cat /usr/local/etc/autoreplies/bounce-file-size ) | $SENDMAIL -t
|     #
|     # Trash the message
|     #
|     :0 h
|     /dev/null
| }

You must have removed the code that included the old headers with no
newlines; this wouldn't include the old headers at all.

Let's try something like this inside the braces:

 :0 # lose items we don't want to bounce
 * 9876543210^0 ^FROM_DAEMON
 * 1^0 ^X-Loop: X-BOUNCE-FILE-SIZE
 /dev/null

 :0fi # double the head, lose the body
 | sed -eH -e /./b -eg -eq

 :0f # invert and let second copy of head (the new body) be cited:
 | formail -rtk \
        -I"Subject: Returned Mail: ${SUBJECT}" \
        -I"From: MAILER-DAEMON(_at_)${HOST}" \
        -A"X-Max-Message-Size: ${MAXMSGSIZE} bytes" \
        -A"X-Bounced-Reason: Maximum Message Size Exceeded" \
        -A"X-Loop: X-BOUNCE-FILE-SIZE"

      # insert explanation between head and new body;
 :0bf # explanation file should end with an empty line
 | sed -e '1,/^$/!b' -e/./b -e 'r /usr/local/etc/autoreplies/bounce-file-size'

 :0
 ! -t