sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 9bfe7ee6169eb3e5c722112340291ca5a7ca73a7
parent 89ac0a7fd8a9da8cc5627b6423ea144bd0962f08
Author: Dan Callaghan <djc@djc.id.au>
Date:   Sat, 21 Nov 2026 14:50:28 +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.

Diffstat:
M lib/sup/message_chunks.rb | 9 ++++++++-
M lib/sup/modes/edit_message_mode.rb | 14 +++++++++++++-
M 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
@@ -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
@@ -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
@@ -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