4 # onak-mail.pl - Mail processing interface for onak, an OpenPGP Keyserver.
6 # Written by Jonathan McDowell <noodles@earth.li>
7 # Copyright 2002 Project Purple
8 # Released under the GPL.
10 # $Id: onak-mail.pl,v 1.7 2003/09/28 17:25:40 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 (/^syncsite (.*)/) {
43 push @{$config{'syncsites'}}, $1;
55 # Takes an armored OpenPGP stream and submits it to the keyserver. Returns the
56 # difference between what we just added and what we had before (ie the least
57 # data need to get from what we had to what we have).
61 my (@errors, @mergedata);
63 open3(\*MERGEIN, \*MERGEOUT, \*MERGEERR,
64 $config{'pks_bin_dir'}."/onak", "-u", "add");
68 @mergedata = <MERGEOUT>;
74 my ($inheader, %seenby, $subject, $from, $replyto, @body, @syncmail);
82 if (/^Subject:\s*(.*)\s*$/i) {
84 } elsif (/^X-KeyServer-Sent:\s*(.*)\s*$/i) {
86 } elsif (/^From:\s*(.*)\s*$/i) {
88 } elsif (/^Reply-To:\s*(.*)\s*$/i) {
99 # HELP, ADD, INCREMENTAL, VERBOSE INDEX <keyid>, INDEX <keyid>, GET <keyid>,
102 if ($subject =~ /^INCREMENTAL$/i) {
106 my @newupdate = submitupdate(@body);
110 foreach $i (@{$config{'syncsites'}}) {
111 if (! defined($seenby{$i})) {
116 open (LOG, ">>$config{'logfile'}");
117 @time = localtime(time);
119 print LOG sprintf "%02d/%02d/%04d %02d:%02d:%02d",
120 $time[3], $time[4] + 1, $time[5] + 1900,
121 $time[2], $time[1], $time[0];
122 print LOG "] onak-mail[$$]: Syncing with $count sites.\n";
125 if ((! defined($newupdate[0])) || $newupdate[0] eq '') {
126 open (LOG, ">>$config{'logfile'}");
128 print LOG sprintf "%02d/%02d/%04d %02d:%02d:%02d",
129 $time[3], $time[4] + 1, $time[5] + 1900,
130 $time[2], $time[1], $time[0];
131 print LOG "] onak-mail[$$]: Nothing to sync.\n";
137 open(MAIL, "|$config{mta}");
138 print MAIL "From: $config{adminemail}\n";
140 foreach $i (@{$config{'syncsites'}}) {
141 if (! defined($seenby{$i})) {
150 print MAIL "Subject: incremental\n";
151 foreach $site (keys %seenby) {
152 print MAIL "X-KeyServer-Sent: $site\n";
154 print MAIL "X-KeyServer-Sent: $config{thissite}\n";
155 print MAIL "Precedence: list\n";
156 print MAIL "MIME-Version: 1.0\n";
157 print MAIL "Content-Type: application/pgp-keys\n";