Till Brehm
2016-05-26 7de9c4d3213536399c1b4eb794f9e668f4084752
server/plugins-available/mail_plugin.inc.php
@@ -98,10 +98,10 @@
         if ($mail_config["mailbox_virtual_uidgid_maps"] == 'y') {
            $app->log('Map uid to linux-user',LOGLEVEL_DEBUG);
            $email_parts = explode('@',$data['new']['email']);
            $webdomain = $app->db->queryOneRecord("SELECT domain_id, server_id, system_user, parent_domain_id FROM web_domain WHERE domain = '".$app->db->quote($email_parts[1])."'");
            $webdomain = $app->db->queryOneRecord("SELECT domain_id, server_id, system_user, parent_domain_id FROM web_domain WHERE domain = ?", $email_parts[1]);
            if ($webdomain) {
               while (($webdomain['system_user'] == null) && ($webdomain['parent_domain_id'] != 0)) {
                  $webdomain = $app->db->queryOneRecord("SELECT domain_id, server_id, system_user, parent_domain_id FROM web_domain WHERE domain_id = '".$webdomain['parent_domain_id']."'");
                  $webdomain = $app->db->queryOneRecord("SELECT domain_id, server_id, system_user, parent_domain_id FROM web_domain WHERE domain_id = ?", $webdomain['parent_domain_id']);
               }
               $app->log($data['new']['server_id'].' == '.$webdomain['server_id'],LOGLEVEL_DEBUG);
@@ -118,7 +118,7 @@
      $app->log('Mailuser uid: '.$data['new']['uid'].', gid: '.$data['new']['gid'],LOGLEVEL_DEBUG);
      // update DB if values changed
      $app->db->query("UPDATE mail_user SET uid = ".$data['new']['uid'].", gid = ".$data['new']['gid']." WHERE mailuser_id = ".$data['new']['mailuser_id']);
      $app->db->query("UPDATE mail_user SET uid = ?, gid = ? WHERE mailuser_id = ?", $data['new']['uid'], $data['new']['gid'], $data['new']['mailuser_id']);
      // now get names of uid and gid
      $user = $app->system->getuser($data['new']['uid']);
@@ -206,7 +206,19 @@
      }
      //* Send the welcome email message
      if(file_exists($conf['rootpath'].'/conf-custom/mail/welcome_email_'.$conf['language'].'.txt')) {
      $tmp = explode('@', $data["new"]["email"]);
      $domain = $tmp[1];
      unset($tmp);
      $html = false;
      if(file_exists($conf['rootpath'].'/conf-custom/mail/welcome_email_'.$domain.'.html')) {
         $lines = file($conf['rootpath'].'/conf-custom/mail/welcome_email_'.$domain.'.html');
         $html = true;
      } elseif(file_exists($conf['rootpath'].'/conf-custom/mail/welcome_email_'.$conf['language'].'.html')) {
         $lines = file($conf['rootpath'].'/conf-custom/mail/welcome_email_'.$conf['language'].'.html');
         $html = true;
      } elseif(file_exists($conf['rootpath'].'/conf-custom/mail/welcome_email_'.$domain.'.txt')) {
         $lines = file($conf['rootpath'].'/conf-custom/mail/welcome_email_'.$domain.'.txt');
      } elseif(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');
@@ -233,8 +245,13 @@
      unset($tmp);
      $mailHeaders      = "MIME-Version: 1.0" . "\n";
      $mailHeaders     .= "Content-type: text/plain; charset=utf-8" . "\n";
      $mailHeaders     .= "Content-Transfer-Encoding: 8bit" . "\n";
      if($html) {
         $mailHeaders     .= "Content-Type: text/html; charset=utf-8" . "\n";
         $mailHeaders     .= "Content-Transfer-Encoding: quoted-printable" . "\n";
      } else {
         $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"];
@@ -280,10 +297,10 @@
         if ($mail_config["mailbox_virtual_uidgid_maps"] == 'y') {
            $app->log('Map uid to linux-user',LOGLEVEL_DEBUG);
            $email_parts = explode('@',$data['new']['email']);
            $webdomain = $app->db->queryOneRecord("SELECT domain_id, server_id, system_user, parent_domain_id FROM web_domain WHERE domain = '".$app->db->quote($email_parts[1])."'");
            $webdomain = $app->db->queryOneRecord("SELECT domain_id, server_id, system_user, parent_domain_id FROM web_domain WHERE domain = ?", $email_parts[1]);
            if ($webdomain) {
               while ($webdomain['parent_domain_id'] != 0) {
                  $webdomain = $app->db->queryOneRecord("SELECT domain_id, server_id, system_user, parent_domain_id FROM web_domain WHERE domain_id = '".$webdomain['parent_domain_id']."'");
                  $webdomain = $app->db->queryOneRecord("SELECT domain_id, server_id, system_user, parent_domain_id FROM web_domain WHERE domain_id = ?", $webdomain['parent_domain_id']);
               }
               $app->log($data['new']['server_id'].' == '.$webdomain['server_id'],LOGLEVEL_DEBUG);
@@ -300,7 +317,7 @@
      $app->log('Mailuser uid: '.$data['new']['uid'].', gid: '.$data['new']['gid'],LOGLEVEL_DEBUG);
      // update DB if values changed
      $app->db->query("UPDATE mail_user SET uid = ".$data['new']['uid'].", gid = ".$data['new']['gid']." WHERE mailuser_id = ".$data['new']['mailuser_id']);
      $app->db->query("UPDATE mail_user SET uid = ?, gid = ? WHERE mailuser_id = ?", $data['new']['uid'], $data['new']['gid'], $data['new']['mailuser_id']);
      $user = $app->system->getuser($data['new']['uid']);
      $group = $app->system->getgroup($data['new']['gid']);
@@ -451,7 +468,9 @@
         if( $server_config['backup_dir_is_mount'] == 'y' && !$app->system->mount_backup_dir($backup_dir) ) $mount_backup = false;
         if($mount_backup){
            $sql = "SELECT * FROM mail_domain WHERE domain = ?";
            $domain_rec = $app->db->queryOneRecord($sql, explode("@",$data['old']['email'])[1]);
            $tmp = explode("@",$data['old']['email']);
            $domain_rec = $app->db->queryOneRecord($sql,$tmp[1]);
            unset($tmp);
            if (is_array($domain_rec)) {
               $mail_backup_dir = $backup_dir.'/mail'.$domain_rec['domain_id'];
               $mail_backup_files = 'mail'.$data['old']['mailuser_id'];