Code

Backport from trunk
[gosa.git] / gosa-plugins / mail / personal / mail / class_mailAccount.inc
index 2abcabb7cae8aadc6fe883785625a8fe009b7706..1d3993a1dca3468f42cd1e203e80e3ace9dc3d26 100644 (file)
@@ -43,11 +43,30 @@ Functions :
 
  */
 
+/*
+
+    FLAG    POSTNAME                DESC
+    ####################################################################################################
+    L  (!)  only_local              Enables: "User is only allowed to send and receive local mails"
+
+                                    <REVERSED> If checked in the ui, the flag is not present in the 
+                                     gosaMailDeliveryMode attribute. If its unchecked in the ui, the 
+                                     character 'L' is added to the delivery flags.
+
+    R       use_mailsize_limit      Enables rule: "Reject mails bigger than [n] MB";
+    S       use_spam_filter         Enables rule: "Move mails tagged with SPAM level greater than [n] 
+                                     to folder [x]"
+    V       use_vacation            Enables: "Vacation message"
+    C       own_script              Enables: "Use custom sieve script (disables all Mail options!)"
+    I       drop_own_mails          Enables: "No delivery to own mailbox."
+
+*/
+
 class mailAccount extends plugin
 {
   /* Definitions */
   var $plHeadline     = "Mail";
-  var $plDescription  = "This does something";
+  var $plDescription  = "Manage personal mail settings";
   var $view_logged    = FALSE;
   var $is_account     = FALSE;
   var $initially_was_account = FALSE;
@@ -135,7 +154,7 @@ class mailAccount extends plugin
 
     /* Initialize configured values 
      */ 
-    if($this->is_account){
+    if($this->is_account && !$this->is_template){
 
       if($this->mailMethod->connect() && $this->mailMethod->account_exists()){
 
@@ -168,7 +187,7 @@ class mailAccount extends plugin
         if($this->mailMethod->domainSelectionEnabled()){
           $this->mailDomainPart = preg_replace("/^[^@]*+@/","",$this->mail);
           $this->mail = preg_replace("/@.*$/","\\1",$this->mail);
-          if(!in_array($this->mailDomainPart,$this->mailDomainParts)){
+          if(!in_array_strict($this->mailDomainPart,$this->mailDomainParts)){
             $this->mailDomainParts[] = $this->mailDomainPart;
           }
         }
@@ -295,7 +314,7 @@ class mailAccount extends plugin
         $list = $this->mailAddressSelect->save();
         foreach ($list as $entry){
           $val = $entry['mail'][0];
-          if (!in_array ($val, $this->gosaMailAlternateAddress) && $val != $this->mail){
+          if (!in_array_strict($val, $this->gosaMailAlternateAddress) && $val != $this->mail){
             $this->addForwarder($val);
             $this->is_modified= TRUE;
           }
@@ -318,9 +337,9 @@ class mailAccount extends plugin
       return($this->mailAddressSelect->execute());
     }
 
-    if (isset($_POST['add_forwarder'])){
-      if ($_POST['forward_address'] != ""){
-        $address= $_POST['forward_address'];
+    if (isset($_POST['add_forwarder']) && isset($_POST['forward_address'])){
+      if (!empty($_POST['forward_address'])){
+        $address= get_post('forward_address');
         $valid= FALSE;
         if (!tests::is_email($address)){
           if (!tests::is_email($address, TRUE)){
@@ -332,7 +351,7 @@ class mailAccount extends plugin
             }
           }
         } elseif ($address == $this->mail
-            || in_array($address, $this->gosaMailAlternateAddress)) {
+            || in_array_strict($address, $this->gosaMailAlternateAddress)) {
           msg_dialog::display(_("Error"),_("Cannot add primary address to the list of forwarders!") , ERROR_DIALOG);
         } else {
           $valid= TRUE;
@@ -345,7 +364,7 @@ class mailAccount extends plugin
         }
       }
     }
-    if (isset($_POST['delete_forwarder'])){
+    if (isset($_POST['delete_forwarder']) && isset($_POST['forwarder_list'])){
       $this->delForwarder ($_POST['forwarder_list']);
     }
     if ($this->mailAddressSelect instanceOf mailAddressSelect){
@@ -373,7 +392,7 @@ class mailAccount extends plugin
       } else {
         $valid= TRUE;
       }
-      if ($valid && ($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
+      if ($valid && ($user= $this->addAlternate (get_post('alternate_address'))) != ""){
         $ui= get_userinfo();
         $addon= "";
         if ($user[0] == "!") {
@@ -404,28 +423,28 @@ class mailAccount extends plugin
       $smarty->assign("$name"."ACL", $this->getacl($name));
     }
     foreach($this->attributes as $attr){
-      $smarty->assign($attr,$this->$attr);
+      $smarty->assign($attr,set_post($this->$attr));
     }
     $smarty->assign("quotaEnabled", $this->mailMethod->quotaEnabled());
     if($this->mailMethod->quotaEnabled()){
       $smarty->assign("quotaUsage",   mailMethod::quota_to_image($this->quotaUsage,$this->gosaMailQuota));
-      $smarty->assign("gosaMailQuota",$this->gosaMailQuota);
+      $smarty->assign("gosaMailQuota",set_post($this->gosaMailQuota));
     }
     $smarty->assign("domainSelectionEnabled", $this->mailMethod->domainSelectionEnabled());
-    $smarty->assign("MailDomains", $this->mailDomainParts);
-    $smarty->assign("MailDomain" , $this->mailDomainPart);
-    $smarty->assign("MailServers", $this->mailMethod->getMailServers());
+    $smarty->assign("MailDomains", set_post($this->mailDomainParts));
+    $smarty->assign("MailDomain" , set_post($this->mailDomainPart));
+    $smarty->assign("MailServers", set_post($this->mailMethod->getMailServers()));
     $smarty->assign("allowSieveManagement", $this->mailMethod->allowSieveManagement());
     $smarty->assign("own_script",  $this->sieveManagementUsed);
 
     /* _Multiple users vars_ */
     foreach($this->attributes as $attr){
       $u_attr = "use_".$attr;
-      $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
+      $smarty->assign($u_attr,in_array_strict($attr,$this->multi_boxes));
     }
     foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
       $u_attr = "use_".$attr;
-      $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
+      $smarty->assign($u_attr,in_array_strict($attr,$this->multi_boxes));
     }
 
 
@@ -460,9 +479,9 @@ class mailAccount extends plugin
     $smarty->assign("template", "");
     if (count($this->vacationTemplates)){
       $smarty->assign("show_templates", "true");
-      $smarty->assign("vacationtemplates", $this->vacationTemplates);
+      $smarty->assign("vacationtemplates", set_post($this->vacationTemplates));
       if (isset($_POST['vacation_template'])){
-        $smarty->assign("template", $_POST['vacation_template']);
+        $smarty->assign("template", set_post(get_post('vacation_template')));
       }
     } else {
       $smarty->assign("show_templates", "false");
@@ -478,7 +497,7 @@ class mailAccount extends plugin
      */
     $smarty->assign("spamlevel", $this->SpamLevels);
     $smarty->assign("spambox"  , $this->MailBoxes);
-
+    $smarty->assign("is_template", $this->is_template);
     $smarty->assign("multiple_support",$this->multiple_support_active);  
     return($display.$smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
   }
@@ -495,18 +514,18 @@ class mailAccount extends plugin
       $server = $this->gosaMailServer;
       plugin::save_object();
 
-      if(!$this->mailMethod->isModifyableServer() && $this->initially_was_account){
+      if(!$this->mailMethod->isModifyableServer() && $this->initially_was_account && !$this->is_template){
         $this->gosaMailServer = $server;
       }
 
-      if(!$this->mailMethod->isModifyableMail() && $this->initially_was_account){
+      if(!$this->mailMethod->isModifyableMail() && $this->initially_was_account && !$this->is_template){
         $this->mail = $mail;
       }else{
 
         /* Get posted mail domain part, if necessary  
          */
         if($this->mailMethod->domainSelectionEnabled() && isset($_POST['MailDomain'])){
-          if(in_array(get_post('MailDomain'), $this->mailDomainParts)){
+          if(in_array_strict(get_post('MailDomain'), $this->mailDomainParts)){
             $this->mailDomainPart = get_post('MailDomain');
           }
         }
@@ -516,9 +535,9 @@ class mailAccount extends plugin
        */
       if (isset($_POST["import_vacation"]) && isset($this->vacationTemplates[$_POST["vacation_template"]])){
         if($this->multiple_support_active){
-          $contents = ltrim(preg_replace("/^DESC:.*$/m","",file_get_contents($_POST["vacation_template"])));
+          $contents = ltrim(preg_replace("/^DESC:.*$/m","",file_get_contents(get_post("vacation_template"))));
         }else{
-          $contents = $this->prepare_vacation_template(file_get_contents($_POST["vacation_template"]));
+          $contents = $this->prepare_vacation_template(file_get_contents(get_post("vacation_template")));
         }
         $this->gosaVacationMessage= htmlspecialchars($contents);
       }
@@ -584,10 +603,10 @@ class mailAccount extends plugin
         if($this->mailMethod->vacationRangeEnabled()){
           if($this->acl_is_writeable("gosaVacationMessage") && preg_match("/V/",$this->gosaMailDeliveryMode)){
             if(isset($_POST['gosaVacationStart'])){
-              $this->gosaVacationStart = $_POST['gosaVacationStart'];
+              $this->gosaVacationStart = get_post('gosaVacationStart');
             }
             if(isset($_POST['gosaVacationStop'])){
-              $this->gosaVacationStop = $_POST['gosaVacationStop'];
+              $this->gosaVacationStop = get_post('gosaVacationStop');
             }
           }
         }
@@ -682,7 +701,7 @@ class mailAccount extends plugin
         }
         return ($attrs["uid"][0]);
       }
-      if (!in_array($address, $this->gosaMailAlternateAddress)){
+      if (!in_array_strict($address, $this->gosaMailAlternateAddress)){
         $this->gosaMailAlternateAddress[]= $address;
         $this->is_modified= TRUE;
       }
@@ -1010,7 +1029,7 @@ class mailAccount extends plugin
       }
       if ($this->is_template){
         if (!tests::is_email($mail, TRUE)){
-          $message[]= msgPool::invalid(_("Mail address"),"","","%givenName.%sn@your-domain.com");
+          $message[]= msgPool::invalid(_("Mail address"),"","","{%givenName}.{%sn}@your-domain.com");
         }
       } else {
         if (!tests::is_email($mail)){
@@ -1100,7 +1119,7 @@ class mailAccount extends plugin
 
     foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
 
-      if (in_array($val, $skip)){
+      if (in_array_strict($val, $skip)){
         continue;
       }
 
@@ -1113,17 +1132,31 @@ class mailAccount extends plugin
               $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
             }
           }
+            
+          // Remove non ASCII charcters
+          $value = iconv('UTF-8', 'US-ASCII//TRANSLIT', $value);
+          $value = preg_replace('/[^(\x20-\x7F)]*/','',$value);
+
+          // No spaces are allowed here
+          $value = preg_replace("/[ ]/","", $value);
           array_push($this->$val, strtolower(rewrite($value)));
         }
       }
     }
     $this->mail= strtolower(rewrite($this->mail));
 
+    // Remove non ASCII charcters
+    $this->mail= iconv('UTF-8', 'US-ASCII//TRANSLIT', $this->mail);
+    $this->mail= preg_replace('/[^(\x20-\x7F)]*/','',$this->mail);
+
+    // No spaces are allowed here
+    $this->mail = preg_replace("/[ ]/","", $this->mail);
+
     // Fix mail address when using templates
     if($this->is_account && $this->mailMethod->domainSelectionEnabled()){
       $this->mailDomainPart = preg_replace("/^[^@]*+@/","",$this->mail);
       $this->mail = preg_replace("/@.*$/","\\1",$this->mail);
-      if(!in_array($this->mailDomainPart,$this->mailDomainParts)){
+      if(!in_array_strict($this->mailDomainPart,$this->mailDomainParts)){
         $this->mailDomainParts[] = $this->mailDomainPart;
       }
     }
@@ -1165,7 +1198,7 @@ class mailAccount extends plugin
       /* Execute to save mailAlternateAddress && gosaMailForwardingAddress */
       $this->execute();
       if(isset($_POST['mail'])){
-          $this->mail = $_POST['mail'];
+          $this->mail = get_post('mail');
       }
   }
 
@@ -1185,7 +1218,7 @@ class mailAccount extends plugin
       if($this->mailMethod->domainSelectionEnabled()){
           $this->mailDomainPart = preg_replace("/^[^@]*+@/","",$this->mail);
           $this->mail = preg_replace("/@.*$/","\\1",$this->mail);
-          if(!in_array($this->mailDomainPart,$this->mailDomainParts)){
+          if(!in_array_strict($this->mailDomainPart,$this->mailDomainParts)){
               $this->mailDomainParts[] = $this->mailDomainPart;
           }
       }
@@ -1205,7 +1238,7 @@ class mailAccount extends plugin
   function get_multi_edit_values()
   {
     $ret = plugin::get_multi_edit_values();
-    if(in_array("gosaMailQuota",$this->multi_boxes)){
+    if(in_array_strict("gosaMailQuota",$this->multi_boxes)){
       $ret['gosaMailQuota'] = $this->gosaMailQuota;
     }
     $flag_add = $flag_remove = array();
@@ -1218,7 +1251,7 @@ class mailAccount extends plugin
         "C"   => "own_script",
         "I"   => "drop_own_mails");
     foreach($opts as $flag => $post){
-      if(in_array($post, $this->multi_boxes)){
+      if(in_array_strict($post, $this->multi_boxes)){
         if(preg_match("/".$flag."/",$tmp)){
           $flag_add[] = $flag;
         }else{
@@ -1230,9 +1263,9 @@ class mailAccount extends plugin
     $ret['flag_remove'] = $flag_remove;
 
     if($this->mailMethod->vacationRangeEnabled()){
-      if(in_array("V",$flag_add)){
-        $ret['gosaVacationStart'] =  $this->gosaVacationStart = $_POST['gosaVacationStart'];
-        $ret['gosaVacationStop'] =  $this->gosaVacationStop = $_POST['gosaVacationStop'];
+      if(in_array_strict("V",$flag_add)){
+        $ret['gosaVacationStart'] =  $this->gosaVacationStart = get_post('gosaVacationStart');
+        $ret['gosaVacationStop'] =  $this->gosaVacationStop = get_post('gosaVacationStop');
       }
     }
     return($ret);
@@ -1245,12 +1278,12 @@ class mailAccount extends plugin
   {
     $message = plugin::multiple_check();
 
-    if(empty($this->gosaMailServer) && in_array("gosaMailServer",$this->multi_boxes)){
+    if(empty($this->gosaMailServer) && in_array_strict("gosaMailServer",$this->multi_boxes)){
       $message[]= msgPool::noserver(_("Mail"));
     }
 
     /* Check quota */
-    if ($this->gosaMailQuota != ''  && in_array("gosaMailQuota",$this->multi_boxes)){
+    if ($this->gosaMailQuota != ''  && in_array_strict("gosaMailQuota",$this->multi_boxes)){
       if (!is_numeric($this->gosaMailQuota)) {
         $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
       } else {
@@ -1259,7 +1292,7 @@ class mailAccount extends plugin
     }
 
     /* Check rejectsize for integer */
-    if ($this->gosaMailMaxSize != '' && in_array("gosaMailMaxSize",$this->multi_boxes)){
+    if ($this->gosaMailMaxSize != '' && in_array_strict("gosaMailMaxSize",$this->multi_boxes)){
       if (!is_numeric($this->gosaMailMaxSize)){
         $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
       } else {
@@ -1267,7 +1300,7 @@ class mailAccount extends plugin
       }
     }
 
-    if(empty($this->gosaSpamMailbox) && in_array("gosaSpamMailbox",$this->multi_boxes)){
+    if(empty($this->gosaSpamMailbox) && in_array_strict("gosaSpamMailbox",$this->multi_boxes)){
       $message[]= msgPool::required(_("Spam folder"));
     }
 
@@ -1421,7 +1454,10 @@ class mailAccount extends plugin
                   "plCategory"    => array("users"),
                   "plOptions"       => array(),
 
-                  "plRequirements"=> array('ldapSchema' => array('gosaMailAccount' => '>=2.7')),    
+                  "plRequirements"=> array(
+                      'ldapSchema' => array('gosaMailAccount' => '>=2.7'),
+                      'onFailureDisablePlugin' => array(get_class())
+                      ),
     
                   "plProperties"  =>
                   array(
@@ -1429,7 +1465,7 @@ class mailAccount extends plugin
                           "name"          => "cyrusDeleteMailbox",
                           "type"          => "bool",
                           "default"       => 'true',
-                          "description"   => _("The 'cyrusDeleteMailbox' statement determines if GOsa should remove the mailbox from your IMAP server  or keep it after the account is deleted in LDAP."),
+                          "description"   => _("Remove mail boxes from the IMAP storage after they their user gets removed."),
                           "check"         => "gosaProperty::isBool",
                           "migrate"       => "",
                           "group"         => "mail",
@@ -1439,7 +1475,7 @@ class mailAccount extends plugin
                           "name"          => "cyrusAutocreateFolders",
                           "type"          => "string",
                           "default"       => "",
-                          "description"   => _("The 'cyrusAutocreateFolders' statement contains a comma seperated list of personal IMAP folders that should be created along initial account creation."),
+                          "description"   => _("Comma separated list of folders to be automatically created on user creation."),
                           "check"         => "gosaProperty::isString",
                           "migrate"       => "",
                           "group"         => "mail",
@@ -1456,13 +1492,13 @@ class mailAccount extends plugin
                               "gosaMailDeliveryModeV"     =>  _("Add vacation information"),  // This is flag of gosaMailDeliveryMode
                               "gosaVacationMessage"       =>  _("Vacation message"),
 
-                              "gosaMailDeliveryModeS"     =>  _("Use spam filter"),           // This is flag of gosaMailDeliveryMode
-                              "gosaSpamSortLevel"         =>  _("Spam level"),
-                              "gosaSpamMailbox"           =>  _("Spam mail box"),
+                              "gosaMailDeliveryModeS"     =>  _("Use SPAM filter"),           // This is flag of gosaMailDeliveryMode
+                              "gosaSpamSortLevel"         =>  _("SPAM level"),
+                              "gosaSpamMailbox"           =>  _("SPAM mail box"),
 
                               "sieveManagement"           =>  _("Sieve management"),
 
-                              "gosaMailDeliveryModeR"     =>  _("Reject due to mailsize"),    // This is flag of gosaMailDeliveryMode
+                              "gosaMailDeliveryModeR"     =>  _("Reject due to mail size"),    // This is flag of gosaMailDeliveryMode
                               "gosaMailMaxSize"           =>  _("Mail max size"),
 
                               "gosaMailForwardingAddress" =>  _("Forwarding address"),