@@ -74,30 +74,31 @@ function onLoad() {
7474 function user_insert ($ event_name ,$ data ) {
7575 global $ app , $ conf ;
7676
77- // get the config
77+ //* get the config
7878 $ app ->uses ("getconf " );
7979 $ mail_config = $ app ->getconf ->get_server_config ($ conf ["server_id " ], 'mail ' );
8080
81- // Create the maildir, if it does not exist
82- if (!empty ($ data ['new ' ]['maildir ' ]) && !is_dir ($ data ['new ' ]['maildir ' ])) {
83- $ tmp_path = $ data ['new ' ]['maildir ' ];
84- $ tmp_path_parts = explode ('/ ' ,$ tmp_path );
85- unset($ tmp_path_parts [count ($ tmp_path_parts )-2 ]);
86- $ maildomain_path = implode ('/ ' ,$ tmp_path_parts );
87- if (!is_dir ($ maildomain_path )) {
88- exec ("su -c 'mkdir -p " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ]);
89- $ app ->log ('Created Directory: ' .$ maildomain_path ,LOGLEVEL_DEBUG );
90- }
91- exec ("su -c 'maildirmake " .escapeshellcmd ($ data ['new ' ]['maildir ' ])."' " .$ mail_config ['mailuser_name ' ]);
92- $ app ->log ('Executed: ' ."su -c 'maildirmake " .escapeshellcmd ($ data ['new ' ]['maildir ' ])."' " .$ mail_config ['mailuser_name ' ],LOGLEVEL_DEBUG );
93- //exec('maildirmake '.escapeshellcmd($data['new']['maildir']));
94- exec ('chown -R ' .$ mail_config ['mailuser_name ' ].': ' .$ mail_config ['mailuser_group ' ].' ' .escapeshellcmd ($ data ['new ' ]['maildir ' ]));
95- $ app ->log ('Created Maildir: ' .$ data ['new ' ]['maildir ' ],LOGLEVEL_DEBUG );
81+ $ maildomain_path = $ data ['new ' ]['maildir ' ];
82+ $ tmp_basepath = $ data ['new ' ]['maildir ' ];
83+ $ tmp_basepath_parts = explode ('/ ' ,$ tmp_basepath );
84+ unset($ tmp_basepath_parts [count ($ tmp_basepath_parts )-1 ]);
85+ $ base_path = implode ('/ ' ,$ tmp_basepath_parts );
86+
87+ //* Create the mail domain directory, if it does not exist
88+ if (!empty ($ base_path ) && !is_dir ($ base_path )) {
89+ exec ("su -c 'mkdir -p " .escapeshellcmd ($ base_path )."' " .$ mail_config ['mailuser_name ' ]);
90+ $ app ->log ('Created Directory: ' .$ base_path ,LOGLEVEL_DEBUG );
9691 }
97- //This is to fix the maildrop quota not being rebuilt after the quota is changed.
98- exec ("su -c 'maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .escapeshellcmd ($ data ['new ' ]['maildir ' ])."' " .$ mail_config ['mailuser_name ' ]);
99- $ app ->log ('Created Maildir: ' ."su -c 'maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .escapeshellcmd ($ data ['new ' ]['maildir ' ])."' " .$ mail_config ['mailuser_name ' ],LOGLEVEL_DEBUG );
100-
92+
93+ //* Create the maildir, if it doesn not exist, set permissions, set quota.
94+ if (!empty ($ maildomain_path ) && !is_dir ($ maildomain_path )) {
95+ exec ("su -c 'maildirmake " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ]);
96+ exec ('chown -R ' .$ mail_config ['mailuser_name ' ].': ' .$ mail_config ['mailuser_group ' ].' ' .escapeshellcmd ($ data ['new ' ]['maildir ' ]));
97+ $ app ->log ("Set ownership on " .escapeshellcmd ($ data ['new ' ]['maildir ' ]),LOGLEVEL_DEBUG );
98+ //* This is to fix the maildrop quota not being rebuilt after the quota is changed.
99+ exec ("su -c 'maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ]); // Avoid maildirmake quota bug, see debian bug #214911
100+ $ app ->log ('Created Maildir: ' ."su -c 'maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ],LOGLEVEL_DEBUG );
101+ }
101102 }
102103
103104 function user_update ($ event_name ,$ data ) {
@@ -116,9 +117,14 @@ function user_update($event_name,$data) {
116117
117118 // Move mailbox, if domain has changed and delete old mailbox
118119 if ($ data ['new ' ]['maildir ' ] != $ data ['old ' ]['maildir ' ] && is_dir ($ data ['old ' ]['maildir ' ])) {
119- exec ('mv -f ' .escapeshellcmd ($ data ['old ' ]['maildir ' ]).'/* ' .escapeshellcmd ($ data ['new ' ]['maildir ' ]));
120- if (is_file ($ data ['old ' ]['maildir ' ].'.ispconfig_mailsize ' ))exec ('mv -f ' .escapeshellcmd ($ data ['old ' ]['maildir ' ]).'.ispconfig_mailsize ' .escapeshellcmd ($ data ['new ' ]['maildir ' ]));
121- rmdir ($ data ['old ' ]['maildir ' ]);
120+ if (is_dir ($ data ['new ' ]['maildir ' ])) {
121+ exec ("rm -f " .escapeshellcmd ($ data ['new ' ]['maildir ' ]).'/* ' );
122+ rmdir ($ data ['new ' ]['maildir ' ]);
123+ }
124+ exec ('mv -f ' .escapeshellcmd ($ data ['old ' ]['maildir ' ]).' ' .escapeshellcmd ($ data ['new ' ]['maildir ' ]));
125+ // exec('mv -f '.escapeshellcmd($data['old']['maildir']).'/* '.escapeshellcmd($data['new']['maildir']));
126+ // if(is_file($data['old']['maildir'].'.ispconfig_mailsize'))exec('mv -f '.escapeshellcmd($data['old']['maildir']).'.ispconfig_mailsize '.escapeshellcmd($data['new']['maildir']));
127+ // rmdir($data['old']['maildir']);
122128 $ app ->log ('Moved Maildir from: ' .$ data ['old ' ]['maildir ' ].' to ' .$ data ['new ' ]['maildir ' ],LOGLEVEL_DEBUG );
123129 }
124130 //This is to fix the maildrop quota not being rebuilt after the quota is changed.
0 commit comments