sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/

test/test_messages_dir.rb (3208B) - raw

      1 #!/usr/bin/ruby
      2 
      3 require 'test_helper'
      4 require 'sup'
      5 require 'stringio'
      6 
      7 require 'dummy_source'
      8 
      9 module Redwood
     10 
     11 class TestMessagesDir < ::Minitest::Test
     12 
     13   def setup
     14     @path = Dir.mktmpdir
     15     Redwood::HookManager.init File.join(@path, 'hooks')
     16     @log = StringIO.new
     17     Redwood::Logger.add_sink @log
     18     Redwood::Logger.remove_sink $stderr
     19   end
     20 
     21   def teardown
     22     Redwood::Logger.clear!
     23     Redwood::Logger.remove_sink @log
     24     Redwood::Logger.add_sink $stderr
     25     Redwood::HookManager.deinstantiate!
     26     FileUtils.rm_r @path
     27   end
     28 
     29   def test_binary_content_transfer_encoding
     30     source = DummySource.new("sup-test://test_messages")
     31     source.messages = [ fixture_path('binary-content-transfer-encoding-2.eml') ]
     32     source_info = 0
     33 
     34     sup_message = Message.build_from_source(source, source_info)
     35     sup_message.load_from_source!
     36 
     37     from = sup_message.from
     38     # "from" is just a simple person item
     39 
     40     assert_equal("foo@example.org", from.email)
     41     #assert_equal("Fake Sender", from.name)
     42 
     43     subj = sup_message.subj
     44     assert_equal("Important", subj)
     45 
     46     chunks = sup_message.load_from_source!
     47 
     48     # there should be only one chunk
     49     #assert_equal(1, chunks.length)
     50 
     51     lines = chunks[0].lines
     52 
     53     # lines should contain an error message
     54     assert (lines.join.include? "An error occurred while loading this message."), "This message should not load successfully"
     55 
     56     assert_match(/WARNING: problem reading message/, @log.string)
     57   end
     58 
     59   def test_bad_content_transfer_encoding
     60     source = DummySource.new("sup-test://test_messages")
     61     source.messages = [ fixture_path('bad-content-transfer-encoding-1.eml') ]
     62     source_info = 0
     63 
     64     sup_message = Message.build_from_source(source, source_info)
     65     sup_message.load_from_source!
     66 
     67     from = sup_message.from
     68     # "from" is just a simple person item
     69 
     70     assert_equal("foo@example.org", from.email)
     71     #assert_equal("Fake Sender", from.name)
     72 
     73     subj = sup_message.subj
     74     assert_equal("Content-Transfer-Encoding:-bug in sup", subj)
     75 
     76     chunks = sup_message.load_from_source!
     77 
     78     # there should be only one chunk
     79     #assert_equal(1, chunks.length)
     80 
     81     lines = chunks[0].lines
     82 
     83     # lines should contain an error message
     84     assert (lines.join.include? "An error occurred while loading this message."), "This message should not load successfully"
     85 
     86     assert_match(/WARNING: problem reading message/, @log.string)
     87   end
     88 
     89   def test_missing_line
     90     source = DummySource.new("sup-test://test_messages")
     91     source.messages = [ fixture_path('missing-line.eml') ]
     92     source_info = 0
     93 
     94     sup_message = Message.build_from_source(source, source_info)
     95     sup_message.load_from_source!
     96 
     97     from = sup_message.from
     98     # "from" is just a simple person item
     99 
    100     assert_equal("foo@aol.com", from.email)
    101     #assert_equal("Fake Sender", from.name)
    102 
    103     subj = sup_message.subj
    104     assert_equal("Encoding bug", subj)
    105 
    106     chunks = sup_message.load_from_source!
    107 
    108     # there should be only one chunk
    109     #assert_equal(1, chunks.length)
    110 
    111     lines = chunks[0].lines
    112 
    113     badline = lines[0]
    114     assert (badline.display_length > 0), "The length of this line should greater than 0: #{badline}"
    115 
    116   end
    117 end
    118 
    119 end
    120 
    121 # vim:noai:ts=2:sw=2: