/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: 2019-05-29 03:22:34 UTC
  • mfrom: (7303 work)
  • mto: This revision was merged to the branch mainline in revision 7306.
  • Revision ID: jelmer@jelmer.uk-20190529032234-mt3fuws8gq03tapi
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 
39
39
 
40
40
smtp_password = config.Option('smtp_password', default=None,
41
 
        help='''\
 
41
                              help='''\
42
42
Password to use for authentication to SMTP server.
43
43
''')
44
44
smtp_server = config.Option('smtp_server', default=None,
45
 
        help='''\
 
45
                            help='''\
46
46
Hostname of the SMTP server to use for sending email.
47
47
''')
48
48
smtp_username = config.Option('smtp_username', default=None,
49
 
        help='''\
 
49
                              help='''\
50
50
Username to use for authentication to SMTP server.
51
51
''')
52
52
 
73
73
    _fmt = "Please specify smtp_server.  No server at default %(host)s."
74
74
 
75
75
 
76
 
 
77
76
class NoDestinationAddress(InternalBzrError):
78
77
 
79
78
    _fmt = "Message does not have a destination address."
80
79
 
81
80
 
82
 
 
83
81
class SMTPConnection(object):
84
82
    """Connect to an SMTP server and send an email.
85
83
 
112
110
 
113
111
        self._create_connection()
114
112
        # FIXME: _authenticate() should only be called when the server has
115
 
        # refused unauthenticated access, so it can safely try to authenticate 
 
113
        # refused unauthenticated access, so it can safely try to authenticate
116
114
        # with the default username. JRV20090407
117
115
        self._authenticate()
118
116
 
143
141
        if self._connection.has_extn("starttls"):
144
142
            code, resp = self._connection.starttls()
145
143
            if not (200 <= code <= 299):
146
 
                raise SMTPError("server refused STARTTLS: %d %s" % (code, resp))
 
144
                raise SMTPError("server refused STARTTLS: %d %s" %
 
145
                                (code, resp))
147
146
            # Say EHLO again, to check for newly revealed features
148
147
            code, resp = self._connection.ehlo()
149
148
            if not (200 <= code <= 299):
154
153
        auth = config.AuthenticationConfig()
155
154
        if self._smtp_username is None:
156
155
            # FIXME: Since _authenticate gets called even when no authentication
157
 
            # is necessary, it's not possible to use the default username 
 
156
            # is necessary, it's not possible to use the default username
158
157
            # here yet.
159
158
            self._smtp_username = auth.get_user('smtp', self._smtp_server)
160
159
            if self._smtp_username is None:
190
189
            value = message.get(header, None)
191
190
            if value:
192
191
                to_full_addresses.append(value)
193
 
        to_emails = [ pair[1] for pair in
194
 
                getaddresses(to_full_addresses) ]
 
192
        to_emails = [pair[1] for pair in
 
193
                     getaddresses(to_full_addresses)]
195
194
 
196
195
        return from_email, to_emails
197
196
 
216
215
                                      message.as_string())
217
216
        except smtplib.SMTPRecipientsRefused as e:
218
217
            raise SMTPError('server refused recipient: %d %s' %
219
 
                    next(iter(e.recipients.values())))
 
218
                            next(iter(e.recipients.values())))
220
219
        except smtplib.SMTPResponseException as e:
221
220
            raise SMTPError('%d %s' % (e.smtp_code, e.smtp_error))
222
221
        except smtplib.SMTPException as e: