Mercurial > p > roundup > code
comparison test/test_mailgw.py @ 4423:579802067547
Fix charset of first text-part of outgoing multipart messages...
...thanks Dirk Geschke for reporting, see
http://thread.gmane.org/gmane.comp.bug-tracking.roundup.user/10223
This also adds some regression tests to test incoming latin1 and
outgoing single- and multipart utf-8 and latin1 messages
| author | Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net> |
|---|---|
| date | Mon, 04 Oct 2010 12:56:37 +0000 |
| parents | f6a2bfd351ee |
| children | f1affb6b7a08 |
comparison
equal
deleted
inserted
replaced
| 4422:ad7176d22f43 | 4423:579802067547 |
|---|---|
| 458 --bCsyhTFzCvuiizWF-- | 458 --bCsyhTFzCvuiizWF-- |
| 459 | 459 |
| 460 --bxyzzy-- | 460 --bxyzzy-- |
| 461 ''' | 461 ''' |
| 462 | 462 |
| 463 multipart_msg_latin1 = '''From: mary <mary@test.test> | |
| 464 To: issue_tracker@your.tracker.email.domain.example | |
| 465 Message-Id: <followup_dummy_id> | |
| 466 In-Reply-To: <dummy_test_message_id> | |
| 467 Subject: [issue1] Testing... | |
| 468 Content-Type: multipart/alternative; boundary=001485f339f8f361fb049188dbba | |
| 469 | |
| 470 | |
| 471 --001485f339f8f361fb049188dbba | |
| 472 Content-Type: text/plain; charset=ISO-8859-1 | |
| 473 Content-Transfer-Encoding: quoted-printable | |
| 474 | |
| 475 umlaut =E4=F6=FC=C4=D6=DC=DF | |
| 476 | |
| 477 --001485f339f8f361fb049188dbba | |
| 478 Content-Type: text/html; charset=ISO-8859-1 | |
| 479 Content-Transfer-Encoding: quoted-printable | |
| 480 | |
| 481 <html>umlaut =E4=F6=FC=C4=D6=DC=DF</html> | |
| 482 | |
| 483 --001485f339f8f361fb049188dbba-- | |
| 484 ''' | |
| 485 | |
| 463 def testMultipartKeepAlternatives(self): | 486 def testMultipartKeepAlternatives(self): |
| 464 self.doNewIssue() | 487 self.doNewIssue() |
| 465 self._handle_mail(self.multipart_msg) | 488 self._handle_mail(self.multipart_msg) |
| 466 messages = self.db.issue.get('1', 'messages') | 489 messages = self.db.issue.get('1', 'messages') |
| 467 messages.sort() | 490 messages.sort() |
| 493 self.assertEqual(f.name, names.get (n, 'unnamed')) | 516 self.assertEqual(f.name, names.get (n, 'unnamed')) |
| 494 if n in content : | 517 if n in content : |
| 495 self.assertEqual(f.content, content [n]) | 518 self.assertEqual(f.content, content [n]) |
| 496 self.assertEqual(msg.content, 'test attachment second text/plain') | 519 self.assertEqual(msg.content, 'test attachment second text/plain') |
| 497 | 520 |
| 521 def testMultipartCharsetUTF8NoAttach(self): | |
| 522 c = 'umlaut \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f' | |
| 523 self.doNewIssue() | |
| 524 self.db.config.NOSY_MAX_ATTACHMENT_SIZE = 0 | |
| 525 self._handle_mail(self.multipart_msg_latin1) | |
| 526 messages = self.db.issue.get('1', 'messages') | |
| 527 messages.sort() | |
| 528 msg = self.db.msg.getnode (messages[-1]) | |
| 529 assert(len(msg.files) == 1) | |
| 530 name = 'unnamed' | |
| 531 content = '<html>' + c + '</html>\n' | |
| 532 for n, id in enumerate (msg.files): | |
| 533 f = self.db.file.getnode (id) | |
| 534 self.assertEqual(f.name, name) | |
| 535 self.assertEqual(f.content, content) | |
| 536 self.assertEqual(msg.content, c) | |
| 537 self.compareMessages(self._get_mail(), | |
| 538 '''FROM: roundup-admin@your.tracker.email.domain.example | |
| 539 TO: chef@bork.bork.bork, richard@test.test | |
| 540 Content-Type: text/plain; charset="utf-8" | |
| 541 Subject: [issue1] Testing... | |
| 542 To: chef@bork.bork.bork, richard@test.test | |
| 543 From: "Contrary, Mary" <issue_tracker@your.tracker.email.domain.example> | |
| 544 Reply-To: Roundup issue tracker | |
| 545 <issue_tracker@your.tracker.email.domain.example> | |
| 546 MIME-Version: 1.0 | |
| 547 Message-Id: <followup_dummy_id> | |
| 548 In-Reply-To: <dummy_test_message_id> | |
| 549 X-Roundup-Name: Roundup issue tracker | |
| 550 X-Roundup-Loop: hello | |
| 551 X-Roundup-Issue-Status: chatting | |
| 552 X-Roundup-Issue-Files: unnamed | |
| 553 Content-Transfer-Encoding: quoted-printable | |
| 554 | |
| 555 | |
| 556 Contrary, Mary <mary@test.test> added the comment: | |
| 557 | |
| 558 umlaut =C3=A4=C3=B6=C3=BC=C3=84=C3=96=C3=9C=C3=9F | |
| 559 File 'unnamed' not attached - you can download it from http://tracker.examp= | |
| 560 le/cgi-bin/roundup.cgi/bugs/file1. | |
| 561 | |
| 562 ---------- | |
| 563 status: unread -> chatting | |
| 564 | |
| 565 _______________________________________________________________________ | |
| 566 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example> | |
| 567 <http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1> | |
| 568 _______________________________________________________________________ | |
| 569 ''') | |
| 570 | |
| 571 def testMultipartCharsetLatin1NoAttach(self): | |
| 572 c = 'umlaut \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f' | |
| 573 self.doNewIssue() | |
| 574 self.db.config.NOSY_MAX_ATTACHMENT_SIZE = 0 | |
| 575 self.db.config.MAIL_CHARSET = 'iso-8859-1' | |
| 576 self._handle_mail(self.multipart_msg_latin1) | |
| 577 messages = self.db.issue.get('1', 'messages') | |
| 578 messages.sort() | |
| 579 msg = self.db.msg.getnode (messages[-1]) | |
| 580 assert(len(msg.files) == 1) | |
| 581 name = 'unnamed' | |
| 582 content = '<html>' + c + '</html>\n' | |
| 583 for n, id in enumerate (msg.files): | |
| 584 f = self.db.file.getnode (id) | |
| 585 self.assertEqual(f.name, name) | |
| 586 self.assertEqual(f.content, content) | |
| 587 self.assertEqual(msg.content, c) | |
| 588 self.compareMessages(self._get_mail(), | |
| 589 '''FROM: roundup-admin@your.tracker.email.domain.example | |
| 590 TO: chef@bork.bork.bork, richard@test.test | |
| 591 Content-Type: text/plain; charset="iso-8859-1" | |
| 592 Subject: [issue1] Testing... | |
| 593 To: chef@bork.bork.bork, richard@test.test | |
| 594 From: "Contrary, Mary" <issue_tracker@your.tracker.email.domain.example> | |
| 595 Reply-To: Roundup issue tracker | |
| 596 <issue_tracker@your.tracker.email.domain.example> | |
| 597 MIME-Version: 1.0 | |
| 598 Message-Id: <followup_dummy_id> | |
| 599 In-Reply-To: <dummy_test_message_id> | |
| 600 X-Roundup-Name: Roundup issue tracker | |
| 601 X-Roundup-Loop: hello | |
| 602 X-Roundup-Issue-Status: chatting | |
| 603 X-Roundup-Issue-Files: unnamed | |
| 604 Content-Transfer-Encoding: quoted-printable | |
| 605 | |
| 606 | |
| 607 Contrary, Mary <mary@test.test> added the comment: | |
| 608 | |
| 609 umlaut =E4=F6=FC=C4=D6=DC=DF | |
| 610 File 'unnamed' not attached - you can download it from http://tracker.examp= | |
| 611 le/cgi-bin/roundup.cgi/bugs/file1. | |
| 612 | |
| 613 ---------- | |
| 614 status: unread -> chatting | |
| 615 | |
| 616 _______________________________________________________________________ | |
| 617 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example> | |
| 618 <http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1> | |
| 619 _______________________________________________________________________ | |
| 620 ''') | |
| 621 | |
| 622 def testMultipartCharsetUTF8AttachFile(self): | |
| 623 c = 'umlaut \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f' | |
| 624 self.doNewIssue() | |
| 625 self._handle_mail(self.multipart_msg_latin1) | |
| 626 messages = self.db.issue.get('1', 'messages') | |
| 627 messages.sort() | |
| 628 msg = self.db.msg.getnode (messages[-1]) | |
| 629 assert(len(msg.files) == 1) | |
| 630 name = 'unnamed' | |
| 631 content = '<html>' + c + '</html>\n' | |
| 632 for n, id in enumerate (msg.files): | |
| 633 f = self.db.file.getnode (id) | |
| 634 self.assertEqual(f.name, name) | |
| 635 self.assertEqual(f.content, content) | |
| 636 self.assertEqual(msg.content, c) | |
| 637 self.compareMessages(self._get_mail(), | |
| 638 '''FROM: roundup-admin@your.tracker.email.domain.example | |
| 639 TO: chef@bork.bork.bork, richard@test.test | |
| 640 Content-Type: multipart/mixed; boundary="utf-8" | |
| 641 Subject: [issue1] Testing... | |
| 642 To: chef@bork.bork.bork, richard@test.test | |
| 643 From: "Contrary, Mary" <issue_tracker@your.tracker.email.domain.example> | |
| 644 Reply-To: Roundup issue tracker | |
| 645 <issue_tracker@your.tracker.email.domain.example> | |
| 646 MIME-Version: 1.0 | |
| 647 Message-Id: <followup_dummy_id> | |
| 648 In-Reply-To: <dummy_test_message_id> | |
| 649 X-Roundup-Name: Roundup issue tracker | |
| 650 X-Roundup-Loop: hello | |
| 651 X-Roundup-Issue-Status: chatting | |
| 652 X-Roundup-Issue-Files: unnamed | |
| 653 Content-Transfer-Encoding: quoted-printable | |
| 654 | |
| 655 | |
| 656 --utf-8 | |
| 657 MIME-Version: 1.0 | |
| 658 Content-Type: text/plain; charset="utf-8" | |
| 659 Content-Transfer-Encoding: quoted-printable | |
| 660 | |
| 661 | |
| 662 Contrary, Mary <mary@test.test> added the comment: | |
| 663 | |
| 664 umlaut =C3=A4=C3=B6=C3=BC=C3=84=C3=96=C3=9C=C3=9F | |
| 665 | |
| 666 ---------- | |
| 667 status: unread -> chatting | |
| 668 | |
| 669 _______________________________________________________________________ | |
| 670 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example> | |
| 671 <http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1> | |
| 672 _______________________________________________________________________ | |
| 673 --utf-8 | |
| 674 Content-Type: text/html | |
| 675 MIME-Version: 1.0 | |
| 676 Content-Transfer-Encoding: base64 | |
| 677 Content-Disposition: attachment; | |
| 678 filename="unnamed" | |
| 679 | |
| 680 PGh0bWw+dW1sYXV0IMOkw7bDvMOEw5bDnMOfPC9odG1sPgo= | |
| 681 | |
| 682 --utf-8-- | |
| 683 ''') | |
| 684 | |
| 685 def testMultipartCharsetLatin1AttachFile(self): | |
| 686 c = 'umlaut \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f' | |
| 687 self.doNewIssue() | |
| 688 self.db.config.MAIL_CHARSET = 'iso-8859-1' | |
| 689 self._handle_mail(self.multipart_msg_latin1) | |
| 690 messages = self.db.issue.get('1', 'messages') | |
| 691 messages.sort() | |
| 692 msg = self.db.msg.getnode (messages[-1]) | |
| 693 assert(len(msg.files) == 1) | |
| 694 name = 'unnamed' | |
| 695 content = '<html>' + c + '</html>\n' | |
| 696 for n, id in enumerate (msg.files): | |
| 697 f = self.db.file.getnode (id) | |
| 698 self.assertEqual(f.name, name) | |
| 699 self.assertEqual(f.content, content) | |
| 700 self.assertEqual(msg.content, c) | |
| 701 self.compareMessages(self._get_mail(), | |
| 702 '''FROM: roundup-admin@your.tracker.email.domain.example | |
| 703 TO: chef@bork.bork.bork, richard@test.test | |
| 704 Content-Type: multipart/mixed; boundary="utf-8" | |
| 705 Subject: [issue1] Testing... | |
| 706 To: chef@bork.bork.bork, richard@test.test | |
| 707 From: "Contrary, Mary" <issue_tracker@your.tracker.email.domain.example> | |
| 708 Reply-To: Roundup issue tracker | |
| 709 <issue_tracker@your.tracker.email.domain.example> | |
| 710 MIME-Version: 1.0 | |
| 711 Message-Id: <followup_dummy_id> | |
| 712 In-Reply-To: <dummy_test_message_id> | |
| 713 X-Roundup-Name: Roundup issue tracker | |
| 714 X-Roundup-Loop: hello | |
| 715 X-Roundup-Issue-Status: chatting | |
| 716 X-Roundup-Issue-Files: unnamed | |
| 717 Content-Transfer-Encoding: quoted-printable | |
| 718 | |
| 719 | |
| 720 --utf-8 | |
| 721 MIME-Version: 1.0 | |
| 722 Content-Type: text/plain; charset="iso-8859-1" | |
| 723 Content-Transfer-Encoding: quoted-printable | |
| 724 | |
| 725 | |
| 726 Contrary, Mary <mary@test.test> added the comment: | |
| 727 | |
| 728 umlaut =E4=F6=FC=C4=D6=DC=DF | |
| 729 | |
| 730 ---------- | |
| 731 status: unread -> chatting | |
| 732 | |
| 733 _______________________________________________________________________ | |
| 734 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example> | |
| 735 <http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1> | |
| 736 _______________________________________________________________________ | |
| 737 --utf-8 | |
| 738 Content-Type: text/html | |
| 739 MIME-Version: 1.0 | |
| 740 Content-Transfer-Encoding: base64 | |
| 741 Content-Disposition: attachment; | |
| 742 filename="unnamed" | |
| 743 | |
| 744 PGh0bWw+dW1sYXV0IMOkw7bDvMOEw5bDnMOfPC9odG1sPgo= | |
| 745 | |
| 746 --utf-8-- | |
| 747 ''') | |
| 748 | |
| 498 def testSimpleFollowup(self): | 749 def testSimpleFollowup(self): |
| 499 self.doNewIssue() | 750 self.doNewIssue() |
| 500 self._handle_mail('''Content-Type: text/plain; | 751 self._handle_mail('''Content-Type: text/plain; |
| 501 charset="iso-8859-1" | 752 charset="iso-8859-1" |
| 502 From: mary <mary@test.test> | 753 From: mary <mary@test.test> |
