3 # onak-mail.pl - Mail processing interface for onak, an OpenPGP Keyserver.
5 # Written by Jonathan McDowell <noodles@earth.li>
6 # Copyright 2002 Project Purple
7 # Released under the GPL.
9 # $Id: onak-mail.pl,v 1.8 2003/10/11 22:17:17 noodles Exp $
20 # Reads in our config file. Ignores any command it doesn't understand rather
21 # than having to list all the ones that are of no interest to us.
25 open(CONFIG, "/home/noodles/projects/onak/onak.conf") or
26 die "Can't read config file: $!";
30 # Ignore; comment line.
31 } elsif (/^this_site (.*)/) {
32 $config{'thissite'} = $1;
33 } elsif (/^logfile (.*)/) {
34 $config{'logfile'} = $1;
35 } elsif (/^maintainer_email (.*)/) {
36 $config{'adminemail'} = $1;
37 } elsif (/^mail_delivery_client (.*)/) {
39 } elsif (/^pks_bin_dir (.*)/) {
40 $config{'pks_bin_dir'} = $1;
41 } elsif (/^syncsite (.*)/) {
42 push @{$config{'syncsites'}}, $1;
54 # Takes an armored OpenPGP stream and submits it to the keyserver. Returns the
55 # difference between what we just added and what we had before (ie the least
56 # data need to get from what we had to what we have).
60 my (@errors, @mergedata);
62 open3(\*MERGEIN, \*MERGEOUT, \*MERGEERR,
63 $config{'pks_bin_dir'}."/onak", "-u", "add");
67 @mergedata = <MERGEOUT>;
75 my ($inheader, %seenby, $subject, $from, $replyto, @body, @syncmail);
83 if (/^Subject:\s*(.*)\s*$/i) {
85 } elsif (/^X-KeyServer-Sent:\s*(.*)\s*$/i) {
87 } elsif (/^From:\s*(.*)\s*$/i) {
89 } elsif (/^Reply-To:\s*(.*)\s*$/i) {
99 if (! defined($replyto)) {
103 # HELP, ADD, INCREMENTAL, VERBOSE INDEX <keyid>, INDEX <keyid>, GET <keyid>,
106 if ($subject =~ /^INCREMENTAL$/i) {
110 my @newupdate = submitupdate(@body);
114 foreach $i (@{$config{'syncsites'}}) {
115 if (! defined($seenby{$i})) {
120 open (LOG, ">>$config{'logfile'}");
121 @time = localtime(time);
123 print LOG sprintf "%02d/%02d/%04d %02d:%02d:%02d",
124 $time[3], $time[4] + 1, $time[5] + 1900,
125 $time[2], $time[1], $time[0];
126 print LOG "] onak-mail[$$]: Syncing with $count sites.\n";
129 if ((! defined($newupdate[0])) || $newupdate[0] eq '') {
130 open (LOG, ">>$config{'logfile'}");
132 print LOG sprintf "%02d/%02d/%04d %02d:%02d:%02d",
133 $time[3], $time[4] + 1, $time[5] + 1900,
134 $time[2], $time[1], $time[0];
135 print LOG "] onak-mail[$$]: Nothing to sync.\n";
141 open(MAIL, "|$config{mta}");
142 print MAIL "From: $config{adminemail}\n";
144 foreach $i (@{$config{'syncsites'}}) {
145 if (! defined($seenby{$i})) {
154 print MAIL "Subject: incremental\n";
155 foreach $site (keys %seenby) {
156 print MAIL "X-KeyServer-Sent: $site\n";
158 print MAIL "X-KeyServer-Sent: $config{thissite}\n";
159 print MAIL "Precedence: list\n";
160 print MAIL "MIME-Version: 1.0\n";
161 print MAIL "Content-Type: application/pgp-keys\n";
163 print MAIL @newupdate;
166 } elsif ($subject =~ /^(VERBOSE )?INDEX (.*)$/i) {
167 my (@indexdata, $command);
174 open3(\*INDEXIN, \*INDEXOUT, \*INDEXERR,
175 $config{'pks_bin_dir'}."/onak", $command, "$2");
177 @indexdata = <INDEXOUT>;
181 open(MAIL, "|$config{mta}");
182 print MAIL "From: $config{adminemail}\n";
183 print MAIL "To: $replyto\n";
184 print MAIL "Subject: Reply to INDEX $2\n";
185 print MAIL "Precedence: list\n";
186 print MAIL "MIME-Version: 1.0\n";
187 print MAIL "Content-Type: text/plain\n";
189 print MAIL "Below follows the reply to your recent keyserver query:\n";
191 print MAIL @indexdata;