From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by bl2.djc.id.au (Postfix, from userid 1000) id 780AF2D45CD; Sat, 28 Nov 2026 17:13:35 +1100 (AEDT) Date: Sat, 28 Nov 2026 17:13:38 +1100 To: sup-commits@supmua.dev Subject: [sup.git] 03/08: show both raw and encoded sizes of attachments MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Reply-To: Dan Callaghan In-Reply-To: <179584641514.302139.17817016268117078700@bl2.djc.id.au> References: <179584641514.302139.17817016268117078700@bl2.djc.id.au> Thread-Index: AQAAEjRW8AyDbWtbRRaCMIXB6V3YXw== 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: 9bfe7ee6169eb3e5c722112340291ca5a7ca73a7 X-Git-NotificationType: diff X-Git-Multimail-Version: 1.7.dev Auto-Submitted: auto-generated Message-Id: <20261128061335.780AF2D45CD@bl2.djc.id.au> From: Dan Callaghan List-Id: New commit on branch develop: https://supmua.dev/git/sup/commit/9bfe7ee6169eb3e5c722112340291ca5a7ca73a7.html commit 9bfe7ee6169eb3e5c722112340291ca5a7ca73a7 Author: Dan Callaghan AuthorDate: Sat Nov 21 14:50:28 2026 +1100 show both raw and encoded sizes of attachments Also make the attachment line in edit-message-mode consistent with thread-view-mode. Both will now display the content type, decoded byte size, and encoded byte size (if it is different) in human friendly units. Fixes #457. --- lib/sup/message_chunks.rb | 9 ++++++++- lib/sup/modes/edit_message_mode.rb | 14 +++++++++++++- test/test_message.rb | 12 ++++++++---- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/lib/sup/message_chunks.rb b/lib/sup/message_chunks.rb index e9055d86..60ed47b6 100644 --- a/lib/sup/message_chunks.rb +++ b/lib/sup/message_chunks.rb @@ -95,6 +95,7 @@ EOS @filename = filename @quotable = false # changed to true if we can parse it through the # mime-decode hook, or if it's plain text + @encoded_content = encoded_content @raw_content = if encoded_content.body encoded_content.decode @@ -141,7 +142,13 @@ EOS if expandable? "Attachment: #{filename} (#{lines.length} lines)" else - "Attachment: #{filename} (#{content_type}; #{@raw_content.size.to_human_size})" + raw_size = @raw_content.bytesize.to_human_size + encoded_size = @encoded_content.body.bytesize.to_human_size + if encoded_size == raw_size + "Attachment: #{filename} (#{content_type}; #{raw_size})" + else + "Attachment: #{filename} (#{content_type}; #{raw_size}; #{encoded_size} encoded)" + end end end def safe_filename; Shellwords.escape(@filename).gsub("/", "_") end diff --git a/lib/sup/modes/edit_message_mode.rb b/lib/sup/modes/edit_message_mode.rb index aa3f4177..2cc8adaa 100644 --- a/lib/sup/modes/edit_message_mode.rb +++ b/lib/sup/modes/edit_message_mode.rb @@ -457,7 +457,19 @@ protected unless @attachments.empty? @text += [""] @attachment_lines_offset = @text.length - @text += (0 ... @attachments.size).map { |i| [[:attachment_color, "+ Attachment: #{@attachment_names[i]} (#{@attachments[i].body.size.to_human_size})"]] } + @text += (0 ... @attachments.size).map do |i| + name = @attachment_names[i] + content_type = @attachments[i].header.content_type + raw_size = @attachments[i].decode.bytesize.to_human_size + encoded_size = @attachments[i].body.bytesize.to_human_size + line = + if encoded_size == raw_size + "+ Attachment: #{name} (#{content_type}; #{raw_size})" + else + "+ Attachment: #{name} (#{content_type}; #{raw_size}; #{encoded_size} encoded)" + end + [[:attachment_color, line]] + end end end diff --git a/test/test_message.rb b/test/test_message.rb index 95b7378a..598aec31 100644 --- a/test/test_message.rb +++ b/test/test_message.rb @@ -112,13 +112,15 @@ class TestMessage < Minitest::Test assert_equal(4, chunks.length) assert(chunks[0].is_a? Redwood::Chunk::Quote) + assert_equal ["Excerpts from Fake Sender's message of Sun Dec 09 21:48:19 +0200 2007:", + "> Test message!"], + chunks[0].lines assert(chunks[1].is_a? Redwood::Chunk::Text) + assert_equal ["", "Thanks for the message!"], chunks[1].lines assert(chunks[2].is_a? Redwood::Chunk::Attachment) + assert_equal "Attachment: HACKING (application/octet-stream; 627B; 850B encoded)", chunks[2].patina_text assert(chunks[3].is_a? Redwood::Chunk::Attachment) - - # further testing of chunks will happen in test_message_chunks.rb - # (possibly not yet implemented) - + assert_equal "Attachment: Manifest.txt (13 lines)", chunks[3].patina_text end def test_broken_message_1 @@ -170,6 +172,8 @@ class TestMessage < Minitest::Test assert_equal(1, chunks.length) assert(chunks[0].is_a? Redwood::Chunk::Attachment) + assert_match(/^Attachment: sup-attachment-\d+-\d+\.html \(text\/html; 635B; 661B encoded\)$/, + chunks[0].patina_text) end def test_text_attachment_decoding