comparison test/test_mailgw.py @ 4424:f1affb6b7a08

Mail gateway fixes and improvements. - new mailgw config item unpack_rfc822 that unpacks message attachments of type message/rfc822 and attaches the individual parts instead of attaching the whole message/rfc822 attachment to the roundup issue. - Fix handling of incoming message/rfc822 attachments. These resulted in a weird mail usage error because the email module threw a TypeError which roundup interprets as a Reject exception. Fixes issue2550667. Added regression tests for message/rfc822 attachments with and without configured unpacking (mailgw unpack_rfc822, see Features above) Thanks to Benni Bärmann for reporting.
author Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
date Tue, 05 Oct 2010 14:24:25 +0000
parents 579802067547
children 502a1a8620e6
comparison
equal deleted inserted replaced
4423:579802067547 4424:f1affb6b7a08
481 <html>umlaut =E4=F6=FC=C4=D6=DC=DF</html> 481 <html>umlaut =E4=F6=FC=C4=D6=DC=DF</html>
482 482
483 --001485f339f8f361fb049188dbba-- 483 --001485f339f8f361fb049188dbba--
484 ''' 484 '''
485 485
486 multipart_msg_rfc822 = '''From: mary <mary@test.test>
487 To: issue_tracker@your.tracker.email.domain.example
488 Message-Id: <followup_dummy_id>
489 In-Reply-To: <dummy_test_message_id>
490 Subject: [issue1] Testing...
491 Content-Type: multipart/mixed; boundary=001485f339f8f361fb049188dbba
492
493 This is a multi-part message in MIME format.
494 --001485f339f8f361fb049188dbba
495 Content-Type: text/plain; charset=ISO-8859-15
496 Content-Transfer-Encoding: 7bit
497
498 First part: Text
499
500 --001485f339f8f361fb049188dbba
501 Content-Type: message/rfc822; name="Fwd: Original email subject.eml"
502 Content-Transfer-Encoding: 7bit
503 Content-Disposition: attachment; filename="Fwd: Original email subject.eml"
504
505 Message-Id: <followup_dummy_id_2>
506 In-Reply-To: <dummy_test_message_id_2>
507 MIME-Version: 1.0
508 Subject: Fwd: Original email subject
509 Date: Mon, 23 Aug 2010 08:23:33 +0200
510 Content-Type: multipart/alternative; boundary="090500050101020406060002"
511
512 This is a multi-part message in MIME format.
513 --090500050101020406060002
514 Content-Type: text/plain; charset=ISO-8859-15; format=flowed
515 Content-Transfer-Encoding: 7bit
516
517 some text in inner email
518 ========================
519
520 --090500050101020406060002
521 Content-Type: text/html; charset=ISO-8859-15
522 Content-Transfer-Encoding: 7bit
523
524 <html>
525 some text in inner email
526 ========================
527 </html>
528
529 --090500050101020406060002--
530
531 --001485f339f8f361fb049188dbba--
532 '''
533
486 def testMultipartKeepAlternatives(self): 534 def testMultipartKeepAlternatives(self):
487 self.doNewIssue() 535 self.doNewIssue()
488 self._handle_mail(self.multipart_msg) 536 self._handle_mail(self.multipart_msg)
489 messages = self.db.issue.get('1', 'messages') 537 messages = self.db.issue.get('1', 'messages')
490 messages.sort() 538 messages.sort()
744 PGh0bWw+dW1sYXV0IMOkw7bDvMOEw5bDnMOfPC9odG1sPgo= 792 PGh0bWw+dW1sYXV0IMOkw7bDvMOEw5bDnMOfPC9odG1sPgo=
745 793
746 --utf-8-- 794 --utf-8--
747 ''') 795 ''')
748 796
797 def testMultipartRFC822(self):
798 self.doNewIssue()
799 self._handle_mail(self.multipart_msg_rfc822)
800 messages = self.db.issue.get('1', 'messages')
801 messages.sort()
802 msg = self.db.msg.getnode (messages[-1])
803 assert(len(msg.files) == 1)
804 name = "Fwd: Original email subject.eml"
805 for n, id in enumerate (msg.files):
806 f = self.db.file.getnode (id)
807 self.assertEqual(f.name, name)
808 self.assertEqual(msg.content, 'First part: Text')
809 self.compareMessages(self._get_mail(),
810 '''TO: chef@bork.bork.bork, richard@test.test
811 Content-Type: text/plain; charset="utf-8"
812 Subject: [issue1] Testing...
813 To: chef@bork.bork.bork, richard@test.test
814 From: "Contrary, Mary" <issue_tracker@your.tracker.email.domain.example>
815 Reply-To: Roundup issue tracker
816 <issue_tracker@your.tracker.email.domain.example>
817 MIME-Version: 1.0
818 Message-Id: <followup_dummy_id>
819 In-Reply-To: <dummy_test_message_id>
820 X-Roundup-Name: Roundup issue tracker
821 X-Roundup-Loop: hello
822 X-Roundup-Issue-Status: chatting
823 X-Roundup-Issue-Files: Fwd: Original email subject.eml
824 Content-Transfer-Encoding: quoted-printable
825
826
827 --utf-8
828 MIME-Version: 1.0
829 Content-Type: text/plain; charset="utf-8"
830 Content-Transfer-Encoding: quoted-printable
831
832
833 Contrary, Mary <mary@test.test> added the comment:
834
835 First part: Text
836
837 ----------
838 status: unread -> chatting
839
840 _______________________________________________________________________
841 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
842 <http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1>
843 _______________________________________________________________________
844 --utf-8
845 Content-Type: message/rfc822
846 MIME-Version: 1.0
847 Content-Disposition: attachment;
848 filename="Fwd: Original email subject.eml"
849
850 Message-Id: <followup_dummy_id_2>
851 In-Reply-To: <dummy_test_message_id_2>
852 MIME-Version: 1.0
853 Subject: Fwd: Original email subject
854 Date: Mon, 23 Aug 2010 08:23:33 +0200
855 Content-Type: multipart/alternative; boundary="090500050101020406060002"
856
857 This is a multi-part message in MIME format.
858 --090500050101020406060002
859 Content-Type: text/plain; charset=ISO-8859-15; format=flowed
860 Content-Transfer-Encoding: 7bit
861
862 some text in inner email
863 ========================
864
865 --090500050101020406060002
866 Content-Type: text/html; charset=ISO-8859-15
867 Content-Transfer-Encoding: 7bit
868
869 <html>
870 some text in inner email
871 ========================
872 </html>
873
874 --090500050101020406060002--
875
876 --utf-8--
877 ''')
878
879 def testMultipartRFC822Unpack(self):
880 self.doNewIssue()
881 self.db.config.MAILGW_UNPACK_RFC822 = True
882 self._handle_mail(self.multipart_msg_rfc822)
883 messages = self.db.issue.get('1', 'messages')
884 messages.sort()
885 msg = self.db.msg.getnode (messages[-1])
886 self.assertEqual(len(msg.files), 2)
887 t = 'some text in inner email\n========================\n'
888 content = {0 : t, 1 : '<html>\n' + t + '</html>\n'}
889 for n, id in enumerate (msg.files):
890 f = self.db.file.getnode (id)
891 self.assertEqual(f.name, 'unnamed')
892 if n in content :
893 self.assertEqual(f.content, content [n])
894 self.assertEqual(msg.content, 'First part: Text')
895
749 def testSimpleFollowup(self): 896 def testSimpleFollowup(self):
750 self.doNewIssue() 897 self.doNewIssue()
751 self._handle_mail('''Content-Type: text/plain; 898 self._handle_mail('''Content-Type: text/plain;
752 charset="iso-8859-1" 899 charset="iso-8859-1"
753 From: mary <mary@test.test> 900 From: mary <mary@test.test>

Roundup Issue Tracker: http://roundup-tracker.org/