cfoe
2012-05-22 0ae667e6cfdd1bcc85bacf85cd93a84f99fa88f8
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';
      }
@@ -152,9 +152,49 @@
      
      //* Set the maildir quota
      if(is_dir($data['new']['maildir'].'/new') && $mail_config['pop3_imap_daemon'] != 'dovecot') {
         exec("su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($data['new']['maildir'])."' ".$mail_config['mailuser_name']);
         $app->log('Set Maildir quota: '."su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($data['new']['maildir'])."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
         if($data['new']['quota'] > 0) {
            exec("su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($data['new']['maildir'])."' ".$mail_config['mailuser_name']);
            $app->log('Set Maildir quota: '."su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($data['new']['maildir'])."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
         }
      }
      //* Send the welcome email message
      if(file_exists($conf['rootpath'].'/conf-custom/mail/welcome_email_'.$conf['language'].'.txt')) {
         $lines = file($conf['rootpath'].'/conf-custom/mail/welcome_email_'.$conf['language'].'.txt');
      } elseif(file_exists($conf['rootpath'].'/conf-custom/mail/welcome_email_en.txt')) {
         $lines = file($conf['rootpath'].'/conf-custom/mail/welcome_email_en.txt');
      } elseif(file_exists($conf['rootpath'].'/conf/mail/welcome_email_'.$conf['language'].'.txt')) {
         $lines = file($conf['rootpath'].'/conf/mail/welcome_email_'.$conf['language'].'.txt');
      } else {
         $lines = file($conf['rootpath'].'/conf/mail/welcome_email_en.txt');
      }
      //* Get from address
      $parts = explode(':',trim($lines[0]));
      unset($parts[0]);
      $welcome_mail_from  = implode(':',$parts);
      unset($lines[0]);
      //* Get subject
      $parts = explode(':',trim($lines[1]));
      unset($parts[0]);
      $welcome_mail_subject  = implode(':',$parts);
      unset($lines[1]);
      //* Get message
      $welcome_mail_message = trim(implode($lines));
      unset($tmp);
      $mailHeaders      = "MIME-Version: 1.0" . "\n";
      $mailHeaders     .= "Content-type: text/plain; charset=utf-8" . "\n";
      $mailHeaders     .= "Content-Transfer-Encoding: 8bit" . "\n";
      $mailHeaders     .= "From: $welcome_mail_from" . "\n";
      $mailHeaders     .= "Reply-To: $welcome_mail_from" . "\n";
      $mailTarget       = $data["new"]["email"];
      $mailSubject      = "=?utf-8?B?".base64_encode($welcome_mail_subject)."?=";
      mail($mailTarget, $mailSubject, $welcome_mail_message, $mailHeaders);
   }
   
   function user_update($event_name,$data) {
@@ -185,13 +225,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';
      }
@@ -212,8 +253,13 @@
         $app->log('Set ownership on '.escapeshellcmd($data['new']['maildir']),LOGLEVEL_DEBUG);
         //* This is to fix the maildrop quota not being rebuilt after the quota is changed.
         if($mail_config['pop3_imap_daemon'] != 'dovecot') {
            exec("su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']); // Avoid maildirmake quota bug, see debian bug #214911
            $app->log('Updated Maildir quota: '."su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
            if($data['new']['quota'] > 0) {
               exec("su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']); // Avoid maildirmake quota bug, see debian bug #214911
               $app->log('Updated Maildir quota: '."su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
            } else {
               if(file_exists($data['new']['maildir'].'/maildirsize')) unlink($data['new']['maildir'].'/maildirsize');
               $app->log('Set Maildir quota to unlimited.',LOGLEVEL_DEBUG);
            }
         }
      }
      
@@ -253,8 +299,13 @@
      //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') {
         exec("su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($data['new']['maildir'])."' ".$mail_config['mailuser_name']);
         $app->log('Updated Maildir quota: '."su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($data['new']['maildir'])."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
         if($data['new']['quota'] > 0) {
            exec("su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($data['new']['maildir'])."' ".$mail_config['mailuser_name']);
            $app->log('Updated Maildir quota: '."su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($data['new']['maildir'])."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
         } else {
            if(file_exists($data['new']['maildir'].'/maildirsize')) unlink($data['new']['maildir'].'/maildirsize');
            $app->log('Set Maildir quota to unlimited.',LOGLEVEL_DEBUG);
         }
      }
   }