test/test_message.rb in sup-0.22.1 vs test/test_message.rb in sup-0.23

- old
+ new

@@ -179,10 +179,55 @@ chunks = sup_message.load_from_source! # read the message body chunks # TODO: Add more asserts end + def test_text_attachment_decoding + message = fixture('text-attachments-with-charset.eml') + + source = DummySource.new("sup-test://test_text_attachment_decoding") + source.messages = [ message ] + source_info = 0 + + sup_message = Message.build_from_source(source, source_info) + sup_message.load_from_source! + + chunks = sup_message.load_from_source! + assert_equal(5, chunks.length) + assert(chunks[0].is_a? Redwood::Chunk::Text) + ## The first attachment declares charset=us-ascii + assert(chunks[1].is_a? Redwood::Chunk::Attachment) + assert_equal(["This is ASCII"], chunks[1].lines) + ## The second attachment declares charset=koi8-r and has some Cyrillic + assert(chunks[2].is_a? Redwood::Chunk::Attachment) + assert_equal(["\u041f\u0440\u0438\u0432\u0435\u0442"], chunks[2].lines) + ## The third attachment declares charset=utf-8 and has an emoji + assert(chunks[3].is_a? Redwood::Chunk::Attachment) + assert_equal(["\u{1f602}"], chunks[3].lines) + ## The fourth attachment declares no charset and has a non-ASCII byte, + ## which will be replaced with U+FFFD REPLACEMENT CHARACTER + assert(chunks[4].is_a? Redwood::Chunk::Attachment) + assert_equal(["Embedded\ufffdgarbage"], chunks[4].lines) + end + + def test_mailing_list_header + message = fixture('mailing-list-header.eml') + + source = DummySource.new("sup-test://test_mailing_list_header") + source.messages = [ message ] + source_info = 0 + + sup_message = Message.build_from_source(source, source_info) + sup_message.load_from_source! + + assert(sup_message.list_subscribe.nil?) + assert_equal("<https://lists.openembedded.org/g/openembedded-devel/unsub>", + sup_message.list_unsubscribe) + assert_equal("openembedded-devel@lists.openembedded.org", sup_message.list_address.email) + assert_equal("openembedded-devel", sup_message.list_address.name) + end + def test_blank_header_lines message = fixture('blank-header-fields.eml') source = DummySource.new("sup-test://test_blank_header_lines") source.messages = [ message ] @@ -223,9 +268,38 @@ # TODO: test different error cases, malformed messages etc. # TODO: test different quoting styles, see that they are all divided # to chunks properly + def test_zimbra_quote_with_bottom_post + # Zimbra does an Outlook-style "Original Message" delimiter and then *also* + # prefixes each quoted line with a > marker. That's okay until the sender + # tries to do the right thing and reply after the quote. + # In this case we want to just look at the > markers when determining where + # the quoted chunk ends. + message = fixture('zimbra-quote-with-bottom-post.eml') + + source = DummySource.new("sup-test://test_zimbra_quote_with_bottom_post") + source.messages = [ message ] + source_info = 0 + + sup_message = Message.build_from_source(source, source_info) + chunks = sup_message.load_from_source! + + assert_equal(3, chunks.length) + + # TODO this chunk should ideally be part of the quote chunk after it. + assert(chunks[0].is_a? Redwood::Chunk::Text) + assert_equal(1, chunks[0].lines.length) + assert_equal("----- Original Message -----", chunks[0].lines.first) + + assert(chunks[1].is_a? Redwood::Chunk::Quote) + + assert(chunks[2].is_a? Redwood::Chunk::Text) + assert_equal(3, chunks[2].lines.length) + assert_equal("This is the reply from the Zimbra user.", + chunks[2].lines[2]) + end end end # vim:noai:ts=2:sw=2: