#!/usr/bin/perl #!/usr/local/bin/perl #unsubscribe (c) Kim Holburn 2001 #you can use this script and redistribute it. #usage unsubscribe file [file [file ...]] #will examine a mailbox file for email list messages #and attempt to unsubscribe the user from those lists #written around 1995 so there are probably lots of enhancements possible #meant to be run by a sysadmin # # Download from : # http://www.holburn.net/software/unsubscribe.perl.txt # # released under the GPL v2 http://www.gnu.org/copyleft/gpl.html foreach $file (@ARGV) { %addresses=(); $user=$file; $user =~ s@^.*/@@; if ($file =~ /^\./) { print "skipping wrong type of file \"$file\"\n"; next; } if ($file =~ /\.lock/) { print "skipping lock file \"$file\"\n"; next; } if ($file =~ /\./) { print "skipping wrong type of file \"$file\"\n"; next; } $user =~ s/^\.//; $user =~ s/\..*$//; if (!open (MYFILE, "<$file" )) { print "Couldn't open file \"$file\"\n"; next; } print "--------------------------opening file \"$file\"\n"; while () { if (/(\bowner-[-\w.]+@)|([-\w.]+-owner@)/i) { chop; if (/\bowner-[-\w.]+@/) { s/^.*\bowner-([-\w.]+@[\w.]+)\b.*$/\1/i; } else { s/(^|^.*[^-\w.])([-\w.]+)-owner(@[\w.]+)\b.*$/\2\3/i; } tr/A-Z/a-z/; if (/[^a-z0-9@.-]/) { next; } if (!defined ($addresses{$_})) { $addresses{$_}=""; } } } close MYFILE; while (($key,$value)=each %addresses) { print "a{$key}=$value\n"; } if (! keys %addresses ) { print "no listservers\n"; next; } if (! open (MYFILE, "<$file" )) { print "Couldn't open file \"$file\"\n"; next; } print "looking for listserver addresses\n"; while () { foreach $address (keys %addresses) { $host=$address; $host =~ s/^.*@//; if (/(listserv|listproc|majordomo)@$host/i) { $addresses{$address}=$1; # print "found 1 = \"$1\"\n"; } } } close MYFILE; while (($key,$value)=each %addresses) { $host=$key; $host=~s/^.*@//; $list=$key; $list=~s/@.*$//; # print "$value@$host key=\"$key\" list=\"$list\" \n"; if ($value eq '') { $address="listserv@$host,listproc@$host,majordomo@$host"; } else { $address="$value@$host"; } print "address=\"$address\"\n"; print "unsubscribe $list\n"; next; # open (SEND, "|su $user -c \"/usr/ucb/mail $address\"")|| # { print "Couldn't opem mailer for file \"$file\"\n"; next; } # print SEND "unsubscribe $list\n" ; # close SEND; # open (SEND, "|/usr/ucb/mail -s \"unsubscribed $list\" $user")|| # { print "Couldn't opem mailer for file \"$file\"\n"; next; } # print SEND "You have been automatically unsubscribed from the \n" ; # print SEND "mailing list $list@$host .\n" ; # print SEND "to resubscribe follow the original directions or \n" ; # if ($value eq '') { # print SEND "send a message to the address $address \n" ; # } else { # print SEND "send a message to the appropriate one of the addresses :\n" ; # print SEND "$address \n" ; # } # print SEND "with no subject, no signature and a single line\n" ; # print SEND "subscribe (your name)\n" ; # print SEND "\n" ; # close SEND; } }