procmail
[Top] [All Lists]

Re: Problem with Pipe

1996-01-29 10:28:32
On Mon, 29 Jan 1996, Philip Guenther wrote:

Can you include the approve script that calls procmail?  That's where
the problem is.

Yes, but I don't think that script calls procmail, it is simply called by 
my recipe.  I am assuming that this problem has something to do with 
either my system configuration, or my system's procmail configuration.  
This recipe setup will run on other systems.

Anyway, here's the majordomo approve script.

------------------------------------------------------------------
#!/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(_at_)somewhere" address, and that postings for "List" should
# be sent to "List(_at_)somewhere".
#
# Here's an example of what a .majordomo file should look like:
# 
#       this-list       passwd1         Majordomo(_at_)This(_dot_)COM
#       other-list      passwd2         Majordomo(_at_)Other(_dot_)GOV
# 
# If, for instance, /tmp/request contains a standard request from Majordomo
# to a list manager, such as:
#
#       From: Majordomo(_at_)This(_dot_)COM
#       To: this-list-approval(_at_)This(_dot_)COM
#
#       User(_at_)Fubar(_dot_)COM (Joe User) requests you approve the following:
#
#               subscribe this-list User(_at_)Fubar(_dot_)COM (Joe User)
#
#       If you approve, send a line such as the following to 
Majordomo(_at_)This(_dot_)COM:
#
#               approve PASSWD subscribe this-list User(_at_)Fubar(_dot_)COM 
(Joe User)
# 
# Then, if you run "approve /tmp/request" or "approve < /tmp/request", the
# following message will be sent to Majordomo(_at_)This(_dot_)COM:
#
#       To: Majordomo(_at_)This(_dot_)COM
#
#       approve passwd1 subscribe this-list User(_at_)Fubar(_dot_)COM (Joe User)
# 
# Brent Chapman                                   Great Circle Associates
# Brent(_at_)GreatCircle(_dot_)COM                           1057 West Dana 
Street
# +1 415 962 0841                                 Mountain View, CA  94041

# $Source: /sources/cvsrepos/majordomo/approve,v $
# $Revision: 1.4.4.2 $
# $Date: 1995/01/02 00:14:29 $
# $Author: rouilj $
# $State: Exp $
#
# $Locker:  $

require "getopts.pl";

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

if (!defined($opt_f)) {
    $opt_f = "$ENV{HOME}/.majordomo";
}

&read_config();

# 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);
}

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(_at_)$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, "| /usr/ucb/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 $_;
    }
    print MAIL "\n";
    print MAIL "_" x 72, "\n";
    print MAIL "To unsubscribe send UNSUBSCRIBE THEOLOGY to 
majordomo\(_at_)iclnet(_dot_)org\n";
    print MAIL "Web Page: http://www.whytel.com/users/dgreen/theolist.htm\n";;
    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(_at_)site
        split(/@/, $m);
        $s = $_[1];     $s =~ tr/A-Z/a-z/;      # site

        $passwd{$l} = $p;
        $passwd{"$l(_at_)$m"} = $p;
        $passwd{"$l(_at_)$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);
}


I appreciate your time.

---
Derrick Green
eusdegr(_at_)wser(_dot_)ericsson(_dot_)se
Richardson, Texas

<Prev in Thread] Current Thread [Next in Thread>