/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 bzrlib/email_message.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
from __future__ import absolute_import
20
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
35
 
from . import __version__ as _breezy_version
36
 
from .osutils import safe_unicode
37
 
from .sixish import (
38
 
    text_type,
 
21
from email import (
 
22
    Header,
 
23
    Message,
 
24
    MIMEMultipart,
 
25
    MIMEText,
 
26
    Utils,
39
27
    )
40
 
from .smtp_connection import SMTPConnection
 
28
 
 
29
from bzrlib import __version__ as _bzrlib_version
 
30
from bzrlib.osutils import safe_unicode
 
31
from bzrlib.smtp_connection import SMTPConnection
41
32
 
42
33
 
43
34
class EmailMessage(object):
69
60
        self._body = body
70
61
        self._parts = []
71
62
 
72
 
        if isinstance(to_address, (str, text_type)):
 
63
        if isinstance(to_address, basestring):
73
64
            to_address = [ to_address ]
74
65
 
75
66
        to_addresses = []
79
70
 
80
71
        self._headers['To'] = ', '.join(to_addresses)
81
72
        self._headers['From'] = self.address_to_encoded_header(from_address)
82
 
        self._headers['Subject'] = Header(safe_unicode(subject))
83
 
        self._headers['User-Agent'] = 'Bazaar (%s)' % _breezy_version
 
73
        self._headers['Subject'] = Header.Header(safe_unicode(subject))
 
74
        self._headers['User-Agent'] = 'Bazaar (%s)' % _bzrlib_version
84
75
 
85
76
    def add_inline_attachment(self, body, filename=None, mime_subtype='plain'):
86
77
        """Add an inline attachment to the message.
111
102
            Used for tests.
112
103
        """
113
104
        if not self._parts:
114
 
            msgobj = Message()
 
105
            msgobj = Message.Message()
115
106
            if self._body is not None:
116
107
                body, encoding = self.string_with_encoding(self._body)
117
108
                msgobj.set_payload(body, encoding)
118
109
        else:
119
 
            msgobj = MIMEMultipart()
 
110
            msgobj = MIMEMultipart.MIMEMultipart()
120
111
 
121
112
            if boundary is not None:
122
113
                msgobj.set_boundary(boundary)
123
114
 
124
115
            for body, filename, mime_subtype in self._parts:
125
116
                body, encoding = self.string_with_encoding(body)
126
 
                payload = MIMEText(body, mime_subtype, encoding)
 
117
                payload = MIMEText.MIMEText(body, mime_subtype, encoding)
127
118
 
128
119
                if filename is not None:
129
120
                    content_type = payload['Content-Type']
181
172
        """
182
173
        # Can't call Header over all the address, because that encodes both the
183
174
        # name and the email address, which is not permitted by RFCs.
184
 
        user, email = parseaddr(address)
 
175
        user, email = Utils.parseaddr(address)
185
176
        if not user:
186
177
            return email
187
178
        else:
188
 
            return formataddr((str(Header(safe_unicode(user))),
 
179
            return Utils.formataddr((str(Header.Header(safe_unicode(user))),
189
180
                email))
190
181
 
191
182
    @staticmethod