/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: 2020-07-05 12:50:01 UTC
  • mfrom: (7490.40.46 work)
  • mto: (7490.40.48 work)
  • mto: This revision was merged to the branch mainline in revision 7519.
  • Revision ID: jelmer@jelmer.uk-20200705125001-7s3vo0p55szbbws7
Merge lp:brz/3.1.

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 email.message import Message
20
 
from email.header import Header
21
 
from email.mime.multipart import MIMEMultipart
22
 
from email.mime.text import MIMEText
23
 
from email.utils import formataddr, parseaddr
 
19
from __future__ import absolute_import
 
20
 
 
21
try:
 
22
    from email.message import Message
 
23
    from email.header import Header
 
24
    from email.mime.multipart import MIMEMultipart
 
25
    from email.mime.text import MIMEText
 
26
    from email.utils import formataddr, parseaddr
 
27
except ImportError:   # python < 3
 
28
    from email import (
 
29
        Header,
 
30
        Message,
 
31
        MIMEMultipart,
 
32
        MIMEText,
 
33
        )
 
34
    from email.Utils import formataddr, parseaddr
24
35
from . import __version__ as _breezy_version
25
36
from .errors import BzrBadParameterNotUnicode
26
37
from .osutils import safe_unicode
 
38
from .sixish import (
 
39
    text_type,
 
40
    )
27
41
from .smtp_connection import SMTPConnection
28
42
 
29
43
 
56
70
        self._body = body
57
71
        self._parts = []
58
72
 
59
 
        if isinstance(to_address, (bytes, str)):
 
73
        if isinstance(to_address, (bytes, text_type)):
60
74
            to_address = [to_address]
61
75
 
62
76
        to_addresses = []
166
180
        :param address: An unicode string, or UTF-8 byte string.
167
181
        :return: A possibly RFC2047-encoded string.
168
182
        """
169
 
        if not isinstance(address, str):
 
183
        if not isinstance(address, (str, text_type)):
170
184
            raise BzrBadParameterNotUnicode(address)
171
185
        # Can't call Header over all the address, because that encodes both the
172
186
        # name and the email address, which is not permitted by RFCs.
190
204
        # avoid base64 when it's not necessary in order to be most compatible
191
205
        # with the capabilities of the receiving side, we check with encode()
192
206
        # and decode() whether the body is actually ascii-only.
193
 
        if isinstance(string_, str):
 
207
        if isinstance(string_, text_type):
194
208
            try:
195
209
                return (string_.encode('ascii'), 'ascii')
196
210
            except UnicodeEncodeError: