home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!decwrl!deccrl!news.crl.dec.com!quabbin!rwk
- From: rwk@crl.dec.com (Bob Kerns)
- Subject: Re: Sendmail and perl
- In-Reply-To: drich@sandman.lerc.nasa.gov's message of Wed, 5 Aug 1992 15:14:24 GMT
- Message-ID: <RWK.92Aug18170427@taunton.crl.dec.com>
- Lines: 84
- Sender: news@crl.dec.com (USENET News System)
- Organization: Cambridge Research Lab, Digital Equipment Corp.
- References: <1992Aug5.151424.6313@eagle.lerc.nasa.gov>
- Date: Tue, 18 Aug 1992 08:04:32 GMT
-
- In article <1992Aug5.151424.6313@eagle.lerc.nasa.gov> drich@sandman.lerc.nasa.gov (Daniel Rich) writes:
-
- From: drich@sandman.lerc.nasa.gov (Daniel Rich)
- Date: Wed, 5 Aug 1992 15:14:24 GMT
-
- I am in need of a perl script that will talk to sendmail (allow me to
- send commands to the sendmail port on a specified machine, and process
- the output). While I could write this myself, I assume that this is
- something that people have done before. What is available out there?
-
- Here's one I find very useful: It expands mailing lists. I use this
- to help figure out what the right place to send to is.
-
- ----------------------------------------------------------------
- #!/usr/local/bin/perl
-
- require 'chat2.pl';
-
- select((select(STDOUT),$|=1)[0]);
-
- (@ARGV[0] eq '-recursive') && ($recursive = shift(@ARGV));
-
- (@ARGV >= 2) || die("Usage: $0 [-recursive] host address ...\n");
-
- &expn(@ARGV);
-
- %BUCKETS=();
-
- sub address
- { local($old_host,$old_user,$address) = @_;
- local($user, $host) = ($address =~/<(.+)@(.+)>/);
- $host=~tr/a-z/A-Z/;
- print " $address\n";
- if ($host=~/^[^.]+$/) {
- $host .= "." . $old_host;
- }
- if ($host && (($host ne $old_host) || ($user ne $old_user))) {
- if (!($user=~/^".*"$/)) {
- local($bucket) = $BUCKETS{$host};
- $BUCKETS{$host} = ($bucket ? ($bucket . "\n" . $user) : $user);
- }
- }
- }
-
- sub expn
- { local($host,@addresses) = @_;
- local($addresses);
- $host=~tr/a-z/A-Z/;
- while (@addresses) {
- print("Expanding users on $host.\n");
- if (!&chat'open_port($host,25) # '
- ) {
- print("Could not connect to $host\n");
- } else {
- 1 while &chat'expect(20,
- '^(220-.*)\r?\n\r?','1',
- '^(220 .*)\r?\n\r?','0',
- '^(.*)\n\r?','warn("No header: $1\n");0'
- ); # '
- for $user (@addresses) {
- print(" $user:\n");
- &chat'print("expn $user\r\n"); # '
- while (&chat'expect(40,
- '^250-(.*[^\r])\r?\n\r?',"&address('$host','$user',\$1); 1",
- '^250 (.*[^\r])\r?\n\r?',"&address('$host','$user',\$1); 0",
- '^550(.*)\n\r?', q!print "no such user as $user: $1\n"; 0!,
- '^5\d\d(.*)\n\r?', q!print "Error: $1\n"; 0!,
- TIMEOUT,'print("$host: timeout\n"); 0',
- '(.*)\n','print "Unknown response: $1\n";0'
- ) # '
- ) {1;}
- }
- &chat'close(); # '
- }
- shift(@addresses);
- if ($recursive) {
- ($host,$addresses)=(%BUCKETS)[0,1];
- delete $BUCKETS{$host};
- push(@addresses,split("\n",$addresses));
- } else {
- next;
- }
- }
- }
-