* 'VirtualMailManager/VirtualMailManager.py'
authorPascal Volk <neverseen@users.sourceforge.net>
Wed, 27 Aug 2008 04:52:32 +0000
changeset 68 7ae95b9938c4
parent 67 e4d25f50164d
child 69 0c124160a991
* 'VirtualMailManager/VirtualMailManager.py' - Implemented VirtualMailManager.__subscribeFL() for the 'subscriptions' file. - Modified VirtualMailManager.__mailDirMake() for configurable folders inside the Maildir. * 'VirtualMailManager/Config.py' * 'vmm.cfg' - Updated Maildir options * 'update_config_0.4.x-0.5.py' - Added to repository * 'man/de/man5/vmm.cfg.5' * 'man/man5/vmm.cfg.5' - updated
VirtualMailManager/Config.py
VirtualMailManager/VirtualMailManager.py
man/de/man5/vmm.cfg.5
man/man5/vmm.cfg.5
update_config_0.4.x-0.5.py
upgrade.sh
vmm.cfg
--- a/VirtualMailManager/Config.py	Tue Aug 26 01:53:48 2008 +0000
+++ b/VirtualMailManager/Config.py	Wed Aug 27 04:52:32 2008 +0000
@@ -56,7 +56,8 @@
                 ['name', 'mailsys']
                 ]
         self.__mdopts = [
-                ['folder', 'Maildir'],
+                ['name', 'Maildir'],
+                ['folders', 'Drafts:Sent:Templates:Trash'],
                 ['mode', 448],
                 ['diskusage', 'false'],
                 ['delete', 'false']
--- a/VirtualMailManager/VirtualMailManager.py	Tue Aug 26 01:53:48 2008 +0000
+++ b/VirtualMailManager/VirtualMailManager.py	Wed Aug 27 04:52:32 2008 +0000
@@ -37,6 +37,7 @@
 RE_DOMAIN_SRCH = """^[a-z0-9-\.]+$"""
 RE_LOCALPART = """[^\w!#$%&'\*\+-\.\/=?^_`{\|}~]"""
 RE_MAILLOCATION = """^[\w]{1,20}$"""
+RE_MBOX_NAMES = """^[\x20-\x25\x27-\x7E]*$"""
 
 class VirtualMailManager:
     """The main class for vmm"""
@@ -278,10 +279,21 @@
                 gid)
         os.chdir(oldpwd)
 
+    def __subscribeFL(self, folderlist, uid, gid):
+        fname = self.__Cfg.get('maildir', 'name') + '/subscriptions'
+        sf = file(fname, 'w')
+        for f in folderlist:
+            sf.write(f+'\n')
+        sf.flush()
+        sf.close()
+        os.chown(fname, uid, gid)
+        os.chmod(fname, 384)
+
     def __mailDirMake(self, domdir, uid, gid):
         """Creates maildirs and maildir subfolders.
 
         Keyword arguments:
+        domdir -- the path to the domain directory
         uid -- user id from the account
         gid -- group id from the account
         """
@@ -289,9 +301,14 @@
         oldpwd = os.getcwd()
         os.chdir(domdir)
 
-        maildir = '%s' % self.__Cfg.get('maildir', 'folder')
-        folders = [maildir , maildir+'/.Drafts', maildir+'/.Sent',
-                maildir+'/.Templates', maildir+'/.Trash']
+        re.compile(RE_MBOX_NAMES)
+        maildir = self.__Cfg.get('maildir', 'name')
+        folders = [maildir]
+        for folder in self.__Cfg.get('maildir', 'folders').split(':'):
+            folder = folder.strip()
+            if len(folder) and not folder.count('..')\
+            and re.match(RE_MBOX_NAMES, folder):
+                folders.append('%s/.%s' % (maildir, folder))
         subdirs = ['cur', 'new', 'tmp']
         mode = self.__Cfg.getint('maildir', 'mode')
 
@@ -301,6 +318,8 @@
             self.__makedir(folder, mode, uid, gid)
             for subdir in subdirs:
                 self.__makedir(folder+'/'+subdir, mode, uid, gid)
+        self.__subscribeFL([f.replace(maildir+'/.', '') for f in folders[1:]],
+                uid, gid)
         os.chdir(oldpwd)
 
     def __userDirDelete(self, domdir, uid, gid):
@@ -560,7 +579,7 @@
         if password is None:
             password = self._readpass()
             acc.setPassword(self.__pwhash(password))
-        acc.save(self.__Cfg.get('maildir', 'folder'),
+        acc.save(self.__Cfg.get('maildir', 'name'),
                 self.__Cfg.getboolean('services', 'smtp'),
                 self.__Cfg.getboolean('services', 'pop3'),
                 self.__Cfg.getboolean('services', 'imap'),
--- a/man/de/man5/vmm.cfg.5	Tue Aug 26 01:53:48 2008 +0000
+++ b/man/de/man5/vmm.cfg.5	Wed Aug 27 04:52:32 2008 +0000
@@ -1,5 +1,5 @@
 .\" $Id$
-.TH vmm.cfg 5 "17. Jun 2008" "Pascal Volk"
+.TH vmm.cfg 5 "27. Aug 2008" "Pascal Volk"
 .SH NAME
 vmm.cfg \- Konfigurationsdatei für vmm
 .SH SYNOPSIS
@@ -71,10 +71,17 @@
 Im \fBmaildir\fP-Abschnitt werden die für die Maildirs erforderlichen Optionen
 festgelegt.
 .TP
-\fBfolder\fP (\fIString\fP)
+\fBname\fP (\fIString\fP)
 Standard-Name des Maildir-Verzeichnisses im Verzeichnis des jeweiligen
 Anwenders.
 .TP
+\fBfolders\fP (\fIString\fP)
+Eine durch Doppelpunkten getrennte Liste mit Verzeichnisnamen, die innerhalb des
+Maildirs erstellt werden sollen.
+.br
+Sollen innerhalb des Maildirs keine Verzeichnisse angelegt werden, ist dieser
+Optionen ein einzelner Doppelpunkt (':') als Wert zuzuweisen.
+.TP
 \fBmode\fP (\fIInt\fP)
 Zugriffsbits des Maildirs in Dezimal-Schreibweise (Basis 10).
 .br
@@ -92,7 +99,9 @@
 \fBBeispiel\fP:
 [maildir]
 .br
-folder = Maildir
+name = Maildir
+.br
+folders = Drafts:Sent:Templates:Trash:INBOX.News
 .br
 mode = 448
 .br
--- a/man/man5/vmm.cfg.5	Tue Aug 26 01:53:48 2008 +0000
+++ b/man/man5/vmm.cfg.5	Wed Aug 27 04:52:32 2008 +0000
@@ -1,5 +1,5 @@
 .\" $Id$
-.TH vmm.cfg 5 "11. Jun 2008" "Pascal Volk"
+.TH vmm.cfg 5 "27. Aug 2008" "Pascal Volk"
 .SH NAME
 vmm.cfg \- configuration file for vmm
 .SH SYNOPSIS
@@ -64,9 +64,15 @@
 .SH MAILDIR SECTION
 The \fBmaildir\fP section is used to specify some options for the Maildirs.
 .TP
-\fBfolder\fP (\fIString\fP)
+\fBname\fP (\fIString\fP)
 Default name of the maildir folder in users home directory.
 .TP
+\fBfolders\fP (\fIString\fP)
+A colon separated list of folder names, that should be created.
+.br
+If no folders should be created inside the Maildir, set the value of this option
+to a single colon (':').
+.TP
 \fBmode\fP (\fIInt\fP)
 Access mode for the maildir in decimal (base 10) notation. For example:
 \'drwx------' -> octal 0700 -> decimal 448
@@ -81,7 +87,9 @@
 \fBExample\fP:
 [maildir]
 .br
-folder = Maildir
+name = Maildir
+.br
+folders = Drafts:Sent:Templates:Trash:INBOX.News
 .br
 mode = 448
 .br
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/update_config_0.4.x-0.5.py	Wed Aug 27 04:52:32 2008 +0000
@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+# -*- coding: UTF-8 -*-
+# Copyright 2008 VEB IT
+# See COPYING for distribution information.
+# $Id$
+
+from ConfigParser import ConfigParser
+from shutil import copy2
+
+cf = '/usr/local/etc/vmm.cfg'
+fh = file(cf, 'r')
+cp = ConfigParser()
+cp.readfp(fh)
+fh.close()
+
+if not cp.has_option('maildir', 'name') or not cp.has_option('maildir',
+        'folders') or cp.has_option('maildir', 'folder'):
+    copy2(cf, cf+'.bak_upd_0.4.x-0.5')
+    fh = file(cf, 'w')
+    if not cp.has_option('maildir', 'name'):
+        if cp.has_option('maildir', 'folder'):
+            cp.set('maildir', 'name', cp.get('maildir', 'folder'))
+            cp.remove_option('maildir', 'folder')
+        else:
+            cp.set('maildir', 'name', 'Maildir')
+    if not cp.has_option('maildir', 'folders'):
+        cp.set('maildir', 'folders', 'Drafts:Sent:Templates:Trash')
+    if cp.has_option('maildir', 'folder'):
+        cp.remove_option('maildir', 'folder')
+    cp.write(fh)
+    fh.close()
--- a/upgrade.sh	Tue Aug 26 01:53:48 2008 +0000
+++ b/upgrade.sh	Wed Aug 27 04:52:32 2008 +0000
@@ -80,3 +80,7 @@
 [ -d ${DOC_DIR}/examples ] || mkdir -m 0755 -p ${DOC_DIR}/examples
 install -m 0644 ${INSTALL_OPTS} pgsql-*.cf ${DOC_DIR}/examples
 install -m 0644 ${INSTALL_OPTS} vmm.cfg ${DOC_DIR}/examples
+
+# update config file
+./update_config_0.4.x-0.5.py
+
--- a/vmm.cfg	Tue Aug 26 01:53:48 2008 +0000
+++ b/vmm.cfg	Wed Aug 27 04:52:32 2008 +0000
@@ -20,8 +20,11 @@
 # Mail directories
 #
 [maildir]
-; default name of the Maildir folder (String)
-folder = Maildir
+; Default name of the Maildir folder (String)
+name = Maildir
+; A colon separated list of folder names, that should be created (String)
+; e.g.: folders = Drafts:Sent:Templates:Trash
+folders = Drafts:Sent:Templates:Trash
 ; Permissions for maildirs (Int)
 ; octal 0700 -> decimal 448
 mode = 448