~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smtp_connection.py

  • Committer: James Henstridge
  • Date: 2009-03-24 07:29:23 UTC
  • mto: This revision was merged to the branch mainline in revision 4203.
  • Revision ID: james@jamesh.id.au-20090324072923-4l42qpdtur9nqsc5
Encode usernames and passwords as UTF-8 rather than ASCII.  While 
CRAM-MD5 gives no guidance on encodings, other authentication methods 
(e.g. SASL PLAIN) do.

Show diffs side-by-side

added added

removed removed

Lines of Context:
112
112
                'smtp', self._smtp_server, self._smtp_username)
113
113
 
114
114
        # smtplib requires that the username and password be byte
115
 
        # strings (and the relevant RFCs don't seem to address
116
 
        # character encoding for usernames and passwords).
 
115
        # strings.  The CRAM-MD5 spec doesn't give any guidance on
 
116
        # encodings, but the SASL PLAIN says UTF-8, so that's what
 
117
        # we'll use.
117
118
        if isinstance(self._smtp_username, unicode):
118
 
            self._smtp_username = self._smtp_username.encode('ascii')
 
119
            self._smtp_username = self._smtp_username.encode('utf-8')
119
120
        if isinstance(self._smtp_password, unicode):
120
 
            self._smtp_password = self._smtp_password.encode('ascii')
 
121
            self._smtp_password = self._smtp_password.encode('utf-8')
121
122
 
122
123
        self._connection.login(self._smtp_username, self._smtp_password)
123
124