From f339ebf3a37fc23aac843ce1c7008d4a77d87fa8 Mon Sep 17 00:00:00 2001
From: Dominik <info@profi-webdesign.com>
Date: Sat, 25 Apr 2015 14:23:33 +0200
Subject: [PATCH] mdbox format as alternative for Maildir

---
 .../sql/incremental/upd_dev_collection.sql    |   1 +
 install/sql/ispconfig3.sql                    |   1 +
 install/tpl/debian6_dovecot-sql.conf.master   |   4 +-
 install/tpl/debian_dovecot-sql.conf.master    |   4 +-
 install/tpl/fedora_dovecot-sql.conf.master    |   4 +-
 install/tpl/opensuse_dovecot-sql.conf.master  |   4 +-
 .../web/admin/form/server_config.tform.php    |   6 +
 .../web/admin/lib/lang/ar_server_config.lng   |   1 +
 .../web/admin/lib/lang/bg_server_config.lng   |   1 +
 .../web/admin/lib/lang/br_server_config.lng   |   1 +
 .../web/admin/lib/lang/cz_server_config.lng   |   1 +
 .../web/admin/lib/lang/de_server_config.lng   |   1 +
 .../web/admin/lib/lang/el_server_config.lng   |   1 +
 .../web/admin/lib/lang/en_server_config.lng   |   1 +
 .../web/admin/lib/lang/es_server_config.lng   |   1 +
 .../web/admin/lib/lang/fi_server_config.lng   |   1 +
 .../web/admin/lib/lang/fr_server_config.lng   |   1 +
 .../web/admin/lib/lang/hr_server_config.lng   |   1 +
 .../web/admin/lib/lang/hu_server_config.lng   |   1 +
 .../web/admin/lib/lang/id_server_config.lng   |   1 +
 .../web/admin/lib/lang/it_server_config.lng   |   1 +
 .../web/admin/lib/lang/ja_server_config.lng   |   1 +
 .../web/admin/lib/lang/nl_server_config.lng   |   1 +
 .../web/admin/lib/lang/pl_server_config.lng   |   1 +
 .../web/admin/lib/lang/pt_server_config.lng   |   1 +
 .../web/admin/lib/lang/ro_server_config.lng   |   1 +
 .../web/admin/lib/lang/ru_server_config.lng   |   1 +
 .../web/admin/lib/lang/se_server_config.lng   |   1 +
 .../web/admin/lib/lang/sk_server_config.lng   |   1 +
 .../web/admin/lib/lang/tr_server_config.lng   |   1 +
 .../templates/server_config_mail_edit.htm     |   6 +
 interface/web/mail/mail_user_edit.php         |  10 +
 .../classes/cron.d/500-backup_mail.inc.php    |  60 +++-
 .../plugins-available/backup_plugin.inc.php   |  69 +++-
 server/plugins-available/mail_plugin.inc.php  | 305 ++++++++++--------
 35 files changed, 330 insertions(+), 167 deletions(-)

diff --git a/install/sql/incremental/upd_dev_collection.sql b/install/sql/incremental/upd_dev_collection.sql
index 6eea12b71a..221fde9ef6 100644
--- a/install/sql/incremental/upd_dev_collection.sql
+++ b/install/sql/incremental/upd_dev_collection.sql
@@ -37,6 +37,7 @@ ALTER TABLE `web_backup` CHANGE `filesize` `filesize` VARCHAR(20) NOT NULL DEFAU
 
 ALTER TABLE `sys_datalog` ADD INDEX `dbtable` (`dbtable` (25), `dbidx` (25)), ADD INDEX (`action`);
 ALTER TABLE `mail_user` ADD `greylisting` ENUM( 'n', 'y' ) NOT NULL DEFAULT 'n' AFTER `postfix`;
+ALTER TABLE `mail_user` ADD `maildir_format` varchar(255) NOT NULL default 'maildir' AFTER `maildir`;
 ALTER TABLE `mail_forwarding` ADD `greylisting` ENUM( 'n', 'y' ) NOT NULL DEFAULT 'n' AFTER `active`;
 
 ALTER TABLE `openvz_ip` CHANGE `ip_address` `ip_address` VARCHAR(39) DEFAULT NULL;
diff --git a/install/sql/ispconfig3.sql b/install/sql/ispconfig3.sql
index 571d59d5fc..229f76d92c 100644
--- a/install/sql/ispconfig3.sql
+++ b/install/sql/ispconfig3.sql
@@ -914,6 +914,7 @@ CREATE TABLE `mail_user` (
   `uid` int(11) NOT NULL default '5000',
   `gid` int(11) NOT NULL default '5000',
   `maildir` varchar(255) NOT NULL default '',
+  `maildir_format` varchar(255) NOT NULL default 'maildir',
   `quota` bigint(20) NOT NULL default '-1',
   `cc` varchar(255) NOT NULL default '',
   `sender_cc` varchar(255) NOT NULL default '',
diff --git a/install/tpl/debian6_dovecot-sql.conf.master b/install/tpl/debian6_dovecot-sql.conf.master
index 3c58b304a8..5f023501c4 100644
--- a/install/tpl/debian6_dovecot-sql.conf.master
+++ b/install/tpl/debian6_dovecot-sql.conf.master
@@ -14,8 +14,8 @@ connect = host={mysql_server_host} dbname={mysql_server_database} user={mysql_se
 default_pass_scheme = CRYPT
 
 # password-query with prefetch
-password_query = SELECT email as user, password, maildir as userdb_home, CONCAT('maildir:', maildir, '/Maildir') as userdb_mail, uid as userdb_uid, gid as userdb_gid, CONCAT('*:storage=', quota, 'B') AS userdb_quota_rule, CONCAT(maildir, '/.sieve') as userdb_sieve FROM mail_user WHERE (login = '%u' OR email = '%u') AND `disable%Ls` = 'n' AND server_id = '{server_id}'
-user_query = SELECT email as user, maildir as home, CONCAT('maildir:', maildir, '/Maildir') as mail, uid, gid, CONCAT('*:storage=', quota, 'B') AS quota_rule, CONCAT(maildir, '/.sieve') as sieve FROM mail_user WHERE (login = '%u' OR email = '%u') AND `disable%Ls` = 'n' AND server_id = '{server_id}'
+password_query = SELECT email as user, password, maildir as userdb_home, CONCAT( maildir_format, ':', maildir, '/', IF(maildir_format='maildir','Maildir',maildir_format)) as userdb_mail, uid as userdb_uid, gid as userdb_gid, CONCAT('*:storage=', quota, 'B') AS userdb_quota_rule, CONCAT(maildir, '/.sieve') as userdb_sieve FROM mail_user WHERE (login = '%u' OR email = '%u') AND `disable%Ls` = 'n' AND server_id = '{server_id}'
+user_query = SELECT email as user, maildir as home, CONCAT( maildir_format, ':', maildir, '/', IF(maildir_format='maildir','Maildir',maildir_format)) as mail, uid, gid, CONCAT('*:storage=', quota, 'B') AS quota_rule, CONCAT(maildir, '/.sieve') as sieve FROM mail_user WHERE (login = '%u' OR email = '%u') AND `disable%Ls` = 'n' AND server_id = '{server_id}'
 
 # The iterate_query is required for the doveadm command only and works only on dovecot 2 servers.
 # Do not enable it on Dovecot 1.x servers
diff --git a/install/tpl/debian_dovecot-sql.conf.master b/install/tpl/debian_dovecot-sql.conf.master
index adeb8d9d91..647655f6d2 100644
--- a/install/tpl/debian_dovecot-sql.conf.master
+++ b/install/tpl/debian_dovecot-sql.conf.master
@@ -121,8 +121,8 @@ connect = host={mysql_server_host} dbname={mysql_server_database} user={mysql_se
 default_pass_scheme = CRYPT
 
 # password-query with prefetch
-password_query = SELECT email as user, password, maildir as userdb_home, CONCAT('maildir:', maildir, '/Maildir') as userdb_mail, uid as userdb_uid, gid as userdb_gid, CONCAT('*:storage=', quota, 'B') AS userdb_quota_rule, CONCAT(maildir, '/.sieve') as userdb_sieve FROM mail_user WHERE (login = '%u' OR email = '%u') AND `disable%Ls` = 'n' AND server_id = '{server_id}'
-user_query = SELECT email as user, maildir as home, CONCAT('maildir:', maildir, '/Maildir') as mail, uid, gid, CONCAT('*:storage=', quota, 'B') AS quota_rule, CONCAT(maildir, '/.sieve') as sieve FROM mail_user WHERE (login = '%u' OR email = '%u') AND `disable%Ls` = 'n' AND server_id = '{server_id}'
+password_query = SELECT email as user, password, maildir as userdb_home, CONCAT( maildir_format, ':', maildir, '/', IF(maildir_format='maildir','Maildir',maildir_format)) as userdb_mail, uid as userdb_uid, gid as userdb_gid, CONCAT('*:storage=', quota, 'B') AS userdb_quota_rule, CONCAT(maildir, '/.sieve') as userdb_sieve FROM mail_user WHERE (login = '%u' OR email = '%u') AND `disable%Ls` = 'n' AND server_id = '{server_id}'
+user_query = SELECT email as user, maildir as home, CONCAT( maildir_format, ':', maildir, '/', IF(maildir_format='maildir','Maildir',maildir_format)) as mail, uid, gid, CONCAT('*:storage=', quota, 'B') AS quota_rule, CONCAT(maildir, '/.sieve') as sieve FROM mail_user WHERE (login = '%u' OR email = '%u') AND `disable%Ls` = 'n' AND server_id = '{server_id}'
 
 # The iterate_query is required for the doveadm command only and works only on dovecot 2 servers.
 # Do not enable it on Dovecot 1.x servers
diff --git a/install/tpl/fedora_dovecot-sql.conf.master b/install/tpl/fedora_dovecot-sql.conf.master
index 7e88dee6ce..3815a0eb5f 100644
--- a/install/tpl/fedora_dovecot-sql.conf.master
+++ b/install/tpl/fedora_dovecot-sql.conf.master
@@ -134,8 +134,8 @@ connect = host={mysql_server_host} dbname={mysql_server_database} user={mysql_se
 default_pass_scheme = CRYPT
 
 # password-query with prefetch
-password_query = SELECT email as user, password, maildir as userdb_home, CONCAT('maildir:', maildir, '/Maildir') as userdb_mail, uid as userdb_uid, gid as userdb_gid, CONCAT('*:storage=', quota, 'B') AS userdb_quota_rule, CONCAT(maildir, '/.sieve') as userdb_sieve FROM mail_user WHERE (login = '%u' OR email = '%u') AND `disable%Ls` = 'n' AND server_id = '{server_id}'
-user_query = SELECT email as user, maildir as home, CONCAT('maildir:', maildir, '/Maildir') as mail, uid, gid, CONCAT('*:storage=', quota, 'B') AS quota_rule, CONCAT(maildir, '/.sieve') as sieve FROM mail_user WHERE (login = '%u' OR email = '%u') AND `disable%Ls` = 'n' AND server_id = '{server_id}'
+password_query = SELECT email as user, password, maildir as userdb_home, CONCAT( maildir_format, ':', maildir, '/', IF(maildir_format='maildir','Maildir',maildir_format)) as userdb_mail, uid as userdb_uid, gid as userdb_gid, CONCAT('*:storage=', quota, 'B') AS userdb_quota_rule, CONCAT(maildir, '/.sieve') as userdb_sieve FROM mail_user WHERE (login = '%u' OR email = '%u') AND `disable%Ls` = 'n' AND server_id = '{server_id}'
+user_query = SELECT email as user, maildir as home, CONCAT( maildir_format, ':', maildir, '/', IF(maildir_format='maildir','Maildir',maildir_format)) as mail, uid, gid, CONCAT('*:storage=', quota, 'B') AS quota_rule, CONCAT(maildir, '/.sieve') as sieve FROM mail_user WHERE (login = '%u' OR email = '%u') AND `disable%Ls` = 'n' AND server_id = '{server_id}'
 
 # The iterate_query is required for the doveadm command only and works only on dovecot 2 servers.
 # Do not enable it on Dovecot 1.x servers
diff --git a/install/tpl/opensuse_dovecot-sql.conf.master b/install/tpl/opensuse_dovecot-sql.conf.master
index a28fa27f13..938975efbc 100644
--- a/install/tpl/opensuse_dovecot-sql.conf.master
+++ b/install/tpl/opensuse_dovecot-sql.conf.master
@@ -134,8 +134,8 @@ connect = host={mysql_server_host} dbname={mysql_server_database} user={mysql_se
 default_pass_scheme = CRYPT
 
 # password-query with prefetch
-password_query = SELECT email as user, password, maildir as userdb_home, CONCAT('maildir:', maildir, '/Maildir') as userdb_mail, uid as userdb_uid, gid as userdb_gid, CONCAT('*:storage=', quota, 'B') AS userdb_quota_rule, CONCAT(maildir, '/.sieve') as userdb_sieve FROM mail_user WHERE (login = '%u' OR email = '%u') AND `disable%Ls` = 'n' AND server_id = '{server_id}'
-user_query = SELECT email as user, maildir as home, CONCAT('maildir:', maildir, '/Maildir') as mail, uid, gid, CONCAT('*:storage=', quota, 'B') AS quota_rule, CONCAT(maildir, '/.sieve') as sieve FROM mail_user WHERE (login = '%u' OR email = '%u') AND `disable%Ls` = 'n' AND server_id = '{server_id}'
+password_query = SELECT email as user, password, maildir as userdb_home, CONCAT( maildir_format, ':', maildir, '/', IF(maildir_format='maildir','Maildir',maildir_format)) as userdb_mail, uid as userdb_uid, gid as userdb_gid, CONCAT('*:storage=', quota, 'B') AS userdb_quota_rule, CONCAT(maildir, '/.sieve') as userdb_sieve FROM mail_user WHERE (login = '%u' OR email = '%u') AND `disable%Ls` = 'n' AND server_id = '{server_id}'
+user_query = SELECT email as user, maildir as home, CONCAT( maildir_format, ':', maildir, '/', IF(maildir_format='maildir','Maildir',maildir_format)) as mail, uid, gid, CONCAT('*:storage=', quota, 'B') AS quota_rule, CONCAT(maildir, '/.sieve') as sieve FROM mail_user WHERE (login = '%u' OR email = '%u') AND `disable%Ls` = 'n' AND server_id = '{server_id}'
 
 # The iterate_query is required for the doveadm command only and works only on dovecot 2 servers.
 # Do not enable it on Dovecot 1.x servers
diff --git a/interface/web/admin/form/server_config.tform.php b/interface/web/admin/form/server_config.tform.php
index 838ade8979..7827b43f26 100644
--- a/interface/web/admin/form/server_config.tform.php
+++ b/interface/web/admin/form/server_config.tform.php
@@ -295,6 +295,12 @@ $form["tabs"]['mail'] = array(
 			'width' => '40',
 			'maxlength' => '255'
 		),
+		'maildir_format' => array(
+			'datatype' => 'VARCHAR',
+			'formtype' => 'SELECT',
+			'default' => '20',
+			'value' => array('maildir' => 'Maildir', 'mdbox' => 'mdbox')
+		),
 		'homedir_path' => array(
 			'datatype' => 'VARCHAR',
 			'formtype' => 'TEXT',
diff --git a/interface/web/admin/lib/lang/ar_server_config.lng b/interface/web/admin/lib/lang/ar_server_config.lng
index df6605cc2f..b03eaebfdd 100644
--- a/interface/web/admin/lib/lang/ar_server_config.lng
+++ b/interface/web/admin/lib/lang/ar_server_config.lng
@@ -19,6 +19,7 @@ $wb['fastcgi_max_requests_txt'] = 'FastCGI max. Requests';
 $wb['fastcgi_bin_txt'] = 'FastCGI Bin';
 $wb['module_txt'] = 'Module';
 $wb['maildir_path_txt'] = 'Maildir Path';
+$wb['maildir_format_txt'] = 'Maildir Format';
 $wb['homedir_path_txt'] = 'Homedir Path';
 $wb['mailuser_uid_txt'] = 'Mailuser UID';
 $wb['mailuser_gid_txt'] = 'Mailuser GID';
diff --git a/interface/web/admin/lib/lang/bg_server_config.lng b/interface/web/admin/lib/lang/bg_server_config.lng
index 9611c48852..10fbc0b3dd 100644
--- a/interface/web/admin/lib/lang/bg_server_config.lng
+++ b/interface/web/admin/lib/lang/bg_server_config.lng
@@ -17,6 +17,7 @@ $wb['fastcgi_max_requests_txt'] = 'FastCGI max. Requests';
 $wb['fastcgi_bin_txt'] = 'FastCGI Bin';
 $wb['module_txt'] = 'Модул';
 $wb['maildir_path_txt'] = 'Maildir Path';
+$wb['maildir_format_txt'] = 'Maildir Format';
 $wb['homedir_path_txt'] = 'Homedir Path';
 $wb['mailuser_uid_txt'] = 'Mailuser UID';
 $wb['mailuser_gid_txt'] = 'Mailuser GID';
diff --git a/interface/web/admin/lib/lang/br_server_config.lng b/interface/web/admin/lib/lang/br_server_config.lng
index 04e8034805..8946db1763 100644
--- a/interface/web/admin/lib/lang/br_server_config.lng
+++ b/interface/web/admin/lib/lang/br_server_config.lng
@@ -18,6 +18,7 @@ $wb['fastcgi_max_requests_txt'] = 'FastCGI: Requisições máximas';
 $wb['fastcgi_bin_txt'] = 'FastCGI Bin';
 $wb['module_txt'] = 'Módulo';
 $wb['maildir_path_txt'] = 'Caminho do diretório Maildir';
+$wb['maildir_format_txt'] = 'Maildir Format';
 $wb['homedir_path_txt'] = 'Caminho do diretório Home';
 $wb['mailuser_uid_txt'] = 'UID usuário de email';
 $wb['mailuser_gid_txt'] = 'GID usuário de email';
diff --git a/interface/web/admin/lib/lang/cz_server_config.lng b/interface/web/admin/lib/lang/cz_server_config.lng
index 80eeab8b78..c5a3dbc4f3 100644
--- a/interface/web/admin/lib/lang/cz_server_config.lng
+++ b/interface/web/admin/lib/lang/cz_server_config.lng
@@ -19,6 +19,7 @@ $wb['fastcgi_max_requests_txt'] = 'FastCGI max. požadavků';
 $wb['fastcgi_bin_txt'] = 'FastCGI cesta k binarnímu balíčku';
 $wb['module_txt'] = 'Modul';
 $wb['maildir_path_txt'] = 'Cesta k mail adresáři';
+$wb['maildir_format_txt'] = 'Maildir Format';
 $wb['homedir_path_txt'] = 'Cesta k domácímu adresáři';
 $wb['mailuser_uid_txt'] = 'Mail uživatel UID';
 $wb['mailuser_gid_txt'] = 'Mail uživatel GID';
diff --git a/interface/web/admin/lib/lang/de_server_config.lng b/interface/web/admin/lib/lang/de_server_config.lng
index f291f7cfce..336cea82d9 100644
--- a/interface/web/admin/lib/lang/de_server_config.lng
+++ b/interface/web/admin/lib/lang/de_server_config.lng
@@ -18,6 +18,7 @@ $wb['fastcgi_max_requests_txt'] = 'FastCGI max. Anfragen';
 $wb['fastcgi_bin_txt'] = 'FastCGI Bin';
 $wb['module_txt'] = 'Modul';
 $wb['maildir_path_txt'] = 'Maildir Pfad';
+$wb['maildir_format_txt'] = 'Maildir Format';
 $wb['homedir_path_txt'] = 'Homedir Pfad';
 $wb['dkim_path_txt'] = 'DKIM Pfad';
 $wb['mailuser_uid_txt'] = 'Mailbenutzer UID';
diff --git a/interface/web/admin/lib/lang/el_server_config.lng b/interface/web/admin/lib/lang/el_server_config.lng
index 6376ccfcd6..ca7cf2b26e 100644
--- a/interface/web/admin/lib/lang/el_server_config.lng
+++ b/interface/web/admin/lib/lang/el_server_config.lng
@@ -19,6 +19,7 @@ $wb['fastcgi_max_requests_txt'] = 'Όριο πλήθους αιτήσεων Fast
 $wb['fastcgi_bin_txt'] = 'FastCGI Bin';
 $wb['module_txt'] = 'Άρθρωμα';
 $wb['maildir_path_txt'] = 'Διαδρομή Maildir';
+$wb['maildir_format_txt'] = 'Maildir Format';
 $wb['homedir_path_txt'] = 'Διαδρομή Homedir';
 $wb['mailuser_uid_txt'] = 'Mailuser UID';
 $wb['mailuser_gid_txt'] = 'Mailuser GID';
diff --git a/interface/web/admin/lib/lang/en_server_config.lng b/interface/web/admin/lib/lang/en_server_config.lng
index f11a447301..2628abf292 100644
--- a/interface/web/admin/lib/lang/en_server_config.lng
+++ b/interface/web/admin/lib/lang/en_server_config.lng
@@ -29,6 +29,7 @@ $wb["fastcgi_max_requests_txt"] = 'FastCGI max. Requests';
 $wb["fastcgi_bin_txt"] = 'FastCGI Bin';
 $wb["module_txt"] = 'Module';
 $wb["maildir_path_txt"] = 'Maildir Path';
+$wb['maildir_format_txt'] = 'Maildir Format';
 $wb["homedir_path_txt"] = 'Homedir Path';
 $wb["dkim_path_txt"] = 'DKIM Path';
 $wb["mailuser_uid_txt"] = 'Mailuser UID';
diff --git a/interface/web/admin/lib/lang/es_server_config.lng b/interface/web/admin/lib/lang/es_server_config.lng
index 2d834c8422..1c91d0dd6d 100644
--- a/interface/web/admin/lib/lang/es_server_config.lng
+++ b/interface/web/admin/lib/lang/es_server_config.lng
@@ -17,6 +17,7 @@ $wb['fastcgi_max_requests_txt'] = 'Peticiones máximas de FastCGI';
 $wb['fastcgi_bin_txt'] = 'Binario de FastCGI';
 $wb['module_txt'] = 'Módulo';
 $wb['maildir_path_txt'] = 'Ruta de buzones';
+$wb['maildir_format_txt'] = 'Maildir Format';
 $wb['homedir_path_txt'] = 'Ruta base de correo';
 $wb['mailuser_uid_txt'] = 'UID del usuario de correo';
 $wb['mailuser_gid_txt'] = 'GID del usuario de correo';
diff --git a/interface/web/admin/lib/lang/fi_server_config.lng b/interface/web/admin/lib/lang/fi_server_config.lng
index 0316c47c25..8ece953fe8 100755
--- a/interface/web/admin/lib/lang/fi_server_config.lng
+++ b/interface/web/admin/lib/lang/fi_server_config.lng
@@ -17,6 +17,7 @@ $wb['fastcgi_max_requests_txt'] = 'FastCGI-pyyntöraja';
 $wb['fastcgi_bin_txt'] = 'FastCGI-binääri';
 $wb['module_txt'] = 'Ohjelmaosio';
 $wb['maildir_path_txt'] = 'Postilaatikon hakemistopolku';
+$wb['maildir_format_txt'] = 'Maildir Format';
 $wb['homedir_path_txt'] = 'Kotikansion hakemistopolku';
 $wb['mailuser_uid_txt'] = 'Käyttäjätunnus';
 $wb['mailuser_gid_txt'] = 'Käyttäjäryhmä';
diff --git a/interface/web/admin/lib/lang/fr_server_config.lng b/interface/web/admin/lib/lang/fr_server_config.lng
index 247dc7fee3..d566538a5c 100644
--- a/interface/web/admin/lib/lang/fr_server_config.lng
+++ b/interface/web/admin/lib/lang/fr_server_config.lng
@@ -17,6 +17,7 @@ $wb['fastcgi_max_requests_txt'] = 'Nombre maximal de requês FastCGI';
 $wb['fastcgi_bin_txt'] = 'Exétable FastCGI';
 $wb['module_txt'] = 'Module';
 $wb['maildir_path_txt'] = 'Chemin Maildir';
+$wb['maildir_format_txt'] = 'Maildir Format';
 $wb['homedir_path_txt'] = 'Chemin Homedir';
 $wb['mailuser_uid_txt'] = 'UID de l\'utilisateur mail';
 $wb['mailuser_gid_txt'] = 'GID de l\'utilisateur mail';
diff --git a/interface/web/admin/lib/lang/hr_server_config.lng b/interface/web/admin/lib/lang/hr_server_config.lng
index 38b5b08a68..4a73d3f63a 100644
--- a/interface/web/admin/lib/lang/hr_server_config.lng
+++ b/interface/web/admin/lib/lang/hr_server_config.lng
@@ -18,6 +18,7 @@ $wb['fastcgi_max_requests_txt'] = 'Maks. broj FastCGI zahtjeva';
 $wb['fastcgi_bin_txt'] = 'FastCGI Bin';
 $wb['module_txt'] = 'Modul';
 $wb['maildir_path_txt'] = 'Put do Maildir-a';
+$wb['maildir_format_txt'] = 'Maildir Format';
 $wb['homedir_path_txt'] = 'Put do početne stranice';
 $wb['mailuser_uid_txt'] = 'Mailuser UID';
 $wb['mailuser_gid_txt'] = 'Mailuser GID';
diff --git a/interface/web/admin/lib/lang/hu_server_config.lng b/interface/web/admin/lib/lang/hu_server_config.lng
index f59e19d733..b29b74413d 100644
--- a/interface/web/admin/lib/lang/hu_server_config.lng
+++ b/interface/web/admin/lib/lang/hu_server_config.lng
@@ -17,6 +17,7 @@ $wb['fastcgi_max_requests_txt'] = 'FastCGI max. Requests';
 $wb['fastcgi_bin_txt'] = 'FastCGI Bin';
 $wb['module_txt'] = 'Modul';
 $wb['maildir_path_txt'] = 'Maildir Path';
+$wb['maildir_format_txt'] = 'Maildir Format';
 $wb['homedir_path_txt'] = 'Homedir Path';
 $wb['mailuser_uid_txt'] = 'Mailuser UID';
 $wb['mailuser_gid_txt'] = 'Mailuser GID';
diff --git a/interface/web/admin/lib/lang/id_server_config.lng b/interface/web/admin/lib/lang/id_server_config.lng
index d2b7ce95dc..930a58cbf7 100644
--- a/interface/web/admin/lib/lang/id_server_config.lng
+++ b/interface/web/admin/lib/lang/id_server_config.lng
@@ -19,6 +19,7 @@ $wb['fastcgi_max_requests_txt'] = 'Maks. Request FastCGI';
 $wb['fastcgi_bin_txt'] = 'FastCGI Bin';
 $wb['module_txt'] = 'Modul';
 $wb['maildir_path_txt'] = 'Path Direktori Mail';
+$wb['maildir_format_txt'] = 'Maildir Format';
 $wb['homedir_path_txt'] = 'Path Direktori Home';
 $wb['mailuser_uid_txt'] = 'UID Pengguna Mail';
 $wb['mailuser_gid_txt'] = 'GID Pengguna Mail';
diff --git a/interface/web/admin/lib/lang/it_server_config.lng b/interface/web/admin/lib/lang/it_server_config.lng
index f2327c218a..cba103ff83 100644
--- a/interface/web/admin/lib/lang/it_server_config.lng
+++ b/interface/web/admin/lib/lang/it_server_config.lng
@@ -16,6 +16,7 @@ $wb['fastcgi_max_requests_txt'] = 'FastCGI max. Requests';
 $wb['fastcgi_bin_txt'] = 'FastCGI Bin';
 $wb['module_txt'] = 'Module';
 $wb['maildir_path_txt'] = 'Maildir Path';
+$wb['maildir_format_txt'] = 'Maildir Format';
 $wb['homedir_path_txt'] = 'Homedir Path';
 $wb['mailuser_uid_txt'] = 'Mailuser UID';
 $wb['mailuser_gid_txt'] = 'Mailuser GID';
diff --git a/interface/web/admin/lib/lang/ja_server_config.lng b/interface/web/admin/lib/lang/ja_server_config.lng
index 375dbaff94..37fb09ac5d 100644
--- a/interface/web/admin/lib/lang/ja_server_config.lng
+++ b/interface/web/admin/lib/lang/ja_server_config.lng
@@ -19,6 +19,7 @@ $wb['fastcgi_max_requests_txt'] = 'FastCGI 最大リクエスト数';
 $wb['fastcgi_bin_txt'] = 'FastCGI実行ファイル';
 $wb['module_txt'] = 'モジュール';
 $wb['maildir_path_txt'] = 'メールディレクトリ';
+$wb['maildir_format_txt'] = 'Maildir Format';
 $wb['homedir_path_txt'] = 'ホームディレクトリ';
 $wb['mailuser_uid_txt'] = 'メールユーザーのUID';
 $wb['mailuser_gid_txt'] = 'メールユーザーのGID';
diff --git a/interface/web/admin/lib/lang/nl_server_config.lng b/interface/web/admin/lib/lang/nl_server_config.lng
index ea33db0d82..44eea44022 100644
--- a/interface/web/admin/lib/lang/nl_server_config.lng
+++ b/interface/web/admin/lib/lang/nl_server_config.lng
@@ -19,6 +19,7 @@ $wb['fastcgi_max_requests_txt'] = 'FastCGI max. gequests';
 $wb['fastcgi_bin_txt'] = 'FastCGI bin';
 $wb['module_txt'] = 'Module';
 $wb['maildir_path_txt'] = 'Maildir pad';
+$wb['maildir_format_txt'] = 'Maildir Format';
 $wb['homedir_path_txt'] = 'Homedir pad';
 $wb['mailuser_uid_txt'] = 'Mailuser UID';
 $wb['mailuser_gid_txt'] = 'Mailuser GID';
diff --git a/interface/web/admin/lib/lang/pl_server_config.lng b/interface/web/admin/lib/lang/pl_server_config.lng
index 7e51ab2e2b..5e17c41c53 100644
--- a/interface/web/admin/lib/lang/pl_server_config.lng
+++ b/interface/web/admin/lib/lang/pl_server_config.lng
@@ -19,6 +19,7 @@ $wb['fastcgi_max_requests_txt'] = 'Maksymalna ilość zadań FastCGI';
 $wb['fastcgi_bin_txt'] = 'Kosz FastCGI';
 $wb['module_txt'] = 'Moduł';
 $wb['maildir_path_txt'] = 'Adres poczty e-mail';
+$wb['maildir_format_txt'] = 'Maildir Format';
 $wb['homedir_path_txt'] = 'Bazowy adres poczty e-mail';
 $wb['mailuser_uid_txt'] = 'UID użytkownika e-mail';
 $wb['mailuser_gid_txt'] = 'GID użytkownika e-mail';
diff --git a/interface/web/admin/lib/lang/pt_server_config.lng b/interface/web/admin/lib/lang/pt_server_config.lng
index 3696aa6d70..adf708552f 100644
--- a/interface/web/admin/lib/lang/pt_server_config.lng
+++ b/interface/web/admin/lib/lang/pt_server_config.lng
@@ -18,6 +18,7 @@ $wb['fastcgi_max_requests_txt'] = 'FastCGI: Requisições máximas';
 $wb['fastcgi_bin_txt'] = 'FastCGI Bin';
 $wb['module_txt'] = 'Módulo';
 $wb['maildir_path_txt'] = 'Pasta do Maildir';
+$wb['maildir_format_txt'] = 'Maildir Format';
 $wb['homedir_path_txt'] = 'Pasta Home';
 $wb['mailuser_uid_txt'] = 'UID utilizador de email';
 $wb['mailuser_gid_txt'] = 'GID utilizador de email';
diff --git a/interface/web/admin/lib/lang/ro_server_config.lng b/interface/web/admin/lib/lang/ro_server_config.lng
index 1f0907109b..a7ab9bc889 100644
--- a/interface/web/admin/lib/lang/ro_server_config.lng
+++ b/interface/web/admin/lib/lang/ro_server_config.lng
@@ -18,6 +18,7 @@ $wb['fastcgi_max_requests_txt'] = 'FastCGI max. Requests';
 $wb['fastcgi_bin_txt'] = 'FastCGI Bin';
 $wb['module_txt'] = 'Module';
 $wb['maildir_path_txt'] = 'Maildir Path';
+$wb['maildir_format_txt'] = 'Maildir Format';
 $wb['homedir_path_txt'] = 'Homedir Path';
 $wb['mailuser_uid_txt'] = 'Mailuser UID';
 $wb['mailuser_gid_txt'] = 'Mailuser GID';
diff --git a/interface/web/admin/lib/lang/ru_server_config.lng b/interface/web/admin/lib/lang/ru_server_config.lng
index 8358162a9e..6a4080a12b 100644
--- a/interface/web/admin/lib/lang/ru_server_config.lng
+++ b/interface/web/admin/lib/lang/ru_server_config.lng
@@ -16,6 +16,7 @@ $wb['fastcgi_max_requests_txt'] = 'Макс.запросов для FastCGI';
 $wb['fastcgi_bin_txt'] = 'FastCGI Bin';
 $wb['module_txt'] = 'Модуль';
 $wb['maildir_path_txt'] = 'Путь Maildir';
+$wb['maildir_format_txt'] = 'Maildir Format';
 $wb['homedir_path_txt'] = 'Путь Homedir';
 $wb['mailuser_uid_txt'] = 'Mailuser UID';
 $wb['mailuser_gid_txt'] = 'Mailuser GID';
diff --git a/interface/web/admin/lib/lang/se_server_config.lng b/interface/web/admin/lib/lang/se_server_config.lng
index 34d19128aa..5818cfacb3 100644
--- a/interface/web/admin/lib/lang/se_server_config.lng
+++ b/interface/web/admin/lib/lang/se_server_config.lng
@@ -17,6 +17,7 @@ $wb['fastcgi_max_requests_txt'] = 'FastCGI max. Requests';
 $wb['fastcgi_bin_txt'] = 'FastCGI Bin';
 $wb['module_txt'] = 'Module';
 $wb['maildir_path_txt'] = 'Maildir Path';
+$wb['maildir_format_txt'] = 'Maildir Format';
 $wb['homedir_path_txt'] = 'Homedir Path';
 $wb['mailuser_uid_txt'] = 'Mailuser UID';
 $wb['mailuser_gid_txt'] = 'Mailuser GID';
diff --git a/interface/web/admin/lib/lang/sk_server_config.lng b/interface/web/admin/lib/lang/sk_server_config.lng
index c0bebe463a..392664b7e2 100644
--- a/interface/web/admin/lib/lang/sk_server_config.lng
+++ b/interface/web/admin/lib/lang/sk_server_config.lng
@@ -19,6 +19,7 @@ $wb['fastcgi_max_requests_txt'] = 'FastCGI max. Requests';
 $wb['fastcgi_bin_txt'] = 'FastCGI Bin';
 $wb['module_txt'] = 'Modul';
 $wb['maildir_path_txt'] = 'Maildir Cesta';
+$wb['maildir_format_txt'] = 'Maildir Format';
 $wb['homedir_path_txt'] = 'Cesta k domovskému adresáru';
 $wb['mailuser_uid_txt'] = 'Mailuser UID';
 $wb['mailuser_gid_txt'] = 'Mailuser GID';
diff --git a/interface/web/admin/lib/lang/tr_server_config.lng b/interface/web/admin/lib/lang/tr_server_config.lng
index 4a50f56eee..60a24ee48b 100644
--- a/interface/web/admin/lib/lang/tr_server_config.lng
+++ b/interface/web/admin/lib/lang/tr_server_config.lng
@@ -19,6 +19,7 @@ $wb['fastcgi_max_requests_txt'] = 'FastCGI max. Requests';
 $wb['fastcgi_bin_txt'] = 'FastCGI Bin';
 $wb['module_txt'] = 'Modül';
 $wb['maildir_path_txt'] = 'Mail dizini yolu';
+$wb['maildir_format_txt'] = 'Maildir Format';
 $wb['homedir_path_txt'] = 'Kullanıcı dizini yolu';
 $wb['mailuser_uid_txt'] = 'Mail kullanıcısı UID';
 $wb['mailuser_gid_txt'] = 'Mail kullanıcısı GID';
diff --git a/interface/web/admin/templates/server_config_mail_edit.htm b/interface/web/admin/templates/server_config_mail_edit.htm
index e07606929f..926be8e62c 100644
--- a/interface/web/admin/templates/server_config_mail_edit.htm
+++ b/interface/web/admin/templates/server_config_mail_edit.htm
@@ -14,6 +14,12 @@
             <div class="form-group">
                 <label for="maildir_path" class="col-sm-3 control-label">{tmpl_var name='maildir_path_txt'}</label>
                 <div class="col-sm-9"><input type="text" name="maildir_path" id="maildir_path" value="{tmpl_var name='maildir_path'}" class="form-control" /></div></div>
+            <div class="form-group">
+				<label class="col-sm-3 control-label">{tmpl_var name='maildir_format_txt'}</label>
+				<div class="col-sm-9"><select name="maildir_format" id="maildir_format" class="form-control">
+						{tmpl_var name='maildir_format'}
+					</select></div>
+			</div>
             <div class="form-group">
                 <label for="homedir_path" class="col-sm-3 control-label">{tmpl_var name='homedir_path_txt'}</label>
                 <div class="col-sm-9"><input type="text" name="homedir_path" id="homedir_path" value="{tmpl_var name='homedir_path'}" class="form-control" /></div></div>
diff --git a/interface/web/mail/mail_user_edit.php b/interface/web/mail/mail_user_edit.php
index ddc0ceb893..ff92115874 100644
--- a/interface/web/mail/mail_user_edit.php
+++ b/interface/web/mail/mail_user_edit.php
@@ -207,6 +207,16 @@ class page_action extends tform_actions {
 		$app->uses('getconf');
 		$mail_config = $app->getconf->get_server_config(!empty($domain["server_id"]) ? $domain["server_id"] : '', 'mail');
 
+		// Set Maildir format
+		if ($this->id == 0) {
+			$this->dataRecord['maildir_format'] = $sys_config['maildir_format'];
+		}
+		else {
+			// restore Maildir format
+			$tmp = $app->db->queryOneRecord("SELECT maildir_format FROM mail_user WHERE mailuser_id = ".$app->functions->intval($this->id));
+			$this->dataRecord['maildir_format'] = $tmp['maildir_format'];
+		}
+		
 		//* compose the email field
 		if(isset($_POST["email_local_part"]) && isset($_POST["email_domain"])) {
 			$this->dataRecord["email"] = strtolower($_POST["email_local_part"]."@".$app->functions->idn_encode($_POST["email_domain"]));
diff --git a/server/lib/classes/cron.d/500-backup_mail.inc.php b/server/lib/classes/cron.d/500-backup_mail.inc.php
index 81e39ed0cc..e16cce19ee 100644
--- a/server/lib/classes/cron.d/500-backup_mail.inc.php
+++ b/server/lib/classes/cron.d/500-backup_mail.inc.php
@@ -31,6 +31,7 @@ class cronjob_backup_mail extends cronjob {
 
 	// job schedule
 	protected $_schedule = '0 0 * * *';
+	private $tmp_backup_dir = '';
 
 	/* this function is optional if it contains no custom code */
 	public function onPrepare() {
@@ -111,23 +112,46 @@ class cronjob_backup_mail extends cronjob {
 
 						$mail_backup_file = 'mail'.$rec['mailuser_id'].'_'.date('Y-m-d_H-i');
 
-						$domain_dir=explode('/',$rec['maildir']); 
-						$_temp=array_pop($domain_dir);unset($_temp);
-						$domain_dir=implode('/',$domain_dir);
-						
-						$parts=explode('/',$rec['maildir']);
-						$source_dir=array_pop($parts);
-						unset($parts);
-
-						//* create archives
-						if($backup_mode == 'userzip') {
-							$mail_backup_file.='.zip';
-							exec('cd '.$domain_dir.' && zip '.$mail_backup_dir.'/'.$mail_backup_file.' -b /tmp -r '.$source_dir.' > /dev/null', $tmp_output, $retval);
-						} else {
-							/* Create a tar.gz backup */
-							$mail_backup_file.='.tar.gz';
-							exec(escapeshellcmd('tar pczf '.$mail_backup_dir.'/'.$mail_backup_file.' --directory '.$domain_dir.' '.$source_dir), $tmp_output, $retval);
+						// in case of mdbox -> create backup with doveadm before zipping
+						if ($rec['maildir_format'] == 'mdbox') {
+							if (empty($this->tmp_backup_dir)) $this->tmp_backup_dir = $rec['maildir'];
+							// Create temporary backup-mailbox
+							exec("su -c 'dsync backup -u \"".$rec["email"]."\" mdbox:".$this->tmp_backup_dir."/backup'", $tmp_output, $retval);
+		
+							if($backup_mode == 'userzip') {
+								$mail_backup_file.='.zip';
+								exec('cd '.$this->tmp_backup_dir.' && zip '.$mail_backup_dir.'/'.$mail_backup_file.' -b /tmp -r backup > /dev/null && rm -rf backup', $tmp_output, $retval);
+							}
+							else {
+								$mail_backup_file.='.tar.gz';
+								exec(escapeshellcmd('tar pczf '.$mail_backup_dir.'/'.$mail_backup_file.' --directory '.$this->tmp_backup_dir.' backup && rm -rf '.$this->tmp_backup_dir.'/backup'), $tmp_output, $retval);
+							}
+							
+							if ($retval != 0) {
+								// Cleanup
+								if (file_exists($this->tmp_backup_dir.'/backup')) exec('rm -rf '.$this->tmp_backup_dir.'/backup');
+							}
+						}
+						else {
+							$domain_dir=explode('/',$rec['maildir']);
+							$_temp=array_pop($domain_dir);unset($_temp);
+							$domain_dir=implode('/',$domain_dir);
+							
+							$parts=explode('/',$rec['maildir']);
+							$source_dir=array_pop($parts);
+							unset($parts);
+							
+							//* create archives
+							if($backup_mode == 'userzip') {
+								$mail_backup_file.='.zip';
+								exec('cd '.$domain_dir.' && zip '.$mail_backup_dir.'/'.$mail_backup_file.' -b /tmp -r '.$source_dir.' > /dev/null', $tmp_output, $retval);
+							} else {
+								/* Create a tar.gz backup */
+								$mail_backup_file.='.tar.gz';
+								exec(escapeshellcmd('tar pczf '.$mail_backup_dir.'/'.$mail_backup_file.' --directory '.$domain_dir.' '.$source_dir), $tmp_output, $retval);
+							}
 						}
+						
 						if($retval == 0){
 							chown($mail_backup_dir.'/'.$mail_backup_file, $backupusername);
 							chgrp($mail_backup_dir.'/'.$mail_backup_file, $backupgroup);
@@ -141,6 +165,10 @@ class cronjob_backup_mail extends cronjob {
 						} else {
 							/* Backup failed - remove archive */
 							if(is_file($mail_backup_dir.'/'.$mail_backup_file)) unlink($mail_backup_dir.'/'.$mail_backup_file);
+							// And remove backup-mdbox
+							if ($rec['maildir_format'] == 'mdbox') {
+								if(file_exists($rec['maildir'].'/backup'))  exec("su -c 'rm -rf ".$rec['maildir']."/backup'");
+							}
 							$app->log($mail_backup_file.' NOK:'.implode('',$tmp_output), LOGLEVEL_DEBUG);
 						}
 						/* Remove old backups */
diff --git a/server/plugins-available/backup_plugin.inc.php b/server/plugins-available/backup_plugin.inc.php
index 5b46930b10..380b7de2f5 100644
--- a/server/plugins-available/backup_plugin.inc.php
+++ b/server/plugins-available/backup_plugin.inc.php
@@ -204,27 +204,68 @@ class backup_plugin {
 					chown($domain_dir, $mail_config['mailuser_name']);
 					chgrp($domain_dir, $mail_config['mailuser_group']);
 				}
+				if (!is_dir($record['maildir'])) {
+					mkdir($record['maildir'], 0700); //* never create the full path
+					chown($record['maildir'], $mail_config['mailuser_name']);
+					chgrp($record['maildir'], $mail_config['mailuser_group']);
+				}
 			
-				if(file_exists($mail_backup_file) && $record['homedir'] != '' && $record['homedir'] != '/' && !stristr($mail_backup_file,'..') && !stristr($mail_backup_file,'etc') && $mail_config['homedir_path'] == $record['homedir'] && is_dir($domain_dir)) {
-					if($mail_backup['backup_mode'] == 'userzip') {
-						copy($mail_backup_file, $domain_dir.'/'.$mail_backup['filename']);
-						chgrp($domain_dir.'/'.$mail_backup['filename'], $mail_config['mailuser_group']);
-						$command = 'sudo -u '.$mail_config['mailuser_name'].' unzip -qq -o  '.escapeshellarg($domain_dir.'/'.$mail_backup['filename']).' -d '.escapeshellarg($domain_dir).' 2> /dev/null';
-						exec($command,$tmp_output, $retval);
-						unlink($domain_dir.'/'.$mail_backup['filename']);
+				if(file_exists($mail_backup_file) && $record['homedir'] != '' && $record['homedir'] != '/' && !stristr($mail_backup_file,'..') && !stristr($mail_backup_file,'etc') && $mail_config['homedir_path'] == $record['homedir'] && is_dir($domain_dir) && is_dir($record['maildir'])) {
+					if ($record['maildir_format'] == 'mdbox') {
+						$retval = -1;
+						// First unzip backupfile to local backup-folder
+						if($mail_backup['backup_mode'] == 'userzip') {
+							copy($mail_backup_file, $record['maildir'].'/'.$mail_backup['filename']);
+							chgrp($record['maildir'].'/'.$mail_backup['filename'], $mail_config['mailuser_group']);
+							$command = 'sudo -u '.$mail_config['mailuser_name'].' unzip -qq -o  '.escapeshellarg($record['maildir'].'/'.$mail_backup['filename']).' -d '.escapeshellarg($record['maildir']).' 2> /dev/null';
+							exec($command,$tmp_output, $retval);
+							unlink($record['maildir'].'/'.$mail_backup['filename']);
+						}
+						if($mail_backup['backup_mode'] == 'rootgz') {
+							$command='tar xfz '.escapeshellarg($mail_backup_file).' --directory '.escapeshellarg($record['maildir']);
+							exec($command,$tmp_output, $retval);
+						}
+						
+						if($retval == 0) {
+							// Now import backup-mailbox into special backup-folder
+							$backupname = "backup-".date("Y-m-d", $mail_backup['tstamp']);
+							exec("doveadm mailbox create -u \"".$record["email"]."\" $backupname");
+							exec("doveadm import -u \"".$record["email"]."\" mdbox:".$record['maildir']."/backup $backupname all", $tmp_output, $retval);
+							exec("for f in `doveadm mailbox list -u \"".$record["email"]."\" $backupname*`; do doveadm mailbox subscribe -u \"".$record["email"]."\" \$f; done", $tmp_output, $retval);
+							exec('rm -rf '.$record['maildir'].'/backup');
+						}
+						
 						if($retval == 0){
 							$app->log('Restored Mail backup '.$mail_backup_file,LOGLEVEL_DEBUG);
 						} else {
+							// cleanup
+							if (file_exists($record['maildir'].'/'.$mail_backup['filename'])) unlink($record['maildir'].'/'.$mail_backup['filename']);
+							if (file_exists($record['maildir']."/backup")) exec('rm -rf '.$record['maildir']."/backup");
+							
 							$app->log('Unable to restore Mail backup '.$mail_backup_file.' '.$tmp_output,LOGLEVEL_ERROR);
 						}
 					}
-					if($mail_backup['backup_mode'] == 'rootgz') {
-						$command='tar xfz '.escapeshellarg($mail_backup_file).' --directory '.escapeshellarg($domain_dir);
-						exec($command,$tmp_output, $retval);
-						if($retval == 0){
-							$app->log('Restored Mail backup '.$mail_backup_file,LOGLEVEL_DEBUG);
-						} else {
-							$app->log('Unable to restore Mail backup '.$mail_backup_file.' '.$tmp_output,LOGLEVEL_ERROR);
+					else {
+						if($mail_backup['backup_mode'] == 'userzip') {
+							copy($mail_backup_file, $domain_dir.'/'.$mail_backup['filename']);
+							chgrp($domain_dir.'/'.$mail_backup['filename'], $mail_config['mailuser_group']);
+							$command = 'sudo -u '.$mail_config['mailuser_name'].' unzip -qq -o  '.escapeshellarg($domain_dir.'/'.$mail_backup['filename']).' -d '.escapeshellarg($domain_dir).' 2> /dev/null';
+							exec($command,$tmp_output, $retval);
+							unlink($domain_dir.'/'.$mail_backup['filename']);
+							if($retval == 0){
+								$app->log('Restored Mail backup '.$mail_backup_file,LOGLEVEL_DEBUG);
+							} else {
+								$app->log('Unable to restore Mail backup '.$mail_backup_file.' '.$tmp_output,LOGLEVEL_ERROR);
+							}
+						}
+						if($mail_backup['backup_mode'] == 'rootgz') {
+							$command='tar xfz '.escapeshellarg($mail_backup_file).' --directory '.escapeshellarg($domain_dir);
+							exec($command,$tmp_output, $retval);
+							if($retval == 0){
+								$app->log('Restored Mail backup '.$mail_backup_file,LOGLEVEL_DEBUG);
+							} else {
+								$app->log('Unable to restore Mail backup '.$mail_backup_file.' '.$tmp_output,LOGLEVEL_ERROR);
+							}
 						}
 					}
 				}
diff --git a/server/plugins-available/mail_plugin.inc.php b/server/plugins-available/mail_plugin.inc.php
index 9b94fc20ce..faa89f1cd7 100644
--- a/server/plugins-available/mail_plugin.inc.php
+++ b/server/plugins-available/mail_plugin.inc.php
@@ -130,67 +130,80 @@ class mail_plugin {
 			$app->log('Created Directory: '.$base_path, LOGLEVEL_DEBUG);
 		}
 
-		// Dovecot uses a different mail layout with a separate 'Maildir' subdirectory.
-		if($mail_config['pop3_imap_daemon'] == 'dovecot') {
-			//exec("su -c 'mkdir -p ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
-			$app->system->mkdirpath($maildomain_path, 0700, $user, $group);
-			$app->log('Created Directory: '.$maildomain_path, LOGLEVEL_DEBUG);
-			$maildomain_path .= '/Maildir';
+		if ($data['new']['maildir_format'] == 'mdbox') {
+			exec("su -c 'doveadm mailbox create -u \"".$data["new"]["email"]."\" INBOX'");
+			exec("su -c 'doveadm mailbox create -u \"".$data["new"]["email"]."\" Sent'");
+			exec("su -c 'doveadm mailbox create -u \"".$data["new"]["email"]."\" Trash'");
+			exec("su -c 'doveadm mailbox create -u \"".$data["new"]["email"]."\" Junk'");
+			exec("su -c 'doveadm mailbox create -u \"".$data["new"]["email"]."\" Drafts'");
+			
+			exec("su -c 'doveadm mailbox subscribe -u \"".$data["new"]["email"]."\" INBOX'");
+			exec("su -c 'doveadm mailbox subscribe -u \"".$data["new"]["email"]."\" Sent'");
+			exec("su -c 'doveadm mailbox subscribe -u \"".$data["new"]["email"]."\" Trash'");
+			exec("su -c 'doveadm mailbox subscribe -u \"".$data["new"]["email"]."\" Junk'");
+			exec("su -c 'doveadm mailbox subscribe -u \"".$data["new"]["email"]."\" Drafts'");
 		}
-
-		//* When the mail user dir exists but it is not a valid maildir, move it to corrupted maildir folder
-		if(!empty($maildomain_path) && is_dir($maildomain_path) && !is_dir($maildomain_path.'/new') && !is_dir($maildomain_path.'/cur')) {
-			if(!is_dir($mail_config['homedir_path'].'/corrupted/'.$data['new']['mailuser_id'])) $app->system->mkdirpath($mail_config['homedir_path'].'/corrupted/'.$data['new']['mailuser_id'], 0700, $mail_config['mailuser_name'], $mail_config['mailuser_group']);
-			exec("su -c 'mv -f ".escapeshellcmd($data['new']['maildir'])." ".$mail_config['homedir_path'].'/corrupted/'.$data['new']['mailuser_id']."' vmail");
-			$app->log('Moved invalid maildir to corrupted Maildirs folder: '.escapeshellcmd($data['new']['maildir']), LOGLEVEL_WARN);
-		}
-
-		//* Create the maildir, if it doesn not exist, set permissions, set quota.
-		if(!empty($maildomain_path) && !is_dir($maildomain_path)) {
-
-			//exec("su -c 'maildirmake ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
-			$app->system->maildirmake($maildomain_path, $user, '', $group);
-
-			//* This is to fix the maildrop quota not being rebuilt after the quota is changed.
-			if($mail_config['pop3_imap_daemon'] != 'dovecot') {
-				if(is_dir($maildomain_path)) exec("su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($maildomain_path)."' ".$user); // Avoid maildirmake quota bug, see debian bug #214911
-				$app->log('Created Maildir: '."su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($maildomain_path)."' ".$user, LOGLEVEL_DEBUG);
+		else {
+			// Dovecot uses a different mail layout with a separate 'Maildir' subdirectory.
+			if($mail_config['pop3_imap_daemon'] == 'dovecot') {
+				$app->system->mkdirpath($maildomain_path, 0700, $user, $group);
+				$app->log('Created Directory: '.$maildomain_path, LOGLEVEL_DEBUG);
+				$maildomain_path .= '/Maildir';
 			}
-		}
-
-		if(!is_dir($data['new']['maildir'].'/.Sent')) {
-			//exec("su -c 'maildirmake -f Sent ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
-			//$app->log('Created submaildir Sent: '."su -c 'maildirmake -f Sent ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
-			$app->system->maildirmake($maildomain_path, $user, 'Sent', $group);
-		}
-		if(!is_dir($data['new']['maildir'].'/.Drafts')) {
-			//exec("su -c 'maildirmake -f Drafts ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
-			//$app->log('Created submaildir Drafts: '."su -c 'maildirmake -f Drafts ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
-			$app->system->maildirmake($maildomain_path, $user, 'Drafts', $group);
-		}
-		if(!is_dir($data['new']['maildir'].'/.Trash')) {
-			//exec("su -c 'maildirmake -f Trash ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
-			//$app->log('Created submaildir Trash: '."su -c 'maildirmake -f Trash ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
-			$app->system->maildirmake($maildomain_path, $user, 'Trash', $group);
-		}
-		if(!is_dir($data['new']['maildir'].'/.Junk')) {
-			//exec("su -c 'maildirmake -f Junk ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
-			//$app->log('Created submaildir Junk: '."su -c 'maildirmake -f Junk ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
-			$app->system->maildirmake($maildomain_path, $user, 'Junk', $group);
-		}
-
-		// Set permissions now recursive
-		exec('chown -R '.$user.':'.$group.' '.escapeshellcmd($data['new']['maildir']));
-		$app->log('Set ownership on '.escapeshellcmd($data['new']['maildir']), LOGLEVEL_DEBUG);
-
-		//* Set the maildir quota
-		if(is_dir($data['new']['maildir'].'/new') && $mail_config['pop3_imap_daemon'] != 'dovecot') {
-			if($data['new']['quota'] > 0) {
-				if(is_dir($data['new']['maildir'])) exec("su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($data['new']['maildir'])."' ".$user);
-				$app->log('Set Maildir quota: '."su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($data['new']['maildir'])."' ".$user, LOGLEVEL_DEBUG);
+					
+			//* When the mail user dir exists but it is not a valid maildir, move it to corrupted maildir folder
+			if(!empty($maildomain_path) && is_dir($maildomain_path) && !is_dir($maildomain_path.'/new') && !is_dir($maildomain_path.'/cur')) {
+				if(!is_dir($mail_config['homedir_path'].'/corrupted/'.$data['new']['mailuser_id'])) $app->system->mkdirpath($mail_config['homedir_path'].'/corrupted/'.$data['new']['mailuser_id'], 0700, $mail_config['mailuser_name'], $mail_config['mailuser_group']);
+				exec("su -c 'mv -f ".escapeshellcmd($data['new']['maildir'])." ".$mail_config['homedir_path'].'/corrupted/'.$data['new']['mailuser_id']."' vmail");
+				$app->log('Moved invalid maildir to corrupted Maildirs folder: '.escapeshellcmd($data['new']['maildir']), LOGLEVEL_WARN);
+			}
+	
+			//* Create the maildir, if it doesn not exist, set permissions, set quota.
+			if(!empty($maildomain_path) && !is_dir($maildomain_path)) {
+	
+				//exec("su -c 'maildirmake ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
+				$app->system->maildirmake($maildomain_path, $user, '', $group);
+	
+				//* This is to fix the maildrop quota not being rebuilt after the quota is changed.
+				if($mail_config['pop3_imap_daemon'] != 'dovecot') {
+					if(is_dir($maildomain_path)) exec("su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($maildomain_path)."' ".$user); // Avoid maildirmake quota bug, see debian bug #214911
+					$app->log('Created Maildir: '."su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($maildomain_path)."' ".$user, LOGLEVEL_DEBUG);
+				}
+			}
+	
+			if(!is_dir($data['new']['maildir'].'/.Sent')) {
+				//exec("su -c 'maildirmake -f Sent ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
+				//$app->log('Created submaildir Sent: '."su -c 'maildirmake -f Sent ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
+				$app->system->maildirmake($maildomain_path, $user, 'Sent', $group);
+			}
+			if(!is_dir($data['new']['maildir'].'/.Drafts')) {
+				//exec("su -c 'maildirmake -f Drafts ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
+				//$app->log('Created submaildir Drafts: '."su -c 'maildirmake -f Drafts ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
+				$app->system->maildirmake($maildomain_path, $user, 'Drafts', $group);
+			}
+			if(!is_dir($data['new']['maildir'].'/.Trash')) {
+				//exec("su -c 'maildirmake -f Trash ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
+				//$app->log('Created submaildir Trash: '."su -c 'maildirmake -f Trash ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
+				$app->system->maildirmake($maildomain_path, $user, 'Trash', $group);
+			}
+			if(!is_dir($data['new']['maildir'].'/.Junk')) {
+				//exec("su -c 'maildirmake -f Junk ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
+				//$app->log('Created submaildir Junk: '."su -c 'maildirmake -f Junk ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
+				$app->system->maildirmake($maildomain_path, $user, 'Junk', $group);
+			}
+	
+			// Set permissions now recursive
+			exec('chown -R '.$user.':'.$group.' '.escapeshellcmd($data['new']['maildir']));
+			$app->log('Set ownership on '.escapeshellcmd($data['new']['maildir']), LOGLEVEL_DEBUG);
+	
+			//* Set the maildir quota
+			if(is_dir($data['new']['maildir'].'/new') && $mail_config['pop3_imap_daemon'] != 'dovecot') {
+				if($data['new']['quota'] > 0) {
+					if(is_dir($data['new']['maildir'])) exec("su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($data['new']['maildir'])."' ".$user);
+					$app->log('Set Maildir quota: '."su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($data['new']['maildir'])."' ".$user, LOGLEVEL_DEBUG);
+				}
 			}
 		}
-		
 
 		//* Send the welcome email message
 		if(file_exists($conf['rootpath'].'/conf-custom/mail/welcome_email_'.$conf['language'].'.txt')) {
@@ -252,6 +265,9 @@ class mail_plugin {
 		}
 		*/
 
+		// Maildir-Format must not be changed on this way !!
+		$data['new']['maildir_format'] = $data['old']['maildir_format'];
+		
 		$maildomain_path = $data['new']['maildir'];
 		$tmp_basepath = $data['new']['maildir'];
 		$tmp_basepath_parts = explode('/', $tmp_basepath);
@@ -296,86 +312,117 @@ class mail_plugin {
 			$app->log('Created Directory: '.$base_path, LOGLEVEL_DEBUG);
 		}
 
-		// Dovecot uses a different mail layout with a separate 'Maildir' subdirectory.
-		if($mail_config['pop3_imap_daemon'] == 'dovecot') {
-			$app->system->mkdirpath($maildomain_path, 0700, $user, $group);
-			$app->log('Created Directory: '.$base_path, LOGLEVEL_DEBUG);
-			$maildomain_path .= '/Maildir';
-		}
-
-		//* When the mail user dir exists but it is not a valid maildir, move it to corrupted maildir folder
-		if(!empty($maildomain_path) && is_dir($maildomain_path) && !is_dir($maildomain_path.'/new') && !is_dir($maildomain_path.'/cur')) {
-			if(!is_dir($mail_config['homedir_path'].'/corrupted/'.$data['new']['mailuser_id'])) $app->system->mkdirpath($mail_config['homedir_path'].'/corrupted/'.$data['new']['mailuser_id'], 0700, $mail_config['mailuser_name'], $mail_config['mailuser_group']);
-			exec("su -c 'mv -f ".escapeshellcmd($data['new']['maildir'])." ".$mail_config['homedir_path'].'/corrupted/'.$data['new']['mailuser_id']."' vmail");
-			$app->log('Moved invalid maildir to corrupted Maildirs folder: '.escapeshellcmd($data['new']['maildir']), LOGLEVEL_WARN);
+		if ($data['new']['maildir_format'] == 'mdbox') {
+			// Move mailbox, if domain has changed and delete old mailbox
+			if($data['new']['maildir'] != $data['old']['maildir'] && is_dir($data['old']['maildir'])) {
+				if(is_dir($data['new']['maildir'])) {
+					exec("rm -fr ".escapeshellcmd($data['new']['maildir']));
+					//rmdir($data['new']['maildir']);
+				}
+				exec('mv -f '.escapeshellcmd($data['old']['maildir']).' '.escapeshellcmd($data['new']['maildir']));
+				// exec('mv -f '.escapeshellcmd($data['old']['maildir']).'/* '.escapeshellcmd($data['new']['maildir']));
+				// if(is_file($data['old']['maildir'].'.ispconfig_mailsize'))exec('mv -f '.escapeshellcmd($data['old']['maildir']).'.ispconfig_mailsize '.escapeshellcmd($data['new']['maildir']));
+				// rmdir($data['old']['maildir']);
+				$app->log('Moved Maildir from: '.$data['old']['maildir'].' to '.$data['new']['maildir'], LOGLEVEL_DEBUG);
+			}
+				
+			//* Create the maildir, if it doesn not exist, set permissions, set quota.
+			if(!is_dir($data['new']['maildir'].'/mdbox')) {
+				exec("su -c 'doveadm mailbox create -u \"".$data["new"]["email"]."\" INBOX'");
+				exec("su -c 'doveadm mailbox create -u \"".$data["new"]["email"]."\" Sent'");
+				exec("su -c 'doveadm mailbox create -u \"".$data["new"]["email"]."\" Trash'");
+				exec("su -c 'doveadm mailbox create -u \"".$data["new"]["email"]."\" Junk'");
+				exec("su -c 'doveadm mailbox create -u \"".$data["new"]["email"]."\" Drafts'");
+					
+				exec("su -c 'doveadm mailbox subscribe -u \"".$data["new"]["email"]."\" INBOX'");
+				exec("su -c 'doveadm mailbox subscribe -u \"".$data["new"]["email"]."\" Sent'");
+				exec("su -c 'doveadm mailbox subscribe -u \"".$data["new"]["email"]."\" Trash'");
+				exec("su -c 'doveadm mailbox subscribe -u \"".$data["new"]["email"]."\" Junk'");
+				exec("su -c 'doveadm mailbox subscribe -u \"".$data["new"]["email"]."\" Drafts'");
+			}
 		}
-
-		//* Create the maildir, if it doesn not exist, set permissions, set quota.
-		if(!empty($maildomain_path) && !is_dir($maildomain_path.'/new')) {
-			//exec("su -c 'maildirmake ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
-			//$app->log("Created Maildir "."su -c 'maildirmake ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
-			$app->system->maildirmake($maildomain_path, $user, '', $group);
-
-			//* This is to fix the maildrop quota not being rebuilt after the quota is changed.
-			if($mail_config['pop3_imap_daemon'] != 'dovecot') {
+		else {
+			// Dovecot uses a different mail layout with a separate 'Maildir' subdirectory.
+			if($mail_config['pop3_imap_daemon'] == 'dovecot') {
+				$app->system->mkdirpath($maildomain_path, 0700, $user, $group);
+				$app->log('Created Directory: '.$base_path, LOGLEVEL_DEBUG);
+				$maildomain_path .= '/Maildir';
+			}
+	
+			//* When the mail user dir exists but it is not a valid maildir, move it to corrupted maildir folder
+			if(!empty($maildomain_path) && is_dir($maildomain_path) && !is_dir($maildomain_path.'/new') && !is_dir($maildomain_path.'/cur')) {
+				if(!is_dir($mail_config['homedir_path'].'/corrupted/'.$data['new']['mailuser_id'])) $app->system->mkdirpath($mail_config['homedir_path'].'/corrupted/'.$data['new']['mailuser_id'], 0700, $mail_config['mailuser_name'], $mail_config['mailuser_group']);
+				exec("su -c 'mv -f ".escapeshellcmd($data['new']['maildir'])." ".$mail_config['homedir_path'].'/corrupted/'.$data['new']['mailuser_id']."' vmail");
+				$app->log('Moved invalid maildir to corrupted Maildirs folder: '.escapeshellcmd($data['new']['maildir']), LOGLEVEL_WARN);
+			}
+	
+			//* Create the maildir, if it doesn not exist, set permissions, set quota.
+			if(!empty($maildomain_path) && !is_dir($maildomain_path.'/new')) {
+				//exec("su -c 'maildirmake ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
+				//$app->log("Created Maildir "."su -c 'maildirmake ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
+				$app->system->maildirmake($maildomain_path, $user, '', $group);
+	
+				//* This is to fix the maildrop quota not being rebuilt after the quota is changed.
+				if($mail_config['pop3_imap_daemon'] != 'dovecot') {
+					if($data['new']['quota'] > 0) {
+						if(is_dir($maildomain_path)) exec("su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($maildomain_path)."' ".$user); // Avoid maildirmake quota bug, see debian bug #214911
+						$app->log('Updated Maildir quota: '."su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($maildomain_path)."' ".$user, LOGLEVEL_DEBUG);
+					} else {
+						if(file_exists($data['new']['maildir'].'/maildirsize')) unlink($data['new']['maildir'].'/maildirsize');
+						$app->log('Set Maildir quota to unlimited.', LOGLEVEL_DEBUG);
+					}
+				}
+			}
+	
+			if(!is_dir($data['new']['maildir'].'/.Sent')) {
+				//exec("su -c 'maildirmake -f Sent ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
+				//$app->log('Created submaildir Sent: '."su -c 'maildirmake -f Sent ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
+				$app->system->maildirmake($maildomain_path, $user, 'Sent', $group);
+			}
+			if(!is_dir($data['new']['maildir'].'/.Drafts')) {
+				//exec("su -c 'maildirmake -f Drafts ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
+				//$app->log('Created submaildir Drafts: '."su -c 'maildirmake -f Drafts ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
+				$app->system->maildirmake($maildomain_path, $user, 'Drafts', $group);
+			}
+			if(!is_dir($data['new']['maildir'].'/.Trash')) {
+				//exec("su -c 'maildirmake -f Trash ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
+				//$app->log('Created submaildir Trash: '."su -c 'maildirmake -f Trash ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
+				$app->system->maildirmake($maildomain_path, $user, 'Trash', $group);
+			}
+			if(!is_dir($data['new']['maildir'].'/.Junk')) {
+				//exec("su -c 'maildirmake -f Junk ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
+				//$app->log('Created submaildir Junk: '."su -c 'maildirmake -f Junk ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
+				$app->system->maildirmake($maildomain_path, $user, 'Junk', $group);
+			}
+	
+			// Set permissions now recursive
+			exec('chown -R '.$user.':'.$group.' '.escapeshellcmd($data['new']['maildir']));
+			$app->log('Set ownership on '.escapeshellcmd($data['new']['maildir']), LOGLEVEL_DEBUG);
+	
+			// Move mailbox, if domain has changed and delete old mailbox
+			if($data['new']['maildir'] != $data['old']['maildir'] && is_dir($data['old']['maildir'])) {
+				if(is_dir($data['new']['maildir'])) {
+					exec("rm -fr ".escapeshellcmd($data['new']['maildir']));
+					//rmdir($data['new']['maildir']);
+				}
+				exec('mv -f '.escapeshellcmd($data['old']['maildir']).' '.escapeshellcmd($data['new']['maildir']));
+				// exec('mv -f '.escapeshellcmd($data['old']['maildir']).'/* '.escapeshellcmd($data['new']['maildir']));
+				// if(is_file($data['old']['maildir'].'.ispconfig_mailsize'))exec('mv -f '.escapeshellcmd($data['old']['maildir']).'.ispconfig_mailsize '.escapeshellcmd($data['new']['maildir']));
+				// rmdir($data['old']['maildir']);
+				$app->log('Moved Maildir from: '.$data['old']['maildir'].' to '.$data['new']['maildir'], LOGLEVEL_DEBUG);
+			}
+			//This is to fix the maildrop quota not being rebuilt after the quota is changed.
+			// Courier Layout
+			if(is_dir($data['new']['maildir'].'/new') && $mail_config['pop3_imap_daemon'] != 'dovecot') {
 				if($data['new']['quota'] > 0) {
-					if(is_dir($maildomain_path)) exec("su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($maildomain_path)."' ".$user); // Avoid maildirmake quota bug, see debian bug #214911
-					$app->log('Updated Maildir quota: '."su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($maildomain_path)."' ".$user, LOGLEVEL_DEBUG);
+					if(is_dir($data['new']['maildir'])) exec("su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($data['new']['maildir'])."' ".$user);
+					$app->log('Updated Maildir quota: '."su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($data['new']['maildir'])."' ".$user, LOGLEVEL_DEBUG);
 				} else {
 					if(file_exists($data['new']['maildir'].'/maildirsize')) unlink($data['new']['maildir'].'/maildirsize');
 					$app->log('Set Maildir quota to unlimited.', LOGLEVEL_DEBUG);
 				}
 			}
 		}
-
-		if(!is_dir($data['new']['maildir'].'/.Sent')) {
-			//exec("su -c 'maildirmake -f Sent ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
-			//$app->log('Created submaildir Sent: '."su -c 'maildirmake -f Sent ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
-			$app->system->maildirmake($maildomain_path, $user, 'Sent', $group);
-		}
-		if(!is_dir($data['new']['maildir'].'/.Drafts')) {
-			//exec("su -c 'maildirmake -f Drafts ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
-			//$app->log('Created submaildir Drafts: '."su -c 'maildirmake -f Drafts ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
-			$app->system->maildirmake($maildomain_path, $user, 'Drafts', $group);
-		}
-		if(!is_dir($data['new']['maildir'].'/.Trash')) {
-			//exec("su -c 'maildirmake -f Trash ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
-			//$app->log('Created submaildir Trash: '."su -c 'maildirmake -f Trash ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
-			$app->system->maildirmake($maildomain_path, $user, 'Trash', $group);
-		}
-		if(!is_dir($data['new']['maildir'].'/.Junk')) {
-			//exec("su -c 'maildirmake -f Junk ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
-			//$app->log('Created submaildir Junk: '."su -c 'maildirmake -f Junk ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
-			$app->system->maildirmake($maildomain_path, $user, 'Junk', $group);
-		}
-
-		// Set permissions now recursive
-		exec('chown -R '.$user.':'.$group.' '.escapeshellcmd($data['new']['maildir']));
-		$app->log('Set ownership on '.escapeshellcmd($data['new']['maildir']), LOGLEVEL_DEBUG);
-
-		// Move mailbox, if domain has changed and delete old mailbox
-		if($data['new']['maildir'] != $data['old']['maildir'] && is_dir($data['old']['maildir'])) {
-			if(is_dir($data['new']['maildir'])) {
-				exec("rm -fr ".escapeshellcmd($data['new']['maildir']));
-				//rmdir($data['new']['maildir']);
-			}
-			exec('mv -f '.escapeshellcmd($data['old']['maildir']).' '.escapeshellcmd($data['new']['maildir']));
-			// exec('mv -f '.escapeshellcmd($data['old']['maildir']).'/* '.escapeshellcmd($data['new']['maildir']));
-			// if(is_file($data['old']['maildir'].'.ispconfig_mailsize'))exec('mv -f '.escapeshellcmd($data['old']['maildir']).'.ispconfig_mailsize '.escapeshellcmd($data['new']['maildir']));
-			// rmdir($data['old']['maildir']);
-			$app->log('Moved Maildir from: '.$data['old']['maildir'].' to '.$data['new']['maildir'], LOGLEVEL_DEBUG);
-		}
-		//This is to fix the maildrop quota not being rebuilt after the quota is changed.
-		// Courier Layout
-		if(is_dir($data['new']['maildir'].'/new') && $mail_config['pop3_imap_daemon'] != 'dovecot') {
-			if($data['new']['quota'] > 0) {
-				if(is_dir($data['new']['maildir'])) exec("su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($data['new']['maildir'])."' ".$user);
-				$app->log('Updated Maildir quota: '."su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($data['new']['maildir'])."' ".$user, LOGLEVEL_DEBUG);
-			} else {
-				if(file_exists($data['new']['maildir'].'/maildirsize')) unlink($data['new']['maildir'].'/maildirsize');
-				$app->log('Set Maildir quota to unlimited.', LOGLEVEL_DEBUG);
-			}
-		}
 	}
 
 	function user_delete($event_name, $data) {
-- 
GitLab