gurgitate-mail 1.10.0 → 1.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/test/test_header.rb CHANGED
@@ -1,10 +1,5 @@
1
- #!/opt/bin/ruby -w
2
-
3
- #------------------------------------------------------------------------
4
- #
5
- #------------------------------------------------------------------------
6
-
7
1
  builddir = File.join(File.dirname(__FILE__),"..")
2
+
8
3
  unless $:[0] == builddir
9
4
  $:.unshift builddir
10
5
  end
@@ -14,7 +9,6 @@ require 'test/unit/ui/console/testrunner'
14
9
  require 'stringio'
15
10
 
16
11
  class TC_Header < Test::Unit::TestCase
17
-
18
12
  def setup
19
13
  require 'gurgitate-mail'
20
14
  end
@@ -43,6 +37,17 @@ class TC_Header < Test::Unit::TestCase
43
37
  end
44
38
  end
45
39
 
40
+ def test_illegal_header
41
+ assert_raises Gurgitate::IllegalHeader do
42
+ h=Gurgitate::Header.new("not actually a header")
43
+ end
44
+ end
45
+
46
+ def test_header_name_and_values_separate
47
+ h=Gurgitate::Header.new("From", "test@example.com")
48
+ assert_equal h.name, "From", "Preparsed header is not From"
49
+ assert_equal h.contents, "test@example.com", "Preparsed header has wrong contents"
50
+ end
46
51
 
47
52
  # This is an illegal header that turns up in spam sometimes.
48
53
  # Crashing when you get spam is bad.
@@ -152,5 +157,12 @@ class TC_Header < Test::Unit::TestCase
152
157
  assert_equal(0,h.matches(/fromheader/),"Matches regex that would match input")
153
158
  assert_equal(nil,h.matches(/notininput/),"Does not match regex that would not match input")
154
159
  end
160
+
161
+ def test_string_match
162
+ h=Gurgitate::Header.new("From: fromheader@example.com")
163
+ assert_equal 0, h.matches("fromheader"), "doesn't match string properly"
164
+ assert_equal nil, h.matches("notininput"),
165
+ "matches something it shouldn't"
166
+ end
155
167
  end
156
168
 
data/test/test_headers.rb CHANGED
@@ -1,9 +1,3 @@
1
- #!/opt/bin/ruby -w
2
-
3
- #------------------------------------------------------------------------
4
- #
5
- #------------------------------------------------------------------------
6
-
7
1
  require 'test/unit'
8
2
  require 'test/unit/ui/console/testrunner'
9
3
  require 'stringio'
@@ -15,16 +9,15 @@ end
15
9
 
16
10
  class TC_Headers < Test::Unit::TestCase
17
11
  def setup
18
- require 'gurgitate-mail'
12
+ $:.unshift File.dirname(__FILE__)
13
+ require "gurgitate/headers"
19
14
  end
20
15
 
21
16
  def test_single_header
22
17
  h=Gurgitate::Headers.new(<<'EOF'
23
- From fromline@example.com Sat Sep 27 12:20:25 PDT 2003
24
18
  From: fromheader@example.com
25
19
  EOF
26
20
  )
27
- assert_equal("fromline@example.com",h.from)
28
21
  assert_equal(1,h["From"].length)
29
22
  assert_equal("From",h["From"][0].name)
30
23
  assert_equal("fromheader@example.com",h["From"][0].contents)
@@ -36,14 +29,14 @@ From fromline Sat Sep 27 12:20:25 PDT 2003
36
29
  From: fromheader@example.com
37
30
  EOF
38
31
  )
39
- assert_equal("fromline",h.from)
32
+ assert_equal("fromline", h.from)
40
33
  assert_equal(1,h["From"].length)
41
34
  assert_equal("From",h["From"][0].name)
42
35
  assert_equal("fromheader@example.com",h["From"][0].contents)
43
36
  assert_equal nil, h["To"]
44
37
  end
45
38
 
46
- def test_changing_headers
39
+ def basic_header_test
47
40
  h = Gurgitate::Headers.new(<<'EOF', "sender@example.com", "recipient@example.com")
48
41
  From: fromheader@example.com
49
42
  To: toheader@example.com
@@ -53,27 +46,28 @@ EOF
53
46
  assert_equal("From", h["From"][0].name)
54
47
  assert_equal("fromheader@example.com",h["From"][0].contents)
55
48
 
56
- h["From"].sub! "fromheader", "changedheader"
57
-
58
- assert_equal("changedheader@example.com",h["From"][0].contents)
49
+ yield h
59
50
  end
60
51
 
61
- def test_altered_headers
62
- h = Gurgitate::Headers.new(<<'EOF', "sender@example.com", "recipient@example.com")
63
- From: fromheader@example.com
64
- To: toheader@example.com
65
- Subject: Subject
66
- EOF
67
- assert_equal(1,h["From"].length)
68
- assert_equal("From", h["From"][0].name)
69
- assert_equal("fromheader@example.com",h["From"][0].contents)
52
+ def test_changing_headers
53
+ basic_header_test do |h|
54
+ h["From"].sub! "fromheader", "changedheader"
55
+
56
+ assert_equal("changedheader@example.com",h["From"][0].contents)
57
+ end
58
+ end
70
59
 
71
- new_header = h["From"].sub "fromheader", "changedheader"
72
60
 
73
- assert Gurgitate::HeaderBag === new_header
74
- assert_equal("changedheader@example.com",
75
- new_header[0].contents)
76
- assert_equal("fromheader@example.com",h["From"][0].contents)
61
+ def test_altered_headers
62
+ basic_header_test do |h|
63
+ new_header = h["From"].sub "fromheader", "changedheader"
64
+
65
+ assert Gurgitate::HeaderBag === new_header
66
+ assert_equal("changedheader@example.com",
67
+ new_header[0].contents, "sub didn't change contents")
68
+ assert_equal("fromheader@example.com",h["From"][0].contents,
69
+ "sub is changing in-place")
70
+ end
77
71
  end
78
72
 
79
73
  def test_matches
@@ -96,7 +90,7 @@ From Sat Sep 27 12:20:25 PDT 2003
96
90
  From: fromheader@example.com
97
91
  EOF
98
92
  )
99
- assert_equal("",h.from)
93
+ assert_equal("", h.from)
100
94
  assert_equal(1,h["From"].length)
101
95
  assert_equal("From",h["From"][0].name)
102
96
  assert_equal("fromheader@example.com",h["From"][0].contents)
@@ -107,7 +101,6 @@ EOF
107
101
  From: fromheader@example.com
108
102
  EOF
109
103
  )
110
- assert_equal('fromheader@example.com',h.from)
111
104
  assert_equal(1,h["From"].length)
112
105
  assert_equal("From",h["From"][0].name)
113
106
  assert_equal("fromheader@example.com",h["From"][0].contents)
@@ -117,22 +110,13 @@ EOF
117
110
  h = Gurgitate::Headers.new(<<'EOF', "sender@example.com", "recipient@example.com")
118
111
  From: fromheader@example.com
119
112
  To: toheader@example.com
120
- Subject: Subject
113
+ Subject: Subject line
121
114
  EOF
122
115
  assert_equal('sender@example.com', h.from)
123
116
  assert_equal('recipient@example.com', h.to)
124
117
  end
125
-
126
118
 
127
- def test_multiple_headers
128
- h=Gurgitate::Headers.new(<<'EOF'
129
- From fromline@example.com Sat Sep 27 12:20:25 PDT 2003
130
- From: fromheader@example.com
131
- To: toheader@example.com
132
- Subject: Subject line
133
- EOF
134
- )
135
- assert_equal(h.from,"fromline@example.com")
119
+ def standard_headers_tests h
136
120
  assert_equal(1,h["From"].length)
137
121
  assert_equal("From",h["From"][0].name)
138
122
  assert_equal("fromheader@example.com",h["From"][0].contents)
@@ -144,6 +128,17 @@ EOF
144
128
  assert_equal("Subject line",h["Subject"][0].contents)
145
129
  end
146
130
 
131
+ def multiple_headers_test
132
+ h=Gurgitate::Headers.new(<<'EOF'
133
+ From: fromheader@example.com
134
+ To: toheader@example.com
135
+ Subject: Subject line
136
+ EOF
137
+ )
138
+ assert_equal('fromheader@example.com',h.from)
139
+ standard_headers_tests h
140
+ end
141
+
147
142
  def test_missing_fromline
148
143
  h=Gurgitate::Headers.new(<<'EOF'
149
144
  From: fromheader@example.com
@@ -152,12 +147,16 @@ Subject: Subject line
152
147
  EOF
153
148
  )
154
149
  assert_equal('fromheader@example.com',h.from)
150
+ standard_headers_tests h
151
+ end
152
+
153
+ def multiline_default_tests h
154
+ assert_equal(h.from,"fromline@example.com")
155
155
  assert_equal(1,h["From"].length)
156
156
  assert_equal("From",h["From"][0].name)
157
157
  assert_equal("fromheader@example.com",h["From"][0].contents)
158
158
  assert_equal(1,h["To"].length)
159
159
  assert_equal("To",h["To"][0].name)
160
- assert_equal("toheader@example.com",h["To"][0].contents)
161
160
  assert_equal(1,h["Subject"].length)
162
161
  assert_equal("Subject",h["Subject"][0].name)
163
162
  assert_equal("Subject line",h["Subject"][0].contents)
@@ -172,16 +171,9 @@ To: toheader@example.com,
172
171
  Subject: Subject line
173
172
  EOF
174
173
  )
175
- assert_equal(h.from,"fromline@example.com")
176
- assert_equal(1,h["From"].length)
177
- assert_equal("From",h["From"][0].name)
178
- assert_equal("fromheader@example.com",h["From"][0].contents)
179
- assert_equal(1,h["To"].length)
180
- assert_equal("To",h["To"][0].name)
174
+ multiline_default_tests h
175
+
181
176
  assert_equal("toheader@example.com,\n nexttoheader@example.com",h["To"][0].contents)
182
- assert_equal(1,h["Subject"].length)
183
- assert_equal("Subject",h["Subject"][0].name)
184
- assert_equal("Subject line",h["Subject"][0].contents)
185
177
  end
186
178
 
187
179
  def test_multiline_headers_with_extra_colons
@@ -193,16 +185,9 @@ To: toheader@example.com,
193
185
  Subject: Subject line
194
186
  EOF
195
187
  )
196
- assert_equal(h.from,"fromline@example.com")
197
- assert_equal(1,h["From"].length)
198
- assert_equal("From",h["From"][0].name)
199
- assert_equal("fromheader@example.com",h["From"][0].contents)
200
- assert_equal(1,h["To"].length)
201
- assert_equal("To",h["To"][0].name)
188
+ multiline_default_tests h
189
+
202
190
  assert_equal("toheader@example.com,\n nexttoheader@example.com (The test: header)",h["To"][0].contents)
203
- assert_equal(1,h["Subject"].length)
204
- assert_equal("Subject",h["Subject"][0].name)
205
- assert_equal("Subject line",h["Subject"][0].contents)
206
191
  end
207
192
 
208
193
  def test_multiline_headers_with_various_levels_of_indentation
@@ -216,16 +201,8 @@ To: toheader@example.com,
216
201
  Subject: Subject line
217
202
  EOF
218
203
  )
219
- assert_equal(h.from,"fromline@example.com")
220
- assert_equal(1,h["From"].length)
221
- assert_equal("From",h["From"][0].name)
222
- assert_equal("fromheader@example.com",h["From"][0].contents)
223
- assert_equal(1,h["To"].length)
224
- assert_equal("To",h["To"][0].name)
204
+ multiline_default_tests h
225
205
  assert_equal("toheader@example.com,\n nexttoheader@example.com,\n thirdtoheader@example.com,\n fourthtoheader@example.com",h["To"][0].contents)
226
- assert_equal(1,h["Subject"].length)
227
- assert_equal("Subject",h["Subject"][0].name)
228
- assert_equal("Subject line",h["Subject"][0].contents)
229
206
  end
230
207
 
231
208
  def test_a_header_that_actually_crashed_gurgitate
@@ -298,7 +275,7 @@ List-Help: <mailto:nifty-request@mail.neurotica.com?subject=help>
298
275
  List-Id: Nifty <nifty.mail.neurotica.com>
299
276
  Original-recipient: rfc822;dagbrown@shaw.ca
300
277
  EOF
301
- )
278
+ )
302
279
  assert_equal(h.from,"nifty-bounces@neurotica.com")
303
280
  assert_equal(1,h["From"].length)
304
281
  assert_equal("From",h["From"][0].name)
@@ -325,7 +302,7 @@ EOF
325
302
  assert_equal("IAP password",h["Subject"][0].contents)
326
303
  end
327
304
 
328
- def test_fromline_no_hostname # illegal from line
305
+ def test_fromheader_no_hostname # illegal from header?
329
306
  m=<<'EOF'
330
307
  From HEYITBLEWUP Sat Mar 27 16:02:12 PST 2004
331
308
  Received: from ohno.mrbill.net (ohno.mrbill.net [207.200.6.75])
@@ -348,13 +325,19 @@ EOF
348
325
  assert_equal(1,h["From"].length)
349
326
  end
350
327
 
351
- def test_editing_header
328
+ def editing_template
352
329
  m = <<'EOF'
353
330
  From fromline@example.com Sat Oct 25 12:58:31 PDT 2003
354
331
  From: fromline@example.com
355
332
  To: toline@example.com
356
333
  Subject: Subject line
357
334
  EOF
335
+ return m.clone
336
+ end
337
+
338
+ def test_editing_header
339
+ m = editing_template
340
+
358
341
  h=Gurgitate::Headers.new(m)
359
342
  h["From"]="anotherfromline@example.com"
360
343
  assert_equal("anotherfromline@example.com",h["From"][0].contents,
@@ -364,12 +347,8 @@ EOF
364
347
  end
365
348
 
366
349
  def test_editing_from
367
- m = <<'EOF'
368
- From fromline@example.com Sat Oct 25 12:58:31 PDT 2003
369
- From: fromline@example.com
370
- To: toline@example.com
371
- Subject: Subject line
372
- EOF
350
+ m = editing_template
351
+
373
352
  h=Gurgitate::Headers.new(m)
374
353
  t=Time.new.to_s
375
354
  h.from="anotherfromline@example.com"
@@ -380,12 +359,8 @@ EOF
380
359
  end
381
360
 
382
361
  def test_match_multiple_headers
383
- m = <<'EOF'
384
- From fromline@example.com Sat Oct 25 12:58:31 PDT 2003
385
- From: fromline@example.com
386
- To: toline@example.com
387
- Subject: Subject line
388
- EOF
362
+ m = editing_template
363
+
389
364
  h=Gurgitate::Headers.new(m)
390
365
  assert_equal(true,h["From","To"] =~ /fromline@example.com/,
391
366
  "headers contains fromline")
@@ -482,3 +457,4 @@ EOF
482
457
  end
483
458
  end
484
459
 
460
+
@@ -0,0 +1,18 @@
1
+ builddir = File.join(File.dirname(__FILE__),"..")
2
+
3
+ unless $:[0] == builddir
4
+ $:.unshift builddir
5
+ end
6
+
7
+ require "test/test_headers_meddling_with_headers"
8
+
9
+ class TC_Headers_creating_from_hash < TC_Headers_meddling_with_headers
10
+ def setup
11
+ $:.unshift File.dirname(__FILE__)
12
+ require "gurgitate/headers"
13
+
14
+ @headers = Gurgitate::Headers.new :from => "fromline@example.com",
15
+ :to => "toline@example.com",
16
+ :subject => "Subject line"
17
+ end
18
+ end
@@ -0,0 +1,57 @@
1
+ require 'test/unit'
2
+ require 'test/unit/ui/console/testrunner'
3
+ require 'stringio'
4
+
5
+ builddir = File.join(File.dirname(__FILE__),"..")
6
+
7
+ unless $:[0] == builddir
8
+ $:.unshift builddir
9
+ end
10
+
11
+ class TC_Headers_meddling_with_headers < Test::Unit::TestCase
12
+ def setup
13
+ $:.unshift File.dirname(__FILE__)
14
+ require "gurgitate/headers"
15
+
16
+ @message = <<'EOF'
17
+ From: fromline@example.com
18
+ To: toline@example.com
19
+ Subject: Subject Line
20
+ EOF
21
+
22
+ @headers = Gurgitate::Headers.new @message
23
+ end
24
+
25
+ def test_match
26
+ assert @headers.match("From", /example.com/)
27
+ end
28
+
29
+ def test_nomatch
30
+ assert !@headers.match("From", /lart.ca/)
31
+ end
32
+
33
+ def test_match_regex
34
+ result = nil
35
+ assert_nothing_raised do
36
+ result = @headers.match "From", /example.com/
37
+ end
38
+ assert result
39
+ end
40
+
41
+ def test_match_string
42
+ result = nil
43
+
44
+ assert_nothing_raised do
45
+ assert result = @headers.match("From", "example.com")
46
+ end
47
+
48
+ assert result
49
+ result = nil
50
+
51
+ assert_nothing_raised do
52
+ result = @headers.match("From", "e.ample.com")
53
+ end
54
+
55
+ assert !result
56
+ end
57
+ end
@@ -0,0 +1,429 @@
1
+ require 'test/unit'
2
+ require 'test/unit/ui/console/testrunner'
3
+ require 'stringio'
4
+
5
+ builddir = File.join(File.dirname(__FILE__),"..")
6
+
7
+ unless $:[0] == builddir
8
+ $:.unshift builddir
9
+ end
10
+
11
+ class TC_Mail_headers < Test::Unit::TestCase
12
+ def setup
13
+ require 'gurgitate/mail_headers'
14
+ end
15
+
16
+ def test_single_header
17
+ h=Gurgitate::MailHeaders.new(<<'EOF'
18
+ From fromline@example.com Sat Sep 27 12:20:25 PDT 2003
19
+ From: fromheader@example.com
20
+ EOF
21
+ )
22
+ assert_equal("fromline@example.com",h.from)
23
+ assert_equal(1,h["From"].length)
24
+ assert_equal("From",h["From"][0].name)
25
+ assert_equal("fromheader@example.com",h["From"][0].contents)
26
+ end
27
+
28
+ def test_fromline_simple_username
29
+ h=Gurgitate::MailHeaders.new(<<'EOF'
30
+ From fromline Sat Sep 27 12:20:25 PDT 2003
31
+ From: fromheader@example.com
32
+ EOF
33
+ )
34
+ assert_equal("fromline",h.from)
35
+ assert_equal(1,h["From"].length)
36
+ assert_equal("From",h["From"][0].name)
37
+ assert_equal("fromheader@example.com",h["From"][0].contents)
38
+ assert_equal nil, h["To"]
39
+ end
40
+
41
+ def test_changing_headers
42
+ h = Gurgitate::MailHeaders.new(<<'EOF', "sender@example.com", "recipient@example.com")
43
+ From: fromheader@example.com
44
+ To: toheader@example.com
45
+ Subject: Subject
46
+ EOF
47
+ assert_equal(1,h["From"].length)
48
+ assert_equal("From", h["From"][0].name)
49
+ assert_equal("fromheader@example.com",h["From"][0].contents)
50
+
51
+ h["From"].sub! "fromheader", "changedheader"
52
+
53
+ assert_equal("changedheader@example.com",h["From"][0].contents)
54
+ end
55
+
56
+ def test_altered_headers
57
+ h = Gurgitate::MailHeaders.new(<<'EOF', "sender@example.com", "recipient@example.com")
58
+ From: fromheader@example.com
59
+ To: toheader@example.com
60
+ Subject: Subject
61
+ EOF
62
+ assert_equal(1,h["From"].length)
63
+ assert_equal("From", h["From"][0].name)
64
+ assert_equal("fromheader@example.com",h["From"][0].contents)
65
+
66
+ new_header = h["From"].sub "fromheader", "changedheader"
67
+
68
+ assert Gurgitate::HeaderBag === new_header
69
+ assert_equal("changedheader@example.com",
70
+ new_header[0].contents)
71
+ assert_equal("fromheader@example.com",h["From"][0].contents)
72
+ end
73
+
74
+ def test_matches
75
+ h = Gurgitate::MailHeaders.new(<<'EOF', "sender@example.com", "recipient@example.com")
76
+ From: fromheader@example.com
77
+ To: toheader@example.com
78
+ Subject: Subject
79
+ EOF
80
+ assert h.matches(["From", "To"], /example.com/)
81
+ assert !h.matches(["From", "To"], /example.net/)
82
+
83
+ assert h.matches("From", /example.com/)
84
+ assert !h.matches("From", /example.net/)
85
+ end
86
+
87
+
88
+ def test_fromline_no_username
89
+ h=Gurgitate::MailHeaders.new(<<'EOF'
90
+ From Sat Sep 27 12:20:25 PDT 2003
91
+ From: fromheader@example.com
92
+ EOF
93
+ )
94
+ assert_equal("",h.from)
95
+ assert_equal(1,h["From"].length)
96
+ assert_equal("From",h["From"][0].name)
97
+ assert_equal("fromheader@example.com",h["From"][0].contents)
98
+ end
99
+
100
+ def test_missing_toline
101
+ h=Gurgitate::MailHeaders.new(<<'EOF'
102
+ From: fromheader@example.com
103
+ EOF
104
+ )
105
+ assert_equal('fromheader@example.com',h.from)
106
+ assert_equal(1,h["From"].length)
107
+ assert_equal("From",h["From"][0].name)
108
+ assert_equal("fromheader@example.com",h["From"][0].contents)
109
+ end
110
+
111
+ def test_sender_and_recipient
112
+ h = Gurgitate::MailHeaders.new(<<'EOF', "sender@example.com", "recipient@example.com")
113
+ From: fromheader@example.com
114
+ To: toheader@example.com
115
+ Subject: Subject
116
+ EOF
117
+ assert_equal('sender@example.com', h.from)
118
+ assert_equal('recipient@example.com', h.to)
119
+ end
120
+
121
+
122
+ def test_multiple_headers
123
+ h=Gurgitate::MailHeaders.new(<<'EOF'
124
+ From fromline@example.com Sat Sep 27 12:20:25 PDT 2003
125
+ From: fromheader@example.com
126
+ To: toheader@example.com
127
+ Subject: Subject line
128
+ EOF
129
+ )
130
+ assert_equal(h.from,"fromline@example.com")
131
+ assert_equal(1,h["From"].length)
132
+ assert_equal("From",h["From"][0].name)
133
+ assert_equal("fromheader@example.com",h["From"][0].contents)
134
+ assert_equal(1,h["To"].length)
135
+ assert_equal("To",h["To"][0].name)
136
+ assert_equal("toheader@example.com",h["To"][0].contents)
137
+ assert_equal(1,h["Subject"].length)
138
+ assert_equal("Subject",h["Subject"][0].name)
139
+ assert_equal("Subject line",h["Subject"][0].contents)
140
+ end
141
+
142
+ def test_missing_fromline
143
+ h=Gurgitate::MailHeaders.new(<<'EOF'
144
+ From: fromheader@example.com
145
+ To: toheader@example.com
146
+ Subject: Subject line
147
+ EOF
148
+ )
149
+ assert_equal('fromheader@example.com',h.from)
150
+ assert_equal(1,h["From"].length)
151
+ assert_equal("From",h["From"][0].name)
152
+ assert_equal("fromheader@example.com",h["From"][0].contents)
153
+ assert_equal(1,h["To"].length)
154
+ assert_equal("To",h["To"][0].name)
155
+ assert_equal("toheader@example.com",h["To"][0].contents)
156
+ assert_equal(1,h["Subject"].length)
157
+ assert_equal("Subject",h["Subject"][0].name)
158
+ assert_equal("Subject line",h["Subject"][0].contents)
159
+ end
160
+
161
+ def test_multiline_headers
162
+ h=Gurgitate::MailHeaders.new(<<'EOF'
163
+ From fromline@example.com Sat Oct 25 12:58:31 PDT 2003
164
+ From: fromheader@example.com
165
+ To: toheader@example.com,
166
+ nexttoheader@example.com
167
+ Subject: Subject line
168
+ EOF
169
+ )
170
+ assert_equal(h.from,"fromline@example.com")
171
+ assert_equal(1,h["From"].length)
172
+ assert_equal("From",h["From"][0].name)
173
+ assert_equal("fromheader@example.com",h["From"][0].contents)
174
+ assert_equal(1,h["To"].length)
175
+ assert_equal("To",h["To"][0].name)
176
+ assert_equal("toheader@example.com,\n nexttoheader@example.com",h["To"][0].contents)
177
+ assert_equal(1,h["Subject"].length)
178
+ assert_equal("Subject",h["Subject"][0].name)
179
+ assert_equal("Subject line",h["Subject"][0].contents)
180
+ end
181
+
182
+ def test_multiline_headers_with_extra_colons
183
+ h=Gurgitate::MailHeaders.new(<<'EOF'
184
+ From fromline@example.com Sat Oct 25 12:58:31 PDT 2003
185
+ From: fromheader@example.com
186
+ To: toheader@example.com,
187
+ nexttoheader@example.com (The test: header)
188
+ Subject: Subject line
189
+ EOF
190
+ )
191
+ assert_equal(h.from,"fromline@example.com")
192
+ assert_equal(1,h["From"].length)
193
+ assert_equal("From",h["From"][0].name)
194
+ assert_equal("fromheader@example.com",h["From"][0].contents)
195
+ assert_equal(1,h["To"].length)
196
+ assert_equal("To",h["To"][0].name)
197
+ assert_equal("toheader@example.com,\n nexttoheader@example.com (The test: header)",h["To"][0].contents)
198
+ assert_equal(1,h["Subject"].length)
199
+ assert_equal("Subject",h["Subject"][0].name)
200
+ assert_equal("Subject line",h["Subject"][0].contents)
201
+ end
202
+
203
+ def test_multiline_headers_with_various_levels_of_indentation
204
+ h=Gurgitate::MailHeaders.new(<<'EOF'
205
+ From fromline@example.com Sat Oct 25 12:58:31 PDT 2003
206
+ From: fromheader@example.com
207
+ To: toheader@example.com,
208
+ nexttoheader@example.com,
209
+ thirdtoheader@example.com,
210
+ fourthtoheader@example.com
211
+ Subject: Subject line
212
+ EOF
213
+ )
214
+ assert_equal(h.from,"fromline@example.com")
215
+ assert_equal(1,h["From"].length)
216
+ assert_equal("From",h["From"][0].name)
217
+ assert_equal("fromheader@example.com",h["From"][0].contents)
218
+ assert_equal(1,h["To"].length)
219
+ assert_equal("To",h["To"][0].name)
220
+ assert_equal("toheader@example.com,\n nexttoheader@example.com,\n thirdtoheader@example.com,\n fourthtoheader@example.com",h["To"][0].contents)
221
+ assert_equal(1,h["Subject"].length)
222
+ assert_equal("Subject",h["Subject"][0].name)
223
+ assert_equal("Subject line",h["Subject"][0].contents)
224
+ end
225
+
226
+ def test_a_header_that_actually_crashed_gurgitate
227
+ h=Gurgitate::MailHeaders.new(<<'EOF'
228
+ Return-path: <nifty-bounces@neurotica.com>
229
+ Received: from pd8mr3no.prod.shaw.ca
230
+ (pd8mr3no-qfe2.prod.shaw.ca [10.0.144.160]) by l-daemon
231
+ (iPlanet Messaging Server 5.2 HotFix 1.16 (built May 14 2003))
232
+ with ESMTP id <0HO6002FDGPREL@l-daemon> for dagbrown@shaw.ca; Tue,
233
+ 11 Nov 2003 00:56:15 -0700 (MST)
234
+ Received: from pd7mi4no.prod.shaw.ca ([10.0.149.117])
235
+ by l-daemon (iPlanet Messaging Server 5.2 HotFix 1.18 (built Jul 28 2003))
236
+ with ESMTP id <0HO60055LGPR40@l-daemon> for dagbrown@shaw.ca
237
+ (ORCPT dagbrown@shaw.ca); Tue, 11 Nov 2003 00:56:15 -0700 (MST)
238
+ Received: from venom.easydns.com (smtp.easyDNS.com [216.220.40.247])
239
+ by l-daemon (iPlanet Messaging Server 5.2 HotFix 1.18 (built Jul 28 2003))
240
+ with ESMTP id <0HO60079HGPR79@l-daemon> for dagbrown@shaw.ca; Tue,
241
+ 11 Nov 2003 00:56:15 -0700 (MST)
242
+ Received: from ohno.mrbill.net (ohno.mrbill.net [207.200.6.75])
243
+ by venom.easydns.com (Postfix) with ESMTP id D6493722BB for
244
+ <dagbrown@lart.ca>; Tue, 11 Nov 2003 02:53:50 -0500 (EST)
245
+ Received: by ohno.mrbill.net (Postfix) id ED0AD53380; Tue,
246
+ 11 Nov 2003 01:56:13 -0600 (CST)
247
+ Received: from mail.neurotica.com (neurotica.com [207.100.203.161])
248
+ by ohno.mrbill.net (Postfix) with ESMTP id 5CD465337F for
249
+ <dagbrown@dagbrown.com>; Tue, 11 Nov 2003 01:56:13 -0600 (CST)
250
+ Received: from mail.neurotica.com (localhost [127.0.0.1])
251
+ by mail.neurotica.com (Postfix) with ESMTP id CDAA2364C; Tue,
252
+ 11 Nov 2003 02:56:03 -0500 (EST)
253
+ Received: from smtpzilla5.xs4all.nl (smtpzilla5.xs4all.nl [194.109.127.141])
254
+ by mail.neurotica.com (Postfix) with ESMTP id B6A22361E for
255
+ <nifty@neurotica.com>; Tue, 11 Nov 2003 02:56:00 -0500 (EST)
256
+ Received: from xs1.xs4all.nl (xs1.xs4all.nl [194.109.21.2])
257
+ by smtpzilla5.xs4all.nl (8.12.9/8.12.9) with ESMTP id hAB7u5ZZ042116 for
258
+ <nifty@neurotica.com>; Tue, 11 Nov 2003 08:56:05 +0100 (CET)
259
+ Received: from xs1.xs4all.nl (wstan@localhost.xs4all.nl [127.0.0.1])
260
+ by xs1.xs4all.nl (8.12.10/8.12.9) with ESMTP id hAB7u5xE048677 for
261
+ <nifty@neurotica.com>; Tue,
262
+ 11 Nov 2003 08:56:05 +0100 (CET envelope-from wstan@xs4all.nl)
263
+ Received: (from wstan@localhost) by xs1.xs4all.nl (8.12.10/8.12.9/Submit)
264
+ id hAB7u4sZ048676 for nifty@neurotica.com; Tue,
265
+ 11 Nov 2003 08:56:04 +0100 (CET envelope-from wstan)
266
+ Date: Tue, 11 Nov 2003 08:56:04 +0100
267
+ From: William Staniewicz <wstan@xs4all.nl>
268
+ Subject: Re: [nifty] Ping...
269
+ In-reply-to: <9636B78C-140B-11D8-9EE6-003065D0C184@nimitzbrood.com>
270
+ Sender: nifty-bounces@neurotica.com
271
+ To: Nifty <nifty@neurotica.com>
272
+ Cc:
273
+ Errors-to: nifty-bounces@neurotica.com
274
+ Reply-to: Nifty <nifty@neurotica.com>
275
+ Message-id: <20031111075604.GE79497@xs4all.nl>
276
+ MIME-version: 1.0
277
+ Content-type: text/plain; charset=us-ascii
278
+ Content-disposition: inline
279
+ Precedence: list
280
+ X-BeenThere: nifty@mail.neurotica.com
281
+ Delivered-to: dagbrown@mrbill.net
282
+ Delivered-to: nifty@neurotica.com
283
+ User-Agent: Mutt/1.4.1i
284
+ X-Original-To: nifty@neurotica.com
285
+ References: <9636B78C-140B-11D8-9EE6-003065D0C184@nimitzbrood.com>
286
+ X-Mailman-Version: 2.1.2
287
+ List-Post: <mailto:nifty@mail.neurotica.com>
288
+ List-Subscribe: <http://mail.neurotica.com:8080/mailman/listinfo/nifty>,
289
+ <mailto:nifty-request@mail.neurotica.com?subject=subscribe>
290
+ List-Unsubscribe: <http://mail.neurotica.com:8080/mailman/listinfo/nifty>,
291
+ <mailto:nifty-request@mail.neurotica.com?subject=unsubscribe>
292
+ List-Help: <mailto:nifty-request@mail.neurotica.com?subject=help>
293
+ List-Id: Nifty <nifty.mail.neurotica.com>
294
+ Original-recipient: rfc822;dagbrown@shaw.ca
295
+ EOF
296
+ )
297
+ assert_equal(h.from,"nifty-bounces@neurotica.com")
298
+ assert_equal(1,h["From"].length)
299
+ assert_equal("From",h["From"][0].name)
300
+ assert_equal("William Staniewicz <wstan@xs4all.nl>",h["From"][0].contents)
301
+ assert_equal(1,h["To"].length)
302
+ assert_equal("To",h["To"][0].name)
303
+ assert_equal('Nifty <nifty@neurotica.com>',h["To"][0].contents)
304
+
305
+ assert_equal(1,h["Subject"].length)
306
+ assert_equal("Subject",h["Subject"][0].name)
307
+ assert_equal("Re: [nifty] Ping...",h["Subject"][0].contents)
308
+ end
309
+
310
+ def test_another_crashy_set_of_headers
311
+ h=Gurgitate::MailHeaders.new(<<'EOF'
312
+ From HEYITBLEWUP Fri Nov 21 14:41:08 PST 2003
313
+ Received: from unknown (harley.radius [192.168.0.123]) by yoda.radius with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13)
314
+ id LYN7YZKG; Wed, 9 Jul 2003 14:36:40 -0700
315
+ Subject: IAP password
316
+ EOF
317
+ )
318
+ assert_equal(h.from,"HEYITBLEWUP")
319
+ assert_equal(nil,h["From"])
320
+ assert_equal("IAP password",h["Subject"][0].contents)
321
+ end
322
+
323
+ def test_fromline_no_hostname # illegal from line
324
+ m=<<'EOF'
325
+ From HEYITBLEWUP Sat Mar 27 16:02:12 PST 2004
326
+ Received: from ohno.mrbill.net (ohno.mrbill.net [207.200.6.75])
327
+ by lart.ca (Postfix) with ESMTP id A485F104CA9
328
+ for <dagbrown@lart.ca>; Sat, 27 Mar 2004 15:58:06 -0800 (PST)
329
+ Received: by ohno.mrbill.net (Postfix)
330
+ id 0D3423A289; Sat, 27 Mar 2004 17:58:42 -0600 (CST)
331
+ Delivered-To: dagbrown@mrbill.net
332
+ Received: from 66-168-59-126.jvl.wi.charter.com (66-168-59-126.jvl.wi.charter.com [66.168.59.126])
333
+ by ohno.mrbill.net (Postfix) with SMTP id 948BD3A288
334
+ for <dagbrown@dagbrown.com>; Sat, 27 Mar 2004 17:58:41 -0600 (CST)
335
+ X-Message-Info: HOCBSQX
336
+ Message-Id: <20040327235841.948BD3A288@ohno.mrbill.net>
337
+ Date: Sat, 27 Mar 2004 17:58:41 -0600 (CST)
338
+ From: ""@
339
+ To: undisclosed-recipients: ;
340
+ EOF
341
+ h=Gurgitate::MailHeaders.new(m)
342
+ assert_equal(%{""@},h["From"][0].contents)
343
+ assert_equal(1,h["From"].length)
344
+ end
345
+
346
+ def test_editing_header
347
+ m = <<'EOF'
348
+ From fromline@example.com Sat Oct 25 12:58:31 PDT 2003
349
+ From: fromline@example.com
350
+ To: toline@example.com
351
+ Subject: Subject line
352
+ EOF
353
+ h=Gurgitate::MailHeaders.new(m)
354
+ h["From"]="anotherfromline@example.com"
355
+ assert_equal("anotherfromline@example.com",h["From"][0].contents,
356
+ "From line correctly changed")
357
+ assert_match(/^From: anotherfromline@example.com$/,h.to_s,
358
+ "From line correctly turns up in finished product")
359
+ end
360
+
361
+ def test_editing_from
362
+ m = <<'EOF'
363
+ From fromline@example.com Sat Oct 25 12:58:31 PDT 2003
364
+ From: fromline@example.com
365
+ To: toline@example.com
366
+ Subject: Subject line
367
+ EOF
368
+ h=Gurgitate::MailHeaders.new(m)
369
+ t=Time.new.to_s
370
+ h.from="anotherfromline@example.com"
371
+ assert_equal("anotherfromline@example.com",h.from,
372
+ "Envelope from correctly changed")
373
+ assert_match(/^From anotherfromline@example.com #{Regexp.escape(t)}/,
374
+ h.to_mbox, "Envelope from changed in finished product")
375
+ end
376
+
377
+ def test_match_multiple_headers
378
+ m = <<'EOF'
379
+ From fromline@example.com Sat Oct 25 12:58:31 PDT 2003
380
+ From: fromline@example.com
381
+ To: toline@example.com
382
+ Subject: Subject line
383
+ EOF
384
+ h=Gurgitate::MailHeaders.new(m)
385
+ assert_equal(true,h["From","To"] =~ /fromline@example.com/,
386
+ "headers contains fromline")
387
+ assert_equal(true,h["From","To"] =~ /toline@example.com/,
388
+ "headers contains toline")
389
+ assert_equal(false,h["From","To"] =~ /nonexistent@example.com/,
390
+ "headers do not contain nonexistent value")
391
+ assert(!(h["Rabbit"] =~ /nonexistent/),
392
+ "Asking for a nonexistent header")
393
+ end
394
+
395
+ def test_broken_spam
396
+ m=<<'EOF'
397
+ Return-Path: kirstenparsonsry@yahoo.com
398
+ Delivery-Date: Fri May 21 19:42:02 PDT
399
+ Return-Path: kirstenparsonsry@yahoo.com
400
+ Delivery-Date: Fri May 21 17:39:51 2004
401
+ Return-Path: <kirstenparsonsry@yahoo.com>
402
+ X-Original-To: dagbrown@lart.ca
403
+ Delivered-To: dagbrown@lart.ca
404
+ Received: from anest.co.jp (c-24-1-221-189.client.comcast.net [24.1.221.189])
405
+ by lart.ca (Postfix) with ESMTP id 05B7F5704
406
+ for <dagbrown@lart.ca>; Fri, 21 May 2004 17:39:51 -0700 (PDT)
407
+ Message-ID: <NKELFLPJDPLDHJCMGFHDFEKLLNAA.kirstenparsonsry@yahoo.com>
408
+ From: "Kirsten Parsons" <kirstenparsonsry@yahoo.com>
409
+ To: dagbrown@lart.ca
410
+ Subject: Congrats!
411
+ Date: Fri, 21 May 2004 20:56:27 +0000
412
+ MIME-Version: 1.0
413
+ Content-Type: text/plain
414
+ Content-Transfer-Encoding: base64
415
+ EOF
416
+ h=Gurgitate::MailHeaders.new(m)
417
+
418
+ assert_equal(Gurgitate::Header.new("To","dagbrown@lart.ca").contents,
419
+ h["To"][0].contents,"To header is as expected")
420
+
421
+ assert_equal(false,h["To","Cc"] =~ /\blunar@lunar-linux.org\b/i,
422
+ "There should be no Lunar Linux mailing list here")
423
+
424
+ assert_equal(false,h["To"] =~ /\blunar@lunar-linux.org\b/i,
425
+ "There should be no Lunar Linux mailing list in To line")
426
+ assert(!(h["Cc"] =~ /\blunar@lunar-linux.org\b/i),
427
+ "There should be no Lunar Linux mailing list in Cc line")
428
+ end
429
+ end