unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/2] watch: import_eml: avoid Eml dup for non-scrub case
Date: Mon, 30 Dec 2024 22:28:46 +0000	[thread overview]
Message-ID: <20241230222846.2251518-3-e@80x24.org> (raw)
In-Reply-To: <20241230222846.2251518-1-e@80x24.org>

Most inboxes don't use filters, so the destructive ->scrub won't
be called and we can avoid duplicating the Eml object in the
common case.  We'll also drop the last inbox optimization for
net_cb since it's likely unnecessary given that filters are not
very common.

This may be more noticeable for users who map multiple inboxes
to a single Maildir|IMAP|NNTP source.
---
 lib/PublicInbox/Watch.pm | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/lib/PublicInbox/Watch.pm b/lib/PublicInbox/Watch.pm
index c270f587..a37038b5 100644
--- a/lib/PublicInbox/Watch.pm
+++ b/lib/PublicInbox/Watch.pm
@@ -222,8 +222,10 @@ sub import_eml ($$$) {
 	eval {
 		my $im = _importer_for($self, $ibx);
 		if (my $filter = $ibx->filter($im)) {
-			my $ret = $filter->scrub($eml) or return;
+			my $tmp = PublicInbox::Eml->new(\($eml->as_string));
+			my $ret = $filter->scrub($tmp) or return;
 			$ret == REJECT and return;
+			$eml = $tmp;
 		}
 		$im->add($eml, $self->{spamcheck});
 	};
@@ -263,9 +265,9 @@ sub _try_path ($$) {
 		$warn_cb->($pfx, "path: $path\n", @_);
 	};
 	return _remove_spam($self, $path) if $inboxes eq 'watchspam';
+	my $eml = eml_from_path($path) or return;
 	for my $ibx (@$inboxes) {
-		my $eml = eml_from_path($path) or next;
-		import_eml($self, $ibx, $eml); # $eml may be scrubbed
+		import_eml($self, $ibx, $eml);
 	}
 	1;
 }
@@ -323,13 +325,9 @@ sub net_cb { # NetReader::(nntp|imap)_each callback
 	return if grep(/\Adraft\z/, @$kw);
 	local $self->{cur_uid} = $art; # IMAP UID or NNTP article
 	if (ref($inboxes)) {
-		my @ibx = @$inboxes;
-		my $last = pop @ibx;
-		for my $ibx (@ibx) {
-			my $tmp = PublicInbox::Eml->new(\($eml->as_string));
-			import_eml($self, $ibx, $tmp);
+		for my $ibx (@$inboxes) {
+			import_eml($self, $ibx, $eml);
 		}
-		import_eml($self, $last, $eml);
 	} elsif ($inboxes eq 'watchspam') {
 		if ($uri->scheme =~ /\Aimaps?\z/ && !grep(/\Aseen\z/, @$kw)) {
 			return;

  parent reply	other threads:[~2024-12-30 22:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-30 22:28 [PATCH 0/2] watch-related fixes for filter users Eric Wong
2024-12-30 22:28 ` [PATCH 1/2] watch|mda|purge: Filter::*->scrub is destructive Eric Wong
2024-12-30 22:28 ` Eric Wong [this message]
2025-01-01 23:11   ` [PATCH 3/2] watch: don't propagate header changes to other inboxes Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241230222846.2251518-3-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).