#!/usr/bin/perl # # autoresponder.pl # # This is a usenet autoresponder, answering each article # it's given by mail, provided it's not filtered out ;-) # # v1.0 1999 02 19 ekb@ivm.net # # This one has been developed for inn2.x and storage-api, # but should just as well work with inn1.x, provided you # set the flag correct and have it fed with Wf, not Wn ;-) # # History # # 1999 02 19 elmi@newsbone.org (Elmar K. Bins) # started hacking away... # # Notes # # This version works perfectly with inn2.x by this newsfeeds line: # autoresponder!:!*,*.test:Tp:/reflektor.pl %s # # Resources # # The current version can be found at http://detebe.org/~news/software/ # # Do you use the storage api for groups being fed here? $STORAGEAPI = 1; # Version and copyright stuff $version = "1.0"; $date = "1999 02 19"; $authors = "elmi\@newsbone.org (Elmar K. Bins)"; $copyright = "-- \nautoresponder.pl v$version $date $authors\n"; # System dependent stuff $sendmail = "/usr/sbin/sendmail"; $date = "/bin/date"; $now = `$date \"+%a %b %d %T %z (%Z)\"`; chomp($now); # Installation dependent stuff (pathnames) $sm = "/usr/local/inn/bin/sm" if ($STORAGEAPI); $logfile = "/var/log/news/autoresponder.log"; $mymessage = "/usr/local/inn/contrib/elmi/autoresponder.msg"; # Localizable stuff $mymail = "reflector\@detebe.org"; $systemname = "detebe.org"; $myname = "$systemname autoreflector"; $location = "Germany"; $maintainermail = "usenet\@detebe.org"; $myxheaders = "X-Reflector: $systemname\nX-URL: http://www.detebe.org/"; # Configuration $lines = 20; # lines of body to cite @addressblacklist = ( "\@.*nospam.*", "middle.earth" ); @ignorewords = ( "ignore", "dont reply", "don\'t reply", "no reply", "no replies", "fuck off", "keine antwort", "keine reply", "ignoriere", "norep" ); # select whether to use API or file if ($STORAGEAPI) { open (ARTICLE, "$sm -R $ARGV[0]|") || exit 1; } else { open (ARTICLE, "<$ARGV[0]") || exit 1; } # 1. Read header # 2. Read first $lines lines from body # 3. Bail out if any of the filters match (log) # 4. Send mail (log) $body = ""; # 1. Read header while (
) { s/ //g; $body .= "| " . $_; chomp; last if ($_ eq ""); ($key,@value) = split(":",$_); $value = join(":",@value); $key =~ s/\s//g; $value =~ s/^\s//; $header{lc($key)} = $value; } # 2. Read first $lines lines from body $count = 0; while (
) { s/ //g; last if ($count >= $lines); $body .= "| " . $_ if $count < $lines; $count++; } # 3. Bail out if any of the filters match (log) $mail = $header{from}; $mail = $header{'reply-to'} if ($header{'reply-to'} ne ""); # a/ control message? &leave(0,"control message") if ($header{control} || # control header ($header{subject} =~ m/^cmsg/i) || # old style by subject ($header{newsgroups} =~ m/\.ctl,/i) || # old style by group ($header{newsgroups} =~ m/\.ctl$/i)); # old style by group # b/ mail address invalid? $mail =~ m/([^ <>]+\@[^ <>]+)/; $cmail = $1; &leave(0,"invalid mail address $mail") if ($cmail !~ m/^[^\@ ]+\@([^\@ ]+\.)+[a-z][a-z]+$/i); # c/ mail address matches blacklist patterns? foreach $pattern (@addressblacklist) { &leave(0,"blacklisted mail address $mail") if ($mail =~ m/$pattern/i); } # d/ magic words in message: ignore foreach $pattern (@ignorewords) { &leave(0,"user wish") if (($header{subject} =~ m/$pattern/i) || ($header{keywords} =~ m/$pattern/i) || ($header{summary} =~ m/$pattern/i) || ($body =~ m/$pattern/i)) } # 4. Send mail (log) @msg = &filltemplate($mymessage,1); if (@msg == ()) { &leave(0,"could not load $mymessage"); } open (MAIL, "| $sendmail -t") || &leave(0,"could not start $sendmail"); # print header print MAIL <<__EOMAIL__; From: $mymail ($myname) To: $mail Subject: Answer from reflector (Re: $header{subject}) Precedence: bulk $myxheaders @msg $body $copyright __EOMAIL__ close(MAIL); &leave(1,""); exit 0; #-------------------------------------------------------------------- sub leave { my ($ok,$string) = @_; open(LOG, ">>$logfile") || die "Cannot open log $logfile.\nBailing out"; $logstr = "$mail in $header{newsgroups} ["; if ($ok) { $logstr .= "replied]"; } else { $logstr .= "ignored]"; } $logstr .= " ($string)" if ($string ne ""); print LOG "$logstr\n"; close(LOG); exit 2 if (!$ok); } sub filltemplate { my ($tmplfile,$purge) = @_; open(TMPL, "<$tmplfile") || return (); my @tmpl = ; close(TMPL); @result = (); foreach $line (@tmpl) { $line =~ s/%%newsgroups%%/$header{newsgroups}/g; $line =~ s/%%date%%/$header{date}/g; $line =~ s/%%path%%/$header{path}/g; $line =~ s/%%mydate%%/$now/g; $line =~ s/%%mymail%%/$mymail/g; $line =~ s/%%maintainermail%%/$maintainermail/g; $line =~ s/%%systemname%%/$systemname/g; $line =~ s/%%location%%/$location/g; $line =~ s/%%lines%%/$lines/g; if (($line !~ m/%%/) || (!purge)) { push @result, $line; } } return @result; }