]> Sergey Matveev's repositories - public-inbox.git/commitdiff
mda: rename PI_FAILBOX to PI_EMERGENCY
authorEric Wong <e@80x24.org>
Fri, 18 Apr 2014 22:18:17 +0000 (22:18 +0000)
committerEric Wong <e@80x24.org>
Sat, 19 Apr 2014 23:05:51 +0000 (23:05 +0000)
The emergency destination may be Maildir.  A Maildir emergency
destination is better for volatile data which is written to
and deleted-from frequently.

Documentation/public-inbox-mda.txt
public-inbox-mda
t/cgi.t
t/mda.t

index e29b119bc228a97b4745c5558d3739f5d4c375d4..2957093904af88ddd44ab9332fe1691d7f4b0d94 100644 (file)
@@ -13,7 +13,7 @@ Each system user may have their own public-inbox instances
 
 * RECIPIENT - the recipient email address, from Postfix
 * PI_CONFIG - config file. default: ~/.public-inbox/config
-* PI_FAILBOX - emergency destination.  default: ~/public-inbox-fail.mbox
+* PI_EMERGENCY - emergency destination.  default: ~/.public-inbox/emergency/
 
 # PI_CONFIG FILE
 
index 2335cd3e068437321f58cfd83b396a8d8fa266ad..1f4d339f63eaa1e561586cae84ed9334634d9d90 100755 (executable)
@@ -16,14 +16,14 @@ use PublicInbox;
 use PublicInbox::Filter;
 use PublicInbox::Config;
 
-# n.b: hopefully we can setup the failbox path without bailing due to
+# n.b: hopefully we can setup the emergency path without bailing due to
 # user error, we really want to setup the emergency destination ASAP
 # in case there's bugs in our code or user error.
-my $failbox = $ENV{PI_FAILBOX} || '~/public-inbox-fail.mbox';
-$failbox = expand_filename($failbox);
+my $emergency = $ENV{PI_EMERGENCY} || '~/.public-inbox/emergency/';
+$emergency = expand_filename($emergency);
 
 # this reads the message from stdin
-my $filter = Email::Filter->new(emergency => $failbox);
+my $filter = Email::Filter->new(emergency => $emergency);
 my $config = PublicInbox::Config->new;
 
 my $recipient = $ENV{RECIPIENT};
@@ -64,7 +64,7 @@ if (PublicInbox->precheck($filter, $recipient) &&
                }
        }
 }
-exit 0; # goes to failbox
+exit 0; # goes to emergency
 
 # we depend on "report_safe 0" in /etc/spamassassin/*.cf with --headers
 # not using Email::Filter->pipe here since we want the stdout of
diff --git a/t/cgi.t b/t/cgi.t
index 3cf230c005dcb4f9bd54f865238ddf97c9b8e0af..b992af311e4fefedd098ffbb5c2af10bda7a226e 100644 (file)
--- a/t/cgi.t
+++ b/t/cgi.t
@@ -40,7 +40,7 @@ my $cfgpfx = "publicinbox.test";
 }
 
 my $failbox = "$home/fail.mbox";
-local $ENV{PI_FAILBOX} = $failbox;
+local $ENV{PI_EMERGENCY} = $failbox;
 {
        local $ENV{HOME} = $home;
        local $ENV{RECIPIENT} = $addr;
diff --git a/t/mda.t b/t/mda.t
index b403c6b37998ffa56c40fdb3621a1a66c5bdf704..d70288bc785d419039cb0f367f65e071e4e247b1 100644 (file)
--- a/t/mda.t
+++ b/t/mda.t
@@ -45,7 +45,7 @@ my $failbox = "$home/fail.mbox";
 
 {
        my $good_rev;
-       local $ENV{PI_FAILBOX} = $failbox;
+       local $ENV{PI_EMERGENCY} = $failbox;
        local $ENV{HOME} = $home;
        local $ENV{RECIPIENT} = $addr;
        my $simple = Email::Simple->new(<<EOF);
@@ -77,13 +77,13 @@ EOF
 
        # ensure failures work, fail with bad spamc
        {
-               ok(!-e $failbox, "nothing in PI_FAILBOX before");
+               ok(!-e $failbox, "nothing in PI_EMERGENCY before");
                local $ENV{PATH} = $fail_path;
                run([$mda], \$in);
                local $ENV{GIT_DIR} = $maindir;
                my @revs = `git rev-list HEAD`;
                is(scalar @revs, 1, "bad revision not committed");
-               ok(-s $failbox > 0, "PI_FAILBOX is written to");
+               ok(-s $failbox > 0, "PI_EMERGENCY is written to");
        }
 
        fail_bad_header($good_rev, "bad recipient", <<"");
@@ -133,7 +133,7 @@ Date: deadbeef
 
 # spam training
 {
-       local $ENV{PI_FAILBOX} = $failbox;
+       local $ENV{PI_EMERGENCY} = $failbox;
        local $ENV{HOME} = $home;
        local $ENV{RECIPIENT} = $addr;
        local $ENV{PATH} = $main_path;
@@ -167,7 +167,7 @@ EOF
 
 # train ham message
 {
-       local $ENV{PI_FAILBOX} = $failbox;
+       local $ENV{PI_EMERGENCY} = $failbox;
        local $ENV{HOME} = $home;
        local $ENV{RECIPIENT} = $addr;
        local $ENV{PATH} = $main_path;
@@ -194,6 +194,28 @@ EOF
        is($?, 0, "learned ham idempotently ");
 }
 
+# faildir - emergency destination is maildir
+{
+       my $faildir= "$home/faildir/";
+       local $ENV{PI_EMERGENCY} = $faildir;
+       local $ENV{HOME} = $home;
+       local $ENV{RECIPIENT} = $addr;
+       local $ENV{PATH} = $fail_path;
+       my $in = <<EOF;
+From: Faildir <faildir\@example.com>
+To: You <you\@example.com>
+Cc: $addr
+Message-ID: <faildir\@example.com>
+Subject: faildir subject
+Date: Thu, 01 Jan 1970 00:00:00 +0000
+
+EOF
+       run([$mda], \$in);
+       ok(-d $faildir, "emergency exists");
+       my @new = glob("$faildir/new/*");
+       is(scalar(@new), 1, "message delivered");
+}
+
 done_testing();
 
 sub fail_bad_header {
@@ -207,6 +229,6 @@ sub fail_bad_header {
        my $rev = `git rev-list HEAD`;
        chomp $rev;
        is($rev, $good_rev, "bad revision not commited ($msg)");
-       ok(-s $failbox > 0, "PI_FAILBOX is written to ($msg)");
+       ok(-s $failbox > 0, "PI_EMERGENCY is written to ($msg)");
        [ $in, $out, $err ];
 }