about summary refs log tree commit homepage
path: root/lib/PublicInbox/Filter
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2017-01-26 02:09:36 +0000
committerEric Wong <e@80x24.org>2017-01-26 03:22:54 +0000
commit7e40887e8d2bef4126b4a3680594860a3b2fd67c (patch)
tree222b7fbbf7457eac086b193384bf7de3dbb08ce4 /lib/PublicInbox/Filter
parenta465cc132b8d1ad96dbd0f51ad6da2ce75c79568 (diff)
downloadpublic-inbox-7e40887e8d2bef4126b4a3680594860a3b2fd67c.tar.gz
Some mailing lists add annoying tags into the Subject line which
discourages readers from doing proper mail organization on the
client side.  They also waste precious screen space and
attention span.

Remove them from our archives to reduce clutter.
Diffstat (limited to 'lib/PublicInbox/Filter')
-rw-r--r--lib/PublicInbox/Filter/SubjectTag.pm33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/PublicInbox/Filter/SubjectTag.pm b/lib/PublicInbox/Filter/SubjectTag.pm
new file mode 100644
index 00000000..1d281425
--- /dev/null
+++ b/lib/PublicInbox/Filter/SubjectTag.pm
@@ -0,0 +1,33 @@
+# Copyright (C) 2017 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+
+# Filter for various [tags] in subjects
+package PublicInbox::Filter::SubjectTag;
+use strict;
+use warnings;
+use base qw(PublicInbox::Filter::Base);
+
+sub new {
+        my ($class, %opts) = @_;
+        my $tag = delete $opts{-tag};
+        die "tag not defined!\n" unless defined $tag && $tag ne '';
+        my $self = $class->SUPER::new(%opts);
+        $self->{tag_re} = qr/\A\s*(re:\s+|)\Q$tag\E\s*/i;
+        $self;
+}
+
+sub scrub {
+        my ($self, $mime) = @_;
+        my $subj = $mime->header('Subject');
+        $subj =~ s/$self->{tag_re}/$1/; # $1 is "Re: "
+        $mime->header_str_set('Subject', $subj);
+        $self->ACCEPT($mime);
+}
+
+# no suffix/article rejection for mirrors
+sub delivery {
+        my ($self, $mime) = @_;
+        $self->scrub($mime);
+}
+
+1;