Code

Removed duplicated code
[gosa.git] / gosa-plugins / mail / personal / mail / class_mail-methods.inc
index 60764445e1094fce25051b0e75f3d5b0dcebcc9a..7b4abf37473245aac27d15e95a0cd29205ee8815 100644 (file)
@@ -43,6 +43,17 @@ class mailMethod{
   protected $error              = "";
   protected $parent             = NULL;   
   protected $MailServer         = "";
+
+  protected $acl_map = array(
+      "lrsw"     => "read",
+      "lrswp"    => "post",
+      "p"        => "external post",
+      "lrswip"   => "append",
+      "lrswipcd" => "write",
+      "lrswipcda"=> "admin",
+      " "         => "none");
+
+  protected $acl_mapping = array();
  
 
   /*! \brief  Constructs the mail class 
@@ -98,6 +109,12 @@ class mailMethod{
             sprintf(_("The configured mail attribute '%s' is unsupported!"), $new_uattrib), ERROR_DIALOG);
       }
     }
+
+    /* Create ACL map */
+    foreach($this->acl_map as $acl => $name){
+      $this->acl_mapping[$acl] = _($name);
+    }
+
     $this->build_account_id();
     $this->initial_account_id = $this->account_id;
   }
@@ -112,6 +129,9 @@ class mailMethod{
       if(isset($this->parent->$source)){
         $this->parent->$dest = $this->parent->$source;
       }
+      if(isset($this->parent->attrs[$source][0])){
+        $this->parent->saved_attributes[$source] = $this->parent->attrs[$source][0];
+      }
     }
   }
 
@@ -240,6 +260,12 @@ class mailMethod{
   }
 
 
+  public function get_account_id()
+  {
+    $this->build_account_id();
+    return($this->account_id);
+  }
+
   /*! \brief  Create a new account id, like 'user/name@domain.com'.
    */
   protected function build_account_id()
@@ -250,11 +276,17 @@ class mailMethod{
     }else{
       $str = $this->share_prefix;
     }
+
+    /* Create account prefix and respect "cyrusUseSlashes" 
+       Do not replace escaped dots for cyrusUseSlashes.
+     */
     $uattrib = $this->uattrib;
     if($this->cyrusUseSlashes){
-      $str = preg_replace("/\./","/",$str);
+      $str = preg_replace('/([^\\\\])\./',"\\1/",$str);
     }
+    $str = preg_replace("/\\\\([\.\/])/","\\1",$str);
     $str = trim(strtolower($str . $this->parent->$uattrib));
+
     if($this->account_id != $str){
       $this->account_id = $str;
       @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "accountID generated: <b>".$str."</b>","");
@@ -288,10 +320,16 @@ class mailMethod{
       $str = $this->share_prefix;
     } 
 
+    /* Create account prefix and respect "cyrusUseSlashes"
+       Do not replace escaped dots for cyrusUseSlashes.
+     */
     $uattrib = $this->uattrib;
     if($this->cyrusUseSlashes){
-      $str = preg_replace("/\./","/",$str);
+      $str = preg_replace('/([^\\\\])\./',"\\1/",$str);
     }
+    $str = preg_replace("/\\\\([\.\/])/","\\1",$str);
+    $str = trim(strtolower($str . $this->parent->$uattrib));
+
     if(preg_match("/\@/",$this->parent->$uattrib)){
       list($mail,$domain) = split("\@",$this->parent->$uattrib);
       $str = trim(strtolower($str . $mail . $folder . "@" . $domain));
@@ -470,7 +508,7 @@ class mailMethod{
    */
   public function getMailDomains()
   {
-    return(array("gonicus.de","test.intranet.de"));
+    return(array("Unconfigured"));
   } 
 
   
@@ -525,22 +563,6 @@ class mailMethod{
    */
   public function accountRemoveable(&$reason = ""){
     return(TRUE);
-
-     /* We are in administrational edit mode.
-        Check tab configurations directly * /
-
-    $
-    if(isset($this->attrs)){
-      $checkArray  = array("kolabInvitationPolicy","unrestrictedMailSize", "calFBURL","kolabDelegate","kolabFreeBusyFuture");
-      foreach($checkArray as $index){
-        if(isset($this->attrs[$index])){
-           return(true);
-        }
-      }
-    }
-    return(false);
-
-    */
   }
 
   
@@ -586,13 +608,8 @@ class mailMethod{
   public function getAvailableFolderTypes()
   {
     $ret = array();
-    $ret['CAT']['mail'] = _("Mail"); 
-    $ret['CAT']['peter']= _("User"); 
-    $ret['SUB_CAT']['mail']['a'] = "a";
-    $ret['SUB_CAT']['mail']['b'] = "b";
-    $ret['SUB_CAT']['peter']['tt'] = "tt";
-    $ret['SUB_CAT']['peter']['dd'] = "dd";
-    $ret['SUB_CAT']['peter']['did'] = "did";
+    $ret['CAT'][''] = _("None"); 
+    $ret['SUB_CAT'][''][''] = _("None");
     return($ret);
   }
 
@@ -603,12 +620,7 @@ class mailMethod{
    */
   public function getFolderType($default)
   {
-    if($this->enableFolderTypes && $this->parent->attrs['kolabFolderType'][0]){
-      list($cat,$sub) = split("\.",$this->parent->attrs['kolabFolderType'][0]);
-      return(array("CAT" => $cat, "SUB_CAT" => $sub));
-    }else{
-      return($default);
-    }
+    return($default);
   }
 
  
@@ -618,10 +630,7 @@ class mailMethod{
    */
   public function setFolderType($type)
   {
-    $ldap = $this->config->get_ldap_link();
-    $ldap->cd ($this->parent->dn);
-    $ldap->modify(array("kolabFolderType" => $type['CAT'].".".$type['SUB_CAT']));
-    echo "Move me to KOLAB";
+    return(TRUE) ;   
   }
 
 
@@ -629,6 +638,15 @@ class mailMethod{
    */
   public function  getFolderACLs($folder_acls)
   {
+    /* Merge given ACL with acl mapping 
+       This ensures that no ACL will accidentally overwritten by gosa.
+     */
+    foreach($folder_acls as $user => $acl){
+      if(!isset($this->acl_mapping[$acl])){
+        $this->acl_mapping[$acl] = $acl;
+      }
+    }
+
     return($folder_acls);
   }
 
@@ -646,21 +664,36 @@ class mailMethod{
   */
   public function getAclTypes()
   {
-    $acls["lrsw"]     = _("read");
-    $acls["lrswp"]    = _("post");
-    $acls["p"]        = _("external post");
-    $acls["lrswip"]   = _("append");
-    $acls["lrswipcd"] = _("write");
-    $acls["lrswipcda"]= _("admin");
-    $acls[" "]= _("none");
-    return($acls);
+    return( $this->acl_mapping);
   }
 
   public function folderTypesEnabled()
   {
     return($this->enableFolderTypes);
   }
-   
+
+  public function allow_remove(&$reason)
+  {
+    return(TRUE);
+  }
+
+
+  /*! \brief  Returns the configured mailMethod
+      @return String  the configured mail method or ""
+   */
+  static public function get_current_method($config)
+  {
+    global $class_mapping;
+    $method= $config->get_cfg_value("mailmethod");
+    $cls = get_correct_class_name("mailMethod$method");
+    foreach($class_mapping as $class => $path){
+      if($class == $cls){
+        return($class);
+      }
+    }
+    return("");
+  }
+
 }