From: Dan Callaghan <dan@bl2.djc.id.au>
To: sup-commits@supmua.dev
Subject: [sup.git] 02/02: fix wrong top-level Content-Type when sending messages with attachments
Date: Thu, 19 Nov 2026 21:13:06 +1100 [thread overview]
Message-ID: <20261119101304.F168D2D037D@bl2.djc.id.au> (raw)
In-Reply-To: <179508318470.228777.12759209988489611778@bl2.djc.id.au>
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.
prev parent reply other threads:[~2026-11-19 10:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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=20261119101304.F168D2D037D@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