system filters and pipe

Top Page
Delete this message
Reply to this message
Author: Roger Books
Date:  
To: exim-users
Subject: system filters and pipe
Well, I looked through the list archives and found nothing about this, so
I'll start off with a question. :)

I have a problem (not exim related yet.) One of my largest groups of users
is using a mail program which chokes when it recieves mail messages with
more than about 100 names in the To: line. Unfortunately one of the
largest senders of e-mail to people in this group sends e-mail to 300+
people in one line.

In order to correct this problem I'd like to have a system filter that
filters things for local delivery, stripping out whoever is in the
To: line and replacing it with ${local_part}@???, not exactly
standard but it would correct my problem and save me a ton of phone calls.

To that end I made the following changes:

In exim.conf I changed the script exactly as in the docs. In what I
cut and pasted I left the stuff before and after in case it makes a
difference where I put the filter info.

###########################################################################
# excerpt from my exim.conf file                                          #
###########################################################################
userforward:
  no_verify,
  driver = forwardfile;
  directory = /
  file = /mail/forwards/${local_part}
  owners = root
  filter


# This director handles a systemwide filter
system_filter:
no_verify,
driver=forwardfile;
no_check_local_user,
filter,
file = /etc/system-mail-filter,
user = nobody

# This director matches local user mailboxes.

localuser:
driver = localuser,
transport = local_delivery;
############################################################################

Then in /etc/system-mail-filter I put the following, I feel rather strange
just piping it to my tcl program, I feel I should be doing something
else with it here. I don't want to have the tcl program do delivery because
I want over quota messages to come back to exim.

############################################################################
# /etc/system-mail-filter                                                  #
# note my system except mail as mail.state.fl.us, mail.dms.state.fl.us     #
# and devnull.dms.state.fl.us                                              #
############################################################################
# Exim filter
save /tmp/system-mail-filter.out
if ${domain} is mail.dms.state.fl.us or
    ${domain} is mail.dms.state.fl.us or
    ${domain} is rtssec1.dms.state.fl.us 
then
    pipe "/usr/local/bin/remove_to_line ${local_part}@???"
endif
############################################################################



Then I wrote the following tcl script.  Its rather simple and needs some
improvement, but it was more of a proof-of-concept than a finished product.
############################################################################
# /usr/local/bin/remove_to_line                                            #
############################################################################
#!/usr/local/bin/tclsh7.5


regexp {.*@} $argv username

# I would prefer setting insideTo to BEFORE DURING and AFTER, but then I
# have to deal with string tests and that adds complexity to the code.
#
# Assumptions are that the first left justified line after the To: line
# is the first line after the list of addresses.

set insideTo 0

while { [gets stdin curLine] > -1 } {
    # not hit the to yet
    if { $insideTo == 0 } then {
    if { [regexp {^[tT][oO]} $curLine] == 1 } {
        set insideTo 1
        puts "To: $argv"
    } else {
        puts $curLine
    }
    } elseif { $insideTo == 1 } then {
    if { [regexp {^[a-zA-Z]} $curLine] == 1 } {
        set insideTo 2
        puts $curLine
    }
    } else {
    puts $curLine
    }
}
############################################################################


If anyone can point where I am going wrong I would appreciate it.

Roger