File: test_messages_dir.rb

package info (click to toggle)
sup-mail 0.22.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 1,168 kB
  • sloc: ruby: 12,583; sh: 115; makefile: 9
file content (123 lines) | stat: -rw-r--r-- 3,229 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/ruby

require 'test_helper'
require 'sup'
require 'stringio'

require 'dummy_source'

module Redwood

class TestMessagesDir < ::Minitest::Test

  def setup
    @path = Dir.mktmpdir
    Redwood::HookManager.init File.join(@path, 'hooks')
  end

  def teardown
    Redwood::HookManager.deinstantiate!
    FileUtils.rm_r @path
  end

  def test_binary_content_transfer_encoding
    message = ''
    File.open('test/fixtures/binary-content-transfer-encoding-2.eml') { |f| message = f.read }

    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@example.org", from.email)
    #assert_equal("Fake Sender", from.name)

    subj = sup_message.subj
    assert_equal("Important", 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

    # 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_bad_content_transfer_encoding
    message = ''
    File.open('test/fixtures/bad-content-transfer-encoding-1.eml') { |f| message = f.read }

    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@example.org", from.email)
    #assert_equal("Fake Sender", from.name)

    subj = sup_message.subj
    assert_equal("Content-Transfer-Encoding:-bug in sup", 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

    # 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/fixtures/missing-line.eml') { |f| message = f.read }

    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

# vim:noai:ts=2:sw=2: