/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: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2020-02-03 23:21:15 UTC
  • mfrom: (7290.42.6 paramiko-compat)
  • Revision ID: breezy.the.bot@gmail.com-20200203232115-g7k11bhsfeiqcprv
Fix compatibility with newer versions of paramiko, which break on noise before keys in pem files.

Merged from https://code.launchpad.net/~jelmer/brz/paramiko-compat/+merge/378480

Show diffs side-by-side

added added

removed removed

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