/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-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

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