Great Circle Associates Majordomo-Workers
(November 1996)
 

Indexed By Date: [Previous] [Next] Indexed By Thread: [Previous] [Next]

Subject: approve perl script - addition suggestion
From: molivier @ senor . engr . sgi . com (Michael Olivier)
Date: Fri, 29 Nov 1996 23:39:19 -0800 (PST)
To: Majordomo-Workers @ GreatCircle . COM

Hi folks,

A while back I grabbed a copy of your 'approve' script, and it didn't
work on my SGI system. Tonight I figured out why - it was running
'mail' instead of 'Mail'... which for SGI system (perl4 or 5.003)
caused an error "null names not allowed" from mail. The majordomo
server is on someone else's machine (with a nifty web interface to all
the lists), running MD version 1.92.

So I made that change, and also added a feature to set aside my
.signature file as .signature.approve, so that Mail doesn't see it and
tack it onto every msg. It's generalized for anyone's home
dir. Although it seems like 'mail' ignores sig's, right? Anyway seemed
like I had to use Mail, so... the .sig feature is demarked in the
script below with my initials, 'mvo'.

Just thought I'd drop you a quick line.

Michael

--

#!/usr/local/bin/perl

# Approve Majordomo requests or "resend" bounces.
#
# Given arguments, approves the requests in those files;
# given no arguments, reads standard input.
#
# If the "Subject: " line is "APPROVE <list>", the message is treated as
# a request for approval from Majordomo.  An appropriate command is generated
# and mailed to Majordomo to approve the request.
#
# If the "Subject: " line is "BOUNCE <list>: <reason>", the message is treated
# as a posting rejected by "resend" for some reason, and is reformatted with
# appropriate "Approved:" headers to cause it to succeed, then resubmitted
# for posting.
#
# Assumes that the "approve" password for each list is the same as the
# "approval" password used by "resend", and that this password is stored
# in a file called ".majordomo" in the user's home directory, in the
# following format:
# 
# 	List		Password	Majordomo-Address
# 
# Assumes that the "Majordomo-Address" field is an Internet-style 
# "something@somewhere" address, and that postings for "List" should
# be sent to "List@somewhere".
#
# Here's an example of what a .majordomo file should look like:
# 
# 	this-list	passwd1		Majordomo@This.COM
# 	other-list	passwd2		Majordomo@Other.GOV
# 
# If, for instance, /tmp/request contains a standard request from Majordomo
# to a list manager, such as:
#
#	From: Majordomo@This.COM
#	To: this-list-approval@This.COM
#
#	User@Fubar.COM (Joe User) requests you approve the following:
#
#		subscribe this-list User@Fubar.COM (Joe User)
#
#	If you approve, send a line such as the following to Majordomo@This.COM:
#
#		approve PASSWD subscribe this-list User@Fubar.COM (Joe User)
# 
# Then, if you run "approve /tmp/request" or "approve < /tmp/request", the
# following message will be sent to Majordomo@This.COM:
#
#	To: Majordomo@This.COM
#
# 	approve passwd1 subscribe this-list User@Fubar.COM (Joe User)
# 
# Brent Chapman                                   Great Circle Associates
# Brent@GreatCircle.COM                           1057 West Dana Street
# +1 415 962 0841                                 Mountain View, CA  94041

# $Source: /sources/cvsrepos/majordomo/approve,v $
# $Revision: 1.4 $
# $Date: 1994/03/14 18:13:57 $
# $Author: rouilj $
# $State: Exp $
#
# $Locker:  $

#
# mvo modifications
#
#   - changed 'mail' to 'Mail' due to "null names not allowed" error
#   - now move .signature file aside during execution to avoid my sig
#

require "getopts.pl";

&Getopts("df:") ||
    die("USAGE: approve [-f <config-file>] [-d] [<file> ...]\nStopped");

if (!defined($opt_f)) {
    $opt_f = <~/.majordomo>;
}

&read_config();

# mvo - move .signature file aside
$home = $ENV{'HOME'} || $ENV{'LOGDIR'} ||
    (getpwuid($<))[7] || "";
if (!$home) { warn "You're homeless!\n"; }
else { system("mv $home/.signature $home/.signature.approve"); }

# Read the headers.  Look at the "Reply-To:" header to figure out where to
# respond to.  Look at the "Subject:" header to figure out if this is an
# APPROVE or a BOUNCE request.

if ($#ARGV >= $[) {
    foreach $file (@ARGV) {
	open(FILE, $file) || (warn("can't open \"$file\"; skipping"), next);
	&process_file(FILE);
	close(FILE);
    }
} else {
    &process_file(STDIN);
}

# mvo - move .signature file back
if ($home) {
  system("mv $home/.signature.approve $home/.signature");
}

exit(0);

sub process_file {
    local($FILE) = shift;
    local($reply_to);
    local($subject);
    local($request);
    local($list);

    while (<$FILE>) {
	s/\n$//;
	if (/^reply-to:/i) {
	    s/^\S*:\s+//;
	    $reply_to = $_;
	    $reply_to =~ tr/A-Z/a-z/;
	    next;
	}
	if (/^subject:/i) {
	    s/^\S*:\s+//;
	    $subject = $_;
	    $subject =~ tr/A-Z/a-z/;
	    ($request, $list) = split(/\s/, $subject, 2);
	    $list =~ s/:.*//;
	    next;
	}
	if (/^$/) {
	    last;
	}
    }

    # we've read the headers, so we should know now if this is an "APPROVE"
    # or a "BOUNCE" that we're processing.

    if ($request eq "approve") { &process_approve($FILE); }
    elsif ($request eq "bounce") { &process_bounce($FILE); }
    else {
	warn("unknown request type '$request' in file '$file'; skipping");
	next;
    }
}

sub process_approve {
    local($FILE) = shift;
    while (<$FILE>) {
	if ((/^\tsubscribe\s/) || (/^\tunsubscribe\s/)) {
	    if (!defined($reply_to)) {
		warn("No \"Reply-To:\"; exiting");
		exit(1);;
	    }
	    s/^\t//;
	    split;
	    $list = $_[1];
	    $list =~ tr/A-Z/a-z/;
	    $passwd = $passwd{"$list\@$reply_to"};
	    if (! $passwd) {
		warn("no password for list $list; skipping \"$_\"");
		next;
	    }
	    if (defined($opt_d)) {
		open(MAIL, ">&STDOUT");
		print MAIL "-" x 20, "\n";
		print MAIL "To: $reply_to\n\n";
	    } else {
		open(MAIL, "|Mail -s \"\" $reply_to") ||
		    die ("open(\"|Mail ...\"): $!");
	    }
	    print MAIL "approve $passwd $_";
	    close(MAIL);
	    last;
	}
    }
}

sub process_bounce {
    local($FILE) = shift;
    local ($from_skipped);

    # we've already skipped the header, so set up to approve the message

    # first, figure out where to send it
    if (defined($reply_to)) {
	# if there's a "Reply-To:" field set, use it.
	$post_to = $reply_to;
    } elsif ($list =~ /@/) {
	# if the list name already appears fully qualified, use it
	$post_to = $list;
    } else {
	# Well, can we figure it out?
	if ($site{$list} eq "MULTIPLE") {
	    warn("Can't distinguish between multiple lists named '$list'\nSkipping '$file'");
	    return;
	} else {
	    $post_to = $list . "\@" . $site{$list};
	}
    }

    warn "Can't find password for list $list, Stopped" , return
		if !defined($passwd{$list});

    if (defined($opt_d)) {
	open(MAIL, ">&STDOUT");
	print MAIL "-" x 20, "\n";
	print MAIL "To: $post_to\n\n";
    } else {
	open(MAIL, "|Mail -s \"\" $post_to") || die("open(\"|Mail ...\"): $!");
    }

    print MAIL "Approved: $passwd{$list}\n\n";

    while (<$FILE>) {
	if (/^>?From / && ! defined($from_skipped)) {
	    # Skip any initial "From " or ">From " line
	    $from_skipped = 1;
	    next;
	}
	print MAIL $_;
    }
    close(MAIL);
}

sub read_config {
    local($l);
    local($p);
    local($m);
    local($s);
    open(CONF, $opt_f) || die("open(CONF, \"$opt_f\"): $!");
    while (<CONF>) {
	s/\n$//;
	s/#.*//;
	if (/^$/) { next; }
	split;
	$l = $_[0];	$l =~ tr/A-Z/a-z/;	# list
	$p = $_[1];				# password
	$m = $_[2];	$m =~ tr/A-Z/a-z/;	# majordomo@site
	split(/@/, $m);
	$s = $_[1];	$s =~ tr/A-Z/a-z/;	# site

	$passwd{$l} = $p;
	$passwd{"$l\@$m"} = $p;
	$passwd{"$l\@$s"} = $p;
	if (defined($site{$l})) {
	    # if it's already defined, there's more than one list by this name
	    $site{$l} = "MULTIPLE";
	} else {
	    $site{$l} = $s;
	}
    }
    close(CONF);
}

-- 
Michael Olivier, molivier@sgi.com, http://reality.sgi.com/molivier/


Follow-Ups:
Indexed By Date Previous: Resend man page
From: "Shane P. McCarron" <ahby@themacs.com>
Next: Re: approve perl script - addition suggestion
From: Jason L Tibbitts III <tibbs@hpc.uh.edu>
Indexed By Thread Previous: Resend man page
From: "Shane P. McCarron" <ahby@themacs.com>
Next: Re: approve perl script - addition suggestion
From: Jason L Tibbitts III <tibbs@hpc.uh.edu>

Google
 
Search Internet Search www.greatcircle.com