#
# Copyright (c) 2014 ThoughtWorks, Inc.
#
# Pixelated is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pixelated is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Pixelated. If not, see
blablabla
', 'headers': {'Content-Type': 'text/html'}}) mail = PixelatedMail.from_soledad(None, None, None, None, parts=parts) self.assertRegexpMatches(mail.body, '^--' + mail.boundary + '\n.*') self.assertRegexpMatches(mail.body, '\nContent-Type: text/html\n\nblablabla
\n') self.assertRegexpMatches(mail.body, '\nContent-Type: text/plain\n\nblablabla\n') self.assertRegexpMatches(mail.body, '.*--' + mail.boundary + '--$') def test_percent_character_is_allowed_on_body(self): parts = {'alternatives': [], 'attachments': []} parts['alternatives'].append({'content': '100% happy with percentage symbol', 'headers': {'Content-Type': 'text/plain'}}) parts['alternatives'].append({'content': '100% happy with percentage symbol
', 'headers': {'Content-Type': 'text/html'}}) mail = PixelatedMail.from_soledad(None, None, None, None, parts=parts) self.assertRegexpMatches(mail.body, '([\s\S]*100%){2}') class InputMailTest(unittest.TestCase): mail_dict = lambda x: { 'body': 'Este \xe9 o corpo', 'header': { 'cc': ['cc@pixelated.org', 'anothercc@pixelated.org'], 'to': ['to@pixelated.org', 'anotherto@pixelated.org'], 'bcc': ['bcc@pixelated.org', 'anotherbcc@pixelated.org'], 'subject': 'Oi' }, 'ident': '', 'tags': ['sent'] } multipart_mail_dict = lambda x: { 'body': [{'content-type': 'plain', 'raw': 'Hello world!'}, {'content-type': 'html', 'raw': 'Hello html world!
'}], 'header': { 'cc': ['cc@pixelated.org', 'anothercc@pixelated.org'], 'to': ['to@pixelated.org', 'anotherto@pixelated.org'], 'bcc': ['bcc@pixelated.org', 'anotherbcc@pixelated.org'], 'subject': 'Oi', }, 'ident': '', 'tags': ['sent'] } def test_to_mime_multipart_should_add_blank_fields(self): pixelated.support.date.iso_now = lambda: 'date now' mail_dict = self.mail_dict() mail_dict['header']['to'] = '' mail_dict['header']['bcc'] = '' mail_dict['header']['cc'] = '' mail_dict['header']['subject'] = '' mime_multipart = InputMail.from_dict(mail_dict).to_mime_multipart() self.assertNotRegexpMatches(mime_multipart.as_string(), "\nTo: \n") self.assertNotRegexpMatches(mime_multipart.as_string(), "\nBcc: \n") self.assertNotRegexpMatches(mime_multipart.as_string(), "\nCc: \n") self.assertNotRegexpMatches(mime_multipart.as_string(), "\nSubject: \n") def test_to_mime_multipart(self): pixelated.support.date.iso_now = lambda: 'date now' mime_multipart = InputMail.from_dict(self.mail_dict()).to_mime_multipart() self.assertRegexpMatches(mime_multipart.as_string(), "\nTo: to@pixelated.org, anotherto@pixelated.org\n") self.assertRegexpMatches(mime_multipart.as_string(), "\nCc: cc@pixelated.org, anothercc@pixelated.org\n") self.assertRegexpMatches(mime_multipart.as_string(), "\nBcc: bcc@pixelated.org, anotherbcc@pixelated.org\n") self.assertRegexpMatches(mime_multipart.as_string(), "\nDate: date now\n") self.assertRegexpMatches(mime_multipart.as_string(), "\nSubject: Oi\n") self.assertRegexpMatches(mime_multipart.as_string(), "\nEste \xe9 o corpo") def test_smtp_format(self): InputMail.FROM_EMAIL_ADDRESS = 'pixelated@org' smtp_format = InputMail.from_dict(self.mail_dict()).to_smtp_format() self.assertRegexpMatches(smtp_format, "\nFrom: pixelated@org") def test_to_mime_multipart_handles_alternative_bodies(self): mime_multipart = InputMail.from_dict(self.multipart_mail_dict()).to_mime_multipart() part_one = 'Content-Type: text/plain; charset="us-ascii"\nMIME-Version: 1.0\nContent-Transfer-Encoding: 7bit\n\nHello world!' part_two = 'Content-Type: text/html; charset="us-ascii"\nMIME-Version: 1.0\nContent-Transfer-Encoding: 7bit\n\nHello html world!
' self.assertRegexpMatches(mime_multipart.as_string(), part_one) self.assertRegexpMatches(mime_multipart.as_string(), part_two)