From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] SaPlugin::ListMirror: follow RFC 2919 List-ID rules
Date: Fri, 25 Nov 2022 11:44:35 +0000 [thread overview]
Message-ID: <20221125114435.499-1-e@80x24.org> (raw)
List-ID headers are sometimes populated with a descriptive phrase
before the angle-bracketed value and making things difficult to
match.
Tweak our handling to allow checking the angle-bracketed portion
only in accordance with RFC 2919.
Handling of all other headers and senselessly non-bracketed
values for List-ID remain unchanged.
---
lib/PublicInbox/SaPlugin/ListMirror.pm | 10 +++++++--
lib/PublicInbox/SaPlugin/ListMirror.pod | 27 +++++++++++++++++--------
2 files changed, 27 insertions(+), 10 deletions(-)
diff --git a/lib/PublicInbox/SaPlugin/ListMirror.pm b/lib/PublicInbox/SaPlugin/ListMirror.pm
index 9acf86c0..06903cad 100644
--- a/lib/PublicInbox/SaPlugin/ListMirror.pm
+++ b/lib/PublicInbox/SaPlugin/ListMirror.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
# SpamAssassin rules useful for running a mailing list mirror. We want to:
@@ -39,7 +39,11 @@ sub check_list_mirror_received {
my $v = $pms->get($hdr) or next;
local $/ = "\n";
chomp $v;
- next if $v ne $hval;
+ if (ref($hval)) {
+ next if $v !~ $hval;
+ } else {
+ next if $v ne $hval;
+ }
return 1 if $recvd !~ $host_re;
}
@@ -91,6 +95,8 @@ sub config_list_mirror {
$host_glob =~ s!(.)!$patmap{$1} || "\Q$1"!ge;
my $host_re = qr/\A\s*from\s+$host_glob(?:\s|$)/si;
+ (lc($hdr) eq 'list-id' && $hval =~ /<([^>]+)>/) and
+ $hval = qr/\A<\Q$1\E>\z/;
push @{$self->{list_mirror_check}}, [ $hdr, $hval, $host_re, $addr ];
}
diff --git a/lib/PublicInbox/SaPlugin/ListMirror.pod b/lib/PublicInbox/SaPlugin/ListMirror.pod
index d931d762..e6a6c2ad 100644
--- a/lib/PublicInbox/SaPlugin/ListMirror.pod
+++ b/lib/PublicInbox/SaPlugin/ListMirror.pod
@@ -6,11 +6,11 @@ PublicInbox::SaPlugin::ListMirror - SpamAssassin plugin for mailing list mirrors
loadplugin PublicInbox::SaPlugin::ListMirror
-Declare some mailing lists based on the expected List-Id value,
+Declare some mailing lists based on the expected List-ID value,
expected servers, and mailing list address:
- list_mirror List-Id <foo.example.com> *.example.com foo@example.com
- list_mirror List-Id <bar.example.com> *.example.com bar@example.com
+ list_mirror List-ID <foo.example.com> *.example.com foo@example.com
+ list_mirror List-ID <bar.example.com> *.example.com bar@example.com
Bump the score for messages which come from unexpected servers:
@@ -43,14 +43,25 @@ C<allow_user_rules 1>
=item list_mirror HEADER HEADER_VALUE HOSTNAME_GLOB [LIST_ADDRESS]
-Declare a list based on an expected C<HEADER> matching C<HEADER_NAME>
-exactly coming from C<HOSTNAME_GLOB>. C<LIST_ADDRESS> is optional,
+Declare a list based on an expected C<HEADER> matching C<HEADER_VALUE>
+coming from C<HOSTNAME_GLOB>. C<LIST_ADDRESS> is optional,
but may specify the address of the mailing list being mirrored.
-C<List-Id> or C<X-Mailing-List> are common values of C<HEADER>
+C<List-ID> is the recommended value of C<HEADER> as most
+mailing lists support it.
An example of C<HEADER_VALUE> is C<E<lt>foo.example.orgE<gt>>
-if C<HEADER> is C<List-Id>.
+if C<HEADER> is C<List-ID>.
+
+As of public-inbox 2.0, using C<List-ID> as the C<HEADER> and a
+C<HEADER_VALUE> contained by angle brackets (E<lt>list-idE<gt>),
+matching is done in accordance with
+L<RFC 2919|https://tools.ietf.org/html/rfc2919>. That is,
+C<HEADER_VALUE> will be a case-insensitive substring match
+and ignore the optional description C<phrase> as documented
+in RFC 2919.
+
+All other C<HEADER> values use exact matches for backwards-compatibility.
C<HOSTNAME_GLOB> may be a wildcard match for machines where mail can
come from or an exact match.
@@ -105,7 +116,7 @@ and L<http://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/meta
=head1 COPYRIGHT
-Copyright (C) 2016-2021 all contributors L<mailto:meta@public-inbox.org>
+Copyright (C) all contributors L<mailto:meta@public-inbox.org>
License: AGPL-3.0+ L<http://www.gnu.org/licenses/agpl-3.0.txt>
reply other threads:[~2022-11-25 11:44 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20221125114435.499-1-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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
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).