Code

Updated acount id creation
[gosa.git] / gosa-plugins / mail / personal / mail / class_mail-methods.inc
index e59b30f128feab35ffa35a860c0492d08da1b487..634cb2a7d370c19991e046268a7cc63063e4700b 100644 (file)
@@ -19,6 +19,10 @@ class mailMethod{
   protected $user_prefix    = "user.";  
   protected $share_prefix   = "share.";
 
+  /* Account ID creation */
+  protected $user_id    = "__PREFIX____UATTRIB__";  
+  protected $share_id   = "__PREFIX____UATTRIB__";
+
   /* Create accounts in cyrus style with '/' instead of '.' */
   protected $cyrusUseSlashes= FALSE;
 
@@ -93,9 +97,9 @@ class mailMethod{
      */
     if ($this->config->get_cfg_value("cyrusUseSlashes") == "true"){
       $this->cyrusUseSlashes = TRUE;
-      @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "cyrusUseSlashes: <b>Enabled</b>","");
+      @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "","<b>MAIL:</b> cyrusUseSlashes: <b>Enabled</b>");
     }else{
-      @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "cyrusUseSlashes: <b>Disabled</b>","");
+      @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "","<b>MAIL:</b> cyrusUseSlashes: <b>Disabled</b>");
     }
 
     /* Check if the mail account identification attribute
@@ -107,7 +111,7 @@ class mailMethod{
         $this->uattrib = $new_uattrib;
       }else{
         @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "<b>".$new_uattrib."</b>",
-            "Unsupported 'mailAttribute' in gosa configuration specified");
+          "<b>MAIL:</b> Unsupported 'mailAttribute' in gosa configuration specified");
         msg_dialog::display(_("Configuration error"), 
             sprintf(_("The configured mail attribute '%s' is unsupported!"), $new_uattrib), ERROR_DIALOG);
       }
@@ -193,8 +197,8 @@ class mailMethod{
   public function connect()
   {
     $this->reset_error();
-    @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"<b>Connect method</b>: ".get_class($this),"");
-    @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"<b>Current server</b>: ".$this->MailServer,"");
+    @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"","<b>MAIL: Connect method</b>: ".get_class($this));
+    @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"","<b>MAIL: Current server</b>: ".$this->MailServer);
  
     $this->connected = TRUE;
     return(TRUE);
@@ -217,7 +221,7 @@ class mailMethod{
   {
     $this->reset_error();
     if($this->is_connected()){
-      @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"<b>Disconnect method</b>: ".get_class($this),"");
+      @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"","<b>MAIL: Disconnect method</b>: ".get_class($this));
       $this->connected =FALSE; 
     }
   }
@@ -281,9 +285,11 @@ class mailMethod{
   {
     /* Build account identicator */
     if($this->type == "user"){
-      $str = $this->user_prefix;
+      $prefix = $this->user_prefix;
+      $acc_string = $this->user_id;
     }else{
-      $str = $this->share_prefix;
+      $prefix = $this->share_prefix;
+      $acc_string = $this->share_id;
     }
 
     /* Create account prefix and respect "cyrusUseSlashes" 
@@ -291,14 +297,26 @@ class mailMethod{
      */
     $uattrib = $this->uattrib;
     if($this->cyrusUseSlashes){
-      $str = preg_replace('/([^\\\\])\./',"\\1/",$str);
+      $prefix = preg_replace('/([^\\\\])\./',"\\1/",$prefix);
+    }
+    $prefix = preg_replace("/\\\\([\.\/])/","\\1",$prefix);
+   
+    $domain = $mailpart = "";
+    if(preg_match("/\@/",$this->parent->$uattrib)){
+      $mailpart = preg_replace("/\@.*$/","",$this->parent->$uattrib);
+      $domain   = preg_replace("/^[^\@]*+\@(.*)$/","\\1",$this->parent->$uattrib);
     }
-    $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>","");
+    /* Create account_id 
+     */ 
+    $from = array("/__CN__/","/__UID__/","/__PREFIX__/","/__UATTRIB__/","/__DOMAIN__/","/__MAILPART__/");
+    $to   = array($this->parent->cn,$this->parent->uid,$prefix,$this->parent->$uattrib, $domain, $mailpart);
+    $acc_id = trim(strtolower(preg_replace($from,$to,$acc_string)));
+
+    if($this->account_id != $acc_id){
+      $this->account_id = $acc_id;
+      @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"", "<b>MAIL:</b> AccountID generated: <b>".$acc_id."</b>");
     }
   }
 
@@ -320,30 +338,40 @@ class mailMethod{
     }
 
     /* Build account identicator */
-    if($type == ""){
-      $type = $this->type;
-    }
-    if($type == "user"){
-      $str = $this->user_prefix;
+    if($this->type == "user"){
+      $prefix = $this->user_prefix;
+      $acc_string = $this->user_id;
     }else{
-      $str = $this->share_prefix;
-    } 
+      $prefix = $this->share_prefix;
+      $acc_string = $this->share_id;
+    }
 
     /* Create account prefix and respect "cyrusUseSlashes"
        Do not replace escaped dots for cyrusUseSlashes.
      */
     $uattrib = $this->uattrib;
     if($this->cyrusUseSlashes){
-      $str = preg_replace('/([^\\\\])\./',"\\1/",$str);
+      $prefix = preg_replace('/([^\\\\])\./',"\\1/",$prefix);
     }
-    $str = preg_replace("/\\\\([\.\/])/","\\1",$str);
-    $str = trim(strtolower($str . $this->parent->$uattrib));
+    $prefix = preg_replace("/\\\\([\.\/])/","\\1",$prefix);
 
+    $domain = $mailpart = "";
     if(preg_match("/\@/",$this->parent->$uattrib)){
-      list($mail,$domain) = split("\@",$this->parent->$uattrib);
-      $str = trim(strtolower($str . $mail . $folder . "@" . $domain));
+      list($mailpart,$domain) = split("\@",$this->parent->$uattrib);
+    }
+
+    /* Create account_id
+     */
+    $from = array("/__CN__/","/__UID__/","/__PREFIX__/","/__UATTRIB__/","/__DOMAIN__/","/__MAILPART__/");
+    $to   = array($this->parent->cn,$this->parent->uid,$prefix,$this->parent->$uattrib, $domain, $mailpart);
+
+    $acc_id = trim(strtolower(preg_replace($from,$to,$acc_string)));
+
+    if(preg_match("/\@/",$acc_id)){
+      list($mail,$domain) = split("\@",$acc_id);
+      $str = trim(strtolower($mail . $folder . "@" . $domain));
     }else{
-      $str = trim(strtolower($str . $this->parent->$uattrib));
+      $str = trim(strtolower($acc_id . $folder));
     }
     return($str) ;
   }
@@ -360,13 +388,13 @@ class mailMethod{
       $method= $this->config->get_cfg_value("mailmethod");
       $cls = get_correct_class_name("mailMethod$method");
       if(isset($methods[$cls])){
-        @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "Selected mailMethod: <b>".$cls."</b>","");
+        @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"", "<b>MAIL:</b> Selected mailMethod: <b>".$cls."</b>");
         $tmp = new $cls($this->config,$this->parent,$this->type);
         $tmp->init();
         return($tmp);
       }else{
-        @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "Invalid mailMethod defined <b>".$cls.
-            "</b> falling back to <b>".get_class($this)."</b>","");
+        @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "","<b>MAIL: Invalid mailMethod defined: <b>".$cls.
+            "</b> falling back to <b>".get_class($this)."</b>");
 
         /* Print out configuration errors directly, we can't catch them everywhere. 
          */
@@ -417,29 +445,9 @@ class mailMethod{
     $this->reset_error();
 
     @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "<b>".$this->account_id."</b>" ,
-        "<b>Remove account</b> from server :".$this->MailServer);
+        "<b>MAIL: Remove account</b> from server :".$this->MailServer);
 
     return(TRUE);
-
-    /* No imap actions here, just updated shared folder membership 
-     */
-    $ldap = $this->config->get_ldap_link();
-    $ldap->cd($this->config->current['BASE']);
-    $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$account."))",array('dn','cn'));
-    if(class_exists("grouptabs")){
-      while($attrs = $ldap->fetch()){
-        $tmp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
-        if(isset($tmp->by_object['mailgroup'])){
-          $tmp->by_object['mailgroup']->members= $tmp->by_object['group']->memberUid;
-          if(!$this->is_account){
-            $tmp->by_object['mailgroup']->removeUserAcl($account);
-            $tmp->by_object['mailgroup']->removeUserAcl($this->mail);
-          }
-          $tmp->by_object['mailgroup']->save();
-        }
-      }
-    }
-    return(TRUE);
   }