]> the.earth.li Git - onak.git/blobdiff - onak-mail.pl.in
Bump debhelper compat level to 13
[onak.git] / onak-mail.pl.in
index 263b7270cf8801c19ef1878267f2fe168bb17887..2083042e86d716ba7bc19fb7c93b599489c4d787 100644 (file)
@@ -2,8 +2,7 @@
 #
 # onak-mail.pl - Mail processing interface for onak, an OpenPGP Keyserver.
 #
-# Written by Jonathan McDowell <noodles@earth.li>
-# Copyright 2002-2005 Project Purple
+# Copyright 2002-2005 Jonathan McDowell <noodles@earth.li>
 # Released under the GPL.
 #
 
@@ -15,14 +14,14 @@ use IPC::Open3;
 my %config;
 
 #
-# readconfig
+# readoldconfig
 #
-# Reads in our config file. Ignores any command it doesn't understand rather
-# than having to list all the ones that are of no interest to us.
+# Read an old pksd-style config file. Currently if both old and new style
+# files are present the old style will be preferred in order to ensure smooth
+# upgrades.
 #
-sub readconfig {
-
-       open(CONFIG, "@CONFIG@") or
+sub readoldconfig {
+       open(CONFIG, "@CMAKE_INSTALL_FULL_SYSCONFDIR@/onak.conf") or
                die "Can't read config file: $!";
        
        while (<CONFIG>) {
@@ -38,8 +37,6 @@ sub readconfig {
                        $config{'mta'} = $1;
                } elsif (/^pks_bin_dir (.*)/) {
                        $config{'pks_bin_dir'} = $1;
-               } elsif (/^db_dir (.*)/) {
-                       $config{'db_dir'} = $1;
                } elsif (/^mail_dir (.*)/) {
                        $config{'mail_dir'} = $1;
                } elsif (/^syncsite (.*)/) {
@@ -52,6 +49,54 @@ sub readconfig {
        return;
 }
 
+#
+# readconfig
+#
+# Reads in our config file. Ignores any command it doesn't understand rather
+# than having to list all the ones that are of no interest to us.
+#
+sub readconfig {
+       # Prefer the old style config if it exists.
+       if (-e "@CMAKE_INSTALL_FULL_SYSCONFDIR@/onak.conf") {
+               &readoldconfig;
+               return;
+       }
+
+       open(CONFIG, "@CMAKE_INSTALL_FULL_SYSCONFDIR@/onak.ini") or
+               die "Can't read config file: $!";
+
+       my $section = "";
+       while (<CONFIG>) {
+               if (/^#/ or /^$/) {
+                       # Ignore; comment line.
+               } elsif (/^\[(\w+)\]/) {
+                       $section = $1;
+               } elsif ($section eq "main") {
+                       if (/^logfile\s*=\s*(.*)/) {
+                               $config{'logfile'} = $1;
+                       }
+               } elsif ($section eq "mail") {
+                       if (/^this_site\s*=\s*(.*)/) {
+                               $config{'thissite'} = $1;
+                       } elsif (/^maintainer_email\s*=\s*(.*)/) {
+                               $config{'adminemail'} = $1;
+                       } elsif (/^mta\s*=\s*(.*)/) {
+                               $config{'mta'} = $1;
+                       } elsif (/^bin_dir\s*=\s*(.*)/) {
+                               $config{'pks_bin_dir'} = $1;
+                       } elsif (/^mail_dir\s*=\s*(.*)/) {
+                               $config{'mail_dir'} = $1;
+                       } elsif (/^syncsite\s*=\s*(.*)/) {
+                               push @{$config{'syncsites'}}, $1;
+                       }
+               }
+       }
+
+       close(CONFIG);
+
+       return;
+}
+
 #
 # submitupdate
 #
@@ -88,7 +133,7 @@ sub processmail($$$$$) {
        # HELP, ADD, INCREMENTAL, VERBOSE INDEX <keyid>, INDEX <keyid>,
        # GET <keyid>, LAST <days>
        
-       if ($subject =~ /^INCREMENTAL$/i) {
+       if ($subject =~ /^(INCREMENTAL|ADD)$/i) {
                my $site;
                my $count;
                my $i;
@@ -110,6 +155,21 @@ sub processmail($$$$$) {
                        $time[2], $time[1], $time[0];
                print LOG "] onak-mail[$$]: Syncing with $count sites.\n";
                close LOG;
+
+               if ($subject =~ /ADD/i) {
+                       open(MAIL, "|$config{mta}");
+                       print MAIL "From: $config{adminemail}\n";
+                       print MAIL "To: $replyto\n";
+                       print MAIL "Subject: Reply to ADD\n";
+                       print MAIL "Precedence: list\n";
+                       print MAIL "MIME-Version: 1.0\n";
+                       print MAIL "Content-Type: text/plain\n";
+                       print MAIL "\n";
+                       print MAIL "Thank you for your recent key submission.",
+                               " It has been processed and synced\n",
+                               "with ", $count, " other keyservers.\n";
+                       close MAIL;
+               }
        
                if ((! defined($newupdate[0])) || $newupdate[0] eq '') {
                        open (LOG, ">>$config{'logfile'}");
@@ -198,17 +258,18 @@ my $tmpfile = sprintf "%s/%04d%02d%02d-%02d%02d%02d-%d.onak",
                        $time[1],
                        $time[0],
                        $$;
-open(MAILFILE, '>'.$tmpfile);
+open(MAILFILE, '>'.$tmpfile.'.tmp');
 while (<>) {
        print MAILFILE $_;
 }
 close(MAILFILE);
+rename $tmpfile.".tmp", $tmpfile;
 
 #
 # Lock here to ensure that only one copy of us is processing the incoming
 # mail queue at any point in time.
 #
-sysopen(LOCKFILE, $config{'db_dir'}.'/onak-mail.lck',
+sysopen(LOCKFILE, $config{'mail_dir'}.'/onak-mail.lck',
                O_WRONLY|O_CREAT|O_EXCL) or exit;
 print LOCKFILE "$$";
 close(LOCKFILE);
@@ -242,7 +303,7 @@ while ($file = readdir(MAILDIR)) {
                        push @body, $_;
                }
        }
-       if (! defined($replyto)) {
+       if ($replyto eq '') {
                $replyto = $from;
        }
        close(FILE);
@@ -251,4 +312,4 @@ while ($file = readdir(MAILDIR)) {
        processmail($subject, $from, $replyto, \%seenby, \@body);
 }
 closedir(MAILDIR);
-unlink $config{'db_dir'}.'/onak-mail.lck';
+unlink $config{'mail_dir'}.'/onak-mail.lck';