#!/usr/bin/perl -w # # listfilter # John Simpson 2004-02-19 # # verify that a message is really from a given mailing list- # searches for a given header and makes sure the line contains the given value # # IF the message is really from a given list # - exit 0, causing the directions in .qmail to continue to be processed # OTHERWISE # - exit 99, preventing any further delivery # # call from .qmail as... # |listfilter headername value # # example: if you have a dummy email address "qmr@jms1.not" which should # only be receiving messages from a certain mailing list, and the mailing # list always adds the header... # List-Post: # you can make sure that a given message actually came from this list using # this line in the user's .qmail file... # |listfilter List-Post qmr@list.qmailrocks.org # and anything sent to this user which doesn't have the correct header to # identify it as part of the mailing list, will be deleted automatically. # # you can also combine this with "condredirect" to redirect mailing list # messages to a certain folder, in cases where you can't subscribe to a # list directly under the dummy email address. for the same mailing list # as above, i could add this to my normal user's .qmail file... # |condredirect qmr@jms1.not listfilter List-Post qmailrocks.org # and any messages which arrive with the list's magic header will be # automatically re-sent to the dummy user. # # 2005-04-11 jms1 - (code not modifed) added GPL-2-ONLY copyright notice, # expanded on the documentation above. # ############################################################################### # # Copyright (C) 2004-2005 John Simpson. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 2, as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # or visit http://www.gnu.org/licenses/gpl.txt # ############################################################################### require 5.003 ; use strict ; my ( $header , $value , $inh , $found ) ; $header = shift || die "Header name not specified\n" ; $value = shift || die "Expected value not specified\n" ; $inh = 1 ; $found = 0 ; while ( my $line = <> ) { next unless $inh ; chomp $line ; if ( $line =~ /^$/ ) { $inh = 0 ; next ; } if ( $line =~ /^$header\:/ ) { if ( $line =~ /$value/ ) { $found = 1 ; } } } exit ( $found ? 0 : 99 ) ;