mailparser 0.4.22a → 0.5.0.beta1

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.
@@ -1,615 +0,0 @@
1
- #!/usr/local/bin/ruby
2
- # -*- coding: euc-jp -*-
3
-
4
- require "test/unit"
5
- require "mailparser/obsolete"
6
- include MailParser
7
-
8
- class TC_MailParser_Obsolete < Test::Unit::TestCase
9
- def setup()
10
- MailParser.output_charset = "euc-jp"
11
- MailParser.text_body_only = false
12
- end
13
- def test_get_mail_address()
14
- assert_equal(["foo@example.jp"], get_mail_address("foo@example.jp"))
15
- end
16
- def test_get_mail_address2()
17
- assert_equal(["foo@example.jp", "bar@example.com"], get_mail_address("foo@example.jp, bar@example.com"))
18
- end
19
- def test_get_mail_address_with_phrase()
20
- assert_equal(["foo@example.jp"], get_mail_address("phrase <foo@example.jp>"))
21
- end
22
- def test_get_mail_address_with_phrase2()
23
- assert_equal(["foo@example.jp"], get_mail_address("\"foo bar\" <foo@example.jp>"))
24
- end
25
- def test_get_mail_address_with_comment()
26
- assert_equal(["foo@example.jp"], get_mail_address("foo@example.jp (comment)"))
27
- end
28
- def test_get_mail_address_with_comment_nest()
29
- assert_equal(["foo@example.jp"], get_mail_address("foo@example.jp (nested (comment))"))
30
- end
31
- def test_get_mail_address_invalid_dquot()
32
- assert_equal(["foo@example.jp"], get_mail_address("\"aaa\"bb\"cc <foo@example.jp>"))
33
- end
34
- def test_get_mail_address_complex()
35
- assert_equal(["foo@example.jp", "bar@example.com"], get_mail_address("\"foo\" <foo@example.jp>, bar@example.com (comment)"))
36
- end
37
- def test_get_mail_address_invalid_parenthes()
38
- str = (["\"aaaa(aaaaa(\\(aaaa(\\)\" <hoge@example.com>"]*50).join(",")
39
- assert_equal(["hoge@example.com"]*50, get_mail_address(str))
40
- end
41
- def test_get_mail_address_parenthes_in_phrace()
42
- assert_equal(["foo@example.com", "bar@example.com"], get_mail_address("\"hoge(xxx\" <foo@example.com>, \")\" <bar@example.com>" ))
43
- end
44
- def test_get_mail_address_angle_in_phrace()
45
- assert_equal(["bar@example.com"], get_mail_address("\"<hoge>\" <bar@example.com>" ))
46
- end
47
- def test_parse_content_type()
48
- h = parse_content_type("text/plain; charset=euc-jp")
49
- assert_equal("text", h[:type])
50
- assert_equal("plain", h[:subtype])
51
- assert_equal("euc-jp", h[:parameter]["charset"])
52
- end
53
- def test_parse_content_type2()
54
- h = parse_content_type("multipart/mixed; boundary=\"boundary-string\"")
55
- assert_equal("multipart", h[:type])
56
- assert_equal("mixed", h[:subtype])
57
- assert_equal("boundary-string", h[:parameter]["boundary"])
58
- end
59
- def test_parse_content_type_caps()
60
- h = parse_content_type("Text/HTML; CharSet=Euc-JP")
61
- assert_equal("text", h[:type])
62
- assert_equal("html", h[:subtype])
63
- assert_equal("Euc-JP", h[:parameter]["charset"])
64
- end
65
- def test_parse_content_type_rfc2231()
66
- h = parse_content_type("message/external-body; access-type=URL; URL*0=\"ftp://\"; URL*1=\"cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar\"")
67
- assert_equal("message", h[:type])
68
- assert_equal("external-body", h[:subtype])
69
- assert_equal("URL", h[:parameter]["access-type"])
70
- assert_equal("ftp://cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar", h[:parameter]["url"])
71
- end
72
- def test_parse_content_type_rfc2231_ext()
73
- h = parse_content_type("application/x-stuff; title*=us-ascii'en-us'This%20is%20%2A%2A%2Afun%2A%2A%2A")
74
- assert_equal("application", h[:type])
75
- assert_equal("x-stuff", h[:subtype])
76
- assert_equal("This is ***fun***", h[:parameter]["title"])
77
- end
78
- def test_parse_content_type_rfc2231_ext_multi()
79
- h = parse_content_type("application/x-stuff; title*0*=us-ascii'en-us'This%20is%20even%20more%20; title*1*=%2A%2A%2Afun%2A%2A%2A%20; title*2*=\"isn't it!\"")
80
- assert_equal("application", h[:type])
81
- assert_equal("x-stuff", h[:subtype])
82
- assert_equal("This is even more ***fun*** isn't it!", h[:parameter]["title"])
83
- end
84
- def test_parse_content_type_rfc2231_ext_nocharset()
85
- h = parse_content_type("application/x-stuff; title*='en-us'This%20is%20%2A%2A%2Afun%2A%2A%2A")
86
- assert_equal("application", h[:type])
87
- assert_equal("x-stuff", h[:subtype])
88
- assert_equal("This is ***fun***", h[:parameter]["title"])
89
- end
90
- def test_parse_content_type_rfc2231_ext_nolang()
91
- h = parse_content_type("application/x-stuff; title*=us-ascii''This%20is%20%2A%2A%2Afun%2A%2A%2A")
92
- assert_equal("application", h[:type])
93
- assert_equal("x-stuff", h[:subtype])
94
- assert_equal("This is ***fun***", h[:parameter]["title"])
95
- end
96
- def test_parse_content_type_rfc2231_ext_nocharset_nolang()
97
- h = parse_content_type("application/x-stuff; title*=''This%20is%20%2A%2A%2Afun%2A%2A%2A")
98
- assert_equal("application", h[:type])
99
- assert_equal("x-stuff", h[:subtype])
100
- assert_equal("This is ***fun***", h[:parameter]["title"])
101
- end
102
- def test_parse_content_type_rfc2231_ext_sjis()
103
- h = parse_content_type("application/octet-stream; name*=shift_jis''%83%65%83%58%83%67")
104
- assert_equal("application", h[:type])
105
- assert_equal("octet-stream", h[:subtype])
106
- assert_equal("�ƥ���", h[:parameter]["name"])
107
- end
108
- def test_parse_content_type_rfc2231_bug()
109
- h = parse_content_type("application/octet-stream; name*0*=ISO-2022-JP'ja'%1b$B$%22$$$%26$%28$%2a$%2b$%2d$%2f$1$3%1b%28B; name*1=.txt")
110
- assert_equal("application", h[:type])
111
- assert_equal("octet-stream", h[:subtype])
112
- assert_equal("��������������������.txt", h[:parameter]["name"])
113
- end
114
- def test_mime_header_decode_plain()
115
- assert_equal("test", mime_header_decode("test"))
116
- end
117
- def test_mime_header_decode_jis()
118
- assert_equal("�ƥ���", mime_header_decode("=?iso-2022-jp?b?GyRCJUYlOSVIGyhC?="))
119
- end
120
- def test_mime_header_decode_sjis()
121
- assert_equal("�ƥ���", mime_header_decode("=?shift_jis?b?g2WDWINn?="))
122
- end
123
- def test_mime_header_decode_euc()
124
- assert_equal("�ƥ���", mime_header_decode("=?euc-jp?b?pcaluaXI?="))
125
- end
126
- def test_mime_header_decode_utf8()
127
- assert_equal("�ƥ���", mime_header_decode("=?utf-8?b?44OG44K544OI?="))
128
- end
129
- def test_mime_header_decode_ascii()
130
- assert_equal("test", mime_header_decode("=?us-ascii?b?dGVzdA==?="))
131
- end
132
- def test_mime_header_decode_unknown()
133
- assert_equal("=?unknown?b?dGVzdA==?=", mime_header_decode("=?unknown?b?dGVzdA==?="))
134
- end
135
- def test_mime_header_decode_q()
136
- assert_equal("test", mime_header_decode("=?us-ascii?q?test?="))
137
- end
138
- def test_mime_header_decode_q_multi()
139
- assert_equal("testtest", mime_header_decode("=?us-ascii?q?test?= =?us-ascii?q?test?="))
140
- end
141
- def test_mime_header_decode_q_euc()
142
- assert_equal("�ƥ���", mime_header_decode("=?euc-jp?q?=A5=C6=A5=B9=A5=C8?="))
143
- end
144
- def test_mime_header_decode_e2u()
145
- MailParser.output_charset = "utf-8"
146
- assert_equal("\xE3\x83\x86\xE3\x82\xB9\xE3\x83\x88", mime_header_decode("=?euc-jp?q?=A5=C6=A5=B9=A5=C8?="))
147
- end
148
- def test_mime_header_decode_s2u()
149
- MailParser.output_charset = "utf-8"
150
- assert_equal("\xE3\x83\x86\xE3\x82\xB9\xE3\x83\x88", mime_header_decode("=?shift_jis?q?=83=65=83=58=83=67?="))
151
- end
152
- def test_mime_header_decode_noconv()
153
- MailParser.output_charset = nil
154
- assert_equal("\x83\x65\x83\x58\x83\x67", mime_header_decode("=?shift_jis?q?=83=65=83=58=83=67?="))
155
- end
156
- def test_trunc_comment()
157
- assert_equal("abcdefg", trunc_comment("abcdefg"))
158
- end
159
- def test_trunc_comment_2()
160
- assert_equal("abcdefg", trunc_comment("abc(comment)defg"))
161
- end
162
- def test_trunc_comment_3()
163
- assert_equal("abcdefg", trunc_comment("abc(com(comment)ment)defg"))
164
- end
165
- def test_trunc_comment_4()
166
- assert_equal("\"abc(comment)def\" hoge", trunc_comment("\"abc(comment)def\" hoge"))
167
- end
168
- def test_trunc_comment_5()
169
- assert_equal("\"abc(com\" hoge", trunc_comment("\"abc(com\" hoge"))
170
- end
171
- def test_trunc_comment_6()
172
- assert_equal("\"abc(com\" hoge \"com)def\"", trunc_comment("\"abc(com\" hoge \"com)def\""))
173
- end
174
- def test_trunc_comment_invalid_parenthes()
175
- assert_equal("abc(def", trunc_comment("abc(def"))
176
- end
177
- def test_trunc_comment_invalid_parenthes2()
178
- assert_equal("abc(def(ghi)", trunc_comment("abc(def(ghi)"))
179
- end
180
- def test_trunc_comment_invalid_parenthes3()
181
- assert_equal("abc(ghi", trunc_comment("abc(def)(ghi"))
182
- end
183
- def test_trunc_comment_invalid_parenthes4()
184
- assert_equal("abc(", trunc_comment("abc("))
185
- end
186
- def test_trunc_comment_last_backslash()
187
- assert_equal("abc\\", trunc_comment("abc\\"))
188
- end
189
- def test_trunc_comment_sub()
190
- assert_equal("def", trunc_comment_sub("abc)def"))
191
- end
192
- def test_trunc_comment_sub2()
193
- assert_equal("", trunc_comment_sub("abc)"))
194
- end
195
- def test_trunc_comment_sub3()
196
- assert_equal(nil, trunc_comment_sub("abc"))
197
- end
198
- def test_trunc_comment_sub4()
199
- assert_equal("jkl", trunc_comment_sub("abc(def)ghi)jkl"))
200
- end
201
- def test_trunc_comment_sub5()
202
- assert_equal("ghi", trunc_comment_sub("abc\\)def)ghi"))
203
- end
204
- def test_trunc_comment_sub6()
205
- assert_equal("ghi", trunc_comment_sub("abc\\(def)ghi"))
206
- end
207
- def test_split_address()
208
- assert_equal(["a@a.a"], split_address("a@a.a"))
209
- end
210
- def test_split_address2()
211
- assert_equal(["a@a.a","b@b.b"], split_address("a@a.a, b@b.b"))
212
- end
213
- def test_split_address3()
214
- assert_equal(["\"a@a.a,\" b@b.b"], split_address("\"a@a.a,\" b@b.b"))
215
- end
216
- def test_split_address4()
217
- assert_equal(["\"a@a.a","b@b.b"], split_address("\"a@a.a, b@b.b"))
218
- end
219
- def test_get_date()
220
- assert_equal(Time.mktime(2005,1,4,23,10,20), get_date("Tue, 4 Jan 2005 23:10:20 +0900"))
221
- end
222
- def test_get_date_far_future()
223
- d = get_date("Tue, 4 Jan 2090 23:10:20 +0900")
224
- assert(d == nil || d == Time.mktime(2090,1,4,23,10,20))
225
- end
226
- def test_get_date_deep_past()
227
- d = get_date("Tue, 4 Jan 1800 23:10:20 +0900")
228
- assert(d == nil || d == Time.mktime(1800,1,4,23,10,20))
229
- end
230
- def test_get_date_invalid()
231
- assert_equal(nil, get_date("XXX, 99 Jan 205 23:10:20 +0900"))
232
- end
233
- def test_parse_message()
234
- require "stringio"
235
- h = parse_message StringIO.new(<<EOS)
236
- From: TOMITA Masahiro <tommy@tmtm.org>
237
- To: Foo Bar <foo.bar@example.com>
238
- Subject: =?iso-2022-jp?b?GyRCNEE7ehsoQg==?=
239
- Content-Type: text/plain; charset=euc-jp
240
- Date: Tue, 4 Jan 2005 14:54:22 +0900
241
-
242
- ���ܸ���ʸ
243
- EOS
244
- assert_equal(["tommy@tmtm.org"], h[:from])
245
- assert_equal(["foo.bar@example.com"], h[:to])
246
- assert_equal("����", h[:subject])
247
- assert_equal(["TOMITA Masahiro <tommy@tmtm.org>"], h[:header]["from"])
248
- assert_equal(["����"], h[:header]["subject"])
249
- assert_equal("text", h[:type])
250
- assert_equal("plain", h[:subtype])
251
- assert_equal("euc-jp", h[:charset])
252
- assert_equal("���ܸ���ʸ\n", h[:body])
253
- assert_equal(<<EOS, h[:rawheader])
254
- From: TOMITA Masahiro <tommy@tmtm.org>
255
- To: Foo Bar <foo.bar@example.com>
256
- Subject: =?iso-2022-jp?b?GyRCNEE7ehsoQg==?=
257
- Content-Type: text/plain; charset=euc-jp
258
- Date: Tue, 4 Jan 2005 14:54:22 +0900
259
- EOS
260
- end
261
- def test_parse_message_with_attachment()
262
- require "stringio"
263
- h = parse_message StringIO.new(<<EOS)
264
- Content-Type: multipart/mixed; boundary="hogehogehoge"
265
-
266
- preamble
267
- --hogehogehoge
268
- Content-Type: text/plain
269
-
270
- This is body.
271
- --hogehogehoge
272
- Content-Type: application/octet-stream
273
- Content-Transfer-Encoding: quoted-printable
274
- Content-Disposition: attachment; filename="file1.bin"
275
-
276
- This is attachment file.
277
- --hogehogehoge--
278
- EOS
279
- assert_equal("multipart", h[:type])
280
- assert_equal("mixed", h[:subtype])
281
- assert_equal("hogehogehoge", h[:boundary])
282
- assert_nil(h[:body])
283
- assert_equal(2, h[:parts].size)
284
- assert_equal("text", h[:parts][0][:type])
285
- assert_equal("plain", h[:parts][0][:subtype])
286
- assert_equal("This is body.\n", h[:parts][0][:body])
287
- assert_equal("application", h[:parts][1][:type])
288
- assert_equal("octet-stream", h[:parts][1][:subtype])
289
- assert_equal("file1.bin", h[:parts][1][:filename])
290
- assert_equal("quoted-printable", h[:parts][1][:encoding])
291
- assert_equal("This is attachment file.\n", h[:parts][1][:body])
292
- end
293
- def test_parse_message_with_attachment_text_only()
294
- require "stringio"
295
- MailParser.text_body_only = true
296
- h = parse_message StringIO.new(<<EOS)
297
- Content-Type: multipart/mixed; boundary="hogehogehoge"
298
-
299
- preamble
300
- --hogehogehoge
301
- Content-Type: text/plain
302
-
303
- This is body.
304
- --hogehogehoge
305
- Content-Type: application/octet-stream
306
- Content-Transfer-Encoding: quoted-printable
307
- Content-Disposition: attachment; filename="file1.bin"
308
-
309
- This is attachment file.
310
- --hogehogehoge--
311
- EOS
312
- assert_equal("multipart", h[:type])
313
- assert_equal("mixed", h[:subtype])
314
- assert_equal("hogehogehoge", h[:boundary])
315
- assert_nil(h[:body])
316
- assert_equal(2, h[:parts].size)
317
- assert_equal("text", h[:parts][0][:type])
318
- assert_equal("plain", h[:parts][0][:subtype])
319
- assert_equal("This is body.\n", h[:parts][0][:body])
320
- assert_equal("application", h[:parts][1][:type])
321
- assert_equal("octet-stream", h[:parts][1][:subtype])
322
- assert_equal("file1.bin", h[:parts][1][:filename])
323
- assert_equal("quoted-printable", h[:parts][1][:encoding])
324
- assert_nil(h[:parts][1][:body])
325
- end
326
- def test_parse_message_with_message_type()
327
- require "stringio"
328
- h = parse_message StringIO.new(<<EOS)
329
- Content-Type: multipart/mixed; boundary="hogehogehoge"
330
-
331
- preamble
332
- --hogehogehoge
333
- Content-Type: message/rfc822
334
-
335
- Content-Type: multipart/mixed; boundary="fugafugafuga"
336
-
337
- preamble
338
- --fugafugafuga
339
- Content-Type: text/plain
340
-
341
- This is body.
342
- --fugafugafuga
343
- Content-Type: application/octet-stream
344
- Content-Transfer-Encoding: quoted-printable
345
- Content-Disposition: attachment; filename="file1.bin"
346
-
347
- This is attachment file.
348
- --fugafugafuga--
349
- --hogehogehoge--
350
- EOS
351
- assert_equal("multipart", h[:type])
352
- assert_equal("mixed", h[:subtype])
353
- assert_equal("hogehogehoge", h[:boundary])
354
- assert_nil(h[:body])
355
- assert_equal(1, h[:parts].size)
356
- assert_equal("message", h[:parts][0][:type])
357
- assert_equal("rfc822", h[:parts][0][:subtype])
358
- assert_nil(h[:parts][0][:message][:body])
359
- assert_equal(2, h[:parts][0][:message][:parts].size)
360
- assert_equal("This is body.\n", h[:parts][0][:message][:parts][0][:body])
361
- assert_equal("application", h[:parts][0][:message][:parts][1][:type])
362
- assert_equal("octet-stream", h[:parts][0][:message][:parts][1][:subtype])
363
- assert_equal("file1.bin", h[:parts][0][:message][:parts][1][:filename])
364
- assert_equal("quoted-printable", h[:parts][0][:message][:parts][1][:encoding])
365
- assert_equal("This is attachment file.\n", h[:parts][0][:message][:parts][1][:body])
366
- end
367
- def test_parse_message_with_multipart_in_multipart()
368
- require "stringio"
369
- h = parse_message StringIO.new(<<EOS)
370
- Content-Type: multipart/mixed; boundary="hogehogehoge"
371
-
372
- preamble
373
- --hogehogehoge
374
- Content-Type: multipart/mixed; boundary="fugafugafuga"
375
-
376
- preamble
377
- --fugafugafuga
378
- Content-Type: text/plain
379
-
380
- This is body.
381
- --fugafugafuga
382
- Content-Type: application/octet-stream
383
- Content-Transfer-Encoding: quoted-printable
384
- Content-Disposition: attachment; filename="file1.bin"
385
-
386
- This is attachment file.
387
- --fugafugafuga--
388
- --hogehogehoge--
389
- EOS
390
- assert_equal("multipart", h[:type])
391
- assert_equal("mixed", h[:subtype])
392
- assert_equal("hogehogehoge", h[:boundary])
393
- assert_nil(h[:body])
394
- assert_equal(1, h[:parts].size)
395
- assert_equal("multipart", h[:parts][0][:type])
396
- assert_equal("mixed", h[:parts][0][:subtype])
397
- assert_equal(2, h[:parts][0][:parts].size)
398
- assert_equal("This is body.\n", h[:parts][0][:parts][0][:body])
399
- assert_equal("application", h[:parts][0][:parts][1][:type])
400
- assert_equal("octet-stream", h[:parts][0][:parts][1][:subtype])
401
- assert_equal("file1.bin", h[:parts][0][:parts][1][:filename])
402
- assert_equal("quoted-printable", h[:parts][0][:parts][1][:encoding])
403
- assert_equal("This is attachment file.\n", h[:parts][0][:parts][1][:body])
404
- end
405
- def test_parse_message_with_multipart_of_multipart_and_singlepart()
406
- require "stringio"
407
- h = parse_message StringIO.new(<<EOS)
408
- Content-Type: multipart/mixed; boundary="hogehogehoge"
409
-
410
- preamble
411
- --hogehogehoge
412
- Content-Type: multipart/mixed; boundary="fugafugafuga"
413
-
414
- preamble
415
- --fugafugafuga
416
- Content-Type: text/plain
417
-
418
- This is body.
419
- --fugafugafuga
420
- Content-Type: application/octet-stream
421
- Content-Transfer-Encoding: quoted-printable
422
- Content-Disposition: attachment; filename="file1.bin"
423
-
424
- This is attachment file.
425
- --fugafugafuga--
426
- --hogehogehoge
427
- Content-Type: text/plain
428
-
429
- This is attachment body.
430
- --hogehogehoge--
431
- EOS
432
- assert_equal("multipart", h[:type])
433
- assert_equal("mixed", h[:subtype])
434
- assert_equal("hogehogehoge", h[:boundary])
435
- assert_nil(h[:body])
436
- assert_equal(2, h[:parts].size)
437
- assert_equal("multipart", h[:parts][0][:type])
438
- assert_equal("mixed", h[:parts][0][:subtype])
439
- assert_equal(2, h[:parts][0][:parts].size)
440
- assert_equal("This is body.\n", h[:parts][0][:parts][0][:body])
441
- assert_equal("application", h[:parts][0][:parts][1][:type])
442
- assert_equal("octet-stream", h[:parts][0][:parts][1][:subtype])
443
- assert_equal("file1.bin", h[:parts][0][:parts][1][:filename])
444
- assert_equal("quoted-printable", h[:parts][0][:parts][1][:encoding])
445
- assert_equal("This is attachment file.\n", h[:parts][0][:parts][1][:body])
446
- assert_equal("text", h[:parts][1][:type])
447
- assert_equal("plain", h[:parts][1][:subtype])
448
- assert_equal("This is attachment body.\n", h[:parts][1][:body])
449
- end
450
- def test_parse_message_with_multipart_of_multipart_and_singlepart2()
451
- require "stringio"
452
- h = parse_message StringIO.new(<<EOS)
453
- Content-Type: multipart/mixed; boundary="hogehogehoge"
454
-
455
- preamble
456
- --hogehogehoge
457
- Content-Type: multipart/mixed; boundary="fugafugafuga"
458
-
459
- preamble
460
- --fugafugafuga
461
- Content-Type: text/plain
462
-
463
- This is body.
464
- --fugafugafuga
465
- Content-Type: application/octet-stream
466
- Content-Transfer-Encoding: quoted-printable
467
- Content-Disposition: attachment; filename="file1.bin"
468
-
469
- This is attachment file.
470
- --fugafugafuga--
471
- --hogehogehoge
472
- Content-Type: text/plain
473
-
474
- This is attachment body.
475
- --hogehogehoge
476
- Content-Type: text/plain
477
-
478
- This is attachment body2.
479
- --hogehogehoge--
480
- EOS
481
- assert_equal("multipart", h[:type])
482
- assert_equal("mixed", h[:subtype])
483
- assert_equal("hogehogehoge", h[:boundary])
484
- assert_nil(h[:body])
485
- assert_equal(3, h[:parts].size)
486
- assert_equal("multipart", h[:parts][0][:type])
487
- assert_equal("mixed", h[:parts][0][:subtype])
488
- assert_equal(2, h[:parts][0][:parts].size)
489
- assert_equal("This is body.\n", h[:parts][0][:parts][0][:body])
490
- assert_equal("application", h[:parts][0][:parts][1][:type])
491
- assert_equal("octet-stream", h[:parts][0][:parts][1][:subtype])
492
- assert_equal("file1.bin", h[:parts][0][:parts][1][:filename])
493
- assert_equal("quoted-printable", h[:parts][0][:parts][1][:encoding])
494
- assert_equal("This is attachment file.\n", h[:parts][0][:parts][1][:body])
495
- assert_equal("text", h[:parts][1][:type])
496
- assert_equal("plain", h[:parts][1][:subtype])
497
- assert_equal("This is attachment body.\n", h[:parts][1][:body])
498
- assert_equal("text", h[:parts][2][:type])
499
- assert_equal("plain", h[:parts][2][:subtype])
500
- assert_equal("This is attachment body2.\n", h[:parts][2][:body])
501
- end
502
- def test_parse_message_with_multipart_of_multipart_and_singlepart3()
503
- require "stringio"
504
- h = parse_message StringIO.new(<<EOS)
505
- Content-Type: multipart/mixed; boundary="hogehogehoge"
506
-
507
- preamble
508
- --hogehogehoge
509
- Content-Type: multipart/mixed; boundary="fugafugafuga"
510
-
511
- preamble
512
- --fugafugafuga
513
- Content-Type: text/plain
514
-
515
- This is body.
516
- --fugafugafuga
517
- Content-Type: application/octet-stream
518
- Content-Transfer-Encoding: quoted-printable
519
- Content-Disposition: attachment; filename="file1.bin"
520
-
521
- This is attachment file.
522
- --fugafugafuga--
523
- --hogehogehoge
524
- Content-Type: multipart/mixed; boundary="heroherohero"
525
-
526
- preamble
527
- --heroherohero
528
- Content-Type: text/plain
529
-
530
- This is attachment body.
531
- --heroherohero
532
- Content-Type: text/plain
533
-
534
- This is attachment body2.
535
- --heroherohero--
536
- --hogehogehoge--
537
- EOS
538
- assert_equal("multipart", h[:type])
539
- assert_equal("mixed", h[:subtype])
540
- assert_equal("hogehogehoge", h[:boundary])
541
- assert_nil(h[:body])
542
- assert_equal(2, h[:parts].size)
543
- assert_equal("multipart", h[:parts][0][:type])
544
- assert_equal("mixed", h[:parts][0][:subtype])
545
- assert_equal(2, h[:parts][0][:parts].size)
546
- assert_equal("This is body.\n", h[:parts][0][:parts][0][:body])
547
- assert_equal("application", h[:parts][0][:parts][1][:type])
548
- assert_equal("octet-stream", h[:parts][0][:parts][1][:subtype])
549
- assert_equal("file1.bin", h[:parts][0][:parts][1][:filename])
550
- assert_equal("quoted-printable", h[:parts][0][:parts][1][:encoding])
551
- assert_equal("This is attachment file.\n", h[:parts][0][:parts][1][:body])
552
- assert_equal("multipart", h[:parts][1][:type])
553
- assert_equal("mixed", h[:parts][1][:subtype])
554
- assert_equal(2, h[:parts][1][:parts].size)
555
- assert_equal("text", h[:parts][1][:parts][0][:type])
556
- assert_equal("plain", h[:parts][1][:parts][0][:subtype])
557
- assert_equal("This is attachment body.\n", h[:parts][1][:parts][0][:body])
558
- assert_equal("text", h[:parts][1][:parts][1][:type])
559
- assert_equal("plain", h[:parts][1][:parts][1][:subtype])
560
- assert_equal("This is attachment body2.\n", h[:parts][1][:parts][1][:body])
561
- end
562
- def test_parse_message_no_content_type()
563
- require "stringio"
564
- h = parse_message StringIO.new(<<EOS)
565
- From: TOMITA Masahiro <tommy@tmtm.org>
566
- To: Foo Bar <foo.bar@example.com>
567
- Subject: =?iso-2022-jp?b?GyRCNEE7ehsoQg==?=
568
- Date: Tue, 4 Jan 2005 14:54:22 +0900
569
-
570
- ���ܸ���ʸ
571
- EOS
572
- assert_equal(["tommy@tmtm.org"], h[:from])
573
- assert_equal(["foo.bar@example.com"], h[:to])
574
- assert_equal("����", h[:subject])
575
- assert_equal(["TOMITA Masahiro <tommy@tmtm.org>"], h[:header]["from"])
576
- assert_equal(["����"], h[:header]["subject"])
577
- assert_equal(nil, h[:type])
578
- assert_equal(nil, h[:subtype])
579
- assert_equal(nil, h[:charset])
580
- assert_equal("���ܸ���ʸ\n", h[:body])
581
- assert_equal(<<EOS, h[:rawheader])
582
- From: TOMITA Masahiro <tommy@tmtm.org>
583
- To: Foo Bar <foo.bar@example.com>
584
- Subject: =?iso-2022-jp?b?GyRCNEE7ehsoQg==?=
585
- Date: Tue, 4 Jan 2005 14:54:22 +0900
586
- EOS
587
- end
588
- def test_parse_message_no_content_type_text_only()
589
- require "stringio"
590
- self.text_body_only = true
591
- h = parse_message StringIO.new(<<EOS)
592
- From: TOMITA Masahiro <tommy@tmtm.org>
593
- To: Foo Bar <foo.bar@example.com>
594
- Subject: =?iso-2022-jp?b?GyRCNEE7ehsoQg==?=
595
- Date: Tue, 4 Jan 2005 14:54:22 +0900
596
-
597
- ���ܸ���ʸ
598
- EOS
599
- assert_equal(["tommy@tmtm.org"], h[:from])
600
- assert_equal(["foo.bar@example.com"], h[:to])
601
- assert_equal("����", h[:subject])
602
- assert_equal(["TOMITA Masahiro <tommy@tmtm.org>"], h[:header]["from"])
603
- assert_equal(["����"], h[:header]["subject"])
604
- assert_equal(nil, h[:type])
605
- assert_equal(nil, h[:subtype])
606
- assert_equal(nil, h[:charset])
607
- assert_equal("���ܸ���ʸ\n", h[:body])
608
- assert_equal(<<EOS, h[:rawheader])
609
- From: TOMITA Masahiro <tommy@tmtm.org>
610
- To: Foo Bar <foo.bar@example.com>
611
- Subject: =?iso-2022-jp?b?GyRCNEE7ehsoQg==?=
612
- Date: Tue, 4 Jan 2005 14:54:22 +0900
613
- EOS
614
- end
615
- end