]> Sergey Matveev's repositories - public-inbox.git/blobdiff - examples/unsubscribe.milter
nntp: use substr to check for trailing CRLF
[public-inbox.git] / examples / unsubscribe.milter
index 608524cbaca40337a8ca45a1f0b7d0ba38cfd774..216b0dddd0cf737e77dfb3780f48b48c5fc9d1cd 100644 (file)
@@ -1,5 +1,5 @@
 #!/usr/bin/perl -w
-# Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use Sendmail::PMilter qw(:all);
@@ -96,6 +96,7 @@ $cbs{eom} = sub {
 
                my $unsub = $priv->{header}->{'list-unsubscribe'} || [];
                my $n = 0;
+               my $added;
                foreach my $u (@$unsub) {
                        # Milter indices are 1-based,
                        # not 0-based like Perl arrays
@@ -114,7 +115,11 @@ $cbs{eom} = sub {
                        $v .= ",\n <https://$domain/u/$u/$list>";
 
                        $ctx->chgheader($k, $index, $v);
+                       $added = 1;
                }
+               # RFC 8058
+               $added and $ctx->addheader('List-Unsubscribe-Post',
+                                       'List-Unsubscribe=One-Click');
        };
        warn $@ if $@;
        SMFIS_CONTINUE;
@@ -127,7 +132,7 @@ my $fds = $ENV{LISTEN_FDS};
 if ($fds && (($ENV{LISTEN_PID} || 0) == $$)) {
        die "$0 can only listen on one FD\n" if $fds != 1;
        my $start_fd = 3;
-       open(my $s, '<&=', $start_fd) or
+       my $s = IO::Socket->new_from_fd($start_fd, 'r') or
                die "inherited bad FD from LISTEN_FDS: $!\n";
        $milter->set_socket($s);
 } else {