From: hickert Date: Fri, 16 Mar 2007 08:52:23 +0000 (+0000) Subject: Added a get sieve function, to reduce code size X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=074a605eb8c63e3d9d0c477223a64bd7422af923;p=gosa.git Added a get sieve function, to reduce code size git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5794 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/include/sieve/class_sieveManagement.inc b/include/sieve/class_sieveManagement.inc index dca53556f..81b6b3452 100644 --- a/include/sieve/class_sieveManagement.inc +++ b/include/sieve/class_sieveManagement.inc @@ -37,6 +37,7 @@ class sieveManagement extends plugin var $script_to_delete =-1; var $sieve_handle = NULL; var $Script_Error = ""; + var $Sieve_Error = ""; var $create_script = FALSE; /* To add new elements we need to know @@ -50,6 +51,28 @@ class sieveManagement extends plugin var $add_element_type = "sieve_comment"; + function get_sieve() + { + /* Connect to sieve class and try to get all available sieve scripts */ + $cfg= $this->config->data['SERVERS']['IMAP'][$this->parent->gosaMailServer]; + $this->Sieve_Error = ""; + + /* Log into the mail server */ + $sieve= new sieve( + $cfg["sieve_server"], + $cfg["sieve_port"], + $this->parent->uid, + $cfg["password"], + $cfg["admin"]); + + /* Try to login */ + if (!$sieve->sieve_login()){ + $this->Sieve_Error = $sieve->error_raw; + return(FALSE); + } + return($sieve); + } + /* Initialize the class and load all sieve scripts * try to parse them and display errors */ @@ -58,21 +81,16 @@ class sieveManagement extends plugin $this->parent = $parent; plugin::plugin($config,$dn); - - /* Connect to sieve class and try to get all available sieve scripts */ - $cfg= $this->config->data['SERVERS']['IMAP'][$this->parent->gosaMailServer]; - - /* Log into the mail server */ - $sieve= new sieve($cfg["sieve_server"], $cfg["sieve_port"], $this->parent->uid, - $cfg["password"], $cfg["admin"]); - - /* Try to login */ - if (!$sieve->sieve_login()){ - print_red(sprintf(_("Can't log into SIEVE server. Server says '%s'."), - to_string($sieve->error_raw))); + /* Get sieve */ + if(!$sieve = $this->get_sieve()){ + print_red( + sprintf( + _("Can't log into SIEVE server. Server says '%s'."), + to_string($this->Sieve_Error))); return; } + /* Get all sieve scripts names */ if($sieve->sieve_listscripts()){ if (is_array($sieve->response)){ @@ -247,19 +265,13 @@ class sieveManagement extends plugin $script = preg_replace("/^active_script_/","",$name); $script = preg_replace("/_(x|y)/","",$script); $once = FALSE; - - /* Connect to sieve class and try to get all available sieve scripts */ - $cfg= $this->config->data['SERVERS']['IMAP'][$this->parent->gosaMailServer]; - $this->sieve_handle= - new sieve( $cfg["sieve_server"], - $cfg["sieve_port"], - $this->parent->mail, - $cfg["password"], - $cfg["admin"]); - - if (!$this->sieve_handle->sieve_login()){ - print_red(sprintf(_("Can't log into SIEVE server. Server says '%s'."),to_string($this->sieve_handle->error_raw))); - return; + + /* Get sieve */ + if(!$sieve = $this->get_sieve()){ + print_red( + sprintf( + _("Can't log into SIEVE server. Server says '%s'."), + to_string($this->Sieve_Error))); } /* Try to activate the given script and update @@ -299,17 +311,12 @@ class sieveManagement extends plugin unset($this->scripts[$this->script_to_delete]); }else{ - /* Connect to sieve class and try to get all available sieve scripts */ - $cfg= $this->config->data['SERVERS']['IMAP'][$this->parent->gosaMailServer]; - $this->sieve_handle= - new sieve( $cfg["sieve_server"], - $cfg["sieve_port"], - $this->parent->mail, - $cfg["password"], - $cfg["admin"]); - if (!$this->sieve_handle->sieve_login()){ - print_red(sprintf(_("Can't log into SIEVE server. Server says '%s'."),to_string($this->sieve_handle->error_raw))); - return; + /* Get sieve */ + if(!$sieve = $this->get_sieve()){ + print_red( + sprintf( + _("Can't log into SIEVE server. Server says '%s'."), + to_string($this->Sieve_Error))); } if(!$this->sieve_handle->sieve_deletescript($this->scripts[$this->script_to_delete]['NAME'])){