Python 3 port:
/!\ this is a huge commit /!\ starting from this commit, SàT is needs Python 3.6+ /!\ SàT maybe be instable or some feature may not work anymore, this will improve with time This patch port backend, bridge and frontends to Python 3. Roughly this has been done this way: - 2to3 tools has been applied (with python 3.7) - all references to python2 have been replaced with python3 (notably shebangs) - fixed files not handled by 2to3 (notably the shell script) - several manual fixes - fixed issues reported by Python 3 that where not handled in Python 2 - replaced "async" with "async_" when needed (it's a reserved word from Python 3.7) - replaced zope's "implements" with @implementer decorator - temporary hack to handle data pickled in database, as str or bytes may be returned, to be checked later - fixed hash comparison for password - removed some code which is not needed anymore with Python 3 - deactivated some code which needs to be checked (notably certificate validation) - tested with jp, fixed reported issues until some basic commands worked - ported Primitivus (after porting dependencies like urwid satext) - more manual fixes
This commit is contained in:
parent
d21a6a660f
commit
fbfe96c505
1 changed files with 6336 additions and 6398 deletions
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SàT plugin for managing imap server
|
||||
|
|
@ -29,10 +29,10 @@ from twisted.mail import imap4
|
|||
from twisted.python import failure
|
||||
from email.parser import Parser
|
||||
import os
|
||||
from cStringIO import StringIO
|
||||
from io import StringIO
|
||||
from twisted.internet import reactor
|
||||
|
||||
from zope.interface import implements
|
||||
from zope.interface import implementer
|
||||
|
||||
PLUGIN_INFO = {
|
||||
C.PI_NAME: "IMAP server Plugin",
|
||||
|
|
@ -75,8 +75,8 @@ class IMAP_server(object):
|
|||
reactor.listenTCP(port, self.server_factory)
|
||||
|
||||
|
||||
@implementer(imap4.IMessage)
|
||||
class Message(object):
|
||||
implements(imap4.IMessage)
|
||||
|
||||
def __init__(self, uid, flags, mess_fp):
|
||||
log.debug("Message Init")
|
||||
|
|
@ -112,10 +112,10 @@ class Message(object):
|
|||
should be omitted from the return value, rather than included.
|
||||
@return: A mapping of header field names to header field values
|
||||
"""
|
||||
log.debug(u"getHeaders %s - %s" % (negate, names))
|
||||
log.debug("getHeaders %s - %s" % (negate, names))
|
||||
final_dict = {}
|
||||
to_check = [name.lower() for name in names]
|
||||
for header in self.message.keys():
|
||||
for header in list(self.message.keys()):
|
||||
if (negate and not header.lower() in to_check) or (
|
||||
not negate and header.lower() in to_check
|
||||
):
|
||||
|
|
@ -150,13 +150,13 @@ class Message(object):
|
|||
return TypeError
|
||||
|
||||
|
||||
@implementer(imap4.IMailbox)
|
||||
class SatMailbox(object):
|
||||
implements(imap4.IMailbox)
|
||||
|
||||
def __init__(self, host, name, profile):
|
||||
self.host = host
|
||||
self.listeners = set()
|
||||
log.debug(u"Mailbox init (%s)" % name)
|
||||
log.debug("Mailbox init (%s)" % name)
|
||||
if name != "INBOX":
|
||||
raise imap4.MailboxException("Only INBOX is managed for the moment")
|
||||
self.mailbox = self.host.plugins["Maildir"].accessMessageBox(
|
||||
|
|
@ -187,7 +187,7 @@ class SatMailbox(object):
|
|||
@param message: The message sequence number
|
||||
@return: The UID of the message.
|
||||
"""
|
||||
log.debug(u"getUID (%i)" % message)
|
||||
log.debug("getUID (%i)" % message)
|
||||
# return self.mailbox.getUid(message-1) #XXX: it seems that this method get uid and not message sequence number
|
||||
return message
|
||||
|
||||
|
|
@ -243,7 +243,7 @@ class SatMailbox(object):
|
|||
@param listener: An object to add to the set of those which will
|
||||
be notified when the contents of this mailbox change.
|
||||
"""
|
||||
log.debug(u"addListener %s" % listener)
|
||||
log.debug("addListener %s" % listener)
|
||||
self.listeners.add(listener)
|
||||
|
||||
def removeListener(self, listener):
|
||||
|
|
@ -288,7 +288,7 @@ class SatMailbox(object):
|
|||
about
|
||||
@param uid: If true, the IDs specified in the query are UIDs;
|
||||
"""
|
||||
log.debug(u"fetch (%s, %s)" % (messages, uid))
|
||||
log.debug("fetch (%s, %s)" % (messages, uid))
|
||||
if uid:
|
||||
messages.last = self.mailbox.getMaxUid()
|
||||
messages.getnext = self.mailbox.getNextExistingUid
|
||||
|
|
@ -412,20 +412,21 @@ class ImapSatAccount(imap4.MemoryAccount):
|
|||
return SatMailbox(self.host, name, self.profile)
|
||||
|
||||
|
||||
@implementer(portal.IRealm)
|
||||
class ImapRealm(object):
|
||||
implements(portal.IRealm)
|
||||
|
||||
def __init__(self, host):
|
||||
self.host = host
|
||||
|
||||
def requestAvatar(self, avatarID, mind, *interfaces):
|
||||
log.debug("requestAvatar")
|
||||
profile = avatarID.decode("utf-8")
|
||||
profile = avatarID
|
||||
if imap4.IAccount not in interfaces:
|
||||
raise NotImplementedError
|
||||
return imap4.IAccount, ImapSatAccount(self.host, profile), lambda: None
|
||||
|
||||
|
||||
@implementer(checkers.ICredentialsChecker)
|
||||
class SatProfileCredentialChecker(object):
|
||||
"""
|
||||
This credential checker check against SàT's profile and associated jabber's password
|
||||
|
|
@ -433,7 +434,6 @@ class SatProfileCredentialChecker(object):
|
|||
Return the profile as avatarId
|
||||
"""
|
||||
|
||||
implements(checkers.ICredentialsChecker)
|
||||
credentialInterfaces = (
|
||||
credentials.IUsernamePassword,
|
||||
credentials.IUsernameHashedPassword,
|
||||
|
|
@ -470,7 +470,7 @@ class ImapServerFactory(protocol.ServerFactory):
|
|||
log.debug(_("IMAP server connection started"))
|
||||
|
||||
def clientConnectionLost(self, connector, reason):
|
||||
log.debug(_(u"IMAP server connection lost (reason: %s)"), reason)
|
||||
log.debug(_("IMAP server connection lost (reason: %s)"), reason)
|
||||
|
||||
def buildProtocol(self, addr):
|
||||
log.debug("Building protocol")
|
||||
|
|
|
|||
Loading…
Reference in a new issue