tbrehm
2012-01-25 b38c883e1dd580bca91469fcd77415bbe2fcb942
Improved maildir path creation code as part of FS#1984
2 files modified
31 ■■■■ changed files
server/lib/classes/system.inc.php 18 ●●●●● patch | view | raw | blame | history
server/plugins-available/mail_plugin.inc.php 13 ●●●● patch | view | raw | blame | history
server/lib/classes/system.inc.php
@@ -1253,6 +1253,24 @@
        $app->log('Created Maildir '.$maildir_path.' with subfolder: '.$subfolder,LOGLEVEL_DEBUG);
        
    }
    //* Function to create directory paths and chown them to a user and group
    function mkdirpath($path, $mode = 0755, $user = '', $group = '') {
        $path_parts = explode('/',$path);
        $new_path = '';
        if(is_array($path_parts)) {
            foreach($path_parts as $part) {
                $new_path .= '/'.$part;
                if(!@is_dir($new_path)) {
                    mkdir($new_path);
                    chmod($new_path,$mode);
                    if($user != '') chown($new_path,$user);
                    if($group != '') chgrp($new_path,$group);
                }
            }
        }
    }
}
?>
server/plugins-available/mail_plugin.inc.php
@@ -91,18 +91,18 @@
        $tmp_basepath_parts = explode('/',$tmp_basepath);
        unset($tmp_basepath_parts[count($tmp_basepath_parts)-1]);
        $base_path = implode('/',$tmp_basepath_parts);
        //* Create the mail domain directory, if it does not exist
        if(!empty($base_path) && !is_dir($base_path)) {
            exec("su -c 'mkdir -p ".escapeshellcmd($base_path)."' ".$mail_config['mailuser_name']);
            //exec("su -c 'mkdir -p ".escapeshellcmd($base_path)."' ".$mail_config['mailuser_name']);
            $app->system->mkdirpath($base_path, 0700, $mail_config['mailuser_name'], $mail_config['mailuser_group']);
            $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']);
            //exec("su -c 'mkdir -p ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
            $app->system->mkdirpath($maildomain_path, 0700, $mail_config['mailuser_name'], $mail_config['mailuser_group']);
            $app->log('Created Directory: '.$maildomain_path,LOGLEVEL_DEBUG);
            $maildomain_path .= '/Maildir';
        }
@@ -221,13 +221,14 @@
        //* Create the mail domain directory, if it does not exist
        if(!empty($base_path) && !is_dir($base_path)) {
            exec("su -c 'mkdir -p ".escapeshellcmd($base_path)."' ".$mail_config['mailuser_name']);
            //exec("su -c 'mkdir -p ".escapeshellcmd($base_path)."' ".$mail_config['mailuser_name']);
            $app->system->mkdirpath($base_path, 0700, $mail_config['mailuser_name'], $mail_config['mailuser_group']);
            $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, $mail_config['mailuser_name'], $mail_config['mailuser_group']);
            $app->log('Created Directory: '.$base_path,LOGLEVEL_DEBUG);
            $maildomain_path .= '/Maildir';
        }