2 # Copyright (C) 2016 all contributors <meta@public-inbox.org>
3 # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
4 # This should not require any other PublicInbox code, but may use
5 # PublicInbox::Config if ~/.public-inbox/config exists or
6 # PI_CONFIG is pointed to an appropriate location
9 use PublicInbox::Unsubscribe;
10 my $app = PublicInbox::Unsubscribe->new(
11 pi_config => eval { # optional, for pointing out archives
12 require PublicInbox::Config;
13 # uses ~/.public-inbox/config by default,
14 # can override with PI_CONFIG or here since
15 # I run this .psgi as the mlmmj user while the
16 # public-inbox-mda code which actually writes to
17 # the archives runs as a different user.
18 PublicInbox::Config->new('/home/pi/.public-inbox/config')
20 code_url => 'git://80x24.org/public-inbox.git', # change if you fork
21 owner_email => 'BOFH@example.com',
24 # First 8 bytes is for the key, next 8 bytes is for the IV
25 # using Blowfish. We want as short URLs as possible to avoid
27 # umask 077 && dd if=/dev/urandom bs=16 count=1 of=.unsubscribe.key
28 key_file => '/home/mlmmj/.unsubscribe.key',
30 # this runs as whatever user has perms to run /usr/bin/mlmmj-unsub
31 # users of other mailing lists. Returns '' on success.
33 my ($user_addr, $list_addr) = @_;
35 # map list_addr to mlmmj spool, I use:
36 # /home/mlmmj/spool/$LIST here
37 my ($list, $domain) = split('@', $list_addr, 2);
38 my $spool = "/home/mlmmj/spool/$list";
40 return "Invalid list: $list" unless -d $spool;
42 # -c to send a confirmation email, -s is important
43 # in case a user is click-happy and clicks twice.
44 my @cmd = (qw(/usr/bin/mlmmj-unsub -c -s),
45 '-L', $spool, '-a', $user_addr);
47 # we don't know which version they're subscribed to,
48 # try both non-digest and digest
49 my $normal = system(@cmd);
50 my $digest = system(@cmd, '-d');
52 # success if either succeeds:
53 return '' if ($normal == 0 || $digest == 0);
55 # missing executable or FS error,
56 # otherwise -s always succeeds, right?
57 return 'Unknown error, contact admin';
62 mount '/u' => builder {
63 eval { enable 'Deflater' }; # optional
64 eval { enable 'ReverseProxy' }; # optional
66 sub { $app->call(@_) };