4 commits - configure.ac pykolab/auth pykolab/cli pykolab/setup

Jeroen van Meeuwen vanmeeuwen at kolabsys.com
Mon Aug 19 11:55:34 CEST 2013


 configure.ac                           |    2 
 pykolab/auth/__init__.py               |    4 
 pykolab/cli/cmd_sync_mailhost_attrs.py |  133 +++++++++++++++++++++++++++++++++
 pykolab/setup/setup_mta.py             |   20 ++--
 4 files changed, 146 insertions(+), 13 deletions(-)

New commits:
commit 53a453ad3a221331dbae9ed148c3bedecbc0015e
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Mon Aug 19 11:55:14 2013 +0200

    Add a command to sync mailhost attributes with what is factually in the murder

diff --git a/pykolab/cli/cmd_sync_mailhost_attrs.py b/pykolab/cli/cmd_sync_mailhost_attrs.py
new file mode 100644
index 0000000..0f2e4d9
--- /dev/null
+++ b/pykolab/cli/cmd_sync_mailhost_attrs.py
@@ -0,0 +1,133 @@
+# -*- coding: utf-8 -*-
+# Copyright 2010-2013 Kolab Systems AG (http://www.kolabsys.com)
+#
+# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 3 or, at your option, any later version
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Library General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+
+import commands
+
+import pykolab
+
+from pykolab import imap_utf7
+from pykolab.auth import Auth
+from pykolab.imap import IMAP
+from pykolab.translate import _
+
+log = pykolab.getLogger('pykolab.cli')
+conf = pykolab.getConf()
+
+def __init__():
+    commands.register('sync_mailhost_attrs', execute, description=description())
+
+def description():
+    return "Synchronize mailHost attribute values with the actual mailserver in a Cyrus IMAP Murder.\n"
+
+def cli_options():
+    my_option_group = conf.add_cli_parser_option_group(_("CLI Options"))
+    my_option_group.add_option( '--delete',
+                                dest    = "delete",
+                                action  = "store_true",
+                                default = False,
+                                help    = _("Delete mailboxes for recipients that do not appear to exist in LDAP."))
+
+    my_option_group.add_option( '--dry-run',
+                                dest    = "dry_run",
+                                action  = "store_true",
+                                default = False,
+                                help    = _("Display changes, do not apply them."))
+
+    my_option_group.add_option( '--server',
+                                dest    = "connect_server",
+                                action  = "store",
+                                default = None,
+                                metavar = "SERVER",
+                                help    = _("List mailboxes on server SERVER only."))
+
+def execute(*args, **kw):
+    """
+        Synchronize or display changes
+    """
+
+    imap = IMAP()
+
+    if not conf.connect_server == None:
+        imap.connect(server=conf.connect_server)
+    else:
+        imap.connect()
+
+    auth = Auth()
+    auth.connect()
+
+    domains = auth.list_domains()
+
+    for primary,secondaries in domains:
+        folders = []
+
+        folders.extend(imap.lm('shared/%%@%s' % (primary)))
+        folders.extend(imap.lm('user/%%@%s' % (primary)))
+
+        for secondary in secondaries:
+            folders.extend(imap.lm('shared/%%@%s' % (secondary)))
+            folders.extend(imap.lm('user/%%@%s' % (secondary)))
+
+        auth = Auth(domain=primary)
+        auth.connect()
+
+        for folder in folders:
+            server = imap.user_mailbox_server(folder)
+            recipient = auth.find_recipient('/'.join(folder.split('/')[1:]))
+            if (isinstance(recipient, list)):
+                if len(recipient) > 1:
+                    log.warning(_("Multiple recipients for '%s'!") % ('/'.join(folder.split('/')[1:])))
+                    continue
+                elif len(recipient) == 0:
+                    if conf.delete:
+                        if conf.dry_run:
+                            if not folder.split('/')[0] == 'shared':
+                                log.warning(_("No recipients for '%s' (would have deleted the mailbox if not for --dry-run)!") % ('/'.join(folder.split('/')[1:])))
+                            else:
+                                continue
+                        else:
+                            if not '/'.join(folder.split('/')[0]) == 'shared':
+                                log.info(_("Deleting mailbox '%s' because it has no recipients") % (folder))
+                                imap.dm(folder)
+                            else:
+                                log.info(_("Not automatically deleting shared folder '%s'") % (folder))
+                    else:
+                        log.warning(_("No recipients for '%s' (use --delete to delete)!") % ('/'.join(folder.split('/')[1:])))
+
+                    continue
+            else:
+                mailhost = auth.get_entry_attribute(primary, recipient, 'mailhost')
+
+            if not server == mailhost:
+                if conf.dry_run:
+                    print folder, server, mailhost
+                else:
+                    auth.set_entry_attribute(primary, recipient, 'mailhost', server)
+
+    folders = []
+    folders.extend(imap.lm("shared/%%"))
+    folders.extend(imap.lm("user/%%"))
+
+    auth = Auth()
+    auth.connect()
+
+    for folder in folders:
+        server = imap.user_mailbox_server(folder)
+        recipient = auth.find_recipient('/'.join(folder.split('/')[1:]))
+
+        print folder, server, recipient


commit 56072df8b03506882b94bc292474d6853c055095
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Sun Aug 18 10:13:54 2013 +0200

    Actually push the value of an attribute to set in set_entry_attribute()

diff --git a/pykolab/auth/__init__.py b/pykolab/auth/__init__.py
index b75f9c3..fd02083 100644
--- a/pykolab/auth/__init__.py
+++ b/pykolab/auth/__init__.py
@@ -264,8 +264,8 @@ class Auth(pykolab.base.Base):
     def search_mail_address(self, domain, mail_address):
         return self._auth._search_mail_address(domain, mail_address)
 
-    def set_entry_attribute(self, domain, entry, attribute):
-        return self._auth.set_entry_attribute(entry, attribute)
+    def set_entry_attribute(self, domain, entry, attribute, value):
+        return self._auth.set_entry_attribute(entry, attribute, value)
 
     def set_entry_attributes(self, domain, entry, attributes):
         return self._auth.set_entry_attributes(entry, attributes)


commit 8fc06463efcc7a596897a3b0d4ff3848cb726f15
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Tue Aug 13 12:45:42 2013 +0100

    Release 2

diff --git a/configure.ac b/configure.ac
index d710f9b..8537159 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,5 +1,5 @@
 AC_INIT([pykolab], 0.6.4)
-AC_SUBST([RELEASE], 1)
+AC_SUBST([RELEASE], 2)
 
 AC_CONFIG_SRCDIR(pykolab/constants.py.in)
 


commit 07a013bd5405ce24e3f04216a0ba45d40e00e342
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Tue Aug 13 12:45:25 2013 +0100

    Don't forget the indentiation level

diff --git a/pykolab/setup/setup_mta.py b/pykolab/setup/setup_mta.py
index ed30f50..9280d18 100644
--- a/pykolab/setup/setup_mta.py
+++ b/pykolab/setup/setup_mta.py
@@ -267,16 +267,16 @@ result_format = shared+%%s
 
     # Copy header checks files
     for hc_file in [ 'inbound', 'internal', 'submission' ]:
-    if not os.path.isfile("/etc/postfix/header_checks.%s" % (hc_file)):
-        if os.path.isfile('/etc/kolab/templates/header_checks.%s' % (hc_file)):
-            input_file = '/etc/kolab/templates/header_checks.%s' % (hc_file)
-        elif os.path.isfile('/usr/share/kolab/templates/header_checks.%s' % (hc_file)):
-            input_file = '/usr/share/kolab/templates/header_checks.%s' % (hc_file)
-        elif os.path.isfile(os.path.abspath(os.path.join(__file__, '..', '..', '..', 'share', 'templates', 'header_checks.%s' % (hc_file)))):
-            input_file = os.path.abspath(os.path.join(__file__, '..', '..', '..', 'share', 'templates', 'header_checks.%s' % (hc_file)))
-
-        shutil.copy(input_file, "/etc/postfix/header_checks.%s" % (hc_file))
-        subprocess.call(["postmap", "/etc/postfix/header_checks.%s" % (hc_file)])
+        if not os.path.isfile("/etc/postfix/header_checks.%s" % (hc_file)):
+            if os.path.isfile('/etc/kolab/templates/header_checks.%s' % (hc_file)):
+                input_file = '/etc/kolab/templates/header_checks.%s' % (hc_file)
+            elif os.path.isfile('/usr/share/kolab/templates/header_checks.%s' % (hc_file)):
+                input_file = '/usr/share/kolab/templates/header_checks.%s' % (hc_file)
+            elif os.path.isfile(os.path.abspath(os.path.join(__file__, '..', '..', '..', 'share', 'templates', 'header_checks.%s' % (hc_file)))):
+                input_file = os.path.abspath(os.path.join(__file__, '..', '..', '..', 'share', 'templates', 'header_checks.%s' % (hc_file)))
+
+            shutil.copy(input_file, "/etc/postfix/header_checks.%s" % (hc_file))
+            subprocess.call(["postmap", "/etc/postfix/header_checks.%s" % (hc_file)])
 
     myaugeas = Augeas()
 




More information about the commits mailing list