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.9 2004/01/04 18:48:37 noodles Exp $
21 # Reads in our config file. Ignores any command it doesn't understand rather
22 # than having to list all the ones that are of no interest to us.
26 open(CONFIG, "/home/noodles/projects/onak/onak.conf") or
27 die "Can't read config file: $!";
31 # Ignore; comment line.
32 } elsif (/^this_site (.*)/) {
33 $config{'thissite'} = $1;
34 } elsif (/^logfile (.*)/) {
35 $config{'logfile'} = $1;
36 } elsif (/^maintainer_email (.*)/) {
37 $config{'adminemail'} = $1;
38 } elsif (/^mail_delivery_client (.*)/) {
40 } elsif (/^pks_bin_dir (.*)/) {
41 $config{'pks_bin_dir'} = $1;
42 } elsif (/^db_dir (.*)/) {
43 $config{'db_dir'} = $1;
44 } elsif (/^syncsite (.*)/) {
45 push @{$config{'syncsites'}}, $1;
57 # Takes an armored OpenPGP stream and submits it to the keyserver. Returns the
58 # difference between what we just added and what we had before (ie the least
59 # data need to get from what we had to what we have).
63 my (@errors, @mergedata);
65 open(LOCKFILE, '>'.$config{'db_dir'}.'/onak-mail.lck');
66 flock(LOCKFILE, LOCK_EX);
69 open3(\*MERGEIN, \*MERGEOUT, \*MERGEERR,
70 $config{'pks_bin_dir'}."/onak", "-u", "add");
74 @mergedata = <MERGEOUT>;
79 flock(LOCKFILE, LOCK_UN);
85 my ($inheader, %seenby, $subject, $from, $replyto, @body, @syncmail);
93 if (/^Subject:\s*(.*)\s*$/i) {
95 } elsif (/^X-KeyServer-Sent:\s*(.*)\s*$/i) {
97 } elsif (/^From:\s*(.*)\s*$/i) {
99 } elsif (/^Reply-To:\s*(.*)\s*$/i) {
109 if (! defined($replyto)) {
113 # HELP, ADD, INCREMENTAL, VERBOSE INDEX <keyid>, INDEX <keyid>, GET <keyid>,
116 if ($subject =~ /^INCREMENTAL$/i) {
120 my @newupdate = submitupdate(@body);
124 foreach $i (@{$config{'syncsites'}}) {
125 if (! defined($seenby{$i})) {
130 open (LOG, ">>$config{'logfile'}");
131 @time = localtime(time);
133 print LOG sprintf "%02d/%02d/%04d %02d:%02d:%02d",
134 $time[3], $time[4] + 1, $time[5] + 1900,
135 $time[2], $time[1], $time[0];
136 print LOG "] onak-mail[$$]: Syncing with $count sites.\n";
139 if ((! defined($newupdate[0])) || $newupdate[0] eq '') {
140 open (LOG, ">>$config{'logfile'}");
142 print LOG sprintf "%02d/%02d/%04d %02d:%02d:%02d",
143 $time[3], $time[4] + 1, $time[5] + 1900,
144 $time[2], $time[1], $time[0];
145 print LOG "] onak-mail[$$]: Nothing to sync.\n";
151 open(MAIL, "|$config{mta}");
152 print MAIL "From: $config{adminemail}\n";
154 foreach $i (@{$config{'syncsites'}}) {
155 if (! defined($seenby{$i})) {
164 print MAIL "Subject: incremental\n";
165 foreach $site (keys %seenby) {
166 print MAIL "X-KeyServer-Sent: $site\n";
168 print MAIL "X-KeyServer-Sent: $config{thissite}\n";
169 print MAIL "Precedence: list\n";
170 print MAIL "MIME-Version: 1.0\n";
171 print MAIL "Content-Type: application/pgp-keys\n";
173 print MAIL @newupdate;
176 } elsif ($subject =~ /^(VERBOSE )?INDEX (.*)$/i) {
177 my (@indexdata, $command);
184 open3(\*INDEXIN, \*INDEXOUT, \*INDEXERR,
185 $config{'pks_bin_dir'}."/onak", $command, "$2");
187 @indexdata = <INDEXOUT>;
191 open(MAIL, "|$config{mta}");
192 print MAIL "From: $config{adminemail}\n";
193 print MAIL "To: $replyto\n";
194 print MAIL "Subject: Reply to INDEX $2\n";
195 print MAIL "Precedence: list\n";
196 print MAIL "MIME-Version: 1.0\n";
197 print MAIL "Content-Type: text/plain\n";
199 print MAIL "Below follows the reply to your recent keyserver query:\n";
201 print MAIL @indexdata;