9 class TestMBoxParsing < Test::Unit::TestCase
16 def test_normal_headers
17 h = Source.parse_raw_email_header StringIO.new(<<EOS)
18 From: Bob <bob@bob.com>
19 To: Sally <sally@sally.com>
22 assert_equal "Bob <bob@bob.com>", h["from"]
23 assert_equal "Sally <sally@sally.com>", h["to"]
24 assert_nil h["message-id"]
28 h = Source.parse_raw_email_header StringIO.new(<<EOS)
29 From: Bob <bob@bob.com>
30 Subject: one two three
32 To: Sally <sally@sally.com>
38 assert_equal "one two three four five six", h["subject"]
39 assert_equal "Sally <sally@sally.com>", h["to"]
40 assert_equal "<seven> <eight>", h["references"]
43 def test_ignore_spacing
45 "Subject:one two three end\n",
46 "Subject: one two three end\n",
47 "Subject: one two three end \n",
50 h = Source.parse_raw_email_header StringIO.new(s)
51 assert_equal "one two three end", h["subject"]
55 def test_message_id_ignore_spacing
57 "Message-Id: <one@bob.com> \n",
58 "Message-Id:<one@bob.com> \n",
61 h = Source.parse_raw_email_header StringIO.new(s)
62 assert_equal "<one@bob.com>", h["message-id"]
67 h = Source.parse_raw_email_header StringIO.new("")
68 assert_equal nil, h["message-id"]
71 def test_empty_headers
77 h = Source.parse_raw_email_header StringIO.new(s)
78 assert_equal "", h["message-id"]
82 def test_detect_end_of_headers
83 h = Source.parse_raw_email_header StringIO.new(<<EOS)
84 From: Bob <bob@bob.com>
88 assert_equal "Bob <bob@bob.com>", h["from"]
91 h = Source.parse_raw_email_header StringIO.new(<<EOS)
92 From: Bob <bob@bob.com>
96 assert_equal "Bob <bob@bob.com>", h["from"]
99 h = Source.parse_raw_email_header StringIO.new(<<EOS)
100 From: Bob <bob@bob.com>
104 assert_equal "Bob <bob@bob.com>", h["from"]
108 def test_from_line_splitting
109 l = MBox::Loader.new StringIO.new(<<EOS)
110 From sup-talk-bounces@rubyforge.org Mon Apr 27 12:56:18 2009
111 From: Bob <bob@bob.com>
114 Hello there friend. How are you?
116 From sea to shining sea
118 From bob@bob.com I get only spam.
124 (that second one has spaces at the endj
126 This is the end of the email.
128 offset, labels = l.next
129 assert_equal 0, offset
130 offset, labels = l.next
134 def test_more_from_line_splitting
135 l = MBox::Loader.new StringIO.new(<<EOS)
136 From sup-talk-bounces@rubyforge.org Mon Apr 27 12:56:18 2009
137 From: Bob <bob@bob.com>
140 Hello there friend. How are you?
142 From bob@bob.com Mon Apr 27 12:56:19 2009
143 From: Bob <bob@bob.com>
146 Hello again! Would you like to buy my products?
148 offset, labels = l.next
149 assert_not_nil offset
151 offset, labels = l.next
152 assert_not_nil offset
154 offset, labels = l.next