svn commit: r1935536 - in spamassassin/trunk: lib/Mail/SpamAssassin t

[email protected] Sun, 21 Jun 2026 05:01:52 -0000
Newsgroups gmane.mail.spam.spamassassin.cvs
Message-ID <178201811230.3766331.6355781583697103282@svn03-he-fi>
Author: fkento
Date: Sun Jun 21 05:01:52 2026
New Revision: 1935536

Log:
Util: keep user token as :name for malformed XS entries (revises r1934692)

Modified:
   spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm
   spamassassin/trunk/t/get_headers.t

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm	Sun Jun 21 04:20:04 2026	(r1935535)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm	Sun Jun 21 05:01:52 2026	(r1935536)
@@ -2806,9 +2806,17 @@ sub _parse_header_addresses_xs {
       $phrase = $comment;
     }
 
-    # Skip entries with neither phrase nor address — XS emits these for
-    # unparseable tails (e.g. a truncated address header), and copying the
-    # whole input into phrase here causes :name to return the entire header.
+    # For malformed entries with no address, XS leaves a bare display token
+    # in user with no phrase (e.g. "Mr" from "Mr, Spam <[email protected]>", or
+    # "Foo" from a bare "Foo Blah"). Keep that token as the name. Gate on
+    # !defined $address so a normal address with no display name keeps :name
+    # undef instead of falling back to its localpart. (Earlier code copied
+    # the whole input into phrase here, leaking the entire header into :name.)
+    if (!defined $phrase && !defined $address && defined $user) {
+      $phrase = $user;
+    }
+
+    # Drop anything still empty (no phrase, no address).
     next if !defined $phrase && !defined $address;
 
     push @results, {

Modified: spamassassin/trunk/t/get_headers.t
==============================================================================
--- spamassassin/trunk/t/get_headers.t	Sun Jun 21 04:20:04 2026	(r1935535)
+++ spamassassin/trunk/t/get_headers.t	Sun Jun 21 05:01:52 2026	(r1935536)
@@ -76,8 +76,9 @@ sub try {
     return 1 if $try eq 'From5:addr' && $result eq '[email protected]';
     # try: Email::Address::XS: 'From5:name' failed! expect: undef got: '=?UTF-8?Q? Foobar _'
     return 1 if $try eq 'From5:name' && $result eq '=?UTF-8?Q? Foobar _';
-    # try: Email::Address::XS: 'From9:name' failed! expect: 'Mr\nSpam' got: 'Mr, Spam <[email protected]>\nSpam'
-    return 1 if $try eq 'From9:name' && $result eq 'Mr, Spam <[email protected]>\nSpam';
+    # try: Email::Address::XS: 'From1:name' failed! expect: 'Foo Blah' got: 'Foo'
+    # XS only parses the first atom of a bare unquoted phrase ("Foo Blah" -> "Foo").
+    return 1 if $try eq 'From1:name' && defined $result && $result eq 'Foo';
   }
 
   if (!defined $expect) {