X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=examples%2Funsubscribe.milter;h=232295112d54b4e6b51716cf814da433ee97a1f9;hb=256b3566e4d57a64bb349a7b896da10381a2a363;hp=d6db766a51beb5bebc750045369ce882f92b8fb1;hpb=9bd675d33ad1e49bd2ebe12a1d216216e61380de;p=public-inbox.git
diff --git a/examples/unsubscribe.milter b/examples/unsubscribe.milter
index d6db766a..23229511 100644
--- a/examples/unsubscribe.milter
+++ b/examples/unsubscribe.milter
@@ -1,5 +1,5 @@
#!/usr/bin/perl -w
-# Copyright (C) 2016-2019 all contributors
+# Copyright (C) 2016-2020 all contributors
# License: AGPL-3.0+
use strict;
use warnings;
@@ -16,6 +16,10 @@ if (read($fh, $key, 8) != 8 || read($fh, $iv, 8) != 8 ||
die "KEY_FILE must be 16 bytes\n";
}
+# optionally support unique mailto: subject in List-Unsubscribe,
+# requires a custom rule in front of mlmmj, see __END__
+my $unique_mailto = $ENV{UNIQUE_MAILTO};
+
# these parameters were chosen to generate shorter parameters
# to reduce the possibility of copy+paste errors
my $crypt = Crypt::CBC->new(-key => $key,
@@ -75,7 +79,7 @@ $cbs{header} = sub {
# We don't want people unsubscribing archivers:
sub archive_addr {
my ($addr) = @_;
- return 1 if ($addr =~ /\@m\.gmane\.org\z/);
+ return 1 if ($addr =~ /\@m\.gmane(?:-mx)?\.org\z/);
return 1 if ($addr eq 'archive@mail-archive.com');
0
}
@@ -102,6 +106,12 @@ $cbs{eom} = sub {
next unless $k && $v && $list && $domain;
my $u = $crypt->encrypt($rcpt[0]);
$u = encode_base64url($u);
+ if ($unique_mailto) {
+ # $u needs to be in the Subject: header since
+ # +$EXTENSION is case-insensitive
+ my $s = "subject=$u";
+ $v = "";
+ }
$v .= ",\n ";
$ctx->chgheader($k, $index, $v);
@@ -132,3 +142,28 @@ if ($fds && (($ENV{LISTEN_PID} || 0) == $$)) {
$milter->register('unsubscribe', \%cbs, SMFI_CURR_ACTS);
$milter->main();
+__END__
+# TMPMSG comes from dc-dlvr, it's populated before the above runs:
+# TMPMSG=$(mktemp -t dc-dlvr.orig.$USER.XXXXXX || exit 1)
+# cat >$TMPMSG
+
+# I use something like this in front of mlmmj for UNIQUE_MAILTO
+# $EXTENSION and $ORIGINAL_RECIPIENT are set by postfix, $list
+# is a local mapping of addresses to mailing list names.
+case $ORIGINAL_RECIPIENT in
+foo+*) list=foo ;;
+# ...
+esac
+
+case $EXTENSION in
+unique-unsub)
+ u="$(formail -z -c -x Subject <$TMPMSG)"
+ d=$(expr "$ORIGINAL_RECIPIENT" : '^.*@\(.*\)')
+
+ # forward this to the unsubscribe.psgi service
+ curl -sSf https://$d/u/$u/$list >/dev/null
+ exit
+ ;;
+esac
+/usr/bin/mlmmj-receive -L /path/to/mlmmj-spool/$list <"$TMPMSG"
+exit