/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/smtp_connection.py

  • Committer: Jelmer Vernooij
  • Date: 2018-04-02 00:52:27 UTC
  • mfrom: (6939 work)
  • mto: This revision was merged to the branch mainline in revision 7274.
  • Revision ID: jelmer@jelmer.uk-20180402005227-pecflp1mvdjrjqd6
Merge trunk.

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 import Utils
 
21
try:
 
22
    from email.utils import getaddresses, parseaddr
 
23
except ImportError:  # python < 3
 
24
    from email.Utils import getaddresses, parseaddr
 
25
 
22
26
import errno
23
27
import smtplib
24
28
import socket
174
178
        """Get the origin and destination addresses of a message.
175
179
 
176
180
        :param message: A message object supporting get() to access its
177
 
            headers, like email.Message or breezy.email_message.EmailMessage.
 
181
            headers, like email.message.Message or
 
182
            breezy.email_message.EmailMessage.
178
183
        :return: A pair (from_email, to_emails), where from_email is the email
179
184
            address in the From header, and to_emails a list of all the
180
185
            addresses in the To, Cc, and Bcc headers.
181
186
        """
182
 
        from_email = Utils.parseaddr(message.get('From', None))[1]
 
187
        from_email = parseaddr(message.get('From', None))[1]
183
188
        to_full_addresses = []
184
189
        for header in ['To', 'Cc', 'Bcc']:
185
190
            value = message.get(header, None)
186
191
            if value:
187
192
                to_full_addresses.append(value)
188
193
        to_emails = [ pair[1] for pair in
189
 
                Utils.getaddresses(to_full_addresses) ]
 
194
                getaddresses(to_full_addresses) ]
190
195
 
191
196
        return from_email, to_emails
192
197
 
196
201
        The message will be sent to all addresses in the To, Cc and Bcc
197
202
        headers.
198
203
 
199
 
        :param message: An email.Message or email.MIMEMultipart object.
 
204
        :param message: An email.message.Message or
 
205
            email.mime.multipart.MIMEMultipart object.
200
206
        :return: None
201
207
        """
202
208
        from_email, to_emails = self.get_message_addresses(message)