/[docman]/contrib/email2htusers.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /contrib/email2htusers.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Mon Mar 5 09:46:29 2001 UTC (23 years, 1 month ago) by dpavlin
Branch: MAIN
CVS Tags: r1_5
File MIME type: text/plain
reads e-mail addresses from stdin and dumps .htusers like output on
stdout using auth_pop3

1 dpavlin 1.1 #!/usr/bin/perl -w
2    
3     # 2001-03-05 Dobrica Pavlinusic <dpavlin@rot13.org>
4     #
5     # reads e-mail addresses from stdin and dump format for .htusers on stdout
6     # which will use auth_pop3 for user authentification
7     #
8     # This tool is good for batch import and it will do it's best to resolve
9     # all sendmail related output from expn. However, it's not tested on
10     # other mailers.
11     #
12     # usage:
13     #
14     # cat emails.txt | email2htusers.pl [remote.smtp.server] [smtp_port] >> .htusers
15     #
16    
17     use strict;
18     use Socket;
19    
20     my $debug=0;
21    
22     my ($remote,$port, $iaddr, $paddr, $proto, $line);
23    
24     $remote = shift || 'intranet.pliva.hr';
25     $port = shift || 25;
26    
27     print "# using remote $remote port $port\n" if ($debug);
28    
29     if ($port =~ /\D/) { $port = getservbyname($port, 'tcp') }
30     die "No port" unless $port;
31     $iaddr = inet_aton($remote) || die "no host: $remote";
32     $paddr = sockaddr_in($port, $iaddr);
33    
34     $proto = getprotobyname('tcp');
35     socket(SOCK, PF_INET, SOCK_STREAM, $proto) || die "socket: $!";
36     connect(SOCK, $paddr) || die "connect: $!";
37     select(SOCK); $|=1;
38     select(STDOUT); $|=1;
39    
40     my $hello=<SOCK>; # hello
41    
42     my %tested;
43    
44     sub try_expn {
45     my $login=$_[0];
46     if (! defined($tested{$login})) {
47     $tested{$login}++;
48     print SOCK "expn $login\n";
49     my $response=<SOCK>;
50     while ($response =~ /^2\d\d-(.+)/) {
51     my $rest=$1;
52     print "# $response\n" if ($debug);
53     if ($rest=~/[\d\. ]+([^<]+) <\\*(\w+)\@$remote>/) {
54     print "# $2:$1:auth_pop3:$2\@$remote\n";
55     }
56     $response=<SOCK>;
57     };
58     print "# $response\n" if ($debug);
59     if ($response =~ /^2\d\d (.+)/) {
60     my $rest=$1;
61     if ($rest=~/[\d\. ]+([^<]+) <\\*(\w+)\@$remote>/) {
62     print "$2:$1:auth_pop3:$2\@$remote\n";
63     }
64     } else {
65     print "# can't add e-mail address $login\n";
66     }
67     return 0;
68     }
69     }
70    
71     while(<>) {
72     chomp;
73     next if (/^#/ || /^$/);
74     try_expn($_);
75     }
76    
77     close (SOCK) || die "close: $!";
78     exit;

  ViewVC Help
Powered by ViewVC 1.1.26