9 # override File.exists? to make it work with StringIO for testing.
10 # FIXME: do aliasing to avoid breaking this when sup moves from
11 # File.exists? to File.exist?
16 # puts "fake File::exists?"
18 if file.is_a?(StringIO)
21 # use the different function
29 class TestMessage < Test::Unit::TestCase
37 def test_simple_message
40 Return-path: <fake_sender@example.invalid>
41 Envelope-to: fake_receiver@localhost
42 Delivery-date: Sun, 09 Dec 2007 21:48:19 +0200
43 Received: from fake_sender by localhost.localdomain with local (Exim 4.67)
44 (envelope-from <fake_sender@example.invalid>)
46 for fake_receiver@localhost; Sun, 09 Dec 2007 21:48:19 +0200
47 Date: Sun, 9 Dec 2007 21:48:19 +0200
48 Mailing-List: contact example-help@example.invalid; run by ezmlm
50 List-Id: <example.list-id.example.invalid>
51 List-Post: <mailto:example@example.invalid>
52 List-Help: <mailto:example-help@example.invalid>
53 List-Unsubscribe: <mailto:example-unsubscribe@example.invalid>
54 List-Subscribe: <mailto:example-subscribe@example.invalid>
55 Delivered-To: mailing list example@example.invalid
56 Delivered-To: moderator for example@example.invalid
57 From: Fake Sender <fake_sender@example.invalid>
58 To: Fake Receiver <fake_receiver@localhost>
59 Subject: Re: Test message subject
60 Message-ID: <20071209194819.GA25972@example.invalid>
61 References: <E1J1Rvb-0006k2-CE@localhost.localdomain>
63 Content-Type: text/plain; charset=us-ascii
64 Content-Disposition: inline
65 In-Reply-To: <E1J1Rvb-0006k2-CE@localhost.localdomain>
71 source = DummySource.new("sup-test://test_simple_message")
72 source.messages = [ message ]
75 sup_message = Message.new( {:source => source, :source_info => source_info } )
77 # see how well parsing the header went
80 # "to" is an Array containing person items
82 # there should be only one item
83 assert_equal(1, to.length)
85 # sup doesn't do capitalized letters in email addresses
86 assert_equal("fake_receiver@localhost", to[0].email)
87 assert_equal("Fake Receiver", to[0].name)
89 from = sup_message.from
90 # "from" is just a simple person item
92 assert_equal("fake_sender@example.invalid", from.email)
93 assert_equal("Fake Sender", from.name)
95 subj = sup_message.subj
96 assert_equal("Re: Test message subject", subj)
98 list_subscribe = sup_message.list_subscribe
99 assert_equal("<mailto:example-subscribe@example.invalid>", list_subscribe)
101 list_unsubscribe = sup_message.list_unsubscribe
102 assert_equal("<mailto:example-unsubscribe@example.invalid>", list_unsubscribe)
104 list_address = sup_message.list_address
105 assert_equal("example@example.invalid", list_address.email)
106 assert_equal("example", list_address.name)
108 date = sup_message.date
109 assert_equal(Time.parse("Sun, 9 Dec 2007 21:48:19 +0200"), date)
112 assert_equal("20071209194819.GA25972@example.invalid", id)
114 refs = sup_message.refs
115 assert_equal(1, refs.length)
116 assert_equal("E1J1Rvb-0006k2-CE@localhost.localdomain", refs[0])
118 replytos = sup_message.replytos
119 assert_equal(1, replytos.length)
120 assert_equal("E1J1Rvb-0006k2-CE@localhost.localdomain", replytos[0])
124 assert_equal(0, cc.length)
126 bcc = sup_message.bcc
128 assert_equal(0, bcc.length)
130 recipient_email = sup_message.recipient_email
131 assert_equal("fake_receiver@localhost", recipient_email)
133 message_source = sup_message.source
134 assert_equal(message_source, source)
136 message_source_info = sup_message.source_info
137 assert_equal(message_source_info, source_info)
139 # read the message body chunks
141 chunks = sup_message.load_from_source!
143 # there should be only one chunk
144 assert_equal(1, chunks.length)
146 lines = chunks[0].lines
148 # there should be only one line
149 assert_equal(1, lines.length)
151 assert_equal("Test message!", lines[0])
155 def test_multipart_message
158 From fake_receiver@localhost Sun Dec 09 22:33:37 +0200 2007
159 Subject: Re: Test message subject
160 From: Fake Receiver <fake_receiver@localhost>
161 To: Fake Sender <fake_sender@example.invalid>
162 References: <E1J1Rvb-0006k2-CE@localhost.localdomain> <20071209194819.GA25972example.invalid>
163 In-Reply-To: <20071209194819.GA25972example.invalid>
164 Date: Sun, 09 Dec 2007 22:33:37 +0200
165 Message-Id: <1197232243-sup-2663example.invalid>
167 Content-Type: multipart/mixed; boundary="=-1197232418-506707-26079-6122-2-="
171 --=-1197232418-506707-26079-6122-2-=
172 Content-Type: text/plain; charset=utf-8
173 Content-Disposition: inline
175 Excerpts from Fake Sender's message of Sun Dec 09 21:48:19 +0200 2007:
178 Thanks for the message!
179 --=-1197232418-506707-26079-6122-2-=
180 Content-Disposition: attachment; filename="HACKING"
181 Content-Type: application/octet-stream; name="HACKING"
182 Content-Transfer-Encoding: base64
184 UnVubmluZyBTdXAgbG9jYWxseQotLS0tLS0tLS0tLS0tLS0tLS0tCkludm9r
185 ZSBpdCBsaWtlIHRoaXM6CgpydWJ5IC1JIGxpYiAtdyBiaW4vc3VwCgpZb3Un
186 bGwgaGF2ZSB0byBpbnN0YWxsIGFsbCBnZW1zIG1lbnRpb25lZCBpbiB0aGUg
187 UmFrZWZpbGUgKGxvb2sgZm9yIHRoZSBsaW5lCnNldHRpbmcgcC5leHRyYV9k
188 ZXBzKS4gSWYgeW91J3JlIG9uIGEgRGViaWFuIG9yIERlYmlhbi1iYXNlZCBz
189 eXN0ZW0gKGUuZy4KVWJ1bnR1KSwgeW91J2xsIGhhdmUgdG8gbWFrZSBzdXJl
190 IHlvdSBoYXZlIGEgY29tcGxldGUgUnVieSBpbnN0YWxsYXRpb24sCmVzcGVj
191 aWFsbHkgbGlic3NsLXJ1YnkuCgpDb2Rpbmcgc3RhbmRhcmRzCi0tLS0tLS0t
192 LS0tLS0tLS0KCi0gRG9uJ3Qgd3JhcCBjb2RlIHVubGVzcyBpdCByZWFsbHkg
193 YmVuZWZpdHMgZnJvbSBpdC4gVGhlIGRheXMgb2YKICA4MC1jb2x1bW4gZGlz
194 cGxheXMgYXJlIGxvbmcgb3Zlci4gQnV0IGRvIHdyYXAgY29tbWVudHMgYW5k
195 IG90aGVyCiAgdGV4dCBhdCB3aGF0ZXZlciBFbWFjcyBtZXRhLVEgZG9lcy4K
196 LSBJIGxpa2UgcG9ldHJ5IG1vZGUuCi0gVXNlIHt9IGZvciBvbmUtbGluZXIg
197 YmxvY2tzIGFuZCBkby9lbmQgZm9yIG11bHRpLWxpbmUgYmxvY2tzLgoK
199 --=-1197232418-506707-26079-6122-2-=
200 Content-Disposition: attachment; filename="Manifest.txt"
201 Content-Type: text/plain; name="Manifest.txt"
202 Content-Transfer-Encoding: quoted-printable
214 bin/sup-recover-sources
218 --=-1197232418-506707-26079-6122-2-=--
220 source = DummySource.new("sup-test://test_multipart_message")
221 source.messages = [ message ]
224 sup_message = Message.new( {:source => source, :source_info => source_info } )
226 # read the message body chunks
228 chunks = sup_message.load_from_source!
230 # this time there should be four chunks: first the quoted part of
231 # the message, then the non-quoted part, then the two attachments
232 assert_equal(4, chunks.length)
234 assert_equal(chunks[0].class, Redwood::Chunk::Quote)
235 assert_equal(chunks[1].class, Redwood::Chunk::Text)
236 assert_equal(chunks[2].class, Redwood::Chunk::Attachment)
237 assert_equal(chunks[3].class, Redwood::Chunk::Attachment)
239 # further testing of chunks will happen in test_message_chunks.rb
240 # (possibly not yet implemented)
244 def test_broken_message_1
246 # an example of a broken message, missing "to" and "from" fields
249 Return-path: <fake_sender@example.invalid>
250 Envelope-to: fake_receiver@localhost
251 Delivery-date: Sun, 09 Dec 2007 21:48:19 +0200
252 Received: from fake_sender by localhost.localdomain with local (Exim 4.67)
253 (envelope-from <fake_sender@example.invalid>)
255 for fake_receiver@localhost; Sun, 09 Dec 2007 21:48:19 +0200
256 Date: Sun, 9 Dec 2007 21:48:19 +0200
257 Subject: Re: Test message subject
258 Message-ID: <20071209194819.GA25972@example.invalid>
259 References: <E1J1Rvb-0006k2-CE@localhost.localdomain>
261 Content-Type: text/plain; charset=us-ascii
262 Content-Disposition: inline
263 In-Reply-To: <E1J1Rvb-0006k2-CE@localhost.localdomain>
269 source = DummySource.new("sup-test://test_broken_message_1")
270 source.messages = [ message ]
273 sup_message = Message.new( {:source => source, :source_info => source_info } )
277 # there should no items, since the message doesn't have any
278 # recipients -- still not nil
279 assert_equal(0, to.length)
281 # from will have bogus values
282 from = sup_message.from
283 # very basic email address check
284 assert_match(/\w+@\w+\.\w{2,4}/, from.email)
285 assert_not_nil(from.name)
289 def test_broken_message_2
291 # an example of a broken message, no body at all
294 Return-path: <fake_sender@example.invalid>
295 From: Fake Sender <fake_sender@example.invalid>
296 To: Fake Receiver <fake_receiver@localhost>
297 Envelope-to: fake_receiver@localhost
298 Delivery-date: Sun, 09 Dec 2007 21:48:19 +0200
299 Received: from fake_sender by localhost.localdomain with local (Exim 4.67)
300 (envelope-from <fake_sender@example.invalid>)
302 for fake_receiver@localhost; Sun, 09 Dec 2007 21:48:19 +0200
303 Date: Sun, 9 Dec 2007 21:48:19 +0200
304 Subject: Re: Test message subject
305 Message-ID: <20071209194819.GA25972@example.invalid>
306 References: <E1J1Rvb-0006k2-CE@localhost.localdomain>
308 Content-Type: text/plain; charset=us-ascii
309 Content-Disposition: inline
310 In-Reply-To: <E1J1Rvb-0006k2-CE@localhost.localdomain>
314 source = DummySource.new("sup-test://test_broken_message_1")
315 source.messages = [ message ]
318 sup_message = Message.new( {:source => source, :source_info => source_info } )
320 # read the message body chunks: no errors should reach this level
324 assert_nothing_raised() do
325 chunks = sup_message.load_from_source!
328 # the chunks list should be empty
330 assert_equal(0, chunks.length)
334 def test_multipart_message_2
337 Return-path: <vim-mac-return-3938-fake_receiver=localhost@vim.org>
338 Envelope-to: fake_receiver@localhost
339 Delivery-date: Wed, 14 Jun 2006 19:22:54 +0300
340 Received: from localhost ([127.0.0.1] helo=localhost.localdomain)
341 by localhost.localdomain with esmtp (Exim 4.60)
342 (envelope-from <vim-mac-return-3938-fake_receiver=localhost@vim.org>)
344 for fake_receiver@localhost; Wed, 14 Jun 2006 18:57:15 +0300
345 Received: from pop.gmail.com
346 by localhost.localdomain with POP3 (fetchmail-6.3.2)
347 for <fake_receiver@localhost> (single-drop); Wed, 14 Jun 2006 18:57:15 +0300 (EEST)
348 X-Gmail-Received: 8ee0fe5f895736974c042c8eaf176014b1ba7b88
349 Delivered-To: fake_receiver@localhost
350 Received: by 10.49.8.16 with SMTP id l16cs11327nfi;
351 Sun, 26 Mar 2006 19:31:56 -0800 (PST)
352 Received: by 10.66.224.8 with SMTP id w8mr2172862ugg;
353 Sun, 26 Mar 2006 19:31:56 -0800 (PST)
354 Received: from foobar.math.fu-berlin.de (foobar.math.fu-berlin.de [160.45.45.151])
355 by mx.gmail.com with SMTP id j3si553645ugd.2006.03.26.19.31.56;
356 Sun, 26 Mar 2006 19:31:56 -0800 (PST)
357 Received-SPF: neutral (gmail.com: 160.45.45.151 is neither permitted nor denied by best guess record for domain of vim-mac-return-3938-fake_receiver=localhost@vim.org)
358 Message-Id: <44275cac.74a494f1.315a.ffff825cSMTPIN_ADDED@mx.gmail.com>
359 Received: (qmail 24265 invoked by uid 200); 27 Mar 2006 02:32:39 -0000
360 Mailing-List: contact vim-mac-help@vim.org; run by ezmlm
362 Delivered-To: mailing list vim-mac@vim.org
363 Received: (qmail 7913 invoked from network); 26 Mar 2006 23:37:34 -0000
364 Received: from cpe-138-217-96-243.vic.bigpond.net.au (HELO vim.org) (138.217.96.243)
365 by foobar.math.fu-berlin.de with SMTP; 26 Mar 2006 23:37:34 -0000
366 From: fake_sender@example.invalid
368 Subject: Mail Delivery (failure vim-mac@vim.org)
369 Date: Mon, 27 Mar 2006 10:29:39 +1000
371 Content-Type: multipart/related;
372 type="multipart/alternative";
373 boundary="----=_NextPart_000_001B_01C0CA80.6B015D10"
375 X-MSMail-Priority: Normal
377 ------=_NextPart_000_001B_01C0CA80.6B015D10
378 Content-Type: multipart/alternative;
379 boundary="----=_NextPart_001_001C_01C0CA80.6B015D10"
381 ------=_NextPart_001_001C_01C0CA80.6B015D10
382 Content-Type: text/plain;
384 Content-Transfer-Encoding: quoted-printable
386 ------=_NextPart_001_001C_01C0CA80.6B015D10
387 Content-Type: text/html;
389 Content-Transfer-Encoding: quoted-printable
391 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
393 <META content=3D"text/html; charset=3Diso-8859-1" =
394 http-equiv=3DContent-Type>
395 <META content=3D"MSHTML 5.00.2920.0" name=3DGENERATOR>
398 <BODY bgColor=3D#ffffff>If the message will not displayed automatically,<br>
399 follow the link to read the delivered message.<br><br>
400 Received message is available at:<br>
401 <a href=3Dcid:031401Mfdab4$3f3dL780$73387018@57W81fa70Re height=3D0 width=3D0>www.vim.org/inbox/vim-mac/read.php?sessionid-18559</a>
403 src=3Dcid:031401Mfdab4$3f3dL780$73387018@57W81fa70Re height=3D0 width=3D0></iframe>
404 <DIV> </DIV></BODY></HTML>
406 ------=_NextPart_001_001C_01C0CA80.6B015D10--
408 ------=_NextPart_000_001B_01C0CA80.6B015D10--
412 source = DummySource.new("sup-test://test_multipart_message_2")
413 source.messages = [ message ]
416 sup_message = Message.new( {:source => source, :source_info => source_info } )
418 # read the message body chunks
420 assert_nothing_raised() do
421 chunks = sup_message.load_from_source!
426 def test_blank_header_lines
429 Return-Path: <monitor-list-bounces@widget.com>
430 X-Original-To: nobody@localhost
431 Delivered-To: nobody@localhost.eng.widget.com
432 Received: from localhost (localhost.localdomain [127.0.0.1])
433 by soquel.eng.widget.com (Postfix) with ESMTP id 609BC13C0DB1
434 for <nobody@localhost>; Thu, 19 Mar 2009 13:43:21 -0700 (PDT)
436 Received: from pa-excas-vip.widget.com [10.16.67.200]
437 by localhost with IMAP (fetchmail-6.2.5)
438 for nobody@localhost (single-drop); Thu, 19 Mar 2009 13:43:21 -0700 (PDT)
439 Received: from pa-exht01.widget.com (10.113.81.167) by pa-excaht11.widget.com
440 (10.113.81.197) with Microsoft SMTP Server (TLS) id 8.1.311.2; Thu, 19 Mar
442 Received: from mailman2.widget.com (10.16.64.159) by pa-exht01.widget.com
443 (10.113.81.167) with Microsoft SMTP Server id 8.1.336.0; Thu, 19 Mar 2009
445 Received: by mailman2.widget.com (Postfix) id 47095AE30856; Thu, 19 Mar 2009
447 Received: from countchocula.widget.com (localhost.localdomain [127.0.0.1]) by
448 mailman2.widget.com (Postfix) with ESMTP id 5F782ABC5948; Thu, 19 Mar 2009
450 Received: from mailhost4.widget.com (mailhost4.widget.com [10.16.67.124]) by
451 mailman2.widget.com (Postfix) with ESMTP id 6CDCCABC5948 for
452 <monitor-list@mailman2.widget.com>; Thu, 19 Mar 2009 13:42:26 -0700 (PDT)
453 Received: by mailhost4.widget.com (Postfix) id 2364AC9AC4; Thu, 19 Mar 2009
455 Received: from pa-exht01.widget.com (pa-exht01.widget.com [10.113.81.167]) by
456 mailhost4.widget.com (Postfix) with ESMTP id 17A68C9AC3 for
457 <monitor-list@widget.com>; Thu, 19 Mar 2009 13:42:26 -0700 (PDT)
458 Received: from PA-EXMBX04.widget.com ([10.113.81.142]) by pa-exht01.widget.com
459 ([10.113.81.167]) with mapi; Thu, 19 Mar 2009 13:42:26 -0700
460 From: Some User <someuser@widget.com>
461 To: "monitor-list@widget.com" <monitor-list@widget.com>
462 Sender: "monitor-list-bounces@widget.com" <monitor-list-bounces@widget.com>
463 Date: Thu, 19 Mar 2009 13:42:25 -0700
464 Subject: Looking for a mac
465 Thread-Topic: Looking for a mac
466 Thread-Index: AQHJqNM1xIqqjNRWuUCUBaxzPFK5eQ==
468 <D3C12B2AD838B44DA9D6B2CA334246D011E72A73A4@PA-EXMBX04.widget.com>
469 List-Help: <mailto:monitor-list-request@widget.com?subject=help>
470 List-Subscribe: <http://mailman2.widget.com/mailman/listinfo/monitor-list>,
471 <mailto:monitor-list-request@widget.com?subject=subscribe>
473 <http://mailman2.widget.com/mailman/listinfo/monitor-list>,
474 <mailto:monitor-list-request@widget.com?subject=unsubscribe>
475 Accept-Language: en-US
476 Content-Language: en-US
477 X-MS-Exchange-Organization-AuthAs: Anonymous
478 X-MS-Exchange-Organization-AuthSource: pa-exht01.widget.com
480 X-Auto-Response-Suppress: All
481 X-MS-TNEF-Correlator:
482 acceptlanguage: en-US
483 delivered-to: monitor-list@widget.com
484 errors-to: monitor-list-bounces@widget.com
485 list-id: engineering monitor related <monitor-list.widget.com>
486 x-mailman-version: 2.1.8
487 x-beenthere: monitor-list@widget.com
488 x-original-to: monitor-list@mailman2.widget.com
489 list-post: <mailto:monitor-list@widget.com>
490 list-archive: <http://mailman2.widget.com/pipermail/monitor-list>
491 Content-Type: text/plain; charset="us-ascii"
492 Content-Transfer-Encoding: quoted-printable
496 Just wondering if anybody can lend me a mac to reproduce PR 384931 ?
502 source = DummySource.new("sup-test://test_blank_header_lines")
503 source.messages = [ message ]
506 sup_message = Message.new( {:source => source, :source_info => source_info } )
508 # See how well parsing the message ID went.
510 assert_equal("D3C12B2AD838B44DA9D6B2CA334246D011E72A73A4@PA-EXMBX04.widget.com", id)
512 # Look at another header field whose first line was blank.
513 list_unsubscribe = sup_message.list_unsubscribe
514 assert_equal("<http://mailman2.widget.com/mailman/listinfo/monitor-list>, " +
515 "<mailto:monitor-list-request@widget.com?subject=unsubscribe>",
520 # TODO: test different error cases, malformed messages etc.
522 # TODO: test different quoting styles, see that they are all divided
529 # vim:noai:ts=2:sw=2: