Commit notifications for all Sup repositories
 help / color / mirror / Atom feed
From: Dan Callaghan <dan@bl2.djc.id.au>
To: sup-commits@supmua.dev
Subject: [sup.git] 03/06: unfold headers before further parsing
Date: Sun, 18 Oct 2026 12:52:25 +1100	[thread overview]
Message-ID: <20261018015223.260CA29C472@bl2.djc.id.au> (raw)
In-Reply-To: <179228834279.389402.1183876010618010579@bl2.djc.id.au>

New commit on branch develop:
https://supmua.dev/git/sup/commit/42ee12157508704adbd4869a252be45c759c4b05.html

commit 42ee12157508704adbd4869a252be45c759c4b05
Author: Dan Callaghan <djc@djc.id.au>
AuthorDate: Sat Oct 17 11:00:31 2026 +1100

    unfold headers before further parsing
    
    Fixes handling of From headers where a CRLF fold appears inside the
    quoted name portion.
---
 Manifest.txt                         |  1 +
 lib/sup/message.rb                   |  5 ++++-
 test/fixtures/folded-from-header.eml |  8 ++++++++
 test/test_message.rb                 | 15 ++++++++++++++-
 4 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/Manifest.txt b/Manifest.txt
index a05e069e..768c91b5 100644
--- a/Manifest.txt
+++ b/Manifest.txt
@@ -146,6 +146,7 @@ test/fixtures/blank-header-fields.eml
 test/fixtures/contacts.txt
 test/fixtures/embedded-message-rfc6532.eml
 test/fixtures/embedded-message.eml
+test/fixtures/folded-from-header.eml
 test/fixtures/invalid-date.eml
 test/fixtures/mailing-list-header.eml
 test/fixtures/malicious-attachment-names.eml
diff --git a/lib/sup/message.rb b/lib/sup/message.rb
index 35f78256..24e5464c 100644
--- a/lib/sup/message.rb
+++ b/lib/sup/message.rb
@@ -72,9 +72,12 @@ class Message
     return unless v
     return v unless v.is_a? String
     return unless v.size < MAX_HEADER_VALUE_SIZE # avoid regex blowup on spam
+    ## Unfold per RFC 5322 2.2.3: remove each CRLF immediately followed
+    ## by WSP, leaving the WSP in place.
+    v = v.gsub(/\r?\n(?=[ \t])/, "")
     ## Header values should be either 7-bit with RFC2047-encoded words
     ## or UTF-8 as per RFC6532. Replace any invalid high bytes with U+FFFD.
-    Rfc2047.decode_to $encoding, v.dup.force_encoding(Encoding::UTF_8).scrub
+    Rfc2047.decode_to $encoding, v.force_encoding(Encoding::UTF_8).scrub
   end
 
   def parse_header encoded_header
diff --git a/test/fixtures/folded-from-header.eml b/test/fixtures/folded-from-header.eml
new file mode 100644
index 00000000..3a56ed31
--- /dev/null
+++ b/test/fixtures/folded-from-header.eml
@@ -0,0 +1,8 @@
+From: "Kevin Frazier, Juliana Schroeder, Brian Frye, Nathanael Fast,
+ and Rob Greer" <user@rss2email.invalid>
+To: someone@example.invalid
+Subject: folded From header
+Date: Fri, 16 Oct 2026 10:00:00 +0000
+Message-Id: <folded-from-header@example.invalid>
+
+body
diff --git a/test/test_message.rb b/test/test_message.rb
index 1e5c431b..097ceb8a 100644
--- a/test/test_message.rb
+++ b/test/test_message.rb
@@ -234,12 +234,25 @@ class TestMessage < Minitest::Test
 
     # Look at another header field whose first line was blank.
     list_unsubscribe = sup_message.list_unsubscribe
-    assert_equal("<http://mailman2.widget.com/mailman/listinfo/monitor-list>,\n\t" +
+    assert_equal("<http://mailman2.widget.com/mailman/listinfo/monitor-list>,\t" +
                  "<mailto:monitor-list-request@widget.com?subject=unsubscribe>",
                  list_unsubscribe)
 
   end
 
+  def test_folded_from_header
+    source = DummySource.new("sup-test://test_folded_from_header")
+    source.messages = [ fixture_path("folded-from-header.eml") ]
+    source_info = 0
+
+    sup_message = Message.build_from_source(source, source_info)
+    sup_message.load_from_source!
+
+    assert_equal "Kevin Frazier, Juliana Schroeder, Brian Frye, " +
+                 "Nathanael Fast, and Rob Greer", sup_message.from.name
+    assert_equal "user@rss2email.invalid", sup_message.from.email
+  end
+
   def test_rfc2047_header_encoding
     source = DummySource.new("sup-test://test_rfc2047_header_encoding")
     source.messages = [ fixture_path("rfc2047-header-encoding.eml") ]

  parent reply	other threads:[~2026-10-18  1:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-18  1:52 [sup.git] branch develop updated (cf3a2e38 -> c9f29b8d) Dan Callaghan
2026-10-18  1:52 ` [sup.git] 01/06: prepend type:mail to every search before parsing Dan Callaghan
2026-10-18  1:52 ` [sup.git] 02/06: always set MIME-Version header on outgoing mails Dan Callaghan
2026-10-18  1:52 ` Dan Callaghan [this message]
2026-10-18  1:52 ` [sup.git] 04/06: delete unused load_header method Dan Callaghan
2026-10-18  1:52 ` [sup.git] 05/06: move Source.parse_raw_email_header to EditMessageMode Dan Callaghan
2026-10-18  1:52 ` [sup.git] 06/06: ncursesw: 1.4.13 → 1.4.14 Dan Callaghan

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

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

  git send-email \
    --in-reply-to=20261018015223.260CA29C472@bl2.djc.id.au \
    --to=dan@bl2.djc.id.au \
    --cc=djc@djc.id.au \
    --cc=sup-commits@supmua.dev \
    /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