cscvs to tla changeset 3
[onak.git] / onak-mail.pl
1 #!/usr/bin/perl -w
2
3 #
4 # onak-mail.pl - Mail processing interface for onak, an OpenPGP Keyserver.
5 #
6 # Written by Jonathan McDowell <noodles@earth.li>
7 # Copyright 2002 Project Purple
8 # Released under the GPL.
9 #
10
11 use strict;
12 use IPC::Open3;
13
14 #
15 # submitupdate
16 #
17 # Takes an armored OpenPGP stream and submits it to the keyserver. Returns the
18 # difference between what we just added and what we had before (ie the least
19 # data need to get from what we had to what we have).
20 #
21 sub submitupdate {
22         my @data = @_;
23         my (@errors, @mergedata);
24
25         open3(\*MERGEIN, \*MERGEOUT, \*MERGEERR, "/home/noodles/onak-0.0.3/onak", "add");
26
27         print MERGEIN @data;
28         close MERGEIN;
29         @errors = <MERGEERR>;
30         @mergedata = <MERGEOUT>;
31
32         open (LOG, ">>/home/noodles/onak-0.0.3/keyadd.log");
33         print LOG @errors;
34         close LOG;
35
36         return @mergedata;
37 }
38
39 my ($inheader, %syncsites, $subject, $from, $replyto, @body, @syncmail);
40
41 $inheader = 1;
42 $subject = "";
43
44 while (<>) {
45         if ($inheader) {
46                 if (/^Subject:\s*(.*)\s*$/i) {
47                         $subject = $1;
48                 } elsif (/^X-KeyServer-Sent:\s*(.*)\s*$/i) {
49                         $syncsites{$1} = 1;
50                 } elsif (/^From:\s*(.*)\s*$/i) {
51                         $from = $1;
52                 } elsif (/^Reply-To:\s*(.*)\s*$/i) {
53                         $replyto = $1;
54                 } elsif (/^$/) {
55                         $inheader = 0;
56                 }
57         }
58         if (!$inheader) {
59                 push @body, $_;
60         }
61 }
62
63 # HELP, ADD, INCREMENTAL, VERBOSE INDEX <keyid>, INDEX <keyid>, GET <keyid>,
64 # LAST <days>
65
66 if ($subject =~ /^INCREMENTAL$/i) {
67         submitupdate(@body);
68 }