I have found that it is important to "clean house" every so often, and
this includes mailing lists. One way is to automatically remind
everyone on a mailing list that they are "on" it; this has two
functions:
* it keeps everyone periodically informed as to which mailing lists
they are on, at least from a given list server
* it automatically "cleans" the list of dead email addresses, since
the bounced email will trigger an "autobounce" (if you've setup the
"list-owner" alias correctly).
The following is my contribution to majordomo to perform this function.
It is designed to be run via "cron" periodically, say once a year. It
will collect all of the users in all of Majordomo's mailing lists, and
send one message to each user; the mail to each user will contain the
particular lists of which the user is a member and an explanatory note
with some small instructions.
# Run on Jan 2 each year to let all users know which lists they're on
0 3 2 1 * /usr/home/majordomo/remind all
The script can also be run manually, if you wish to verify the existence
of a particular user:
cd ~majordomo
remind aks@hub
The script has a -v (verbose) option and a -vv (very verbose) option,
for those who like to watch things work.
Suggestions or comments welcome.
Enjoy
+-------------------------+-----------------------------------------+
| Alan Stebbens | University of California, Santa Barbara |
| Email: aks@hub.ucsb.edu | Center for Computational Sciences |
| CCSE: (805) 893-3221 | & Engineering (CCSE) |
| Voice: (805) 893-8135 | 3107 Engineering I |
| Fax: (805) 893-8121 | Santa Barbara, CA 93106 |
+-------------------------+-----------------------------------------+
============================= cut here ===================================
#!/usr/local/bin/perl
# remind [-d] [-v[v]] [all | emailaddr ...]
#
# Remind the named users, or all of them, of which lists they
# are participating.
#
# This script is intended to be run by "cron", say once a year, to
# remind users that they are participating in an automated mailing list.
#
# If a user's email address is no longer valid, the rejected mail should
# "auto-bounce" (if setup correctly), and the list should be "cleaner".
#
# Written by Alan Stebbens <aks@hub.ucsb.edu>, June 1994.
# $Source$
# $Revision$
# $Date$
# $Author$
# $State$
#
# $Locker: $
# set our path explicitly
# PATH it is set in the wrapper, so there is no need to set it here.
#$ENV{'PATH'} = "/bin:/usr/bin:/usr/ucb";
# What shall we use for temporary files?
$tmp = "/tmp/majordomo.$$";
# Before doing anything else tell the world I am majordomo
# The mj_ prefix is reserved for tools that are part of majordomo proper.
$main'program_name = 'mj_remind';
# Read and execute the .cf file
$cf = $ENV{"MAJORDOMO_CF"} || "/etc/majordomo.cf";
while ($ARGV[0]) { # parse for config file or default list
if ($ARGV[0] eq "-C") {
$cf = $ARGV[1];
shift(@ARGV);
} elsif ($ARGV[0] eq 'all') {
$all_users++;
} elsif ($ARGV[0] eq '-vv') {
$verbose += 2;
} elsif ($ARGV[0] eq '-v') {
$verbose++;
} elsif ($ARGV[0] eq '-d') {
$debug++;
} else {
last;
}
shift(@ARGV);
}
if (! -r $cf) {
die("$cf not readable; stopped");
}
eval(`cat $cf`) || die "eval of majordomo.cf failed $@";
# Go to the home directory specified by the .cf file
chdir("$homedir");
# All these should be in the standard PERL library
unshift(@INC, $homedir);
require "ctime.pl"; # To get MoY definitions for month abbrevs
require "majordomo_version.pl"; # What version of Majordomo is this?
require "majordomo.pl"; # all sorts of general-purpose Majordomo subs
require "shlock.pl"; # NNTP-style file locking
require "config_parse.pl"; # functions to parse the config files
# Here's where the fun begins...
$| = 1;
# check to see if the cf file is valid
die("listdir not defined. Is majordomo.cf being included correctly?")
if !defined($listdir);
# who do we send the body to if we step on a landmine?
&set_abort_addr($whoami_owner);
# who do sendmail messages appear to come from, by default?
&set_mail_from($whoami);
&set_mail_sender($whoami_owner);
if (defined($mailer)) { &set_mailer($mailer); }
# set our hostname (for use in log messages).
$hostname = &chop_nl(`hostname`);
# Collect the lists and remember them by user email addresses.
sub collect_lists {
%Lists = ();
print "Scanning lists..\n" if $verbose;
# scan through all the lists
while (<${listdir}/*>) {
s,^.*/,,; # strip off the leading path
/[^-_0-9a-zA-Z]/ && next; # skip non-list files (*.info, etc.)
$list = $_;
print "Scanning list $list..\n" if $verbose > 1 && !$debug;
# Get the list configuration for the description
&get_config($listdir, $list) if !&cf_ck_bool($list, '', 1);
open(LIST, "$listdir/$list") || &abort("Can't open list $listdir/$_");
while (<LIST>) {
$_ = &chop_nl($_);
($addr) = &ParseAddrs($_); # get only the address part
if (defined($Lists{$addr})) {
$Lists{$addr} .= ' '.$list;
} else {
$Lists{$addr} = $list;
}
}
close(LIST);
}
}
# Remind a user of all the lists they are on.
#
# &remind_user($email_addr)
sub remind_user {
local($subscriber) = shift;
return if $Done{$subscriber};
$Done{$subscriber}++;
print "Reminding $subscriber..\n" if $verbose;
unless ($debug) {
# Set up the sendmail process to send mail to the list
&set_mail_sender($whoami);
&sendmail(MSG, $subscriber, "List membership reminder");
&set_mail_sender($whoami_owner);
} else {
open(MSG,">&STDOUT");
$| = 1;
}
print MSG <<"EOM";
This message is a reminder that you are subscribed to the mailing lists
given below. You do not have to do anything to remain subscribed.
EOM
@lists = split(' ',$Lists{$subscriber});
foreach $list (@lists) {
print "\t$list\n" if $verbose > 1;
printf MSG " %-20s %-56s\n", $list, $config_opts{$list, 'description'};
}
if ( $majordomo_request ) {
print MSG <<"EOM";
If you ever want to remove yourself from any mailing list,
send the following command in email to "LIST-request@$whereami"
where LIST is the name of the list from which you wish to remove
yourself.
unsubscribe
Or you can send mail to "$whoami" with the following command
EOM
} else {
print MSG <<"EOM";
If you ever want to remove yourself from any mailing list,
you can send mail to "$whoami" with the following command
EOM
}
print MSG <<"EOM";
in the body of your email message:
unsubscribe LIST $subscriber
where LIST is the name of the list from which you wish to be removed.
EOM
print MSG <<"EOM";
If you wish additional information on participating with mailing lists
managed by Majordomo, please send a message containing the command:
help
to $whoami.
EOM
# close (and thereby send) the announcement message to the list
close(MSG);
}
$| = 1;
# each arg is a user to remind or 'all'
@ARGV = keys %Lists if $all_users && !@ARGV;
&collect_lists;
@users = keys %Lists;
while ($user = shift(@ARGV)) {
if (grep($user eq $_,@users)) { # check for exact match first
&remind_user($user);
} elsif ((@subs = grep(/^$user\@/,@users)) ||
(@subs = grep(/$user/,@users))) {
if ($#subs == $[) { # exactly one match
&remind_user($subs[0]); # remind him
} else {
unshift(@ARGV,@subs); # and loop back to do these
}
} else {
print STDERR "No such user to remind: $user\n";
}
}
print "Done.\n" if $verbose;
exit;
|
|