]> Sergey Matveev's repositories - public-inbox.git/commitdiff
examples/unsubscribe.milter: support unique mailto:
authorEric Wong <e@yhbt.net>
Fri, 10 Jan 2020 22:55:30 +0000 (22:55 +0000)
committerEric Wong <e@yhbt.net>
Sun, 12 Jan 2020 21:27:52 +0000 (21:27 +0000)
Instead of providing a generic "mailto:foo+unsubscribe@example.com"
address in List-Unsubscribe which requires confirmation, replace it
with a mailto: header with a unique subject which contains the same
unique ID we put in the https:// URL.

This makes it easier for some MUAs without https:// support to
unsubscribe with a single action via the List-Unsubscribe header.

examples/unsubscribe-milter@.service
examples/unsubscribe.milter

index 98e3d478c15d42e25e194ac113f08aaf26096fe7..eb5dcbe489c87c7eb883ae82ab57efa2eecd6d2d 100644 (file)
@@ -14,6 +14,12 @@ After = unsubscribe-milter.socket
 # copy+paste errors
 # umask 077 && dd if=/dev/urandom bs=16 count=1 of=.unsubscribe.key
 ExecStart = /usr/local/sbin/unsubscribe.milter /home/mlmmj/.unsubscribe.key
+
+# UNIQUE_MAILTO makes the List-Unsubscribe mailto: header unique
+# so unsubcribing becomes one-step (requires MDA/MTA configuration,
+# see the bottom of examples/unsubscribe.milter
+# Environment = UNIQUE_MAILTO=1
+
 Sockets = unsubscribe-milter.socket
 
 # the corresponding PSGI app needs permissions to modify the
index f7bf6f1d38b4f18503b8be906d6e9bc35b9c7760..266596faeaefe313baa8991dfd9bfb1da35a4b7f 100644 (file)
@@ -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,
@@ -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 = "<mailto:$list+unique-unsub\@$domain?$s>";
+                       }
                        $v .= ",\n <https://$domain/u/$u/$list>";
 
                        $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