sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 208a6ac6d2a0beb9f5278199d3de81fbe3abf4f4
parent dc987fff83414adfbaaf244d0ef17b9a4a8ac1e3
Author: Gaute Hope <eg@gaute.vetsj.com>
Date:   Thu, 29 Aug 2013 07:36:19 +0200

Merge #136: Ensure valid encoding on attachments in forwarded mail

Fixes #135. Forwarded attachments/parts may contain invalid encoding
resulting in failure when forwarding email. This fix uses fix_encoding!
to ensure valid encoding on all parts.

Squashed commit of the following:

commit 83b057e77b9409dba0a50dab9baf94727d8e5e0f
Author: Gaute Hope 
Date:   Fri Aug 23 09:06:04 2013 +0200

    fix encoding of fields and attachments as well, specify output stream as UTF-8

commit b89bf34e2e47940a7853403a118a11070e0ee8c3
Author: Gaute Hope 
Date:   Fri Aug 23 08:40:54 2013 +0200

    Revert "fix encoding of all parts"

    This reverts commit 98f9a7c609828a9c57ab4db2fe9c2c826f6d201b.

commit 98f9a7c609828a9c57ab4db2fe9c2c826f6d201b
Author: Gaute Hope 
Date:   Fri Aug 23 08:38:45 2013 +0200

    fix encoding of all parts

commit 43e80873e5fd7705a6218071eaff30d53b25515a
Author: Gaute Hope 
Date:   Wed Aug 21 08:45:06 2013 +0200

    Fix encoding on message to be forwarded

Diffstat:
M lib/sup/modes/edit_message_mode.rb | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/lib/sup/modes/edit_message_mode.rb b/lib/sup/modes/edit_message_mode.rb
@@ -489,7 +489,7 @@ protected
               return false
         end
       else
-        IO.popen(acct.sendmail, "w") { |p| p.puts m }
+        IO.popen(acct.sendmail, "w:UTF-8") { |p| p.puts m }
         raise SendmailCommandFailed, "Couldn't execute #{acct.sendmail}" unless $? == 0
       end
 
@@ -517,6 +517,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!
 
     ## there are attachments, so wrap body in an attachment of its own
     unless @attachments.empty?
@@ -525,7 +526,10 @@ protected
       m = RMail::Message.new
 
       m.add_part body_m
-      @attachments.each { |a| m.add_part a }
+      @attachments.each do |a|
+        a.body = a.body.fix_encoding! if a.body.kind_of? String
+        m.add_part a
+      end
     end
 
     ## do whatever crypto transformation is necessary
@@ -547,9 +551,9 @@ protected
       m.header[k] =
         case v
         when String
-          k.match(/subject/i) ? mime_encode_subject(v) : mime_encode_address(v)
+          (k.match(/subject/i) ? mime_encode_subject(v) : mime_encode_address(v)).fix_encoding!
         when Array
-          v.map { |v| mime_encode_address v }.join ", "
+          (v.map { |v| mime_encode_address v }.join ", ").fix_encoding!
         end
     end