summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/kolab_parse_telemetry.py5
-rwxr-xr-xbin/kolab_smtp_access_policy.py20
-rw-r--r--configure.ac2
-rw-r--r--cyruslib.py8
-rwxr-xr-xext/python/Tools/freeze/freeze.py2
-rw-r--r--pykolab/__init__.py3
-rw-r--r--pykolab/auth/ldap/__init__.py6
-rw-r--r--pykolab/auth/ldap/auth_cache.py62
-rw-r--r--pykolab/auth/ldap/syncrepl.py5
-rw-r--r--pykolab/cli/__init__.py8
-rw-r--r--pykolab/cli/cmd_acl_cleanup.py2
-rw-r--r--pykolab/cli/cmd_add_alias.py5
-rw-r--r--pykolab/cli/cmd_add_domain.py2
-rw-r--r--pykolab/cli/cmd_add_user.py2
-rw-r--r--pykolab/cli/cmd_add_user_subscription.py2
-rw-r--r--pykolab/cli/cmd_check_quota.py2
-rw-r--r--pykolab/cli/cmd_count_domain_mailboxes.py2
-rw-r--r--pykolab/cli/cmd_create_mailbox.py2
-rw-r--r--pykolab/cli/cmd_delete_domain.py2
-rw-r--r--pykolab/cli/cmd_delete_mailbox.py2
-rw-r--r--pykolab/cli/cmd_delete_mailbox_acl.py6
-rw-r--r--pykolab/cli/cmd_delete_message.py2
-rw-r--r--pykolab/cli/cmd_export_mailbox.py2
-rw-r--r--pykolab/cli/cmd_find_domain.py2
-rw-r--r--pykolab/cli/cmd_list_deleted_mailboxes.py2
-rw-r--r--pykolab/cli/cmd_list_domain_mailboxes.py2
-rw-r--r--pykolab/cli/cmd_list_domains.py2
-rw-r--r--pykolab/cli/cmd_list_mailbox_acls.py2
-rw-r--r--pykolab/cli/cmd_list_mailbox_metadata.py2
-rw-r--r--pykolab/cli/cmd_list_mailboxes.py2
-rw-r--r--pykolab/cli/cmd_list_messages.py2
-rw-r--r--pykolab/cli/cmd_list_ous.py2
-rw-r--r--pykolab/cli/cmd_list_quota.py2
-rw-r--r--pykolab/cli/cmd_list_user_subscriptions.py2
-rw-r--r--pykolab/cli/cmd_list_users.py2
-rw-r--r--pykolab/cli/cmd_mailbox_cleanup.py2
-rw-r--r--pykolab/cli/cmd_remove_mailaddress.py5
-rw-r--r--pykolab/cli/cmd_remove_user_subscription.py2
-rw-r--r--pykolab/cli/cmd_rename_mailbox.py2
-rw-r--r--pykolab/cli/cmd_server_info.py2
-rw-r--r--pykolab/cli/cmd_set_language.py2
-rw-r--r--pykolab/cli/cmd_set_mail.py2
-rw-r--r--pykolab/cli/cmd_set_mailbox_acl.py2
-rw-r--r--pykolab/cli/cmd_set_mailbox_metadata.py2
-rw-r--r--pykolab/cli/cmd_set_quota.py2
-rw-r--r--pykolab/cli/cmd_sync.py2
-rw-r--r--pykolab/cli/cmd_sync_mailhost_attrs.py2
-rw-r--r--pykolab/cli/cmd_transfer_mailbox.py2
-rw-r--r--pykolab/cli/cmd_undelete_mailbox.py2
-rw-r--r--pykolab/cli/cmd_user_info.py2
-rw-r--r--pykolab/cli/commands.py11
-rw-r--r--pykolab/cli/sieve/cmd_list.py5
-rw-r--r--pykolab/cli/sieve/cmd_put.py5
-rw-r--r--pykolab/cli/sieve/cmd_refresh.py8
-rw-r--r--pykolab/cli/sieve/cmd_test.py5
-rw-r--r--pykolab/conf/__init__.py11
-rw-r--r--pykolab/conf/entitlement.py5
-rw-r--r--pykolab/constants.py.in2
-rw-r--r--pykolab/imap/__init__.py30
-rw-r--r--pykolab/imap/cyrus.py5
-rw-r--r--pykolab/imap/dovecot.py5
-rw-r--r--pykolab/imap_utf7.py52
-rw-r--r--pykolab/logger.py4
-rw-r--r--pykolab/plugins/sievemgmt/__init__.py8
-rw-r--r--pykolab/setup/__init__.py2
-rw-r--r--pykolab/setup/components.py11
-rw-r--r--pykolab/setup/setup_freebusy.py12
-rw-r--r--pykolab/setup/setup_guam.py2
-rw-r--r--pykolab/setup/setup_imap.py2
-rw-r--r--pykolab/setup/setup_kolabd.py2
-rw-r--r--pykolab/setup/setup_ldap.py2
-rw-r--r--pykolab/setup/setup_manticore.py2
-rw-r--r--pykolab/setup/setup_mta.py7
-rw-r--r--pykolab/setup/setup_mysql.py2
-rw-r--r--pykolab/setup/setup_php.py2
-rw-r--r--pykolab/setup/setup_roundcube.py2
-rw-r--r--pykolab/setup/setup_syncroton.py2
-rw-r--r--pykolab/telemetry.py2
-rw-r--r--pykolab/wap_client/__init__.py10
-rw-r--r--pykolab/xml/__init__.py58
-rw-r--r--pykolab/xml/attendee.py2
-rw-r--r--pykolab/xml/contact.py6
-rw-r--r--pykolab/xml/event.py12
-rw-r--r--saslauthd/__init__.py14
-rwxr-xr-xtest-wallace.py9
-rw-r--r--tests/functional/test_wap_client/test_007_policy_uid.py5
-rw-r--r--wallace/__init__.py9
-rw-r--r--wallace/module_footer.py2
-rw-r--r--wallace/module_gpgencrypt.py6
-rw-r--r--wallace/module_invitationpolicy.py10
-rw-r--r--wallace/module_optout.py7
-rw-r--r--wallace/module_resources.py2
-rw-r--r--wallace/module_signature.py2
-rw-r--r--wallace/modules.py7
94 files changed, 364 insertions, 216 deletions
diff --git a/bin/kolab_parse_telemetry.py b/bin/kolab_parse_telemetry.py
index 4832f87..a02182a 100755
--- a/bin/kolab_parse_telemetry.py
+++ b/bin/kolab_parse_telemetry.py
@@ -25,7 +25,10 @@ import sys
import time
from optparse import OptionParser
-from ConfigParser import SafeConfigParser
+try:
+ from ConfigParser import SafeConfigParser
+except ImportError:
+ from configparser import SafeConfigParser
import sqlalchemy
from sqlalchemy import Boolean
diff --git a/bin/kolab_smtp_access_policy.py b/bin/kolab_smtp_access_policy.py
index 6c82165..4299c98 100755
--- a/bin/kolab_smtp_access_policy.py
+++ b/bin/kolab_smtp_access_policy.py
@@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from six import string_types
import datetime
import os
@@ -25,8 +26,11 @@ import sys
import time
from optparse import OptionParser
-from ConfigParser import SafeConfigParser
-
+try:
+ from ConfigParser import SafeConfigParser
+except ImportError:
+ from configparser import SafeConfigParser
+
from sqlalchemy import Boolean
from sqlalchemy import Column
from sqlalchemy import Date
@@ -263,7 +267,7 @@ class PolicyRequest(object):
for search_attr in search_attrs:
if search_attr in rule_subject:
- if isinstance(rule_subject[search_attr], basestring):
+ if isinstance(rule_subject[search_attr], string_types):
values.append(rule_subject[search_attr])
else:
values.extend(rule_subject[search_attr])
@@ -325,7 +329,7 @@ class PolicyRequest(object):
rules = {'allow': [], 'deny': []}
- if isinstance(policy, basestring):
+ if isinstance(policy, string_types):
policy = [policy]
for rule in policy:
@@ -510,7 +514,7 @@ class PolicyRequest(object):
return False
else:
self.sasl_user = {'dn': sasl_users[0]}
- elif isinstance(sasl_users, basestring):
+ elif isinstance(sasl_users, string_types):
self.sasl_user = {'dn': sasl_users}
if not self.sasl_user['dn']:
@@ -613,7 +617,7 @@ class PolicyRequest(object):
else:
self.sender_user = {'dn': False}
- elif isinstance(sender_users, basestring):
+ elif isinstance(sender_users, string_types):
self.sender_user = {'dn': sender_users}
if not self.sender_user['dn']:
@@ -708,7 +712,7 @@ class PolicyRequest(object):
return False
else:
self.sasl_user = {'dn': sasl_users[0]}
- elif isinstance(sasl_users, basestring):
+ elif isinstance(sasl_users, string_types):
self.sasl_user = {'dn': sasl_users}
# Possible values for the kolabDelegate attribute are:
@@ -889,7 +893,7 @@ class PolicyRequest(object):
return True
- elif isinstance(recipients, basestring):
+ elif isinstance(recipients, string_types):
_recipient = {'dn': recipients}
# We have gotten an invalid recipient. We need to catch this case,
diff --git a/configure.ac b/configure.ac
index 471763d..8d10eb8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,4 +1,4 @@
-AC_INIT([pykolab], 0.8.19)
+AC_INIT([pykolab], 0.8.23)
AC_SUBST([RELEASE], 1)
AC_CONFIG_SRCDIR(pykolab/constants.py.in)
diff --git a/cyruslib.py b/cyruslib.py
index a8f6a61..b2a7dcc 100644
--- a/cyruslib.py
+++ b/cyruslib.py
@@ -37,7 +37,7 @@ try:
import imaplib
import re
from binascii import b2a_base64
-except ImportError, e:
+except ImportError as e:
print(e)
exit(1)
@@ -590,6 +590,12 @@ class CYRUS:
res, msg = self.__docommand("setacl", self.decode(mailbox), userid, rights)
self.__verbose( '[SETACL %s %s %s] %s: %s' % (mailbox, userid, rights, res, msg[0]) )
+ def dam(self, mailbox, userid):
+ """Delete ACL (remove any rights) set for userid on mailbox"""
+ self.__prepare('DELETEACL', mailbox)
+ res, msg = self.__docommand("deleteacl", self.decode(mailbox), userid)
+ self.__verbose( '[DELETEACL %s %s] %s: %s' % (mailbox, userid, res, msg[0]) )
+
def lq(self, mailbox):
"""List Quota"""
self.__prepare('GETQUOTA', mailbox)
diff --git a/ext/python/Tools/freeze/freeze.py b/ext/python/Tools/freeze/freeze.py
index 6f74ca2..e584de6 100755
--- a/ext/python/Tools/freeze/freeze.py
+++ b/ext/python/Tools/freeze/freeze.py
@@ -317,7 +317,7 @@ def main():
try:
os.mkdir(odir)
print("Created output directory", odir)
- except os.error, msg:
+ except os.error as msg:
usage('%s: mkdir failed (%s)' % (odir, str(msg)))
base = ''
if odir:
diff --git a/pykolab/__init__.py b/pykolab/__init__.py
index 09e3267..fdbc3a6 100644
--- a/pykolab/__init__.py
+++ b/pykolab/__init__.py
@@ -52,4 +52,5 @@ def getConf():
return conf
-import base
+from . import base
+
diff --git a/pykolab/auth/ldap/__init__.py b/pykolab/auth/ldap/__init__.py
index a2edf12..2b3e56a 100644
--- a/pykolab/auth/ldap/__init__.py
+++ b/pykolab/auth/ldap/__init__.py
@@ -48,8 +48,8 @@ from pykolab.constants import SUPPORTED_LDAP_CONTROLS
from pykolab.errors import *
from pykolab.translate import _ as _l
-import auth_cache
-import cache
+from . import auth_cache
+from . import cache
# pylint: disable=invalid-name
log = pykolab.getLogger('pykolab.auth')
@@ -3038,7 +3038,7 @@ class LDAP(Base):
):
import ldapurl
- import syncrepl
+ from . import syncrepl
ldap_url = ldapurl.LDAPUrl(self.config_get('ldap_uri'))
diff --git a/pykolab/auth/ldap/auth_cache.py b/pykolab/auth/ldap/auth_cache.py
index f32779c..717d079 100644
--- a/pykolab/auth/ldap/auth_cache.py
+++ b/pykolab/auth/ldap/auth_cache.py
@@ -17,6 +17,7 @@
#
import datetime
+import os
import sqlalchemy
@@ -24,8 +25,8 @@ from sqlalchemy import Column
from sqlalchemy import DateTime
from sqlalchemy import Integer
from sqlalchemy import MetaData
-from sqlalchemy import String
-from sqlalchemy import Text
+from sqlalchemy import Unicode
+from sqlalchemy import UnicodeText
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
@@ -61,9 +62,9 @@ class Entry(DeclarativeBase):
__tablename__ = 'entries'
id = Column(Integer, primary_key=True)
- domain = Column(String(256), index=True, nullable=True)
- key = Column(Text, index=True, nullable=False)
- value = Column(Text, nullable=False)
+ domain = Column(Unicode(256), index=True, nullable=True)
+ key = Column(UnicodeText, index=True, nullable=False)
+ value = Column(UnicodeText, nullable=False)
last_change = Column(DateTime, nullable=False, default=datetime.datetime.now())
def __init__(self, key, value):
@@ -84,6 +85,11 @@ def del_entry(key):
db = init_db()
+ if db is None:
+ return
+
+ purge_entries()
+
try:
db.query(Entry).filter_by(key=key).delete()
except sqlalchemy.exc.OperationalError:
@@ -102,6 +108,9 @@ def get_entry(key):
db = init_db()
+ if db is None:
+ return None
+
try:
_entries = db.query(Entry).filter_by(key=key).all()
except sqlalchemy.exc.OperationalError:
@@ -111,18 +120,32 @@ def get_entry(key):
finally:
_entries = db.query(Entry).filter_by(key=key).all()
- if len(_entries) != 1:
+ __entries = []
+
+ for __entry in _entries:
+ if __entry.last_change <= datetime.datetime.now() - datetime.timedelta(0, 7200):
+ continue
+
+ __entries.append(__entry)
+
+ if len(__entries) != 1:
return None
- log.debug("Entry found: %r" % (_entries[0].__dict__))
- log.debug("Returning: %r" % (_entries[0].value))
+ log.debug("Entry found: %r" % (__entries[0].__dict__))
+ log.debug("Returning: %r" % (__entries[0].value))
- return _entries[0].value.encode('utf-8', 'latin1')
+ return __entries[0].value
def set_entry(key, value):
+ # pylint: disable=global-statement
+ global db
+
db = init_db()
+ if db is None:
+ return
+
try:
_entries = db.query(Entry).filter_by(key=key).all()
except sqlalchemy.exc.OperationalError:
@@ -147,12 +170,18 @@ def set_entry(key, value):
db.commit()
-def purge_entries(db):
- db.query(Entry).filter(
- Entry.last_change <= (datetime.datetime.now() - datetime.timedelta(1))
- ).delete()
+def purge_entries():
+ # pylint: disable=global-statement
+ global db
- db.commit()
+ try:
+ db.query(Entry).filter(
+ Entry.last_change <= (datetime.datetime.now() - datetime.timedelta(0, 7200))
+ ).delete()
+
+ db.commit()
+ except Exception:
+ return
def init_db(reinit=False):
@@ -167,11 +196,13 @@ def init_db(reinit=False):
db_uri = conf.get('ldap', 'auth_cache_uri')
+ if db_uri == "null":
+ return None
+
if db_uri is None:
db_uri = 'sqlite:///%s/auth_cache.db' % (KOLAB_LIB_PATH)
if reinit:
- import os
if os.path.isfile('%s/auth_cache.db' % (KOLAB_LIB_PATH)):
os.unlink('%s/auth_cache.db' % (KOLAB_LIB_PATH))
@@ -181,6 +212,5 @@ def init_db(reinit=False):
Session = sessionmaker(bind=engine)
db = Session()
- purge_entries(db)
return db
diff --git a/pykolab/auth/ldap/syncrepl.py b/pykolab/auth/ldap/syncrepl.py
index 6753605..98c2e11 100644
--- a/pykolab/auth/ldap/syncrepl.py
+++ b/pykolab/auth/ldap/syncrepl.py
@@ -1,6 +1,9 @@
#!/usr/bin/python
-import anydbm
+try:
+ import anydbm
+except:
+ import dbm.ndbm as anydbm
import ldap
import ldap.syncrepl
import ldapurl
diff --git a/pykolab/cli/__init__.py b/pykolab/cli/__init__.py
index 46c9930..2b3c511 100644
--- a/pykolab/cli/__init__.py
+++ b/pykolab/cli/__init__.py
@@ -16,7 +16,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-
+try:
+ # Python 2: "reload" is built-in
+ reload
+except NameError:
+ from importlib import reload
import ldap
import ldif
import logging
@@ -42,7 +46,7 @@ conf = pykolab.getConf()
class Cli(object):
def __init__(self):
- import commands
+ from . import commands
commands.__init__()
to_execute = []
diff --git a/pykolab/cli/cmd_acl_cleanup.py b/pykolab/cli/cmd_acl_cleanup.py
index 2d6bd6e..54cfd38 100644
--- a/pykolab/cli/cmd_acl_cleanup.py
+++ b/pykolab/cli/cmd_acl_cleanup.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_add_alias.py b/pykolab/cli/cmd_add_alias.py
index 16fa590..8f90032 100644
--- a/pykolab/cli/cmd_add_alias.py
+++ b/pykolab/cli/cmd_add_alias.py
@@ -18,10 +18,11 @@
#
from __future__ import print_function
+from six import string_types
import sys
-import commands
+from . import commands
import pykolab
@@ -110,7 +111,7 @@ def execute(*args, **kw):
if secondary_rcpt_attr not in primary_recipient:
auth.set_entry_attributes(primary_rcpt_domain, primary_recipient_dn, {secondary_rcpt_attr: [ secondary_rcpt_address ] })
else:
- if isinstance(primary_recipient[secondary_rcpt_attr], basestring):
+ if isinstance(primary_recipient[secondary_rcpt_attr], string_types):
new_secondary_rcpt_attrs = [
primary_recipient[secondary_rcpt_attr],
secondary_rcpt_address
diff --git a/pykolab/cli/cmd_add_domain.py b/pykolab/cli/cmd_add_domain.py
index fecd82a..8034281 100644
--- a/pykolab/cli/cmd_add_domain.py
+++ b/pykolab/cli/cmd_add_domain.py
@@ -19,7 +19,7 @@
import sys
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_add_user.py b/pykolab/cli/cmd_add_user.py
index 09cc08c..b01b9ad 100644
--- a/pykolab/cli/cmd_add_user.py
+++ b/pykolab/cli/cmd_add_user.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_add_user_subscription.py b/pykolab/cli/cmd_add_user_subscription.py
index 06ac0e2..50ba9af 100644
--- a/pykolab/cli/cmd_add_user_subscription.py
+++ b/pykolab/cli/cmd_add_user_subscription.py
@@ -21,7 +21,7 @@ from __future__ import print_function
import sys
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_check_quota.py b/pykolab/cli/cmd_check_quota.py
index cae5077..c102735 100644
--- a/pykolab/cli/cmd_check_quota.py
+++ b/pykolab/cli/cmd_check_quota.py
@@ -21,7 +21,7 @@ from __future__ import print_function
import sys
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_count_domain_mailboxes.py b/pykolab/cli/cmd_count_domain_mailboxes.py
index 47bbcb1..0559bcc 100644
--- a/pykolab/cli/cmd_count_domain_mailboxes.py
+++ b/pykolab/cli/cmd_count_domain_mailboxes.py
@@ -19,7 +19,7 @@
import datetime
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_create_mailbox.py b/pykolab/cli/cmd_create_mailbox.py
index 9e91800..4da5c47 100644
--- a/pykolab/cli/cmd_create_mailbox.py
+++ b/pykolab/cli/cmd_create_mailbox.py
@@ -19,7 +19,7 @@
import sys
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_delete_domain.py b/pykolab/cli/cmd_delete_domain.py
index 60ca55b..28bbcaf 100644
--- a/pykolab/cli/cmd_delete_domain.py
+++ b/pykolab/cli/cmd_delete_domain.py
@@ -19,7 +19,7 @@
import sys
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_delete_mailbox.py b/pykolab/cli/cmd_delete_mailbox.py
index 40f8b44..66ec534 100644
--- a/pykolab/cli/cmd_delete_mailbox.py
+++ b/pykolab/cli/cmd_delete_mailbox.py
@@ -21,7 +21,7 @@ from __future__ import print_function
import sys
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_delete_mailbox_acl.py b/pykolab/cli/cmd_delete_mailbox_acl.py
index d146aac..e4c1d62 100644
--- a/pykolab/cli/cmd_delete_mailbox_acl.py
+++ b/pykolab/cli/cmd_delete_mailbox_acl.py
@@ -21,7 +21,7 @@ from __future__ import print_function
import sys
-import commands
+from . import commands
import pykolab
@@ -48,7 +48,7 @@ def execute(*args, **kw):
except IndexError:
folder = utils.ask_question(_("Folder name"))
- quota = utils.ask_question(_("ACI Subject"))
+ identifier = utils.ask_question(_("ACI Subject"))
if len(folder.split('@')) > 1:
domain = folder.split('@')[1]
@@ -65,7 +65,7 @@ def execute(*args, **kw):
folders = imap.list_folders(folder)
for folder in folders:
try:
- imap.set_acl(folder, identifier, '')
+ imap.del_acl(folder, identifier)
except:
# Mailbox no longer exists?
pass
diff --git a/pykolab/cli/cmd_delete_message.py b/pykolab/cli/cmd_delete_message.py
index 5c7c242..5f68ee8 100644
--- a/pykolab/cli/cmd_delete_message.py
+++ b/pykolab/cli/cmd_delete_message.py
@@ -19,7 +19,7 @@
import sys
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_export_mailbox.py b/pykolab/cli/cmd_export_mailbox.py
index 78d55f1..f37c7b2 100644
--- a/pykolab/cli/cmd_export_mailbox.py
+++ b/pykolab/cli/cmd_export_mailbox.py
@@ -19,7 +19,7 @@
from __future__ import print_function
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_find_domain.py b/pykolab/cli/cmd_find_domain.py
index f65af3f..64dc2de 100644
--- a/pykolab/cli/cmd_find_domain.py
+++ b/pykolab/cli/cmd_find_domain.py
@@ -19,7 +19,7 @@
import sys
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_list_deleted_mailboxes.py b/pykolab/cli/cmd_list_deleted_mailboxes.py
index 55b6b9f..6596142 100644
--- a/pykolab/cli/cmd_list_deleted_mailboxes.py
+++ b/pykolab/cli/cmd_list_deleted_mailboxes.py
@@ -19,7 +19,7 @@
import datetime
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_list_domain_mailboxes.py b/pykolab/cli/cmd_list_domain_mailboxes.py
index fd9a7fd..602fc5d 100644
--- a/pykolab/cli/cmd_list_domain_mailboxes.py
+++ b/pykolab/cli/cmd_list_domain_mailboxes.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_list_domains.py b/pykolab/cli/cmd_list_domains.py
index e76edca..d72ed71 100644
--- a/pykolab/cli/cmd_list_domains.py
+++ b/pykolab/cli/cmd_list_domains.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_list_mailbox_acls.py b/pykolab/cli/cmd_list_mailbox_acls.py
index dc86e47..d4f76d5 100644
--- a/pykolab/cli/cmd_list_mailbox_acls.py
+++ b/pykolab/cli/cmd_list_mailbox_acls.py
@@ -21,7 +21,7 @@ from __future__ import print_function
import sys
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_list_mailbox_metadata.py b/pykolab/cli/cmd_list_mailbox_metadata.py
index 27d881c..7734770 100644
--- a/pykolab/cli/cmd_list_mailbox_metadata.py
+++ b/pykolab/cli/cmd_list_mailbox_metadata.py
@@ -21,7 +21,7 @@ from __future__ import print_function
import sys
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_list_mailboxes.py b/pykolab/cli/cmd_list_mailboxes.py
index 738cd86..3cb7f03 100644
--- a/pykolab/cli/cmd_list_mailboxes.py
+++ b/pykolab/cli/cmd_list_mailboxes.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_list_messages.py b/pykolab/cli/cmd_list_messages.py
index 786a5f0..af2c447 100644
--- a/pykolab/cli/cmd_list_messages.py
+++ b/pykolab/cli/cmd_list_messages.py
@@ -19,7 +19,7 @@
import sys
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_list_ous.py b/pykolab/cli/cmd_list_ous.py
index 61a4cb9..46b991f 100644
--- a/pykolab/cli/cmd_list_ous.py
+++ b/pykolab/cli/cmd_list_ous.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_list_quota.py b/pykolab/cli/cmd_list_quota.py
index d956168..7dd6b9d 100644
--- a/pykolab/cli/cmd_list_quota.py
+++ b/pykolab/cli/cmd_list_quota.py
@@ -21,7 +21,7 @@ from __future__ import print_function
import sys
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_list_user_subscriptions.py b/pykolab/cli/cmd_list_user_subscriptions.py
index ad6e549..3d90812 100644
--- a/pykolab/cli/cmd_list_user_subscriptions.py
+++ b/pykolab/cli/cmd_list_user_subscriptions.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_list_users.py b/pykolab/cli/cmd_list_users.py
index a17eeba..bb5506e 100644
--- a/pykolab/cli/cmd_list_users.py
+++ b/pykolab/cli/cmd_list_users.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_mailbox_cleanup.py b/pykolab/cli/cmd_mailbox_cleanup.py
index 656a978..ccc964d 100644
--- a/pykolab/cli/cmd_mailbox_cleanup.py
+++ b/pykolab/cli/cmd_mailbox_cleanup.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_remove_mailaddress.py b/pykolab/cli/cmd_remove_mailaddress.py
index 10d9a19..cfc4f89 100644
--- a/pykolab/cli/cmd_remove_mailaddress.py
+++ b/pykolab/cli/cmd_remove_mailaddress.py
@@ -18,10 +18,11 @@
#
from __future__ import print_function
+from six import string_types
import sys
-import commands
+from . import commands
import pykolab
@@ -67,7 +68,7 @@ def execute(*args, **kw):
log.debug(_("Using the following mail attributes: %r") % (mail_attributes), level=8)
- if isinstance(recipients, basestring):
+ if isinstance(recipients, string_types):
recipient = recipients
# Only a single recipient found, remove the address
diff --git a/pykolab/cli/cmd_remove_user_subscription.py b/pykolab/cli/cmd_remove_user_subscription.py
index b16249c..208ff4a 100644
--- a/pykolab/cli/cmd_remove_user_subscription.py
+++ b/pykolab/cli/cmd_remove_user_subscription.py
@@ -21,7 +21,7 @@ from __future__ import print_function
import sys
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_rename_mailbox.py b/pykolab/cli/cmd_rename_mailbox.py
index 4373acf..b46c79d 100644
--- a/pykolab/cli/cmd_rename_mailbox.py
+++ b/pykolab/cli/cmd_rename_mailbox.py
@@ -21,7 +21,7 @@ from __future__ import print_function
import sys
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_server_info.py b/pykolab/cli/cmd_server_info.py
index 0ae0c0e..f0f867a 100644
--- a/pykolab/cli/cmd_server_info.py
+++ b/pykolab/cli/cmd_server_info.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_set_language.py b/pykolab/cli/cmd_set_language.py
index 83b5d95..df575c5 100644
--- a/pykolab/cli/cmd_set_language.py
+++ b/pykolab/cli/cmd_set_language.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_set_mail.py b/pykolab/cli/cmd_set_mail.py
index 0b457cb..97512fd 100644
--- a/pykolab/cli/cmd_set_mail.py
+++ b/pykolab/cli/cmd_set_mail.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_set_mailbox_acl.py b/pykolab/cli/cmd_set_mailbox_acl.py
index 63b5c2d..a18c48b 100644
--- a/pykolab/cli/cmd_set_mailbox_acl.py
+++ b/pykolab/cli/cmd_set_mailbox_acl.py
@@ -21,7 +21,7 @@ from __future__ import print_function
import sys
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_set_mailbox_metadata.py b/pykolab/cli/cmd_set_mailbox_metadata.py
index 91aec50..339b664 100644
--- a/pykolab/cli/cmd_set_mailbox_metadata.py
+++ b/pykolab/cli/cmd_set_mailbox_metadata.py
@@ -21,7 +21,7 @@ from __future__ import print_function
import sys
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_set_quota.py b/pykolab/cli/cmd_set_quota.py
index b6c89c1..3692f10 100644
--- a/pykolab/cli/cmd_set_quota.py
+++ b/pykolab/cli/cmd_set_quota.py
@@ -21,7 +21,7 @@ from __future__ import print_function
import sys
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_sync.py b/pykolab/cli/cmd_sync.py
index 2aaf9df..85952cb 100644
--- a/pykolab/cli/cmd_sync.py
+++ b/pykolab/cli/cmd_sync.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
from distutils import version
import multiprocessing
diff --git a/pykolab/cli/cmd_sync_mailhost_attrs.py b/pykolab/cli/cmd_sync_mailhost_attrs.py
index 4d9663f..a3e200f 100644
--- a/pykolab/cli/cmd_sync_mailhost_attrs.py
+++ b/pykolab/cli/cmd_sync_mailhost_attrs.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_transfer_mailbox.py b/pykolab/cli/cmd_transfer_mailbox.py
index 1593eea..071eda4 100644
--- a/pykolab/cli/cmd_transfer_mailbox.py
+++ b/pykolab/cli/cmd_transfer_mailbox.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_undelete_mailbox.py b/pykolab/cli/cmd_undelete_mailbox.py
index 5b74a64..35b7a2f 100644
--- a/pykolab/cli/cmd_undelete_mailbox.py
+++ b/pykolab/cli/cmd_undelete_mailbox.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/cmd_user_info.py b/pykolab/cli/cmd_user_info.py
index beaeb40..eb7dfcb 100644
--- a/pykolab/cli/cmd_user_info.py
+++ b/pykolab/cli/cmd_user_info.py
@@ -21,7 +21,7 @@ from __future__ import print_function
import sys
-import commands
+from . import commands
import pykolab
diff --git a/pykolab/cli/commands.py b/pykolab/cli/commands.py
index a1e9b0c..072c346 100644
--- a/pykolab/cli/commands.py
+++ b/pykolab/cli/commands.py
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from six import string_types
import os
import sys
@@ -44,7 +45,7 @@ def __init__():
cmd_name = module_name.replace('cmd_', '')
#print "exec(\"from %s import __init__ as %s_register\"" % (module_name,cmd_name)
try:
- exec("from %s import __init__ as %s_register" % (module_name,cmd_name))
+ exec("from .%s import __init__ as %s_register" % (module_name,cmd_name))
except ImportError:
pass
@@ -121,7 +122,7 @@ def execute(cmd_name, *args, **kw):
group = commands[cmd_name]['group']
command_name = commands[cmd_name]['cmd_name']
try:
- exec("from %s.cmd_%s import cli_options as %s_%s_cli_options" % (group,command_name,group,command_name))
+ exec("from .%s.cmd_%s import cli_options as %s_%s_cli_options" % (group,command_name,group,command_name))
exec("%s_%s_cli_options()" % (group,command_name))
except ImportError:
pass
@@ -129,7 +130,7 @@ def execute(cmd_name, *args, **kw):
else:
command_name = commands[cmd_name]['cmd_name']
try:
- exec("from cmd_%s import cli_options as %s_cli_options" % (command_name,command_name))
+ exec("from .cmd_%s import cli_options as %s_cli_options" % (command_name,command_name))
exec("%s_cli_options()" % (command_name))
except ImportError:
pass
@@ -151,7 +152,7 @@ def register_group(dirname, module):
module_name = filename.replace('.py','')
cmd_name = module_name.replace('cmd_', '')
#print "exec(\"from %s.%s import __init__ as %s_%s_register\"" % (module,module_name,module,cmd_name)
- exec("from %s.%s import __init__ as %s_%s_register" % (module,module_name,module,cmd_name))
+ exec("from .%s.%s import __init__ as %s_%s_register" % (module,module_name,module,cmd_name))
exec("%s_%s_register()" % (module,cmd_name))
def register(cmd_name, func, group=None, description=None, aliases=[]):
@@ -160,7 +161,7 @@ def register(cmd_name, func, group=None, description=None, aliases=[]):
else:
command = cmd_name
- if isinstance(aliases, basestring):
+ if isinstance(aliases, string_types):
aliases = [aliases]
if command in commands:
diff --git a/pykolab/cli/sieve/cmd_list.py b/pykolab/cli/sieve/cmd_list.py
index 20c967a..0ed7434 100644
--- a/pykolab/cli/sieve/cmd_list.py
+++ b/pykolab/cli/sieve/cmd_list.py
@@ -19,7 +19,10 @@
import sys
import time
-from urlparse import urlparse
+try:
+ from urlparse import urlparse
+except ImportError:
+ from urllib.parse import urlparse
import pykolab
diff --git a/pykolab/cli/sieve/cmd_put.py b/pykolab/cli/sieve/cmd_put.py
index 7286370..5ab937f 100644
--- a/pykolab/cli/sieve/cmd_put.py
+++ b/pykolab/cli/sieve/cmd_put.py
@@ -27,7 +27,10 @@ log = pykolab.getLogger('pykolab.cli')
conf = pykolab.getConf()
import time
-from urlparse import urlparse
+try:
+ from urlparse import urlparse
+except ImportError:
+ from urllib.parse import urlparse
def __init__():
commands.register('put', execute, group='sieve', description=description())
diff --git a/pykolab/cli/sieve/cmd_refresh.py b/pykolab/cli/sieve/cmd_refresh.py
index 0f93208..abb93ae 100644
--- a/pykolab/cli/sieve/cmd_refresh.py
+++ b/pykolab/cli/sieve/cmd_refresh.py
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from six import string_types
import pykolab
@@ -29,7 +30,10 @@ conf = pykolab.getConf()
import sys
import time
-from urlparse import urlparse
+try:
+ from urlparse import urlparse
+except ImportError:
+ from urllib.parse import urlparse
def __init__():
commands.register('refresh', execute, group='sieve', description=description())
@@ -212,7 +216,7 @@ def execute(*args, **kw):
if not forward_active == False:
forward_address_attr = conf.get('sieve', 'forward_address_attr')
if forward_address_attr in user:
- if isinstance(user[forward_address_attr], basestring):
+ if isinstance(user[forward_address_attr], string_types):
forward_addresses = [ user[forward_address_attr] ]
elif isinstance(user[forward_address_attr], str):
forward_addresses = [ user[forward_address_attr] ]
diff --git a/pykolab/cli/sieve/cmd_test.py b/pykolab/cli/sieve/cmd_test.py
index 7906570..0b7bdeb 100644
--- a/pykolab/cli/sieve/cmd_test.py
+++ b/pykolab/cli/sieve/cmd_test.py
@@ -27,7 +27,10 @@ log = pykolab.getLogger('pykolab.cli')
conf = pykolab.getConf()
import time
-from urlparse import urlparse
+try:
+ from urlparse import urlparse
+except ImportError:
+ from urllib.parse import urlparse
def __init__():
diff --git a/pykolab/conf/__init__.py b/pykolab/conf/__init__.py
index 6de3c8e..ca19ac9 100644
--- a/pykolab/conf/__init__.py
+++ b/pykolab/conf/__init__.py
@@ -23,7 +23,10 @@ import os
import sys
from optparse import OptionParser
-from ConfigParser import SafeConfigParser
+try:
+ from ConfigParser import SafeConfigParser
+except ImportError:
+ from configparser import SafeConfigParser
import pykolab
@@ -106,8 +109,8 @@ class Conf(object):
for option in self.cli_keywords.__dict__:
retval = False
if hasattr(self, "check_setting_%s" % (option)):
- exec(
- "retval = self.check_setting_%s(%r)" % (
+ retval = eval(
+ "self.check_setting_%s(%r)" % (
option,
self.cli_keywords.__dict__[option]
)
@@ -596,7 +599,7 @@ class Conf(object):
self.read_config()
if self.cfg_parser.has_option(section, key):
- return self.cfg_parser.get(section, key, 1)
+ return self.cfg_parser.get(section, key, raw=1)
return default
diff --git a/pykolab/conf/entitlement.py b/pykolab/conf/entitlement.py
index 3dd92d6..ac2b169 100644
--- a/pykolab/conf/entitlement.py
+++ b/pykolab/conf/entitlement.py
@@ -17,7 +17,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-from ConfigParser import ConfigParser
+try:
+ from ConfigParser import ConfigParser
+except ImportError:
+ from configparser import ConfigParser
import hashlib
import OpenSSL
import os
diff --git a/pykolab/constants.py.in b/pykolab/constants.py.in
index 0cd1f6d..b99c433 100644
--- a/pykolab/constants.py.in
+++ b/pykolab/constants.py.in
@@ -17,6 +17,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from __future__ import print_function
+
import math
import socket
import sys
diff --git a/pykolab/imap/__init__.py b/pykolab/imap/__init__.py
index 58ef755..a773bfc 100644
--- a/pykolab/imap/__init__.py
+++ b/pykolab/imap/__init__.py
@@ -16,7 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-
+from six import string_types
import logging
import re
@@ -24,7 +24,10 @@ import time
import socket
import sys
-from urlparse import urlparse
+try:
+ from urlparse import urlparse
+except ImportError:
+ from urllib.parse import urlparse
import pykolab
from pykolab import utils
@@ -175,7 +178,7 @@ class IMAP(object):
if hostname not in self._imap:
if backend == 'cyrus-imap':
- import cyrus
+ from . import cyrus
self._imap[hostname] = cyrus.Cyrus(uri)
# Actually connect
if login:
@@ -184,7 +187,7 @@ class IMAP(object):
self._imap[hostname].logged_in = True
elif backend == 'dovecot':
- import dovecot
+ from . import dovecot
self._imap[hostname] = dovecot.Dovecot(uri)
# Actually connect
if login:
@@ -240,17 +243,14 @@ class IMAP(object):
if server is None:
# No server specified, but make sure self.imap is None anyways
if hasattr(self, 'imap'):
- self.imap.disconnect()
del self.imap
# Empty out self._imap as well
- for key in self._imap:
- self._imap[key].disconnect()
+ for key in list(self._imap):
del self._imap[key]
else:
if server in self._imap:
- self._imap[server].disconnect()
del self._imap[server]
else:
log.warning(
@@ -435,6 +435,18 @@ class IMAP(object):
)
)
+ def del_acl(self, folder, identifier):
+ try:
+ self.imap.dam(self.folder_utf7(folder), identifier)
+ except Exception as errmsg:
+ log.error(
+ _("Could not delete ACL for %s on folder %s: %r") % (
+ identifier,
+ folder,
+ errmsg
+ )
+ )
+
def set_metadata(self, folder, metadata_path, metadata_value, shared=True):
"""
Set a metadata entry on a folder
@@ -906,7 +918,7 @@ class IMAP(object):
return
- if isinstance(acls, basestring):
+ if isinstance(acls, string_types):
acls = [ acls ]
old_acls = None
diff --git a/pykolab/imap/cyrus.py b/pykolab/imap/cyrus.py
index 765b0ee..91df698 100644
--- a/pykolab/imap/cyrus.py
+++ b/pykolab/imap/cyrus.py
@@ -23,7 +23,10 @@ import cyruslib
import sys
import time
-from urlparse import urlparse
+try:
+ from urlparse import urlparse
+except ImportError:
+ from urllib.parse import urlparse
import pykolab
diff --git a/pykolab/imap/dovecot.py b/pykolab/imap/dovecot.py
index eb854ab..869ab5b 100644
--- a/pykolab/imap/dovecot.py
+++ b/pykolab/imap/dovecot.py
@@ -44,7 +44,10 @@ import imaplib
import sys
import time
-from urlparse import urlparse
+try:
+ from urlparse import urlparse
+except ImportError:
+ from urllib.parse import urlparse
import pykolab
diff --git a/pykolab/imap_utf7.py b/pykolab/imap_utf7.py
index 0ecb83c..152609c 100644
--- a/pykolab/imap_utf7.py
+++ b/pykolab/imap_utf7.py
@@ -22,58 +22,70 @@
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+# https://twistedmatrix.com/trac/attachment/ticket/6289/imap4.patch
+# #6289 enhancement closed fixed (fixed)
+# Port imap4-utf-7 codec implementation to Python 3
class FolderNameError(ValueError):
pass
+try:
+ unicode()
+except:
+ unicode = str
+
+memory_cast = getattr(memoryview, "cast", lambda *x: x[0])
+
def encode(s):
if isinstance(s, str) and sum(n for n in (ord(c) for c in s) if n > 127):
try:
- s = unicode(s, "UTF-8")
+ s = bytes(s, "UTF-8")
except Exception:
raise FolderNameError("%r contains characters not valid in a str folder name. "
- "Convert to unicode first?" % s)
+ "Convert to unicode first?" % s)
- r = []
+ r = bytearray()
_in = []
+ valid_chars = set(map(chr, range(0x20, 0x7f))) - {u"&"}
for c in s:
- if ord(c) in (range(0x20, 0x26) + range(0x27, 0x7f)):
+ if c in valid_chars:
if _in:
- r.extend(['&', modified_base64(''.join(_in)), '-'])
+ r += b'&' + modified_base64(''.join(_in)) + b'-'
del _in[:]
- r.append(str(c))
- elif c == '&':
+ r.append(ord(c))
+ elif c == u'&':
if _in:
- r.extend(['&', modified_base64(''.join(_in)), '-'])
+ r += b'&' + modified_base64(''.join(_in)) + b'-'
del _in[:]
- r.append('&-')
+ r += b'&-'
else:
_in.append(c)
if _in:
- r.extend(['&', modified_base64(''.join(_in)), '-'])
+ r.extend(b'&' + modified_base64(''.join(_in)) + b'-')
- return ''.join(r)
+ return bytes(r)
def decode(s):
r = []
decode = []
+ s = memory_cast(memoryview(s), 'c')
for c in s:
- if c == '&' and not decode:
- decode.append('&')
- elif c == '-' and decode:
+ if c == b'&' and not decode:
+ decode.append(u'&')
+ elif c == b'-' and decode:
if len(decode) == 1:
- r.append('&')
+ r.append(u'&')
else:
- r.append(modified_unbase64(''.join(decode[1:])))
+ r.append(modified_unbase64(b''.join(decode[1:])))
decode = []
elif decode:
decode.append(c)
else:
- r.append(c)
+ r.append(c.decode())
if decode:
- r.append(modified_unbase64(''.join(decode[1:])))
+ r.append(modified_unbase64(b''.join(decode[1:])))
out = ''.join(r)
if not isinstance(out, unicode):
@@ -83,9 +95,9 @@ def decode(s):
def modified_base64(s):
s_utf7 = s.encode('utf-7')
- return s_utf7[1:-1].replace('/', ',')
+ return s_utf7[1:-1].replace(b'/', b',')
def modified_unbase64(s):
- s_utf7 = '+' + s.replace(',', '/') + '-'
+ s_utf7 = b'+' + s.replace(b',', b'/') + b'-'
return s_utf7.decode('utf-7')
diff --git a/pykolab/logger.py b/pykolab/logger.py
index 8e9c9b6..ab41c94 100644
--- a/pykolab/logger.py
+++ b/pykolab/logger.py
@@ -216,7 +216,7 @@ class Logger(logging.Logger):
os.chmod(self.logfile, 0o660)
except Exception as errmsg:
- self.error(
+ print(
_("Could not change permissions on %s: %r") % (self.logfile, errmsg)
)
@@ -226,7 +226,7 @@ class Logger(logging.Logger):
except Exception as errmsg:
if os.path.isfile(self.logfile):
- self.error(_("Could not change permissions on %s: %r") % (self.logfile, errmsg))
+ print(_("Could not change permissions on %s: %r") % (self.logfile, errmsg))
if self.debuglevel > 8:
import traceback
traceback.print_exc()
diff --git a/pykolab/plugins/sievemgmt/__init__.py b/pykolab/plugins/sievemgmt/__init__.py
index f7e5368..772165d 100644
--- a/pykolab/plugins/sievemgmt/__init__.py
+++ b/pykolab/plugins/sievemgmt/__init__.py
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from six import string_types
import pykolab
@@ -28,7 +29,10 @@ log = pykolab.getLogger('pykolab.plugin_sievemgmt')
import sys
import time
-from urlparse import urlparse
+try:
+ from urlparse import urlparse
+except ImportError:
+ from urllib.parse import urlparse
class KolabSievemgmt(object):
"""
@@ -224,7 +228,7 @@ class KolabSievemgmt(object):
if not forward_active == False:
forward_address_attr = conf.get('sieve', 'forward_address_attr')
if forward_address_attr in user:
- if isinstance(user[forward_address_attr], basestring):
+ if isinstance(user[forward_address_attr], string_types):
forward_addresses = [ user[forward_address_attr] ]
elif isinstance(user[forward_address_attr], str):
forward_addresses = [ user[forward_address_attr] ]
diff --git a/pykolab/setup/__init__.py b/pykolab/setup/__init__.py
index 26638b0..f23d358 100644
--- a/pykolab/setup/__init__.py
+++ b/pykolab/setup/__init__.py
@@ -30,7 +30,7 @@ to_execute = []
class Setup(object):
def __init__(self):
- import components
+ from . import components
components.__init__()
arg_num = 0
diff --git a/pykolab/setup/components.py b/pykolab/setup/components.py
index 49a4f65..bb01f9c 100644
--- a/pykolab/setup/components.py
+++ b/pykolab/setup/components.py
@@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from six import string_types
import os
@@ -49,7 +50,7 @@ def __init__():
module_name = filename.replace('.py','')
component_name = module_name.replace('setup_', '')
#print "exec(\"from %s import __init__ as %s_register\"" % (module_name,component_name)
- exec("from %s import __init__ as %s_register" % (module_name,component_name))
+ exec("from .%s import __init__ as %s_register" % (module_name,component_name))
exec("%s_register()" % (component_name))
for dirname in dirnames:
@@ -128,14 +129,14 @@ def cli_options_from_component(component_name, *args, **kw):
group = components[component_name]['group']
component_name = components[component_name]['component_name']
try:
- exec("from %s.setup_%s import cli_options as %s_%s_cli_options" % (group,component_name,group,component_name))
+ exec("from .%s.setup_%s import cli_options as %s_%s_cli_options" % (group,component_name,group,component_name))
exec("%s_%s_cli_options()" % (group,component_name))
except ImportError:
pass
else:
try:
- exec("from setup_%s import cli_options as %s_cli_options" % (component_name,component_name))
+ exec("from .setup_%s import cli_options as %s_cli_options" % (component_name,component_name))
exec("%s_cli_options()" % (component_name))
except ImportError:
pass
@@ -215,7 +216,7 @@ def register_group(dirname, module):
module_name = filename.replace('.py','')
component_name = module_name.replace('setup_', '')
#print "exec(\"from %s.%s import __init__ as %s_%s_register\"" % (module,module_name,module,component_name)
- exec("from %s.%s import __init__ as %s_%s_register" % (module,module_name,module,component_name))
+ exec("from .%s.%s import __init__ as %s_%s_register" % (module,module_name,module,component_name))
exec("%s_%s_register()" % (module,component_name))
def register(component_name, func, group=None, description=None, aliases=[], after=[], before=[]):
@@ -224,7 +225,7 @@ def register(component_name, func, group=None, description=None, aliases=[], aft
else:
component = component_name
- if isinstance(aliases, basestring):
+ if isinstance(aliases, string_types):
aliases = [aliases]
if component in components:
diff --git a/pykolab/setup/setup_freebusy.py b/pykolab/setup/setup_freebusy.py
index 3138226..f492f73 100644
--- a/pykolab/setup/setup_freebusy.py
+++ b/pykolab/setup/setup_freebusy.py
@@ -17,14 +17,20 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-from ConfigParser import RawConfigParser
+try:
+ from ConfigParser import RawConfigParser
+except ImportError:
+ from configparser import RawConfigParser
import os
import sys
import time
import socket
-from urlparse import urlparse
+try:
+ from urlparse import urlparse
+except ImportError:
+ from urllib.parse import urlparse
-import components
+from . import components
import pykolab
diff --git a/pykolab/setup/setup_guam.py b/pykolab/setup/setup_guam.py
index 6a23527..16b407f 100644
--- a/pykolab/setup/setup_guam.py
+++ b/pykolab/setup/setup_guam.py
@@ -23,7 +23,7 @@ import subprocess
import sys
import time
-import components
+from . import components
import pykolab
diff --git a/pykolab/setup/setup_imap.py b/pykolab/setup/setup_imap.py
index c55582e..e145c0f 100644
--- a/pykolab/setup/setup_imap.py
+++ b/pykolab/setup/setup_imap.py
@@ -22,7 +22,7 @@ from Cheetah.Template import Template
import os
import subprocess
-import components
+from . import components
import pykolab
diff --git a/pykolab/setup/setup_kolabd.py b/pykolab/setup/setup_kolabd.py
index 54892ce..2c4a78e 100644
--- a/pykolab/setup/setup_kolabd.py
+++ b/pykolab/setup/setup_kolabd.py
@@ -20,7 +20,7 @@
import os
import subprocess
-import components
+from . import components
import pykolab
diff --git a/pykolab/setup/setup_ldap.py b/pykolab/setup/setup_ldap.py
index fb865e9..9765545 100644
--- a/pykolab/setup/setup_ldap.py
+++ b/pykolab/setup/setup_ldap.py
@@ -28,7 +28,7 @@ import subprocess
import tempfile
import time
-import components
+from . import components
import pykolab
diff --git a/pykolab/setup/setup_manticore.py b/pykolab/setup/setup_manticore.py
index 2f17244..c199ec6 100644
--- a/pykolab/setup/setup_manticore.py
+++ b/pykolab/setup/setup_manticore.py
@@ -26,7 +26,7 @@ import subprocess
import sys
import time
-import components
+from . import components
import pykolab
diff --git a/pykolab/setup/setup_mta.py b/pykolab/setup/setup_mta.py
index 55b2695..db8766d 100644
--- a/pykolab/setup/setup_mta.py
+++ b/pykolab/setup/setup_mta.py
@@ -23,7 +23,7 @@ import os
import shutil
import subprocess
-import components
+from . import components
import pykolab
@@ -446,7 +446,10 @@ result_format = "shared+%%s"
myaugeas.close()
if os.path.isfile('/usr/lib/systemd/system/clamd@.service'):
- from ConfigParser import SafeConfigParser
+ try:
+ from ConfigParser import SafeConfigParser
+ except ImportError:
+ from configparser import SafeConfigParser
unitfile = SafeConfigParser()
unitfile.optionxform = str
unitfile.read('/usr/lib/systemd/system/clamd@.service')
diff --git a/pykolab/setup/setup_mysql.py b/pykolab/setup/setup_mysql.py
index 335c353..96ad202 100644
--- a/pykolab/setup/setup_mysql.py
+++ b/pykolab/setup/setup_mysql.py
@@ -24,7 +24,7 @@ import subprocess
import tempfile
import time
-import components
+from . import components
import pykolab
diff --git a/pykolab/setup/setup_php.py b/pykolab/setup/setup_php.py
index cbb93c0..a8fa654 100644
--- a/pykolab/setup/setup_php.py
+++ b/pykolab/setup/setup_php.py
@@ -24,7 +24,7 @@ import shutil
import subprocess
import tempfile
-import components
+from . import components
import pykolab
diff --git a/pykolab/setup/setup_roundcube.py b/pykolab/setup/setup_roundcube.py
index b5567be..462c23a 100644
--- a/pykolab/setup/setup_roundcube.py
+++ b/pykolab/setup/setup_roundcube.py
@@ -31,7 +31,7 @@ import time
from Cheetah.Template import Template
-import components
+from . import components
import pykolab
diff --git a/pykolab/setup/setup_syncroton.py b/pykolab/setup/setup_syncroton.py
index 8ad2d8c..507ebf8 100644
--- a/pykolab/setup/setup_syncroton.py
+++ b/pykolab/setup/setup_syncroton.py
@@ -24,7 +24,7 @@ import subprocess
import sys
import time
-import components
+from . import components
import pykolab
diff --git a/pykolab/telemetry.py b/pykolab/telemetry.py
index adeadd7..4ddef32 100644
--- a/pykolab/telemetry.py
+++ b/pykolab/telemetry.py
@@ -19,7 +19,7 @@
#
import os
-import rfc822
+import email.utils as rfc822
import socket
import sys
import time
diff --git a/pykolab/wap_client/__init__.py b/pykolab/wap_client/__init__.py
index f3cf1d7..176ac91 100644
--- a/pykolab/wap_client/__init__.py
+++ b/pykolab/wap_client/__init__.py
@@ -1,9 +1,15 @@
import json
-import httplib
+try:
+ import httplib
+except ImportError:
+ import http.client as httplib
import urllib
import sys
-from urlparse import urlparse
+try:
+ from urlparse import urlparse
+except ImportError:
+ from urllib.parse import urlparse
import pykolab
diff --git a/pykolab/xml/__init__.py b/pykolab/xml/__init__.py
index 99a269b..12ac4e6 100644
--- a/pykolab/xml/__init__.py
+++ b/pykolab/xml/__init__.py
@@ -1,37 +1,37 @@
-from attendee import Attendee
-from attendee import InvalidAttendeeParticipantStatusError
-from attendee import participant_status_label
+from .attendee import Attendee
+from .attendee import InvalidAttendeeParticipantStatusError
+from .attendee import participant_status_label
-from contact import Contact
-from contact import ContactIntegrityError
-from contact import contact_from_string
-from contact import contact_from_message
-from contact_reference import ContactReference
-from recurrence_rule import RecurrenceRule
+from .contact import Contact
+from .contact import ContactIntegrityError
+from .contact import contact_from_string
+from .contact import contact_from_message
+from .contact_reference import ContactReference
+from .recurrence_rule import RecurrenceRule
-from event import Event
-from event import EventIntegrityError
-from event import InvalidEventDateError
-from event import InvalidEventStatusError
-from event import event_from_ical
-from event import event_from_string
-from event import event_from_message
+from .event import Event
+from .event import EventIntegrityError
+from .event import InvalidEventDateError
+from .event import InvalidEventStatusError
+from .event import event_from_ical
+from .event import event_from_string
+from .event import event_from_message
-from todo import Todo
-from todo import TodoIntegrityError
-from todo import todo_from_ical
-from todo import todo_from_string
-from todo import todo_from_message
+from .todo import Todo
+from .todo import TodoIntegrityError
+from .todo import todo_from_ical
+from .todo import todo_from_string
+from .todo import todo_from_message
-from note import Note
-from note import NoteIntegrityError
-from note import note_from_string
-from note import note_from_message
+from .note import Note
+from .note import NoteIntegrityError
+from .note import note_from_string
+from .note import note_from_message
-from utils import property_label
-from utils import property_to_string
-from utils import compute_diff
-from utils import to_dt
+from .utils import property_label
+from .utils import property_to_string
+from .utils import compute_diff
+from .utils import to_dt
__all__ = [
"Attendee",
diff --git a/pykolab/xml/attendee.py b/pykolab/xml/attendee.py
index 050a1d5..cd8458f 100644
--- a/pykolab/xml/attendee.py
+++ b/pykolab/xml/attendee.py
@@ -3,7 +3,7 @@ import kolabformat
from pykolab.translate import _
from pykolab.translate import N_
-from contact_reference import ContactReference
+from .contact_reference import ContactReference
participant_status_labels = {
"NEEDS-ACTION": N_("Needs Action"),
diff --git a/pykolab/xml/contact.py b/pykolab/xml/contact.py
index 7b0a2a7..9a6fd99 100644
--- a/pykolab/xml/contact.py
+++ b/pykolab/xml/contact.py
@@ -1,3 +1,5 @@
+from six import string_types
+
import kolabformat
import datetime
import pytz
@@ -133,13 +135,13 @@ class Contact(kolabformat.Contact):
return [x for x in self.emailAddresses()]
def set_email(self, email, preferred_index=0):
- if isinstance(email, basestring):
+ if isinstance(email, string_types):
self.setEmailAddresses([email], preferred_index)
else:
self.setEmailAddresses(email, preferred_index)
def add_email(self, email):
- if isinstance(email, basestring):
+ if isinstance(email, string_types):
self.add_emails([email])
elif isinstance(email, list):
self.add_emails(email)
diff --git a/pykolab/xml/event.py b/pykolab/xml/event.py
index a80fe20..cfd9289 100644
--- a/pykolab/xml/event.py
+++ b/pykolab/xml/event.py
@@ -1,3 +1,5 @@
+from six import string_types
+
import datetime
import icalendar
import kolabformat
@@ -16,9 +18,9 @@ from pykolab.xml.utils import ustr
from pykolab.translate import _
from os import path
-from attendee import Attendee
-from contact_reference import ContactReference
-from recurrence_rule import RecurrenceRule
+from .attendee import Attendee
+from .contact_reference import ContactReference
+from .recurrence_rule import RecurrenceRule
from collections import OrderedDict
log = pykolab.getLogger('pykolab.xml_event')
@@ -394,7 +396,7 @@ class Event(object):
return attendee.get_participant_status()
def get_attendee(self, attendee):
- if isinstance(attendee, basestring):
+ if isinstance(attendee, string_types):
if attendee in [x.get_email() for x in self.get_attendees()]:
attendee = self.get_attendee_by_email(attendee)
@@ -892,7 +894,7 @@ class Event(object):
getattr(self, default_setter)(value)
def set_ical_attendee(self, _attendee):
- if isinstance(_attendee, basestring):
+ if isinstance(_attendee, string_types):
_attendee = [_attendee]
if isinstance(_attendee, list):
diff --git a/saslauthd/__init__.py b/saslauthd/__init__.py
index d2459ad..d5c9ece 100644
--- a/saslauthd/__init__.py
+++ b/saslauthd/__init__.py
@@ -27,8 +27,10 @@
from __future__ import print_function
from optparse import OptionParser
-from ConfigParser import SafeConfigParser
-
+try:
+ from ConfigParser import SafeConfigParser
+except ImportError:
+ from configparser import SafeConfigParser
import grp
import os
import pwd
@@ -154,6 +156,10 @@ class SASLAuthDaemon(object):
os.close(1)
os.close(2)
+ os.open(os.devnull, os.O_RDONLY)
+ os.open(os.devnull, os.O_WRONLY)
+ os.open(os.devnull, os.O_WRONLY)
+
os.umask(old_umask)
self.thread_count += 1
@@ -268,13 +274,13 @@ class SASLAuthDaemon(object):
if success:
# #1170: Catch broken pipe error (incomplete authentication request)
try:
- clientsocket.send(struct.pack("!H2s", 2, "OK"))
+ clientsocket.send(struct.pack("!H2s", 2, b"OK"))
except:
pass
else:
# #1170: Catch broken pipe error (incomplete authentication request)
try:
- clientsocket.send(struct.pack("!H2s", 2, "NO"))
+ clientsocket.send(struct.pack("!H2s", 2, b"NO"))
except:
pass
diff --git a/test-wallace.py b/test-wallace.py
index 92d69f4..630711c 100755
--- a/test-wallace.py
+++ b/test-wallace.py
@@ -25,11 +25,10 @@ import sys
# For development purposes
sys.path.extend(['.', '..'])
-from email.MIMEMultipart import MIMEMultipart
-from email.MIMEBase import MIMEBase
-from email.MIMEText import MIMEText
-from email.Utils import COMMASPACE, formatdate
-from email import Encoders
+from email.mime.multipart import MIMEMultipart
+from email.mime.base import MIMEBase
+from email.mime.text import MIMEText
+from email.utils import COMMASPACE, formatdate
def send_mail(send_from, send_to, send_with=None):
diff --git a/tests/functional/test_wap_client/test_007_policy_uid.py b/tests/functional/test_wap_client/test_007_policy_uid.py
index a10eeb9..eac4022 100644
--- a/tests/functional/test_wap_client/test_007_policy_uid.py
+++ b/tests/functional/test_wap_client/test_007_policy_uid.py
@@ -1,4 +1,7 @@
-from ConfigParser import RawConfigParser
+try:
+ from ConfigParser import RawConfigParser
+except ImportError:
+ from configparser import RawConfigParser
import time
import unittest
diff --git a/wallace/__init__.py b/wallace/__init__.py
index 4a22e3e..6f11b01 100644
--- a/wallace/__init__.py
+++ b/wallace/__init__.py
@@ -31,7 +31,10 @@ import socket
import struct
import sys
import tempfile
-from threading import _Timer
+try:
+ from threading import _Timer
+except:
+ from threading import Timer as _Timer
import time
import pykolab
@@ -39,8 +42,8 @@ from pykolab import utils
from pykolab.logger import StderrToLogger
from pykolab.translate import _ as _l
-import modules
-from modules import cb_action_ACCEPT
+from . import modules
+from .modules import cb_action_ACCEPT
# pylint: disable=invalid-name
log = pykolab.getLogger('pykolab.wallace')
diff --git a/wallace/module_footer.py b/wallace/module_footer.py
index 2833a59..96e8cf6 100644
--- a/wallace/module_footer.py
+++ b/wallace/module_footer.py
@@ -25,7 +25,7 @@ import time
from email import message_from_file
from email.encoders import encode_quopri
-import modules
+from . import modules
import pykolab
from pykolab.translate import _
diff --git a/wallace/module_gpgencrypt.py b/wallace/module_gpgencrypt.py
index 9083055..a0ddc2e 100644
--- a/wallace/module_gpgencrypt.py
+++ b/wallace/module_gpgencrypt.py
@@ -22,8 +22,8 @@ import tempfile
import time
from email import message_from_string
-from email.MIMEBase import MIMEBase
-from email.MIMEText import MIMEText
+from email.mime.base import MIMEBase
+from email.mime.text import MIMEText
from email.parser import Parser
from email.utils import formataddr
from email.utils import getaddresses
@@ -34,7 +34,7 @@ import email.mime.text
import email.encoders
import gnupg
-import modules
+from . import modules
import pykolab
diff --git a/wallace/module_invitationpolicy.py b/wallace/module_invitationpolicy.py
index 63d8879..da6eec9 100644
--- a/wallace/module_invitationpolicy.py
+++ b/wallace/module_invitationpolicy.py
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from six import string_types
import datetime
import os
@@ -23,7 +24,10 @@ import random
import signal
import tempfile
import time
-from urlparse import urlparse
+try:
+ from urlparse import urlparse
+except ImportError:
+ from urllib.parse import urlparse
import urllib
import hashlib
import traceback
@@ -34,7 +38,7 @@ from email.parser import Parser
from email.utils import formataddr
from email.utils import getaddresses
-import modules
+from . import modules
import pykolab
import kolabformat
@@ -709,7 +713,7 @@ def user_dn_from_email_address(email_address):
user_dn = auth.find_user_dn(email_address, True)
- if isinstance(user_dn, basestring):
+ if isinstance(user_dn, string_types):
log.debug(_("User DN: %r") % (user_dn), level=8)
else:
log.debug(_("No user record(s) found for %r") % (email_address), level=8)
diff --git a/wallace/module_optout.py b/wallace/module_optout.py
index c710180..9220ebe 100644
--- a/wallace/module_optout.py
+++ b/wallace/module_optout.py
@@ -22,14 +22,17 @@ import os
import random
import tempfile
import time
-from urlparse import urlparse
+try:
+ from urlparse import urlparse
+except ImportError:
+ from urllib.parse import urlparse
import urllib
from email import message_from_file
from email.utils import formataddr
from email.utils import getaddresses
-import modules
+from . import modules
import pykolab
diff --git a/wallace/module_resources.py b/wallace/module_resources.py
index e29f193..afaf384 100644
--- a/wallace/module_resources.py
+++ b/wallace/module_resources.py
@@ -36,7 +36,7 @@ import uuid
from dateutil.tz import tzlocal
-import modules
+from . import modules
import kolabformat
diff --git a/wallace/module_signature.py b/wallace/module_signature.py
index c483d93..cfebcb5 100644
--- a/wallace/module_signature.py
+++ b/wallace/module_signature.py
@@ -26,7 +26,7 @@ from email.encoders import encode_quopri
from email.parser import Parser
from email.utils import getaddresses
-import modules
+from . import modules
import pykolab
from pykolab.auth import Auth
diff --git a/wallace/modules.py b/wallace/modules.py
index aed60b6..a1eaa7a 100644
--- a/wallace/modules.py
+++ b/wallace/modules.py
@@ -18,6 +18,7 @@
#
from __future__ import print_function
+from six import string_types
import os
import sys
@@ -64,7 +65,7 @@ def initialize():
module_name = filename.replace('.py', '')
name = module_name.replace('module_', '')
# print("exec(\"from %s import __init__ as %s_register\")" % (module_name,name))
- exec("from %s import __init__ as %s_register" % (module_name, name))
+ exec("from .%s import __init__ as %s_register" % (module_name, name))
exec("%s_register()" % (name))
for dirname in dirnames:
@@ -407,7 +408,7 @@ def register_group(dirname, module):
name = module_name.replace('module_', '')
# TODO: Error recovery from incomplete / incorrect modules.
exec(
- "from %s.%s import __init__ as %s_%s_register" % (
+ "from .%s.%s import __init__ as %s_%s_register" % (
module,
module_name,
module,
@@ -423,7 +424,7 @@ def register(name, func, group=None, description=None, aliases=[], heartbeat=Non
else:
module = name
- if isinstance(aliases, basestring):
+ if isinstance(aliases, string_types):
aliases = [aliases]
if module in modules: