Ticket #16376: python-managesieve-0.3-darkness.patch

File python-managesieve-0.3-darkness.patch, 1.8 KB (added by gboyce@…, 16 years ago)

Patch to correct the problem.

  • managesieve.py

    old new  
    99Ulrich Eck <ueck@net-labs.de> April 2001
    1010"""
    1111
    12 import binascii, re, socket, time, random, sys
     12import binascii, re, socket, time, random, sys, base64
    1313
    1414__all__ = [ 'MANAGESIEVE', 'SIEVE_PORT', 'OK', 'NO', 'BYE', 'Debug']
    1515
    16 from imaplib import _log, _mesg
     16# XXX darky -- these are now in an IMAP4 class, and I don't think we
     17# should be using them.
     18#from imaplib import _log, _mesg
     19
     20import logging
     21log = logging.getLogger("managesieve")
     22def _log(message):
     23    log.debug(message)
     24_mesg = _log
    1725
    1826Debug = 0
    1927CRLF = '\r\n'
     
    135143
    136144
    137145    def _parse_capabilities(self, lines):
     146        # XXX darky: seeing the STARTTLS cap makes managesieve barf
     147        # because 'data' (in the below unpack) has nothing to unpack.
     148        # Fix up lines for this.
     149        for pair in lines:
     150            if len(pair) == 1:
     151                pair.append("")
     152            assert len(pair) == 2
    138153        for typ, data in lines:
    139154            if __debug__:
    140155                if self.debug >= 3:
     
    363378        """ Login to the Sieve server using mechanism LOGIN. """
    364379        return self.authenticate('LOGIN', user, password)
    365380
     381    def auth_plain(self, auth, user, password):
     382        authenticationData = "%s\0%s\0%s" % (auth, user, password)
     383        authenticationData = base64.encodestring(authenticationData)
     384        authenticationData = authenticationData.replace("\n", "")
     385        typ, data = self._command("AUTHENTICATE", sieve_name("PLAIN"),
     386                                  '"%s"' % (authenticationData,))
     387        if typ == 'OK':
     388            self.state = 'AUTH'
     389        return typ
    366390
    367391    def logout(self):
    368392        """Terminate connection to server."""