Barry writes on 17 July 1997 at 12:56:57
I want to save attachments over a certain size, say 2mb's, to a special
folder in /tmp. In place of this, i want the users recieving this mail to
get a mail from the system informing them that they recieved a large mail
and that they should call the office to arrange something.
I use a very brain-dead method and just truncate all messages over a
certain size, sending an auto-response back to the sender telling them
about this.
As as already been pointed out, what you are requesting can be quite
difficult in the general case; in light of that, my simple solution
may work for you too.
Dan
------------------- message is author's opinion only ------------------
J. Daniel Smith <DanS(_at_)bristol(_dot_)com>
http://www.bristol.com/~DanS
Bristol Technology B.V. +31 33 450 50 50, ...51 (FAX)
Amersfoort, The Netherlands {info,jobs}(_at_)bristol(_dot_)com
-----
#####
##### trap large messages. VM and Emacs start getting real sluggish
##### when folders get over a few megabytes. Plus, if I'm away on
##### vacation or just not checking mail for a few days (long
##### weekend), a few large messages could quickly fill up my disk
##### causing all kinds of yucky mail problems. More than likely I'd
##### prefer such "large" messages by some other means (FTP, HTTP,
##### message/external-body, etc.) anyway.
#####
##### Do this here (before mailing list processing) - in case some
##### spammer decides to mailbomb a list, or a bozo/newbie sends it
##### large messages
#####
# 50K is about 1000 lines under normal circumstances, it's easy to
# truncate using "head". Don't use "procmail"'s scorring to actually
# count lines - actual size is more important than lines (although I
# can't think of an easy way to truncate to 50K. N.B. the GNU version
# of "head" has a -bytes=N option).
MAXSIZE=50000
# truncate large messages to this many lines (head -$MAXLINES)
MAXLINES=1000
:0B
* $ > ${MAXSIZE}
{
# I'm lazy...some of this stuff was here before
N=${MAXLINES}
# let procmail do the work of pitching the headers, reduce the
# current message body to just $N lines
#
# Here's why the 'i' flag is needed (courtesy of Stephan):
# You told procmail to filter the entire mail (header and body), so it
# does and it attempts to write out header and body to the filter.
# Then procmail notices that not the entire body is being consumed.
# Procmail, being rather paranoid when it comes to delivery of mail
# assumes something went wrong and considers this a failure of the filter.
:0wifb
| head -$N
# Drop the "Content-Length:" header since its no longer accurate.
# Add a note to the beginning of the message telling the reader that
# its been truncated
:0wfh
| formail -I "Content-Length:" ; \
echo "[large message truncated to $N lines]" ; echo ""
# tell the sender I truncated their message, but only if it was
# sent explictly to me (and not some mailing list). Should whine to
# *anybody* within ${DOMAIN} too - they should know better; but
# that might cause problems with things forwarded from Lotus Notes
:0Whc:large.lock
* $^TO${ME_REGEXP}
* !^FROM_DAEMON
* $!^X-Loop: ${UNIQUE_NAME}
| expired -t8h .large.cache "${SENDER}"
:0 ehc
{
# don't put the exact sizes in the auto-response, makes it
# too easy for someone to send something one character smaller
:0fi
| formail -rt -I "Precedence: junk" -A "X-Loop: ${UNIQUE_NAME}" ;\
echo "This is to let me know that the message you sent" ;\
echo "to ${TO_LINE} about ${SUBJECT}" ;\
echo "was too large and thus has automatically been TRUNCATED." ;\
echo "" ;\
echo "More than likely, I would prefer to receive this message" ;\
echo "by some other means; please contact me so that we can work" ;\
echo "out the necessary arrangements. Kindly accept my apologies" ;\
echo "for any inconvenience this may cause you." ;\
echo "" ;\
echo "Thanks for your understanding and cooperation," ;\
echo " Dan" ;\
cat ${HOME}/.signature
:0
! -oi -t
}
}