Exemplo n.º 1
0
 def test_construct_mail_simple(self):
     """Very simple envelope with a To, From, Subject, and body."""
     headers = {
         'From': '*****@*****.**',
         'To': '*****@*****.**',
         'Subject': 'Test email',
     }
     e = envelope.Envelope(headers={k: [v] for k, v in headers.items()},
                           bodytext='Test')
     self._test_mail(e)
Exemplo n.º 2
0
 def test_construct_encoding(self):
     headers = {
         'From': '*****@*****.**',
         'To': '*****@*****.**',
         'Subject': 'Test email héhé',
     }
     e = envelope.Envelope(account=test_account,
                           headers={k: [v]
                                    for k, v in headers.items()},
                           bodytext='Test')
     mail = e.construct_mail()
     raw = mail.as_string(policy=email.policy.SMTP,
                          maxheaderlen=sys.maxsize)
     actual = email.parser.Parser().parsestr(raw)
     self.assertEqual('Test email =?utf-8?b?aMOpaMOp?=', actual['Subject'])
Exemplo n.º 3
0
    def test_construct_mail_with_attachment(self):
        """Very simple envelope with a To, From, Subject, body and attachment.
        """
        headers = {
            'From': '*****@*****.**',
            'To': '*****@*****.**',
            'Subject': 'Test email',
        }
        e = envelope.Envelope(headers={k: [v] for k, v in headers.items()},
                              bodytext='Test')
        with tempfile.NamedTemporaryFile(mode='wt', delete=False) as f:
            f.write('blah')
        self.addCleanup(os.unlink, f.name)
        e.attach(f.name)

        self._test_mail(e)
Exemplo n.º 4
0
 def test_parse_template(self):
     """Tests multi-line header and body parsing"""
     raw = ('From: [email protected]\n'
            'To: [email protected],\n'
            ' [email protected]\n'
            'Subject: Fwd: Test email\n'
            '\n'
            'Some body content: which is not a header.\n')
     envlp = envelope.Envelope(account=test_account)
     envlp.parse_template(raw)
     self.assertDictEqual(
         envlp.headers, {
             'From': ['*****@*****.**'],
             'To': ['[email protected], [email protected]'],
             'Subject': ['Fwd: Test email']
         })
     self.assertEqual(envlp.body_txt,
                      'Some body content: which is not a header.')
Exemplo n.º 5
0
 def test_setitem_stores_text_unchanged(self):
     "Just ensure that the value is set and unchanged"
     e = envelope.Envelope()
     e['Subject'] = u'sm\xf8rebr\xf8d'
     self.assertEqual(e['Subject'], u'sm\xf8rebr\xf8d')