Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 7
- Log:
Initial import of RForum 0.2 sources from a downloaded Tarball.
RForum is a Ruby On Rails based forum and mail gateway service.
- Author:
- adh
- Date:
- Sat Jul 22 18:43:13 +0100 2006
- Size:
- 13715 Bytes
1 | #!/bin/env ruby |
2 | |
3 | require File.dirname(__FILE__) + '/../test_helper' |
4 | require 'mailer' |
5 | |
6 | class MailerReceiveTest < Test::Unit::TestCase |
7 | |
8 | POSTS_WITH_JUNK = [] |
9 | POSTS_WITH_JUNK.push <<EOF |
10 | Message-ID: <id.junk.root@example.com> |
11 | Date: Sun, 01 May 2005 14:56:53 +0200 |
12 | From: Sergej <sergej@example.com> |
13 | MIME-Version: 1.0 |
14 | To: Forum <list@example.com> |
15 | Subject: [RAILS] Re: [ANN] Test |
16 | Content-Type: text/plain; charset=ISO-8859-1; format=flowed |
17 | Content-Transfer-Encoding: 7bit |
18 | |
19 | This is a post. |
20 | |
21 | Someone wrote xyz: |
22 | > this is a TOFU |
23 | > gfds gdfgs d sfdgfsdg sg fsg ffd ss fgd s gfdsdf g sdfg |
24 | > gfds gdfgs d sfdgfsdg sg fsg ffd ss fgd s gfdsdf g sdfg |
25 | > gfds gdfgs d sfdgfsdg sg fsg ffd ss fgd s gfdsdf g sdfg |
26 | > gfds gdfgs d sfdgfsdg sg fsg ffd ss fgd s gfdsdf g sdfg |
27 | > gfds gdfgs d sfdgfsdg sg fsg ffd ss fgd s gfdsdf g sdfg |
28 | > gfds gdfgs d sfdgfsdg sg fsg ffd ss fgd s gfdsdf g sdfg |
29 | |
30 | -- |
31 | this |
32 | is |
33 | a |
34 | signature |
35 | EOF |
36 | |
37 | POSTS_WITH_JUNK.push <<EOF |
38 | Content-class: urn:content-classes:message |
39 | MIME-Version: 1.0 |
40 | Content-Type: text/plain; |
41 | charset="us-ascii" |
42 | Content-Transfer-Encoding: quoted-printable |
43 | Subject: [RAILS] Re: [ANN] Test |
44 | Date: Mon, 7 Nov 2005 15:10:48 -0600 |
45 | Message-ID: <B14120EE5C432443B21102F7925DAD0202FF59E3@COKE.uwec.edu> |
46 | Thread-Topic: [Rails] treeview, master detail forms, sortable grids, etc..? |
47 | Thread-Index: AcXj3vbbzTj4BStKTeuKEcwZYSHdlwAABMSg |
48 | From: Sergej <sergej@example.com> |
49 | To: Forum <list@example.com> |
50 | X-OriginalArrivalTime: 07 Nov 2005 21:10:49.0762 (UTC) |
51 | FILETIME=[BA975820:01C5E3DF] |
52 | |
53 | This is a post. |
54 | |
55 | -----Original Message----- |
56 | From: rails-bounces@lists.rubyonrails.org |
57 | [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of xyz |
58 | Sent: Monday, November 07, 2005 3:07 PM |
59 | To: Rails Mailing List |
60 | Subject: [Rails] treeview, master detail forms, sortable grids, etc..? |
61 | |
62 | |
63 | Are there any (preferable opensource) pre made widgets like calendar |
64 | widgets, treeviews, sortable grids, etc.. that I can pluginto a rails |
65 | application? |
66 | |
67 | If they are not build in Rubyy, then are there any examples an how to |
68 | integrate them? |
69 | |
70 | xxxx |
71 | _______________________________________________ |
72 | Rails mailing list |
73 | Rails@lists.rubyonrails.org |
74 | http://lists.rubyonrails.org/mailman/listinfo/rails |
75 | _______________________________________________ |
76 | Rails mailing list |
77 | Rails@lists.rubyonrails.org |
78 | http://lists.rubyonrails.org/mailman/listinfo/rails |
79 | EOF |
80 | |
81 | POSTS_WITH_JUNK.push <<EOF |
82 | Content-class: urn:content-classes:message |
83 | MIME-Version: 1.0 |
84 | Content-Type: text/plain; |
85 | charset="us-ascii" |
86 | Content-Transfer-Encoding: quoted-printable |
87 | Subject: [RAILS] Re: [ANN] Test |
88 | Date: Mon, 7 Nov 2005 15:10:48 -0600 |
89 | Message-ID: <B14120EE5C432443B21102F7925DAD0202FF59E3@COKE.uwec.edu> |
90 | Thread-Topic: [Rails] treeview, master detail forms, sortable grids, etc..? |
91 | Thread-Index: AcXj3vbbzTj4BStKTeuKEcwZYSHdlwAABMSg |
92 | From: Sergej <sergej@example.com> |
93 | To: Forum <list@example.com> |
94 | X-OriginalArrivalTime: 07 Nov 2005 21:10:49.0762 (UTC) |
95 | FILETIME=[BA975820:01C5E3DF] |
96 | |
97 | This is a post. |
98 | |
99 | On 11/7/05, X. Y. <x@y> wrote: |
100 | > Anyone know what the Ruby equivalent of PHP's explode and implode are |
101 | > for arrays? |
102 | > |
103 | > - Jim |
104 | > _______________________________________________ |
105 | > Rails mailing list |
106 | > Rails@lists.rubyonrails.org |
107 | > http://lists.rubyonrails.org/mailman/listinfo/rails |
108 | > |
109 | _______________________________________________ |
110 | Rails mailing list |
111 | Rails@lists.rubyonrails.org |
112 | http://lists.rubyonrails.org/mailman/listinfo/rails |
113 | EOF |
114 | |
115 | POST_WITH_QUOTING = <<EOF |
116 | Message-ID: <id.junk.root@example.com> |
117 | Date: Sun, 01 May 2005 14:56:53 +0200 |
118 | From: Sergej <sergej@example.com> |
119 | MIME-Version: 1.0 |
120 | To: Forum <list@example.com> |
121 | Subject: Test |
122 | Content-Type: text/plain; charset=ISO-8859-1; format=flowed |
123 | Content-Transfer-Encoding: 7bit |
124 | |
125 | Hi! |
126 | |
127 | Someone wrote xyz: |
128 | > this is a quoting |
129 | |
130 | This is a post. |
131 | |
132 | -- |
133 | this is a |
134 | short signature without space after "--" |
135 | EOF |
136 | |
137 | POST_WITH_LARGE_QUOTING = <<EOF |
138 | Message-ID: <id.junk.root@example.com> |
139 | Date: Sun, 01 May 2005 14:56:53 +0200 |
140 | From: Sergej <sergej@example.com> |
141 | MIME-Version: 1.0 |
142 | To: Forum <list@example.com> |
143 | Subject: Test |
144 | Content-Type: text/plain; charset=ISO-8859-1; format=flowed |
145 | Content-Transfer-Encoding: 7bit |
146 | |
147 | Hi! |
148 | |
149 | Someone wrote xyz: |
150 | quoting |
151 | This is a post. |
152 | |
153 | -- |
154 | this |
155 | is |
156 | a |
157 | signature |
158 | EOF |
159 | |
160 | POST_WITH_LARGE_QUOTING.gsub!(/quoting/, "> too much quoting\n"*100) |
161 | |
162 | MULTIPART_POST =<<EOF |
163 | Message-ID: <id.123.root@example.com> |
164 | Date: Sun, 01 May 2005 14:56:53 +0200 |
165 | From: Sergej <sergej@example.com> |
166 | MIME-Version: 1.0 |
167 | To: Forum <list@example.com> |
168 | Subject: Multipart test |
169 | Content-Type: multipart/alternative; |
170 | boundary="------------070201060202080704030007" |
171 | |
172 | This is a multi-part message in MIME format. |
173 | --------------070201060202080704030007 |
174 | Content-Type: text/plain; charset=ISO-8859-1; format=flowed |
175 | Content-Transfer-Encoding: 7bit |
176 | |
177 | some text |
178 | |
179 | --------------070201060202080704030007 |
180 | Content-Type: text/html; charset=ISO-8859-1 |
181 | Content-Transfer-Encoding: 7bit |
182 | |
183 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
184 | <html> |
185 | <head> |
186 | <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> |
187 | </head> |
188 | <body bgcolor="#ffffff" text="#000000"> |
189 | <b>some text</b><br> |
190 | </body> |
191 | </html> |
192 | |
193 | --------------070201060202080704030007-- |
194 | EOF |
195 | |
196 | NESTED_MULTIPART_POST = <<eof |
197 | Message-ID: <id.123.root@example.com> |
198 | Date: Sun, 01 May 2005 14:56:53 +0200 |
199 | From: Sergej <sergej@example.com> |
200 | MIME-Version: 1.0 |
201 | To: Forum <list@example.com> |
202 | Subject: Multipart/alternative test |
203 | Content-Type: multipart/mixed; boundary="===============1370243048==" |
204 | |
205 | --===============1370243048== |
206 | Content-Type: multipart/alternative; |
207 | boundary="----=_Part_2735_4512309.1115403812040" |
208 | |
209 | ------=_Part_2735_4512309.1115403812040 |
210 | Content-Type: text/plain; charset=ISO-8859-1 |
211 | Content-Transfer-Encoding: quoted-printable |
212 | Content-Disposition: inline |
213 | |
214 | the only sensible part of this mail |
215 | ------=_Part_2735_4512309.1115403812040 |
216 | Content-Type: text/html; charset=ISO-8859-1 |
217 | Content-Transfer-Encoding: quoted-printable |
218 | Content-Disposition: inline |
219 | |
220 | <br>html crap<br> |
221 | ------=_Part_2735_4512309.1115403812040-- |
222 | |
223 | --===============1370243048== |
224 | Content-Type: text/plain; charset="us-ascii" |
225 | MIME-Version: 1.0 |
226 | Content-Transfer-Encoding: 7bit |
227 | Content-Disposition: inline |
228 | |
229 | useless footer |
230 | --===============1370243048==-- |
231 | eof |
232 | |
233 | ROOT_POST =<<EOF |
234 | Message-ID: <id.123.root@example.com> |
235 | Date: Sun, 01 May 2005 14:56:53 +0200 |
236 | From: Sergej <sergej@example.com> |
237 | MIME-Version: 1.0 |
238 | To: Forum <list@example.com> |
239 | Subject: Test |
240 | Content-Type: text/plain; charset=ISO-8859-1; format=flowed |
241 | Content-Transfer-Encoding: 7bit |
242 | |
243 | This is a post. |
244 | EOF |
245 | |
246 | REPLY_WITH_REFERENCES =<<EOF |
247 | Message-ID: <id.123.reply@example.com> |
248 | References: <thread3-root@xy.com> |
249 | Date: Sun, 01 May 2005 14:56:53 +0200 |
250 | From: Sergej <sergej@example.com> |
251 | MIME-Version: 1.0 |
252 | To: Forum <list@example.com> |
253 | Subject: Re: Test |
254 | Content-Type: text/plain; charset=ISO-8859-1; format=flowed |
255 | Content-Transfer-Encoding: 7bit |
256 | |
257 | This is a reply. |
258 | EOF |
259 | |
260 | REPLY_WITH_IN_REPLY_TO =<<EOF |
261 | Message-ID: <id.123.reply@example.com> |
262 | In-Reply-To: <thread3-root@xy.com> |
263 | Date: Sun, 01 May 2005 14:56:53 +0200 |
264 | From: Sergej <sergej@example.com> |
265 | MIME-Version: 1.0 |
266 | To: Forum <list@example.com> |
267 | Subject: Re: Test |
268 | Content-Type: text/plain; charset=ISO-8859-1; format=flowed |
269 | Content-Transfer-Encoding: 7bit |
270 | |
271 | This is a reply. |
272 | EOF |
273 | |
274 | REPLY_WITH_INVALID_IN_REPLY_TO =<<EOF |
275 | Message-ID: <id.123.reply@example.com> |
276 | In-Reply-To: thread3-root@xy.com |
277 | Date: Sun, 01 May 2005 14:56:53 +0200 |
278 | From: Sergej <sergej@example.com> |
279 | MIME-Version: 1.0 |
280 | To: Forum <list@example.com> |
281 | Subject: Re: Test |
282 | Content-Type: text/plain; charset=ISO-8859-1; format=flowed |
283 | Content-Transfer-Encoding: 7bit |
284 | |
285 | This is a reply. |
286 | EOF |
287 | |
288 | REPLY_WITH_NEW_SUBJECT =<<EOF |
289 | Message-ID: <id.123.reply@example.com> |
290 | In-Reply-To: <thread3-root@xy.com> |
291 | Date: Sun, 01 May 2005 14:56:53 +0200 |
292 | From: Sergej <sergej@example.com> |
293 | MIME-Version: 1.0 |
294 | To: Forum <list@example.com> |
295 | Subject: Test |
296 | Content-Type: text/plain; charset=ISO-8859-1; format=flowed |
297 | Content-Transfer-Encoding: 7bit |
298 | |
299 | This is a new post. |
300 | EOF |
301 | |
302 | REPLY_WITH_NEW_SUBJECT_AND_INVALID_PARENT =<<EOF |
303 | Message-ID: <id.123.reply@example.com> |
304 | References: <invalid@xy.com> |
305 | Date: Sun, 01 May 2005 14:56:53 +0200 |
306 | From: Sergej <sergej@example.com> |
307 | MIME-Version: 1.0 |
308 | To: Forum <list@example.com> |
309 | Subject: Test |
310 | Content-Type: text/plain; charset=ISO-8859-1; format=flowed |
311 | Content-Transfer-Encoding: 7bit |
312 | |
313 | This is a new post. |
314 | EOF |
315 | |
316 | REPLY_WITH_INVALID_PARENT =<<EOF |
317 | Message-ID: <id.123.reply@example.com> |
318 | References: <invalid@xy.com> |
319 | Date: Sun, 01 May 2005 14:56:53 +0200 |
320 | From: Sergej <sergej@example.com> |
321 | MIME-Version: 1.0 |
322 | To: Forum <list@example.com> |
323 | Subject: Re: Test |
324 | Content-Type: text/plain; charset=ISO-8859-1; format=flowed |
325 | Content-Transfer-Encoding: 7bit |
326 | |
327 | This is a new post. |
328 | EOF |
329 | |
330 | GUEST_MAIL =<<EOF |
331 | Message-ID: <id.123.guest@example.com> |
332 | Date: Sun, 01 May 2005 14:56:53 +0200 |
333 | From: Some One <guest@example.com> |
334 | MIME-Version: 1.0 |
335 | To: Forum <list@example.com> |
336 | Subject: Re: Test |
337 | Content-Type: text/plain; charset=ISO-8859-1; format=flowed |
338 | Content-Transfer-Encoding: 7bit |
339 | |
340 | This is a post from someone who is no registered user. |
341 | EOF |
342 | |
343 | |
344 | |
345 | GUEST_MAIL_WITH_SHORT_NAME =<<EOF |
346 | Message-ID: <id.123.unauthorized@example.com> |
347 | Date: Sun, 01 May 2005 14:56:53 +0200 |
348 | From: Me <x@example.com> |
349 | MIME-Version: 1.0 |
350 | To: Forum <list@example.com> |
351 | Subject: Re: Test |
352 | Content-Type: text/plain; charset=ISO-8859-1; format=flowed |
353 | Content-Transfer-Encoding: 7bit |
354 | |
355 | This is a post from a guest. |
356 | EOF |
357 | |
358 | GUEST_MAIL_WITHOUT_NAME =<<EOF |
359 | Message-ID: <id.123.unauthorized@example.com> |
360 | Date: Sun, 01 May 2005 14:56:53 +0200 |
361 | From: x@example.com |
362 | MIME-Version: 1.0 |
363 | To: Forum <list@example.com> |
364 | Subject: Re: Test |
365 | Content-Type: text/plain; charset=ISO-8859-1; format=flowed |
366 | Content-Transfer-Encoding: 7bit |
367 | |
368 | This is a post from a guest with no name. |
369 | EOF |
370 | |
371 | MAIL_FOR_UNKNOWN_FORUM =<<EOF |
372 | Message-ID: <id.123.root@example.com> |
373 | Date: Sun, 01 May 2005 14:56:53 +0200 |
374 | From: Sergej <sergej@example.com> |
375 | MIME-Version: 1.0 |
376 | To: Unknown Forum <xyz@example.com> |
377 | Subject: Test |
378 | Content-Type: text/plain; charset=ISO-8859-1; format=flowed |
379 | Content-Transfer-Encoding: 7bit |
380 | |
381 | This is a post. |
382 | EOF |
383 | |
384 | fixtures 'users', 'posts', 'topics', 'forums' |
385 | |
386 | def setup |
387 | @sent_mail = ActionMailer::Base.deliveries = [] |
388 | end |
389 | |
390 | def teardown |
391 | ActionMailer::Base.deliveries = [] |
392 | end |
393 | |
394 | def test_parent |
395 | [REPLY_WITH_REFERENCES, REPLY_WITH_IN_REPLY_TO, REPLY_WITH_INVALID_IN_REPLY_TO].each do |raw| |
396 | mail = Mailer.receive(raw) |
397 | assert_equal Post.find(20), mail.parent |
398 | end |
399 | end |
400 | |
401 | def test_parent_reply_with_invalid_parent |
402 | assert_raises(RuntimeError) { Mailer.receive(REPLY_WITH_INVALID_PARENT).parent } |
403 | end |
404 | |
405 | def test_parent_reply_with_new_subject |
406 | mail = Mailer.receive(REPLY_WITH_NEW_SUBJECT) |
407 | assert_equal 20, mail.parent.id |
408 | end |
409 | |
410 | def test_parent_reply_with_new_subject_and_invalid_parent |
411 | mail = Mailer.receive(REPLY_WITH_NEW_SUBJECT_AND_INVALID_PARENT) |
412 | assert_equal nil, mail.parent |
413 | end |
414 | |
415 | def test_clean |
416 | for junkpost in POSTS_WITH_JUNK |
417 | post = Mailer.receive(junkpost).to_post |
418 | assert_equal 'Re: [ANN] Test', post.subject |
419 | assert_equal 'This is a post.', post.text |
420 | assert_equal User.find(2), post.author |
421 | end |
422 | end |
423 | |
424 | def test_quoting |
425 | expected = <<EOF |
426 | Hi! |
427 | |
428 | Someone wrote xyz: |
429 | > this is a quoting |
430 | |
431 | This is a post. |
432 | EOF |
433 | |
434 | post = Mailer.receive(POST_WITH_QUOTING).to_post |
435 | assert_equal expected.strip, post.text |
436 | end |
437 | |
438 | def test_large_quoting |
439 | expected = <<EOF |
440 | Hi! |
441 | |
442 | Someone wrote xyz: |
443 | > too much quoting |
444 | > too much quoting |
445 | > too much quoting |
446 | > too much quoting |
447 | > too much quoting |
448 | > too much quoting |
449 | > too much quoting |
450 | > too much quoting |
451 | > too much quoting |
452 | > too much quoting |
453 | |
454 | This is a post. |
455 | EOF |
456 | |
457 | post = Mailer.receive(POST_WITH_LARGE_QUOTING).to_post |
458 | assert_equal expected.strip, post.text |
459 | end |
460 | |
461 | def test_multipart |
462 | post = Mailer.receive(MULTIPART_POST).to_post |
463 | assert_equal "some text", post.text |
464 | end |
465 | |
466 | def test_multipart |
467 | post = Mailer.receive(NESTED_MULTIPART_POST).to_post |
468 | assert_equal "the only sensible part of this mail", post.text |
469 | end |
470 | |
471 | def test_process_root_post |
472 | post = Mailer.process_email(ROOT_POST) |
473 | assert_equal "id.123.root@example.com", post.messageid |
474 | assert_equal "mail", post.post_method |
475 | assert !post.parent |
476 | assert_equal 2, post.topic.forum_id |
477 | end |
478 | |
479 | def test_process_reply_post |
480 | post = Mailer.process_email(REPLY_WITH_REFERENCES) |
481 | assert_equal "id.123.reply@example.com", post.messageid |
482 | assert post.parent |
483 | assert_equal 2, post.topic.forum_id |
484 | end |
485 | |
486 | def test_reject_guest_mail |
487 | RForum::CONFIG[:accept_mail_from_guests] = false |
488 | assert_raises(RuntimeError) { Mailer.process_email(GUEST_MAIL) } |
489 | end |
490 | |
491 | def test_accept_guest_mail |
492 | RForum::CONFIG[:accept_mail_from_guests] = true |
493 | |
494 | post = Mailer.process_email(GUEST_MAIL) |
495 | assert_equal 'Some One', post.author.guest_name |
496 | assert_equal 'guest@example.com', post.author.guest_email |
497 | end |
498 | |
499 | def test_accept_guest_mail_with_short_name |
500 | RForum::CONFIG[:accept_mail_from_guests] = true |
501 | |
502 | post = Mailer.process_email(GUEST_MAIL_WITH_SHORT_NAME) |
503 | assert_equal 'Me', post.author.guest_name |
504 | assert_equal 'x@example.com', post.author.guest_email |
505 | end |
506 | |
507 | def test_accept_guest_mail_without_name |
508 | RForum::CONFIG[:accept_mail_from_guests] = true |
509 | |
510 | post = Mailer.process_email(GUEST_MAIL_WITHOUT_NAME) |
511 | assert_equal 'unknown', post.author.guest_name |
512 | assert_equal 'x@example.com', post.author.guest_email |
513 | end |
514 | |
515 | def test_process_duplicate |
516 | Mailer.process_email(ROOT_POST) |
517 | assert_raises(RuntimeError) { Mailer.process_email(ROOT_POST) } |
518 | end |
519 | |
520 | def test_process_malformed |
521 | assert_raises(TMail::SyntaxError) { Mailer.process_email("foobar") } |
522 | end |
523 | |
524 | def test_unknown_forum |
525 | assert_raises(RuntimeError) { Mailer.process_email(MAIL_FOR_UNKNOWN_FORUM) } |
526 | end |
527 | end |