From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by bl2.djc.id.au (Postfix, from userid 1000) id F168D2D037D; Thu, 19 Nov 2026 21:13:04 +1100 (AEDT) Date: Thu, 19 Nov 2026 21:13:06 +1100 To: sup-commits@supmua.dev Subject: [sup.git] 02/02: fix wrong top-level Content-Type when sending messages with attachments MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Reply-To: Dan Callaghan In-Reply-To: <179508318470.228777.12759209988489611778@bl2.djc.id.au> References: <179508318470.228777.12759209988489611778@bl2.djc.id.au> Thread-Index: AQAAEjRWUmvPWPj2T92INWdgOjRhpw== X-Git-Host: bl2.djc.id.au X-Git-Repo: sup.git X-Git-Refname: refs/heads/develop X-Git-Reftype: branch X-Git-Rev: 154ff507798d88288e3b265049244322833a40bc X-Git-NotificationType: diff X-Git-Multimail-Version: 1.7.dev Auto-Submitted: auto-generated Message-Id: <20261119101304.F168D2D037D@bl2.djc.id.au> From: Dan Callaghan List-Id: New commit on branch develop: https://supmua.dev/git/sup/commit/154ff507798d88288e3b265049244322833a40bc.html commit 154ff507798d88288e3b265049244322833a40bc Author: Dan Callaghan 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.