Commit notifications for all Sup repositories
 help / color / mirror / Atom feed
* [sup.git] branch develop updated (7a1133a1 -> 154ff507)
@ 2026-11-19 10:13 Dan Callaghan
  2026-11-19 10:13 ` [sup.git] 01/02: don't mangle non-UTF-8 attachments with 8bit transfer encoding Dan Callaghan
  2026-11-19 10:13 ` [sup.git] 02/02: fix wrong top-level Content-Type when sending messages with attachments Dan Callaghan
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Callaghan @ 2026-11-19 10:13 UTC (permalink / raw)
  To: sup-commits

Pushed branch develop:
    from 7a1133a1 prepare for next release
     new eae4a257 don't mangle non-UTF-8 attachments with 8bit transfer encoding
     new 154ff507 fix wrong top-level Content-Type when sending messages with attachments


Summary of changes:
 lib/sup/modes/edit_message_mode.rb  | 13 +++-----
 lib/sup/util.rb                     |  2 +-
 test/unit/test_edit_message_mode.rb | 63 ++++++++++++++++++++++++++++++++++++-
 3 files changed, 68 insertions(+), 10 deletions(-)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [sup.git] 01/02: don't mangle non-UTF-8 attachments with 8bit transfer encoding
  2026-11-19 10:13 [sup.git] branch develop updated (7a1133a1 -> 154ff507) Dan Callaghan
@ 2026-11-19 10:13 ` Dan Callaghan
  2026-11-19 10:13 ` [sup.git] 02/02: fix wrong top-level Content-Type when sending messages with attachments Dan Callaghan
  1 sibling, 0 replies; 3+ messages in thread
From: Dan Callaghan @ 2026-11-19 10:13 UTC (permalink / raw)
  To: sup-commits

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

commit eae4a257f16aea67d34957b9a0f64689683a5f90
Author: Dan Callaghan <djc@djc.id.au>
AuthorDate: Thu Nov 19 19:27:48 2026 +1100

    don't mangle non-UTF-8 attachments with 8bit transfer encoding
    
    Commit 208a6ac6d2 called the fix_encoding! method on attachments, but if
    the attachment is being sent with 8bit transfer encoding and it contains
    invalid UTF-8 bytes (for example because it is encoded in some other
    encoding) the attachment contents would be mangled: invalid sequences
    would be wrongly converted to U+FFFD.
    
    A better solution is to deal only with ASCII-8BIT (a.k.a. binary)
    at the RMail layer. The body coming from Sup is already aggressively
    fix_encoding!'ed so it is in $encoding, whereas the attachments can be
    read as binary so as not to assume any particular encoding. We can force
    the body to ASCII-8BIT at the last moment before passing to RMail so
    that RMail is dealing solely with ASCII-8BIT strings. The resulting
    binary data can then be piped directly to the sendmail command.
    
    Relates to #135 and #136.
---
 lib/sup/modes/edit_message_mode.rb  |  9 +++------
 lib/sup/util.rb                     |  2 +-
 test/unit/test_edit_message_mode.rb | 35 ++++++++++++++++++++++++++++++++++-
 3 files changed, 38 insertions(+), 8 deletions(-)

diff --git a/lib/sup/modes/edit_message_mode.rb b/lib/sup/modes/edit_message_mode.rb
index 01661731..eafb931b 100644
--- a/lib/sup/modes/edit_message_mode.rb
+++ b/lib/sup/modes/edit_message_mode.rb
@@ -577,7 +577,7 @@ protected
               return false
         end
       else
-        IO.popen(acct.sendmail, "w:UTF-8") { |p| p.puts m }
+        IO.popen(acct.sendmail, "wb") { |p| p.puts m }
         raise SendmailCommandFailed, "Couldn't execute #{acct.sendmail}" unless $? == 0
       end
 
@@ -605,7 +605,7 @@ protected
     m.body += "\n" + sig_lines.join("\n") unless @sig_edited
     ## body must end in a newline or GPG signatures will be WRONG!
     m.body += "\n" unless m.body =~ /\n\Z/
-    m.body = m.body.fix_encoding!
+    m.body.force_encoding("ASCII-8BIT")
 
     ## there are attachments, so wrap body in an attachment of its own
     unless @attachments.empty?
@@ -614,10 +614,7 @@ protected
       m = RMail::Message.new
 
       m.add_part body_m
-      @attachments.each do |a|
-        a.body = a.body.fix_encoding! if a.body.kind_of? String
-        m.add_part a
-      end
+      @attachments.each { |a| m.add_part a }
     end
 
     ## do whatever crypto transformation is necessary
diff --git a/lib/sup/util.rb b/lib/sup/util.rb
index e9944ad0..b4d58f9a 100644
--- a/lib/sup/util.rb
+++ b/lib/sup/util.rb
@@ -80,7 +80,7 @@ module RMail
     def self.make_file_attachment fn
       bfn = File.basename fn
       t = MIME::Types.type_for(bfn).first || MIME::Types.type_for("exe").first
-      payload = IO.read fn
+      payload = IO.binread fn
       ## Need to encode as base64 or quoted-printable if any lines are longer than 998 chars.
       encoding = if t.encoding != t.default_encoding and payload.each_line.any? { |l| l.length > 998 }
         t.default_encoding
diff --git a/test/unit/test_edit_message_mode.rb b/test/unit/test_edit_message_mode.rb
index 838da113..8d1b664c 100644
--- a/test/unit/test_edit_message_mode.rb
+++ b/test/unit/test_edit_message_mode.rb
@@ -64,7 +64,7 @@ class TestEditMessageMode < Minitest::Test
 
     msg = mode.send :build_message, Time.now
     attachment = msg.part(1)
-    assert_equal attachment_content, attachment.body
+    assert_equal attachment_content.b, attachment.body
     assert_equal "8bit", attachment.header["Content-Transfer-Encoding"]
   end
 
@@ -96,4 +96,37 @@ class TestEditMessageMode < Minitest::Test
     ## This was: https://github.com/sup-heliotrope/sup/issues/502
     assert_equal ["quoted-printable"], attachment.header.fetch_all("Content-Transfer-Encoding")
   end
+
+  ## https://github.com/sup-heliotrope/sup/issues/135
+  def test_attachment_8bit_non_utf8
+    body_content = "löl noñ-ÀSCII bodý"
+    ## CP1251 is not UTF-8 compatible.
+    ## This is a CSV only due to a quirk of mime-types, which wants to use 8bit for text/csv
+    ## (whereas text/plain is quoted-printable).
+    attachment_content = "С днем рождения!\n".encode("cp1251")
+    attachment_filename = File.join @path, "cp1251.csv"
+    File.write attachment_filename, attachment_content
+
+    opts = {
+      :header => {
+        "From" => +"sender@example.invalid",
+        "To" => +"recip@example.invalid",
+      },
+      :attachments => {
+        "cp1251.csv" => RMail::Message.make_file_attachment(attachment_filename),
+      },
+      :body => [body_content],
+    }
+    mode = Redwood::EditMessageMode.new opts
+
+    msg = mode.send :build_message, Time.now
+    attachment = msg.part(1)
+    assert_equal attachment_content.b, attachment.body
+    assert_equal "8bit", attachment.header["Content-Transfer-Encoding"]
+
+    ## Also check the serialized message, which is what the send_message method uses.
+    assert msg.to_s.lines.include? body_content.b + "\n"
+    assert msg.to_s.lines.include? "Content-Type: text/csv; name=\"cp1251.csv\"\n"
+    assert msg.to_s.lines.include? attachment_content.b
+  end
 end

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [sup.git] 02/02: fix wrong top-level Content-Type when sending messages with attachments
  2026-11-19 10:13 [sup.git] branch develop updated (7a1133a1 -> 154ff507) Dan Callaghan
  2026-11-19 10:13 ` [sup.git] 01/02: don't mangle non-UTF-8 attachments with 8bit transfer encoding Dan Callaghan
@ 2026-11-19 10:13 ` Dan Callaghan
  1 sibling, 0 replies; 3+ messages in thread
From: Dan Callaghan @ 2026-11-19 10:13 UTC (permalink / raw)
  To: sup-commits

New commit on branch develop:
https://supmua.dev/git/sup/commit/154ff507798d88288e3b265049244322833a40bc.html

commit 154ff507798d88288e3b265049244322833a40bc
Author: Dan Callaghan <djc@djc.id.au>
AuthorDate: Thu Nov 19 19:36:40 2026 +1100

    fix wrong top-level Content-Type when sending messages with attachments
    
    Commit 38f50a6ce0 regressed the Content-Type headers for a message with
    an attachment. The Content-Type header needs to be filled before the
    body gets converted in-place into an inline part, so that it goes along
    with the part and the top level becomes multipart/mixed.
    
    Fixes #629.
---
 lib/sup/modes/edit_message_mode.rb  |  4 ++--
 test/unit/test_edit_message_mode.rb | 28 ++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/lib/sup/modes/edit_message_mode.rb b/lib/sup/modes/edit_message_mode.rb
index eafb931b..aa3f4177 100644
--- a/lib/sup/modes/edit_message_mode.rb
+++ b/lib/sup/modes/edit_message_mode.rb
@@ -601,6 +601,8 @@ protected
 
   def build_message date
     m = RMail::Message.new
+    m.header["Content-Type"] = "text/plain; charset=#{$encoding}"
+    m.header["Content-Transfer-Encoding"] ||= +"8bit"
     m.body = @body.join("\n")
     m.body += "\n" + sig_lines.join("\n") unless @sig_edited
     ## body must end in a newline or GPG signatures will be WRONG!
@@ -645,8 +647,6 @@ protected
     m.header["Date"] = date.rfc2822
     m.header["Message-Id"] = @message_id
     m.header["User-Agent"] = "Sup/#{Redwood::VERSION}"
-    m.header["Content-Type"] = "text/plain; charset=#{$encoding}"
-    m.header["Content-Transfer-Encoding"] ||= +"8bit"
     m.header["MIME-Version"] = +"1.0"
     m
   end
diff --git a/test/unit/test_edit_message_mode.rb b/test/unit/test_edit_message_mode.rb
index 8d1b664c..5259fbe1 100644
--- a/test/unit/test_edit_message_mode.rb
+++ b/test/unit/test_edit_message_mode.rb
@@ -41,6 +41,27 @@ class TestEditMessageMode < Minitest::Test
     $config = nil
   end
 
+  def test_basic_message
+    opts = {
+      :header => {
+        "From" => +"sender@example.invalid",
+        "To" => +"recip@example.invalid",
+      },
+      :body => ["hello friends"],
+    }
+    mode = Redwood::EditMessageMode.new opts
+
+    msg = mode.send :build_message, Time.now
+    refute msg.multipart?
+    assert_equal "hello friends\n", msg.body
+    assert_equal "text/plain; charset=UTF-8", msg.header["Content-Type"]
+    assert_equal "8bit", msg.header["Content-Transfer-Encoding"]
+    assert_equal "1.0", msg.header["MIME-Version"]
+    assert_match(/^Sup\//, msg.header["User-Agent"])
+    refute_nil msg.header["Date"]
+    refute_nil msg.header["Message-Id"]
+  end
+
   def test_attachment_content_transfer_encoding
     ## RMail::Message#make_attachment will choose
     ## Content-Transfer-Encoding: 8bit for a CSV file.
@@ -120,8 +141,15 @@ class TestEditMessageMode < Minitest::Test
     mode = Redwood::EditMessageMode.new opts
 
     msg = mode.send :build_message, Time.now
+    inline = msg.part(0)
+    assert_equal body_content.b + "\n", inline.body
+    assert_equal "text/plain; charset=UTF-8", inline.header["Content-Type"]
+    assert_equal "inline", inline.header["Content-Disposition"]
+    assert_equal "8bit", inline.header["Content-Transfer-Encoding"]
     attachment = msg.part(1)
     assert_equal attachment_content.b, attachment.body
+    assert_equal 'text/csv; name="cp1251.csv"', attachment.header["Content-Type"]
+    assert_equal 'attachment; filename="cp1251.csv"', attachment.header["Content-Disposition"]
     assert_equal "8bit", attachment.header["Content-Transfer-Encoding"]
 
     ## Also check the serialized message, which is what the send_message method uses.

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-19 10:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 10:13 [sup.git] branch develop updated (7a1133a1 -> 154ff507) Dan Callaghan
2026-11-19 10:13 ` [sup.git] 01/02: don't mangle non-UTF-8 attachments with 8bit transfer encoding Dan Callaghan
2026-11-19 10:13 ` [sup.git] 02/02: fix wrong top-level Content-Type when sending messages with attachments Dan Callaghan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox