gurgitate-mail 1.8.4 → 1.8.5

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