/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/email_message.py

  • Committer: Jelmer Vernooij
  • Date: 2017-09-01 07:15:43 UTC
  • mfrom: (6770.3.2 py3_test_cleanup)
  • Revision ID: jelmer@jelmer.uk-20170901071543-1t83321xkog9qrxh
Merge lp:~gz/brz/py3_test_cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""A convenience class around email.Message and email.MIMEMultipart."""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
from email import (
20
22
    Header,
21
23
    Message,
24
26
    Utils,
25
27
    )
26
28
 
27
 
from bzrlib import __version__ as _bzrlib_version
28
 
from bzrlib.osutils import safe_unicode
29
 
from bzrlib.smtp_connection import SMTPConnection
 
29
from . import __version__ as _breezy_version
 
30
from .osutils import safe_unicode
 
31
from .sixish import (
 
32
    text_type,
 
33
    )
 
34
from .smtp_connection import SMTPConnection
30
35
 
31
36
 
32
37
class EmailMessage(object):
58
63
        self._body = body
59
64
        self._parts = []
60
65
 
61
 
        if isinstance(to_address, basestring):
 
66
        if isinstance(to_address, (str, text_type)):
62
67
            to_address = [ to_address ]
63
68
 
64
69
        to_addresses = []
69
74
        self._headers['To'] = ', '.join(to_addresses)
70
75
        self._headers['From'] = self.address_to_encoded_header(from_address)
71
76
        self._headers['Subject'] = Header.Header(safe_unicode(subject))
72
 
        self._headers['User-Agent'] = 'Bazaar (%s)' % _bzrlib_version
 
77
        self._headers['User-Agent'] = 'Bazaar (%s)' % _breezy_version
73
78
 
74
79
    def add_inline_attachment(self, body, filename=None, mime_subtype='plain'):
75
80
        """Add an inline attachment to the message.
147
152
 
148
153
    @staticmethod
149
154
    def send(config, from_address, to_address, subject, body, attachment=None,
150
 
            attachment_filename=None, attachment_mime_subtype='plain'):
 
155
             attachment_filename=None, attachment_mime_subtype='plain'):
151
156
        """Create an email message and send it with SMTPConnection.
152
157
 
153
158
        :param config: config object to pass to SMTPConnection constructor.
181
186
    def string_with_encoding(string_):
182
187
        """Return a str object together with an encoding.
183
188
 
184
 
        :param string_: A str or unicode object.
 
189
        :param string\\_: A str or unicode object.
185
190
        :return: A tuple (str, encoding), where encoding is one of 'ascii',
186
191
            'utf-8', or '8-bit', in that preferred order.
187
192
        """