whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@apache.org
Subject [whimsy] branch master updated: fix encoding problems
Date Tue, 13 Aug 2019 19:42:30 GMT
This is an automated email from the ASF dual-hosted git repository.

rubys pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new 16768c4  fix encoding problems
16768c4 is described below

commit 16768c4448ebbe733570718522dde1a035ee5f27
Author: Sam Ruby <rubys@intertwingly.net>
AuthorDate: Tue Aug 13 13:28:10 2019 -0400

    fix encoding problems
---
 www/board/agenda/helpers/string.rb         | 11 +++++++++++
 www/secretary/workbench/helpers.rb         | 13 +++++++++++++
 www/secretary/workbench/models/mailbox.rb  |  2 +-
 www/secretary/workbench/views/body.html.rb |  6 +++---
 4 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/www/board/agenda/helpers/string.rb b/www/board/agenda/helpers/string.rb
index d188220..c06bfb4 100644
--- a/www/board/agenda/helpers/string.rb
+++ b/www/board/agenda/helpers/string.rb
@@ -42,4 +42,15 @@ class String
     end
     self
   end
+
+  # fix encoding errors
+  def fix_encoding
+    result = self
+
+    if encoding == Encoding::BINARY
+      result = encode('utf-8', invalid: :replace, undef: :replace)
+    end
+
+    result
+  end
 end
diff --git a/www/secretary/workbench/helpers.rb b/www/secretary/workbench/helpers.rb
index c6b215f..e04f2e8 100644
--- a/www/secretary/workbench/helpers.rb
+++ b/www/secretary/workbench/helpers.rb
@@ -53,3 +53,16 @@ class Wunderbar::JsonBuilder
     _headers message.headers
   end
 end
+
+class String
+  # fix encoding errors
+  def fix_encoding
+    result = self
+
+    if encoding == Encoding::BINARY
+      result = encode('utf-8', invalid: :replace, undef: :replace)
+    end
+
+    result
+  end
+end
diff --git a/www/secretary/workbench/models/mailbox.rb b/www/secretary/workbench/models/mailbox.rb
index c3f3f75..50e8842 100644
--- a/www/secretary/workbench/models/mailbox.rb
+++ b/www/secretary/workbench/models/mailbox.rb
@@ -164,7 +164,7 @@ class Mailbox
       {
         time: message[:time] || '',
         href: "#{message[:source]}/#{id}/",
-        from: message[:name] || message[:from],
+        from: (message[:name] || message[:from]).to_s.fix_encoding,
         subject: message['Subject'],
         status: message[:status]
       }
diff --git a/www/secretary/workbench/views/body.html.rb b/www/secretary/workbench/views/body.html.rb
index 97eed25..02ffbeb 100644
--- a/www/secretary/workbench/views/body.html.rb
+++ b/www/secretary/workbench/views/body.html.rb
@@ -16,18 +16,18 @@ _html do
     end
     _tr do
       _td 'From:'
-      _td @message.from
+      _td @message.from.to_s.fix_encoding
     end
 
     _tr do
       _td 'To:'
-      _td @message.to
+      _td @message.to.to_s.fix_encoding
     end
 
     if @message.cc and not @message.cc.empty?
       _tr do
         _td 'Cc:'
-        _td @message.cc.join(', ')
+        _td @message.cc.join(', ').to_s.fix_encoding
       end
     end
 


Mime
View raw message