Update of /cvsroot/spambayes/spambayes/scripts
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23902/scripts

Modified Files:
        sb_imapfilter.py 
Log Message:
Add [ 1169939 ] Make sb_imapfilter use CRAM MD5 authentication

If available, use CRAM-MD5 authentication when logging in.  I don't have access 
to
 an IMAP server that supports this, so can't verify that it works (it doesn't 
break
 my AUTH=Login, at least).  It looks good though, so it seems worth adding to 
1.1a1
 to me.

Index: sb_imapfilter.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/scripts/sb_imapfilter.py,v
retrieving revision 1.54
retrieving revision 1.55
diff -C2 -d -r1.54 -r1.55
*** sb_imapfilter.py    16 Mar 2005 03:35:02 -0000      1.54
--- sb_imapfilter.py    29 Mar 2005 03:51:23 -0000      1.55
***************
*** 53,56 ****
--- 53,58 ----
        servers I have access to offer any alternative method, however.  If
        someone's does, then it would be nice to offer this.
+       Thanks to #1169939 we now support CRAM_MD5 if available.  It'd still
+       be good to support others, though.
      o Usernames should be able to be literals as well as quoted strings.
        This might help if the username/password has special characters like
***************
*** 80,83 ****
--- 82,86 ----
  import time
  import sys
+ import hmac
  import getopt
  import types
***************
*** 192,200 ****
          return "".join(buffer)
  
      def login(self, username, pwd):
          """Log in to the IMAP server, catching invalid username/password."""
          assert self.connected, "Must be connected before logging in."
          try:
!             BaseIMAP.login(self, username, pwd)  # superclass login
          except BaseIMAP.error, e:
              msg = "There was an error logging in to the IMAP server." \
--- 195,216 ----
          return "".join(buffer)
  
+     def authenticate_cram_md5(self, username, pwd):
+         """Authenticate (login) with CRAM-MD5.
+ 
+         See RFC 2195 and SpamBayes patch #1169939
+         """
+         def cram_md5(response):
+             return " ".join([username,
+                              hmac.HMAC(pwd, response).hexdigest()])
+         self.authenticate('CRAM-MD5', cram_md5)
+ 
      def login(self, username, pwd):
          """Log in to the IMAP server, catching invalid username/password."""
          assert self.connected, "Must be connected before logging in."
          try:
!             if 'AUTH=CRAM-MD5' in self.capabilities:
!                 self.authenticate_cram_md5(username, pwd)
!             else:
!                 BaseIMAP.login(self, username, pwd)  # superclass login
          except BaseIMAP.error, e:
              msg = "There was an error logging in to the IMAP server." \

_______________________________________________
Spambayes-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/spambayes-checkins

Reply via email to