Opened 8 years ago

Closed 5 years ago

Last modified 5 years ago

#4055 defect closed duplicate (duplicate)

when the smtp server auth with 'username', the smtp.py client will thow exception

Reported by: itfront Owned by: itfront
Priority: high Milestone:
Component: mail Keywords:
Cc: Branch:
Author:

Description (last modified by Jean-Paul Calderone)

when I use the smtp.py to send email,I got exception:

Unhandled Error
Traceback (most recent call last):
  File "/usr/local/lib/python2.6/site-packages/Twisted-8.2.0-py2.6-linux-i686.egg/twisted/python/log.py", line 84, in callWithLogger
    return callWithContext({"system": lp}, func, *args, **kw)
  File "/usr/local/lib/python2.6/site-packages/Twisted-8.2.0-py2.6-linux-i686.egg/twisted/python/log.py", line 69, in callWithContext
    return context.call({ILogContext: newCtx}, func, *args, **kw)
  File "/usr/local/lib/python2.6/site-packages/Twisted-8.2.0-py2.6-linux-i686.egg/twisted/python/context.py", line 59, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/usr/local/lib/python2.6/site-packages/Twisted-8.2.0-py2.6-linux-i686.egg/twisted/python/context.py", line 37, in callWithContext
    return func(*args,**kw)
--- <exception caught here> ---
  File "/usr/local/lib/python2.6/site-packages/Twisted-8.2.0-py2.6-linux-i686.egg/twisted/internet/pollreactor.py", line 186, in _doReadOrWrite
    why = selectable.doRead()
  File "/usr/local/lib/python2.6/site-packages/Twisted-8.2.0-py2.6-linux-i686.egg/twisted/internet/tcp.py", line 463, in doRead
    return self.protocol.dataReceived(data)
  File "/usr/local/lib/python2.6/site-packages/Twisted-8.2.0-py2.6-linux-i686.egg/twisted/protocols/basic.py", line 231, in dataReceived
    why = self.lineReceived(line)
  File "/usr/local/lib/python2.6/site-packages/Twisted-8.2.0-py2.6-linux-i686.egg/twisted/mail/smtp.py", line 1052, in lineReceived
/13823106429
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/usr/local/lib/python2.6/site-packages/Twisted-8.2.0-py2.6-linux-i686.egg/twisted/python/context.py", line 37, in callWithContext
    return func(*args,**kw)
--- <exception caught here> ---
  File "/usr/local/lib/python2.6/site-packages/Twisted-8.2.0-py2.6-linux-i686.egg/twisted/internet/pollreactor.py", line 186, in _doReadOrWrite
    why = selectable.doRead()
  File "/usr/local/lib/python2.6/site-packages/Twisted-8.2.0-py2.6-linux-i686.egg/twisted/internet/tcp.py", line 463, in doRead
    return self.protocol.dataReceived(data)
  File "/usr/local/lib/python2.6/site-packages/Twisted-8.2.0-py2.6-linux-i686.egg/twisted/protocols/basic.py", line 231, in dataReceived
    why = self.lineReceived(line)
  File "/usr/local/lib/python2.6/site-packages/Twisted-8.2.0-py2.6-linux-i686.egg/twisted/mail/smtp.py", line 1052, in lineReceived
    why = self._okresponse(self.code,'\n'.join(self.resp))
  File "/usr/local/lib/python2.6/site-packages/Twisted-8.2.0-py2.6-linux-i686.egg/twisted/mail/smtp.py", line 1372, in esmtpState_challenge
    self._authResponse(auth, resp)
  File "/usr/local/lib/python2.6/site-packages/Twisted-8.2.0-py2.6-linux-i686.egg/twisted/mail/smtp.py", line 1388, in _authResponse
    self.sendLine(encode_base64(resp, e

finally , I find out that , at about line 1379:

def _authResponse(self, auth, challenge):
        self._failresponse = self.esmtpAUTHDeclined

        try:
            challenge = base64.decodestring(challenge)
            challenge = challenge.capitalize()  #add this!!

Attachments (1)

smtp.py (66.0 KB) - added by itfront 8 years ago.

Download all attachments as: .zip

Change History (10)

Changed 8 years ago by itfront

Attachment: smtp.py added

comment:1 Changed 8 years ago by itfront

I review the smtp.py and find out that:the error-input detection is too week..beacuse not all smtp server is coded good, you must tolerate non-standard!

comment:2 Changed 8 years ago by itfront

Component: coremail
Owner: changed from Glyph to Jean-Paul Calderone

comment:3 Changed 8 years ago by Jean-Paul Calderone

Owner: changed from Jean-Paul Calderone to itfront

Hi itfront.

Thanks for investigating this problem.

I wonder if you could provide your changes as a patch instead of just attaching a modified copy of smtp.py. Patches are much easier to work with.

Also, it would be be really great if you could add a unit test which triggers this behavior. Unit tests are a much better way to describe bugs than anything else. They let us see what's really happening, reproduce the problem, and verify that a particular change fixes the problem.

Finally, when you've attached a patch with a unit test and a fix, please add the review keyword to the ticket so we know it's ready to look at.

Thanks!

comment:4 Changed 7 years ago by Jean-Paul Calderone

Description: modified (diff)

Fixing description markup

comment:5 Changed 7 years ago by Corbin Simpson

The suggested fix breaks test_crammd5Auth badly and I'm not sure how to fix it as the unit tests are somewhat indecipherable. :T Suggestions?

comment:6 Changed 5 years ago by argonemyth

Resolution: worksforme
Status: newclosed

If itfront means when an smtp server sends 'username' as a challenge, the smtp.py client will throw an exception, the problem is no longer there. Check the following imap4.LOGINAuthenticator code:

    def challengeUsername(self, secret, chal):
        # Respond to somethichallengesng like "Username:"
        self.challengeResponse = self.challengeSecret
        return self.user

It doesn't care about the value chal at all...The following simple test (not test case) should confirm this:

In class smtp.LOGINCredentials, replacing 'Password:' and 'Username:' with whatever words you want, test_smtp.AuthTestCase.test_loginAgainstWeirdServer (which uses the LOGINCredentials) still passes.

I am closing this ticket because I think the bug is no longer there. If anyone could confirm that the bug is still present, feel free to re-open the ticket, thanks!

comment:7 Changed 5 years ago by argonemyth

Resolution: worksforme
Status: closedreopened

comment:8 Changed 5 years ago by argonemyth

Resolution: duplicate
Status: reopenedclosed

This was fixed in ticket #736 (r11917). Marking this one as a duplicate, since #736 is already resolved.

comment:9 Changed 5 years ago by Jean-Paul Calderone

#736 is somewhat related, but # seems more directly related. #736 was resolved 5 years before this ticket was filed, and only changed code in twisted/mail/imap4.py. #4031 actually fixed the SMTP client by making it share that same code from the IMAP4 module.

Note: See TracTickets for help on using tickets.