def testI18nMessage(self): """ Basic unit test which loads a mail message in the utf-8 charset encoding off the filesystem and converts the bytes to a Chandler C{Mail.MailMessage}. This Chandler c{Mail.MailMessage} is then converted back to bytes for sending. The bytes contained in the To, From, Subject, and Body payload are compared with the original. This test confirms that encoded headers are decoded to Unicode, The Body is converted from bytes to Unicode, and that the headers and Body are properly encoded back to bytes. A header in a non-ascii charset should be encoded for sending. For example: To: =?utf-8?b?IsSFxI3EmcSXxK/FocWzxavFviDEhMSMxJjElsSuxaDFssWqxb0i?= <*****@*****.**> """ msgText = self.__loadTestMessage() mOne = email.message_from_string(msgText) messageKind = message.messageObjectToKind(self.view, mOne, msgText)[1] mTwo = message.kindToMessageObject(messageKind) self.assertEquals(mOne['To'], mTwo['To']) self.assertEquals(mOne['From'], mTwo['From']) self.assertEquals(mOne['Subject'], mTwo['Subject']) o = mOne.get_payload(decode=True) self.assertEquals(o, mTwo.get_payload()[0].get_payload()[1].get_payload(decode=True))
def testSubjectWithNewLine(self): # Test for fix to bug 10254. A \n was getting inserted # in the title attribute of an Item. This resulted # in an extra \n in the rfc2822 mail headers which # broke the mail message formating. # This test adds a \n to the mailStamp.subject then # confirms when the MailStamped Item is converted to # a Python email object that it no longer has the \n. mailStamp = self.__getMailMessage(addNewLine=True) messageObject = message.kindToMessageObject(mailStamp) self.assertTrue(mailStamp.subject.endswith('\n')) self.assertEquals(messageObject['Subject'], 'test mail')
def testKindToMessageObject(self): messageObject = message.kindToMessageObject(self.__getMailMessage()) self.__compareMessageObjects(messageObject, self.__getMessageObject())