X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-plugins%2Fmail%2Fpersonal%2Fmail%2Fclass_mail-methods-cyrus.inc;h=367917671e66b495d6afa983988031b47bab66b4;hb=4f9f3bf3404420ec2018894f95ccfc09259a3c78;hp=5f958c9304229fb9b9a02cb455e10b6f78ed3118;hpb=538ef1720e644542055a8e938e45144964e75ef8;p=gosa.git
diff --git a/gosa-plugins/mail/personal/mail/class_mail-methods-cyrus.inc b/gosa-plugins/mail/personal/mail/class_mail-methods-cyrus.inc
index 5f958c930..367917671 100644
--- a/gosa-plugins/mail/personal/mail/class_mail-methods-cyrus.inc
+++ b/gosa-plugins/mail/personal/mail/class_mail-methods-cyrus.inc
@@ -8,7 +8,10 @@ class mailMethodCyrus extends mailMethod{
protected $quota_loaded = FALSE;
/* Allow modification of account_ids for existing mail accounts */
- protected $modifyableMail = FALSE;
+ protected $modifyableMail = FALSE;
+
+ /* Allow modification of the mail server attribute existing mail accounts */
+ protected $modifyableServer = FALSE;
/* Enforces same value for 'mail' as used for 'cn' */
protected $mailEqualsCN = FALSE;
@@ -22,18 +25,25 @@ class mailMethodCyrus extends mailMethod{
protected function init()
{
mailMethod::init();
- $this->ServerList = $this->config->data['SERVERS']['IMAP'];
+ if(isset($this->config->data['SERVERS']['IMAP'])){
+ $this->ServerList = $this->config->data['SERVERS']['IMAP'];
+ }
}
public function connect()
{
mailMethod::connect();
-
- if (!isset($this->ServerList[$this->MailServer])){
+
+ if(!count($this->ServerList)){
+ $this->error = _("There are no IMAP compatible mail servers defined!");
+ @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,
+ "IMAP: No mail servers configured, check systems->server->service->imap.","");
+ return(FALSE);
+ }elseif (!isset($this->ServerList[$this->MailServer])){
$this->error = _("Mail server for this account is invalid!");
@DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,
- "The selected mail server '".$this->MailServer."' is invalid.","");
+ "IMAP: The selected mail server '".$this->MailServer."' is invalid.","");
return(FALSE);
} else {
$cfg= $this->ServerList[$this->MailServer];
@@ -47,15 +57,25 @@ class mailMethodCyrus extends mailMethod{
/* Setting connect timeout to 10 seconds,
else the GOsa UI may freeze for 60 seconds.
(PHP default is 'default_socket_timeout = 60') */
- imap_timeout(1, 10 );
+ $timeout = $this->config->get_cfg_value("imapTimeout",10);
+ @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,$timeout,
+ "IMAP: Setting imap connect timeout to (seconds)");
+ imap_timeout(1, $timeout);
+
$this->imap_handle = @imap_open($cfg['connect'], $cfg['admin'], $cfg['password'], OP_HALFOPEN);
/* Mailbox reachable? */
if ($this->imap_handle === FALSE){
$this->error = imap_last_error();
+
+ @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"Failed :".imap_last_error(),
+ "IMAP: ".$cfg['admin']."@".$cfg['connect']);
+
return (FALSE);
$this->connected = FALSE;
}
+ @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"successful",
+ "IMAP: ".$cfg['admin']."@".$cfg['connect']);
$this->connected = TRUE;
return (TRUE);
@@ -74,9 +94,9 @@ class mailMethodCyrus extends mailMethod{
$list = @imap_listmailbox($this->imap_handle, $cfg["connect"], $this->account_id);
$res = is_array($list) && count($list);
if($res){
- @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"","Account exists in imap server.");
+ @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"","IMAP: Account exists in imap server.");
}else{
- @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"","Account seems NOT to exists in imap server.");
+ @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"","IMAP: Account seems NOT to exists in imap server.");
}
return($res);
}
@@ -104,10 +124,16 @@ class mailMethodCyrus extends mailMethod{
return(FALSE);
}
+ $this->reset_error();
+
/* Load quota settings */
$result = array("quotaUsage"=>"","gosaMailQuota"=>"");
$quota_value = @imap_get_quota($this->imap_handle, $this->account_id);
+ /* Reset error queue, imap_qet_quota() will fail if the quota wasn't set yet.
+ */
+ imap_errors();
+
if(is_array($quota_value) && count($quota_value)) {
if (isset($quota_value["STORAGE"]) && is_array($quota_value["STORAGE"])){
@@ -142,10 +168,10 @@ class mailMethodCyrus extends mailMethod{
$quota = "(".$this->quotaUsage." / ".$this->quotaValue.")";
}
@DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, $quota ,
- "Successfully received account quota");
+ "IMAP: Successfully received account quota");
}else{
@DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, imap_last_error() ,
- "Failed to receive account quota");
+ "IMAP: Failed to receive account quota");
}
}
@@ -196,11 +222,11 @@ class mailMethodCyrus extends mailMethod{
msg_dialog::display(_("IMAP error"), sprintf(_("Cannot modify IMAP mailbox quota: %s"),
'
'.imap_last_error().''), ERROR_DIALOG);
@DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "".$this->account_id.": (".$debug_number.")" ,
- "Set account quota on server '".$this->MailServer."' ".imap_last_error()."");
+ "IMAP: Set account quota on server '".$this->MailServer."' ".imap_last_error()."");
return (FALSE);
}
@DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "".$this->account_id.": (".$debug_number.")" ,
- "Set account quota on server :".$this->MailServer);
+ "IMAP: Set account quota on server :".$this->MailServer);
return (TRUE);
}
@@ -220,11 +246,29 @@ class mailMethodCyrus extends mailMethod{
$list = imap_listmailbox($this->imap_handle, $cfg["connect"], $this->account_id);
if ($list === FALSE){
@DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "".$this->account_id."" ,
- "Add/Update account on server :".$this->MailServer);
- if (!imap_createmailbox($this->imap_handle, $cfg["connect"]. $this->account_id)){
+ "IMAP: Add/Update account on server :".$this->MailServer);
+ if (!imap_createmailbox($this->imap_handle, $cfg["connect"].$this->account_id)){
$this->error = imap_last_error();
return(FALSE);
}
+
+ /* Autocreate configured default folders */
+ $folders= $this->config->get_cfg_value("cyrusAutocreateFolders", null);
+ if ($folders) {
+ $foldersToCreate= explode(",", $folders);
+ $cyrus_delim= $this->cyrusUseSlashes?"/":".";
+
+ // Walk thru list of specified folders
+ foreach ($foldersToCreate as $folder) {
+ @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "".$this->account_id."" ,
+ "IMAP: Add/Update account folder ".$folder." on server :".$this->MailServer);
+ if(!imap_createmailbox($this->imap_handle, $cfg["connect"].$this->account_id.$cyrus_delim.$folder)) {
+ $this->error= imap_last_error();
+ return(FALSE);
+ }
+ }
+
+ }
}
}
return(TRUE);
@@ -244,9 +288,16 @@ class mailMethodCyrus extends mailMethod{
$cfg= $this->ServerList[$this->MailServer];
@imap_setacl ($this->imap_handle, $this->account_id, $cfg["admin"], "lrswipcda");
- if (!imap_deletemailbox($this->imap_handle, $cfg["connect"].$this->account_id)){
- $this->error = imap_last_error();
- return (FALSE);
+
+ if ($this->config->get_cfg_value("cyrusDeleteMailbox", "true") == "true"){
+ if (!imap_deletemailbox($this->imap_handle, $cfg["connect"].$this->account_id)){
+ $this->error = imap_last_error();
+ return (FALSE);
+ }
+ } else{
+ msg_dialog::display(_("Mail info"),
+ sprintf(_("LDAP entry has been removed but cyrus mailbox (%s) is kept.\nPlease delete it manually!"),
+ $this->account_id), INFO_DIALOG);
}
return (TRUE);
}
@@ -270,10 +321,10 @@ class mailMethodCyrus extends mailMethod{
And prepare replacements
*/
if(preg_match("/\@/",$this->account_id)){
- $search = preg_replace("/\@/","*@",$this->account_id);
+ $search = preg_replace("/\@/","/*@",$this->account_id);
$with_domain = TRUE;
}else{
- $search = $this->account_id."*";
+ $search = $this->account_id."/*";
$with_domain = FALSE;
}
$folder = $this->account_id;
@@ -282,10 +333,17 @@ class mailMethodCyrus extends mailMethod{
}
/* Contact imap server */
- $list = @imap_listmailbox($this->imap_handle, $cfg["connect"], $search);
+ $list = @imap_listmailbox($this->imap_handle, $cfg["connect"], $this->account_id);
+ $list2 = @imap_listmailbox($this->imap_handle, $cfg["connect"], $search);
/* Create list of returned folder names */
if (is_array($list)){
+
+ /* Merge in subfolders */
+ if(is_array($list2)){
+ $list = array_merge($list,$list2);
+ }
+
foreach ($list as $val){
$str = trim(preg_replace("/^\{[^\}]*+\}/","",$val));
if($with_domain){
@@ -296,11 +354,11 @@ class mailMethodCyrus extends mailMethod{
$result[] = $str;
}
@DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,trim(implode($result,", "),", "),
- "Received mailbox folders.");
+ "IMAP: Received mailbox folders.");
$this->error = imap_last_error();
}else{
@DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,imap_last_error(),
- "Cannot receive mailbox folders.");
+ "IMAP: Cannot receive mailbox folders.");
$this->error = imap_last_error();
return(array());
}
@@ -324,7 +382,7 @@ class mailMethodCyrus extends mailMethod{
if (!function_exists('imap_getacl')){
$this->error = _("The module imap_getacl is not implemented!");
@DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"The imap_getacl module is missing!",
- "Cannot set folder acls.");
+ "IMAP: Cannot set folder acls.");
return($folder_acls);
}
@@ -361,7 +419,7 @@ class mailMethodCyrus extends mailMethod{
if (!function_exists('imap_getacl')){
$this->error = _("The module imap_getacl is not implemented!");
@DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"The imap_getacl module is missing!",
- "Cannot set folder acls.");
+ "IMAP: Cannot set folder acls.");
return(FALSE);
}
@@ -369,7 +427,6 @@ class mailMethodCyrus extends mailMethod{
$folders= $this->getMailboxList();
foreach ($folders as $subfolder){
$folder_id = $this->create_folder_id($subfolder);
- echo $folder_id."
";
/* Remove all acl's for this folder */
$users= @imap_getacl ($this->imap_handle, $folder_id);
@@ -379,7 +436,7 @@ class mailMethodCyrus extends mailMethod{
$userid = strtolower($userid);
imap_setacl ($this->imap_handle, $folder_id, $userid, "");
@DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,$folder_id." -> ".$userid,
- "Removing folder permissions.");
+ "IMAP: Removing folder permissions.");
}
}
}
@@ -391,7 +448,7 @@ class mailMethodCyrus extends mailMethod{
foreach ($permissions as $user => $acl){
imap_setacl ($this->imap_handle, $folder_id, $user, $acl);
@DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,$folder_id." -> ".$user.": ".$acl,
- "Setting new folder permissions.");
+ "IMAP: Setting new folder permissions.");
}
}
return(TRUE);
@@ -402,6 +459,21 @@ class mailMethodCyrus extends mailMethod{
{
mailMethod::saveSieveSettings();
+ // Check file integrity
+ $files = array();
+ foreach(array("sieve-header.txt","sieve-spam.txt","sieve-mailsize.txt","sieve-vacation.txt","sieve-discard.txt") as $file){
+ if(!file_exists(CONFIG_DIR."/".$file) || ! is_readable(CONFIG_DIR."/".$file)){
+ $files[] = CONFIG_DIR."/".$file;
+ @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__ , CONFIG_DIR."/".$file,
+ "Sieve template missing, please locate and move the template file: ");
+ }
+ }
+ if(count($files)){
+ $msg = sprintf(_("File '%s' does not exist!"),implode($files,", "));
+ $msg .= " "._("The sieve script may not be written correctly.");
+ msg_dialog::display(_("Warning"),$msg,WARNING_DIALOG);
+ }
+
/* Map attribute from parent class
*/
$mail = $this->parent->mail;
@@ -421,9 +493,6 @@ class mailMethodCyrus extends mailMethod{
@DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,$sieve->error_raw ,"SIEVE: login failed.");
$this->error = $sieve->error_raw;
return(FALSE);
- }else{
- @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "Options: ".$cfg["sieve_option"] ,
- "SIEVE: login successfull.");
}
/* Build spamlevel. Spamassassin tags mails with "*" for each integer
@@ -442,12 +511,9 @@ class mailMethodCyrus extends mailMethod{
if(!$sieve->sieve_getscript("gosa")){
$this->error = sprintf(_("Cannot retrieve SIEVE script: %s"),to_string($sieve->error_raw));
@DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,$sieve->error_raw ,
- "SIEVE: Connot read 'gosa' sieve script.");
+ "SIEVE: Connot read 'gosa' sieve script.");
$this->error = $sieve->error_raw;
return(FALSE);
- }else{
- @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,$sieve->error_raw ,
- "SIEVE: Sieve script named 'gosa' found.");
}
$is_valid_script = FALSE;
@@ -462,12 +528,12 @@ class mailMethodCyrus extends mailMethod{
if($is_valid_script || strlen($script) == 0 || empty($script)){
@DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"" ,
- "SIEVE: Sieve script 'gosa' was a valid GOsa script and will be replaced.");
+ "SIEVE: Sieve script 'gosa' was a valid GOsa script and will be replaced.");
}else{
$new_name = "non_gosa_".date("Ymd_H-i-s");
$sieve->sieve_sendscript($new_name, $script);
@DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,$this->sieve->error_raw ,
- "SIEVE: Non GOsa sieve script. Creating backup of the current sieve script '".$new_name."'.");
+ "SIEVE: Non GOsa sieve script. Creating backup of the current sieve script '".$new_name."'.");
}
}
}
@@ -477,11 +543,12 @@ class mailMethodCyrus extends mailMethod{
Build up new sieve script here.
*****/
+
/* Only create a new one, if it is not empty */
$script= "";
if (is_integer(strpos($gosaMailDeliveryMode, "R")) ||
is_integer(strpos($gosaMailDeliveryMode, "C")) ||
- !is_integer(strpos($gosaMailDeliveryMode, "L")) ||
+ !is_integer(strpos($gosaMailDeliveryMode, "I")) ||
is_integer(strpos($gosaMailDeliveryMode, "V")) ||
is_integer(strpos($gosaMailDeliveryMode, "S"))){
@@ -520,7 +587,7 @@ class mailMethodCyrus extends mailMethod{
}
/* If no local delivery is wanted, tell the script to discard the mail */
- if (!is_integer(strpos($gosaMailDeliveryMode, "L"))){
+ if (!is_integer(strpos($gosaMailDeliveryMode, "I"))){
$text= preg_replace('/"/', '\\"', implode ("", file(CONFIG_DIR."/sieve-discard.txt")));
eval ("\$script.=\"$text\";");
}
@@ -533,11 +600,8 @@ class mailMethodCyrus extends mailMethod{
if (!$sieve->sieve_sendscript("gosa", $script)){
$this->error = sprintf(_("Cannot store SIEVE script: %s"), to_string($sieve->error_raw));
@DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "Error was: ".to_string($sieve->error_raw) ,
- "SIEVE: Writing new Sieve script failed!");
+ "SIEVE: Writing new Sieve script failed!");
return(FALSE);
- }else{
- @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"Successfully written!" ,
- "SIEVE: NEW sieve script 'gosa' contains '".strlen($script)."' characters.");
}
if(!$sieve->sieve_setactivescript("gosa")){
@@ -545,7 +609,6 @@ class mailMethodCyrus extends mailMethod{
return(FALSE);
}
- @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"","SIEVE: Logout");
$sieve->sieve_logout();
}
}