about summary refs log tree commit homepage
path: root/lib/PublicInbox/Filter
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2017-02-09 00:43:02 +0000
committerEric Wong <e@80x24.org>2017-02-09 00:43:02 +0000
commitfb9ed5324ec7de9420956840ba9a6585b81e8231 (patch)
treeab6b34f8459a585205a25d1f3d18d31437b89052 /lib/PublicInbox/Filter
parent1ab8dabe04ebba61fd8761dca3d569947cbe20be (diff)
parentba4c50c20b95679580beba1ef290a4281d5285b7 (diff)
downloadpublic-inbox-fb9ed5324ec7de9420956840ba9a6585b81e8231.tar.gz
* origin/master:
  config: do not slurp lines into memory
  TODO: several updates
  search: schema version bump for empty References/In-Reply-To
  Revert "searchidx: reindex clobbers old thread IDs"
  searchidx: reindex clobbers old thread IDs
  searchidx: deal with empty In-Reply-To and References headers
  searchview: increase limit for displaying search results
  searchview: clarify numeric summary at bottom
  add filter for Subject: tags
  watchmaildir: allow arguments for filters
  watchmaildir: limit live importer processes
  learn: implement "rm" only functionality
  mime: avoid SUPER usage in Email::MIME subclass
  inbox: reinstate periodic cleanup of Xapian and SQLite objects
  introduce PublicInbox::MIME wrapper class
Diffstat (limited to 'lib/PublicInbox/Filter')
-rw-r--r--lib/PublicInbox/Filter/SubjectTag.pm33
-rw-r--r--lib/PublicInbox/Filter/Vger.pm2
2 files changed, 34 insertions, 1 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;
diff --git a/lib/PublicInbox/Filter/Vger.pm b/lib/PublicInbox/Filter/Vger.pm
index 2ffed184..905f28d7 100644
--- a/lib/PublicInbox/Filter/Vger.pm
+++ b/lib/PublicInbox/Filter/Vger.pm
@@ -25,7 +25,7 @@ sub scrub {
         # so in multipart (e.g. GPG-signed) messages, the list trailer
         # becomes invisible to MIME-aware email clients.
         if ($s =~ s/$l0\n$l1\n$l2\n$l3\n($l4\n)?\z//os) {
-                $mime = Email::MIME->new(\$s);
+                $mime = PublicInbox::MIME->new(\$s);
         }
         $self->ACCEPT($mime);
 }