]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/Filter/Vger.pm
treewide: run update-copyrights from gnulib for 2019
[public-inbox.git] / lib / PublicInbox / Filter / Vger.pm
1 # Copyright (C) 2016-2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 # Filter for vger.kernel.org list trailer
5 package PublicInbox::Filter::Vger;
6 use base qw(PublicInbox::Filter::Base);
7 use strict;
8 use warnings;
9
10 my $l0 = qr/-+/; # older messages only had one '-'
11 my $l1 =
12  qr/To unsubscribe from this list: send the line "unsubscribe [\w-]+" in/;
13 my $l2 = qr/the body of a message to majordomo\@vger\.kernel\.org/;
14 my $l3 =
15   qr!More majordomo info at +http://vger\.kernel\.org/majordomo-info\.html!;
16
17 # only LKML had this, and LKML nowadays has no list trailer since Jan 2016
18 my $l4 = qr!Please read the FAQ at +http://www\.tux\.org/lkml/!;
19
20 sub scrub {
21         my ($self, $mime) = @_;
22         my $s = $mime->as_string;
23
24         # the vger appender seems to only work on the raw string,
25         # so in multipart (e.g. GPG-signed) messages, the list trailer
26         # becomes invisible to MIME-aware email clients.
27         if ($s =~ s/$l0\n$l1\n$l2\n$l3\n($l4\n)?\z//os) {
28                 $mime = PublicInbox::MIME->new(\$s);
29         }
30         $self->ACCEPT($mime);
31 }
32
33 sub delivery {
34         my ($self, $mime) = @_;
35         $self->scrub($mime);
36 }
37
38 1;