1 # Copyright (C) all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # Filter for lists.ruby-lang.org trailers
5 package PublicInbox::Filter::RubyLang;
7 use parent qw(PublicInbox::Filter::Base);
8 use PublicInbox::MID qw(mids);
10 my $l1 = qr/Unsubscribe:\s
11 <mailto:ruby-\w+-request\@ruby-lang\.org\?subject=unsubscribe>/x;
12 my $l2 = qr{<http://lists\.ruby-lang\.org/cgi-bin/mailman/options/ruby-\w+>};
15 my ($class, %opts) = @_;
16 my $altid = delete $opts{-altid};
17 my $self = $class->SUPER::new(%opts);
18 my $ibx = $self->{ibx};
19 # altid = serial:ruby-core:file=msgmap.sqlite3
20 if (!$altid && $ibx && $ibx->{altid}) {
21 $altid ||= $ibx->{altid}->[0];
24 require PublicInbox::AltId;
25 $self->{-altid} = PublicInbox::AltId->new($ibx, $altid, 1);
32 my $ct = $part->content_type;
33 if (!$ct || $ct =~ m{\btext/plain\b}i) {
34 my $s = eval { $part->body_str };
35 if (defined $s && $s =~ s/\n?$l1\n$l2\n\z//os) {
36 $part->body_str_set($s);
44 my ($self, $mime, $for_remove) = @_;
45 # no msg_iter here, msg_iter is only for read-only access
46 if (my @sub = $mime->subparts) {
48 $changed |= scrub_part($_) for @sub;
49 $mime->parts_set(\@sub) if $changed;
53 my $altid = $self->{-altid};
54 if ($altid && !$for_remove) {
55 my $hdr = $mime->header_obj;
56 my $mids = mids($hdr);
57 return $self->REJECT('Message-ID missing') unless (@$mids);
59 my @v = $hdr->header_raw('X-Mail-Count'); # old host only
62 /\A\s*([0-9]+)\s*\z/ or next;
66 } else { # new host: nue.mailmanlists.eu
67 for ($hdr->header_str('Subject')) {
68 /\A\[ruby-[^:]+:([0-9]+)\]/ or next;
73 $n // return $self->REJECT('could not get count not numeric');
74 foreach my $mid (@$mids) {
75 my $r = $altid->mm_alt->mid_set($n, $mid);
84 my ($self, $mime) = @_;