def test_add_mail_with_special_chars(self): input_mail = MIMEText(u'a utf8 message', _charset='utf-8') input_mail['From'] = Header(u'"Älbert Übrö" <äüö@example.mail>', 'iso-8859-1') input_mail['Subject'] = Header(u'Hällö Wörld', 'iso-8859-1') self._add_create_mail_mocks_to_soledad(input_mail) store = LeapMailStore(self.soledad) message = yield store.add_mail('INBOX', input_mail.as_string()) self.assertEqual(u'"\xc4lbert \xdcbr\xf6" <\xe4\xfc\[email protected]>', message.as_dict()['header']['from'])
def test_add_mail(self): expected_message = self._add_create_mail_mocks_to_soledad_from_fixture_file('mbox00000000') mail = self._load_mail_from_file('mbox00000000') self._mock_get_mailbox('INBOX') store = LeapMailStore(self.soledad) message = yield store.add_mail('INBOX', mail.as_string()) self.assertIsInstance(message, LeapMail) self._assert_message_docs_created(expected_message, message)
def test_add_mail_with_inline_attachment(self): input_mail = MIMEMultipart() input_mail.attach(MIMEText(u'a utf8 message', _charset='utf-8')) attachment = MIMEApplication('pretend to be an inline attachment') attachment.add_header('Content-Disposition', 'u\'inline;\n\tfilename=super_nice_photo.jpg') input_mail.attach(attachment) mocked_message = self._add_create_mail_mocks_to_soledad(input_mail) store = LeapMailStore(self.soledad) message = yield store.add_mail('INBOX', input_mail.as_string()) expected = [{'ident': self._cdoc_phash_from_message(mocked_message, 2), 'name': 'super_nice_photo.jpg', 'encoding': 'base64', 'size': 48, 'content-type': 'application/octet-stream'}] self.assertEqual(expected, message.as_dict()['attachments'])
def test_add_mail_with_inline_attachment(self): input_mail = MIMEMultipart() input_mail.attach(MIMEText(u'a utf8 message', _charset='utf-8')) attachment = MIMEApplication('pretend to be an inline attachment') attachment.add_header('Content-Disposition', 'u\'inline;\n\tfilename=super_nice_photo.jpg') input_mail.attach(attachment) mocked_message = self._add_create_mail_mocks_to_soledad(input_mail) store = LeapMailStore(self.soledad) message = yield store.add_mail('INBOX', input_mail.as_string()) expected = [{'ident': self._cdoc_phash_from_message(mocked_message, 2), 'name': 'super_nice_photo.jpg', 'encoding': 'base64', 'size': 202, 'content-type': 'application/octet-stream'}] self.assertEqual(expected, message.as_dict()['attachments'])
def test_add_mail_with_attachment(self): input_mail = MIMEMultipart() input_mail.attach(MIMEText(u'a utf8 message', _charset='utf-8')) attachment = MIMEApplication('pretend to be binary attachment data') attachment.add_header('Content-Disposition', 'attachment', filename='filename.txt') input_mail.attach(attachment) mocked_message = self._add_create_mail_mocks_to_soledad(input_mail) store = LeapMailStore(self.soledad) message = yield store.add_mail('INBOX', input_mail.as_string()) expected = [{'ident': self._cdoc_phash_from_message(mocked_message, 2), 'name': 'filename.txt', 'encoding': 'base64'}] self.assertEqual(expected, message.as_dict()['attachments'])
def test_add_mail_with_nested_attachments(self): input_mail = MIMEMultipart() input_mail.attach(MIMEText(u'a utf8 message', _charset='utf-8')) attachment = MIMEApplication('pretend to be binary attachment data') attachment.add_header('Content-Disposition', 'attachment', filename='filename.txt') nested_attachment = MIMEMultipart() nested_attachment.attach(attachment) input_mail.attach(nested_attachment) mocked_message = self._add_create_mail_mocks_to_soledad(input_mail) store = LeapMailStore(self.soledad) message = yield store.add_mail('INBOX', input_mail.as_string()) expected = [{'ident': self._cdoc_phash_from_message(mocked_message, 2), 'name': 'filename.txt', 'encoding': 'base64', 'size': 197, 'content-type': 'application/octet-stream'}] self.assertEqual(expected, message.as_dict()['attachments'])