sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 00bd7e6466f2fd698d5d3389072de37f74736f01
parent 0cad7b308237c07b8a46149908b2ad4806ac3d1d
Author: Gaute Hope <eg@gaute.vetsj.com>
Date:   Fri, 14 Mar 2014 08:45:22 +0100

Merge #256: Fix missing lines because of incorrect line width calculation

Diffstat:
M lib/sup/util.rb | 8 ++++++++
A test/messages/missing-line.eml | 9 +++++++++
M test/test_messages_dir.rb | 35 +++++++++++++++++++++++++++++++++++
3 files changed, 52 insertions(+), 0 deletions(-)
diff --git a/lib/sup/util.rb b/lib/sup/util.rb
@@ -267,6 +267,14 @@ end
 class String
   def display_length
     @display_length ||= Unicode.width(self.fix_encoding!, false)
+
+    # if Unicode.width fails and returns -1, fall back to
+    # regular String#length, see pull-request: #256.
+    if @display_length < 0
+      @display_length = self.length
+    end
+
+    @display_length
   end
 
   def slice_by_display_length len
diff --git a/test/messages/missing-line.eml b/test/messages/missing-line.eml
@@ -0,0 +1,9 @@
+From: foo@aol.com
+To: foo@test.com
+Subject: Encoding bug
+Content-Type: text/plain; charset="iso-8859-1"
+Content-Transfer-Encoding: quoted-printable
+
+This is =91 a test: the first line seems to disappear from the mail body but is
+still visible in the thread view.
+
diff --git a/test/test_messages_dir.rb b/test/test_messages_dir.rb
@@ -105,6 +105,41 @@ class TestMessagesDir < ::Minitest::Unit::TestCase
     # lines should contain an error message
     assert (lines.join.include? "An error occurred while loading this message."), "This message should not load successfully"
   end
+
+  def test_missing_line
+    message = ''
+    File.open 'test/messages/missing-line.eml' do |f|
+      message = f.read
+    end
+
+    source = DummySource.new("sup-test://test_messages")
+    source.messages = [ message ]
+    source_info = 0
+
+    sup_message = Message.build_from_source(source, source_info)
+    sup_message.load_from_source!
+
+    from = sup_message.from
+    # "from" is just a simple person item
+
+    assert_equal("foo@aol.com", from.email)
+    #assert_equal("Fake Sender", from.name)
+
+    subj = sup_message.subj
+    assert_equal("Encoding bug", subj)
+
+    chunks = sup_message.load_from_source!
+    indexable_chunks = sup_message.indexable_chunks
+
+    # there should be only one chunk
+    #assert_equal(1, chunks.length)
+
+    lines = chunks[0].lines
+
+    badline = lines[0]
+    assert (badline.display_length > 0), "The length of this line should greater than 0: #{badline}"
+
+  end
 end
 
 end