cscvs to tla changeset 2
[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.2/keymerge");
26
27         print MERGEIN @data;
28         close MERGEIN;
29         @errors = <MERGEERR>;
30         @mergedata = <MERGEOUT>;
31
32         #print @errors;
33
34         return @mergedata;
35 }
36
37 my ($inheader, %syncsites, $subject, $from, $replyto, @body, @syncmail);
38
39 $inheader = 1;
40 $subject = "";
41
42 while (<>) {
43         if ($inheader) {
44                 if (/^Subject:\s*(.*)\s*$/i) {
45                         $subject = $1;
46                 } elsif (/^X-KeyServer-Sent:\s*(.*)\s*$/i) {
47                         $syncsites{$1} = 1;
48                 } elsif (/^From:\s*(.*)\s*$/i) {
49                         $from = $1;
50                 } elsif (/^Reply-To:\s*(.*)\s*$/i) {
51                         $replyto = $1;
52                 } elsif (/^$/) {
53                         $inheader = 0;
54                 }
55         }
56         if (!$inheader) {
57                 push @body, $_;
58         }
59 }
60
61 # HELP, ADD, INCREMENTAL, VERBOSE INDEX <keyid>, INDEX <keyid>, GET <keyid>,
62 # LAST <days>
63
64 if ($subject =~ /^INCREMENTAL$/i) {
65         submitupdate(@body);
66 }