X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fpersonal%2Fmail%2Fclass_mailAccount.inc;h=7673aa45e2ee21cf4102f251176eee6c4ca06589;hb=a9621647e2897d04cdf4f2bd2ee5995aa551f4c7;hp=045d4fe84f719e808fff324c2670e985cd027ef0;hpb=276327c1e8b38e9eeae341986fb3690e2236e32c;p=gosa.git diff --git a/plugins/personal/mail/class_mailAccount.inc b/plugins/personal/mail/class_mailAccount.inc index 045d4fe84..7673aa45e 100644 --- a/plugins/personal/mail/class_mailAccount.inc +++ b/plugins/personal/mail/class_mailAccount.inc @@ -19,44 +19,47 @@ get_dir_list("$BASE_DIR/include"); class mailAccount extends plugin { /* Definitions */ - var $plHeadline= "Mail"; - var $plDescription= "This does something"; - var $method= "mailMethod"; + var $plHeadline = "Mail"; + var $plDescription = "This does something"; + var $method = "mailMethod"; /* CLI vars */ - var $cli_summary= "Manage users mail account"; - var $cli_description= "Some longer text\nfor help"; - var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser"); + var $cli_summary = "Manage users mail account"; + var $cli_description = "Some longer text\nfor help"; + var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser"); /* plugin specific values */ - var $mail= ""; - var $uid= ""; - var $gosaMailAlternateAddress= array(); - var $gosaMailForwardingAddress= array(); - var $gosaMailDeliveryMode= "[L ]"; - var $gosaMailServer= ""; - var $gosaMailQuota= ""; - var $gosaMailMaxSize= ""; - var $gosaVacationMessage= ""; - var $gosaSpamSortLevel= ""; - var $gosaSpamMailbox= ""; - - var $quotaUsage= 0; - var $forward_dialog= FALSE; - var $folder_prefix= ""; - var $mailboxList= array(); - var $default_permissions= "none"; - var $member_permissions= "post"; - var $members= array(); - var $admins= array(); - var $vacations= array(); - var $perms= array( "lrs" => "read", "lrsp" => "post", "lrsip" => "append", - "lrswipcd" => "write", "lrswipcda" => "all" ); + var $mail = ""; + var $uid = ""; + var $gosaMailAlternateAddress = array(); + var $gosaMailForwardingAddress = array(); + var $gosaMailDeliveryMode = "[L ]"; + var $gosaMailServer = ""; + var $gosaMailQuota = ""; + var $gosaMailMaxSize = ""; + var $gosaVacationMessage = ""; + var $gosaSpamSortLevel = ""; + var $gosaSpamMailbox = ""; + + var $quotaUsage = 0; + var $forward_dialog = FALSE; + var $folder_prefix = ""; + var $mailboxList = array(); + var $default_permissions = "none"; + var $member_permissions = "post"; + var $members = array(); + var $admins = array(); + var $vacations = array(); + var $perms = array( "lrs" => "read", + "lrsp" => "post", + "lrsip" => "append", + "lrswipcd" => "write", + "lrswipcda" => "all" ); /* attribute list for save action */ var $attributes= array("mail", "gosaMailServer", "gosaMailQuota", "gosaMailMaxSize","gosaMailForwardingAddress", "gosaMailDeliveryMode", "gosaSpamSortLevel", "gosaSpamMailbox","gosaMailAlternateAddress", - "gosaVacationMessage", "uid", "gosaMailAlternateAddress", "gosaMailForwardingAddress"); + "gosaVacationMessage", "gosaMailAlternateAddress", "gosaMailForwardingAddress"); var $objectclasses= array("gosaMailAccount"); @@ -64,13 +67,21 @@ class mailAccount extends plugin 'dn' from LDAP */ function mailAccount ($config, $dn= NULL) { - /* Configuration is fine, allways */ - $this->config= $config; - /* Load bases attributes */ plugin::plugin($config, $dn); - /* Set mailMethod to the one defined in gosa.conf */ + if(isset($this->attrs['uid'])){ + $this->uid = $this->attrs['uid'][0]; + } + + if(is_array($this->gosaMailServer) && isset($this->gosaMailServer[0])){ + $this->gosaMailServer = $this->gosaMailServer[0]; + } + + /* Save initial account state */ + $this->initially_was_account= $this->is_account; + + /* Set mailMethod to the one defined in gosa.conf */ if (isset($this->config->current['MAILMETHOD'])){ $method= $this->config->current['MAILMETHOD']; if (class_exists("mailMethod$method")){ @@ -80,7 +91,9 @@ class mailAccount extends plugin } } - /* Preset folder prefix. Will change it later to respect + + /* Create the account prefix user. user/ + Preset folder prefix. Will change it later to respect altnamespace. */ if (isset($this->config->current['CYRUSUNIXSTYLE']) && $this->config->current['CYRUSUNIXSTYLE'] == "true"){ $this->folder_prefix= "user/"; @@ -88,7 +101,9 @@ class mailAccount extends plugin $this->folder_prefix= "user."; } - if ($dn != NULL){ + + /* This is not a new account, parse additional attributes */ + if (($dn != NULL) && ($dn != "new") && $this->is_account){ /* Load attributes containing arrays */ foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){ @@ -100,33 +115,51 @@ class mailAccount extends plugin } } + /* Only do IMAP actions if gosaMailServer attribute is set */ if (isset ($this->attrs["gosaMailServer"][0])){ - $method= new $this->method($this->config); - $id= $method->uattrib; + $method = new $this->method($this->config); + $id = $method->uattrib; /* Adapt attributes if needed */ $method->fixAttributesOnLoad($this); + + /* FixAttributesOnLoad possibly creates an array out of gosaMailServer. + If the mail tab wasn't opened once before saving, the account can't be saved */ + if(is_array($this->gosaMailServer)){ + $this->gosaMailServer = $this->gosaMailServer[0]; + } + if ($method->connect($this->attrs["gosaMailServer"][0])){ - $quota= $method->getQuota($this->folder_prefix.$this->$id); /* Update quota values */ - if ($quota['gosaMailQuota'] == 2147483647){ - $this->quotaUsage= ""; - $this->gosaMailQuota= ""; - } else { - $this->quotaUsage= $quota['quotaUsage']; - $this->gosaMailQuota= $quota['gosaMailQuota']; + $quota= $method->getQuota($this->folder_prefix.$this->$id); + + if($quota){ + if ($quota['gosaMailQuota'] == 2147483647){ + $this->quotaUsage = ""; + $this->gosaMailQuota = ""; + } else { + $this->quotaUsage = $quota['quotaUsage']; + $this->gosaMailQuota = $quota['gosaMailQuota']; + } + }else{ + $this->quotaUsage = ""; + $this->gosaMailQuota = ""; + print_red(sprintf(_("Can't get quota information for '%s'."),$this->folder_prefix.$this->$id)); } - $this->mailboxList= $method->getMailboxList( - $this->folder_prefix.$this->$id, - $this->$id); + + /* Get mailboxes / folder like INBOX ..*/ + $this->mailboxList= $method->getMailboxList($this->folder_prefix.$this->$id,$this->$id); + $method->disconnect(); }else{ /* Could not connect to ldap. */ - $this->gosaMailQuota = $this->attrs['gosaMailQuota'][0]; + if (isset($this->attrs['gosaMailQuota'][0])){ + $this->gosaMailQuota = $this->attrs['gosaMailQuota'][0]; + } } } } @@ -149,6 +182,9 @@ class mailAccount extends plugin } } + + /* Create filter */ + /* Get global filter config */ if (!is_global("mailfilter")){ $ui= get_userinfo(); @@ -158,13 +194,6 @@ class mailAccount extends plugin "regex" => "*"); register_global("mailfilter", $mailfilter); } - - if(is_array($this->gosaMailServer) && isset($this->gosaMailServer[0])){ - $this->gosaMailServer = $this->gosaMailServer[0]; - } - - /* Save initial account state */ - $this->initially_was_account= $this->is_account; } @@ -191,29 +220,28 @@ class mailAccount extends plugin function execute() { - /* Call parent execute */ - plugin::execute(); + /* Call parent execute */ + plugin::execute(); + + /* Initialise vars */ /* Load templating engine */ $smarty= get_smarty(); $display= ""; + /* Get available mailserver */ $mailserver= array(); foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){ $mailserver[]= $key; } + /* Handle account state */ + /* Do we need to flip is_account state? */ if (isset($_POST['modify_state'])){ $this->is_account= !$this->is_account; } - /* Show main page */ - $mailserver= array(); - foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){ - $mailserver[]= $key; - } - /* Do we represent a valid account? */ if (!$this->is_account && $this->parent == NULL){ $display= "\"\" ". @@ -234,6 +262,9 @@ class mailAccount extends plugin } } + + /* Forwarder subdialog */ + /* Trigger forward add dialog? */ if (isset($_POST['add_local_forwarder'])){ $this->forward_dialog= TRUE; @@ -309,6 +340,9 @@ class mailAccount extends plugin } } + + /* Alternate address handling */ + /* Add alternate email addresses */ if (isset($_POST['add_alternate'])){ if ($_POST['alternate_address'] != "" && @@ -348,6 +382,9 @@ class mailAccount extends plugin } } + + /* Vacation message */ + /* Import vacation message? */ if (isset($_POST["import_vacation"]) && isset($this->vacation[$_POST["vacation_template"]])){ $contents= ""; @@ -369,6 +406,9 @@ class mailAccount extends plugin $this->gosaVacationMessage= htmlspecialchars($contents); } + + /* Display forward dialog if requested above */ + /* Show forward add dialog */ if ($this->forward_dialog){ $ldap= $this->config->get_ldap_link(); @@ -412,7 +452,8 @@ class mailAccount extends plugin } $acl= array($this->config->current['BASE'] => ":all"); - $res= get_list($acl, "(&(objectClass=gosaMailAccount)$filter)", TRUE, $mailfilter['depselect'], array("sn", "mail", "givenName"), TRUE); + $res= get_list("(&(objectClass=gosaMailAccount)$filter)", $acl, $mailfilter['depselect'], + array("sn", "mail", "givenName"), GL_SIZELIMIT | GL_SUBSEARCH); $ldap->cd($mailfilter['depselect']); $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName")); error_reporting (0); @@ -451,6 +492,8 @@ class mailAccount extends plugin return ($display); } + /* Display mail account tab */ + $smarty->assign("mailServers", $mailserver); foreach(array("gosaMailServer", "gosaMailQuota", "perms", "mail", "gosaMailAlternateAddress", "gosaMailForwardingAddress", @@ -474,12 +517,29 @@ class mailAccount extends plugin $smarty->assign("mailACL", "disabled"); } - /* Fill checkboxes */ + if (!preg_match("/L/", $this->gosaMailDeliveryMode)) { $smarty->assign("drop_own_mails", "checked"); } else { $smarty->assign("drop_own_mails", ""); } + + $types = array( + "V"=>"use_vacation", + "S"=>"use_spam_filter", + "R"=>"use_mailsize_limit", + "I"=>"only_local", + "C"=>"own_script"); + + /* Fill checkboxes */ + foreach($types as $option => $varname){ + if (preg_match("/".$option."/", $this->gosaMailDeliveryMode)) { + $smarty->assign($varname, "checked"); + } else { + $smarty->assign($varname, ""); + } + } + if (preg_match("/V/", $this->gosaMailDeliveryMode)) { $smarty->assign("use_vacation", "checked"); } else { @@ -555,20 +615,12 @@ class mailAccount extends plugin $method= new $this->method($this->config); $method->fixAttributesOnRemove($this); - /* Mailmethod wants us to remove the entry from LDAP. Keep uid! */ - #fixme: || kolab || is differs here, you can't delete all attrs specified in this plugin .... - #fixme: there are some attributes we have to keep, i think. - unset ($this->attrs['uid']); - - - - @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, - $this->attributes, "Save"); + @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save"); $ldap->cd($this->dn); $this->cleanup(); -$ldap->modify ($this->attrs); + $ldap->modify ($this->attrs); - show_ldap_error($ldap->get_error()); + show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/mail account with dn '%s' failed."),$this->dn)); /* Connect to IMAP server for account deletion */ if ($this->gosaMailServer != ""){ @@ -653,11 +705,12 @@ $ldap->modify ($this->attrs); /* Adapt attributes if needed */ $method= new $this->method($this->config); $id= $method->uattrib; + $method->fixAttributesOnStore($this); - /* Remove Mailquota if = "" */ - if((isset($this->attrs['gosaMailQuota']))&&($this->attrs['gosaMailQuota']=="")) { - $this->attrs['gosaMailQuota']=array(); + /* Remove Mailquota if = "" or "0" */ + if((isset($this->attrs['gosaMailQuota']))&&(!$this->attrs['gosaMailQuota'])) { + $this->attrs['gosaMailQuota']=0; } if(empty($this->attrs['gosaSpamMailbox'])){ @@ -669,15 +722,16 @@ $ldap->modify ($this->attrs); /* Save data to LDAP */ $ldap->cd($this->dn); $this->cleanup(); -$ldap->modify ($this->attrs); + $ldap->modify ($this->attrs); - show_ldap_error($ldap->get_error()); + show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/mail account with dn '%s' failed."),$this->dn)); /* Only do IMAP actions if we are not a template */ if (!$this->is_template){ if ($method->connect($this->gosaMailServer)){ $method->updateMailbox($this->folder_prefix.$this->$id); + $method->setQuota($this->folder_prefix.$this->$id, $this->gosaMailQuota); $method->disconnect(); @@ -706,13 +760,16 @@ $ldap->modify ($this->attrs); } + /* Check formular input */ function check() { if(!$this->is_account) return(array()); + $ldap= $this->config->get_ldap_link(); - $message= array(); + /* Call common method to give check the hook */ + $message= plugin::check(); if(empty($this->gosaMailServer)){ $message[]= _("There is no valid mailserver specified, please add one in the system setup."); @@ -769,6 +826,7 @@ $ldap->modify ($this->attrs); return ($message); } + /* Adapt from template, using 'dn' */ function adapt_from_template($dn) { @@ -791,17 +849,18 @@ $ldap->modify ($this->attrs); $this->mail= strtolower(rewrite($this->mail)); } + /* Add entry to forwarder list */ function addForwarder($address) { $this->gosaMailForwardingAddress[]= $address; $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress); - sort ($this->gosaMailForwardingAddress); reset ($this->gosaMailForwardingAddress); $this->is_modified= TRUE; } + /* Remove list of addresses from forwarder list */ function delForwarder($addresses) { @@ -810,13 +869,13 @@ $ldap->modify ($this->attrs); } - + /* Add given mail address to the list of alternate adresses , + check if this mal address is used, skip adding in this case */ function addAlternate($address) { $ldap= $this->config->get_ldap_link(); - $address= strtolower($address); - + /* Is this address already assigned in LDAP? */ $ldap->cd ($this->config->current['BASE']); $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)"."(gosaMailAlternateAddress=$address)))", array("uid")); @@ -834,7 +893,6 @@ $ldap->modify ($this->attrs); sort ($this->gosaMailAlternateAddress); reset ($this->gosaMailAlternateAddress); - return (""); } @@ -866,6 +924,8 @@ $ldap->modify ($this->attrs); return ($name); } + + /* Create the mail part for the copy & paste dialog */ function getCopyDialog() { if(!$this->is_account) return(""); @@ -893,6 +953,53 @@ $ldap->modify ($this->attrs); } } + + function allow_remove() + { + if (isset($this->config->current['MAILMETHOD'])){ + $method= $this->config->current['MAILMETHOD']; + if(preg_match("/kolab/i",$method)){ + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->cat($this->dn); + if($ldap->count()){ + $attrs = $ldap->fetch(); + if(isset($attrs['kolabDeleteFlag'])){ + return(_("Waiting for kolab to remove mail properties.")); + }elseif(in_array("gosaMailAccount",$attrs['objectClass'])){ + return(_("Please remove the mail account first, to allow kolab to call its remove methods.")); + } + } + } + } + } + + + function plInfo() + { + return (array("plDescription" => _("Mail settings"), + "plSelfModify" => TRUE, + "plDepends" => array("objectClass" => "gosaAccount"), + + "mail" => _("Mail address"), + "gosaMailServer" => _("Mail server"), + "gosaMailQuota" => _("Quota sizw"), + "gosaMailMaxSize" => _("Mail max size"), + "gosaMailForwardingAddress" => _("Forwarding address"), + "gosaMailDeliveryMode_L" => "FIXME"._("Local delivery"), // This is flag of gosaMailDeliveryMode + "gosaMailDeliveryMode_R" => "FIXME"._("Reject due to mailsize"), // This is flag of gosaMailDeliveryMode + "gosaMailDeliveryMode_s" => "FIXME"._("Use spam filter"), // This is flag of gosaMailDeliveryMode + "gosaMailDeliveryMode_V" => "FIXME"._("Add vacation information"), // This is flag of gosaMailDeliveryMode + "gosaMailDeliveryMode_C" => "FIXME"._("Use custom sieve script"), // This is flag of gosaMailDeliveryMode + "gosaMailDeliveryMode_I" => "FIXME"._("Only insider delivery"), // This is flag of gosaMailDeliveryMode + "gosaSpamSortLevel" => _("Spam level"), + "gosaSpamMailbox" => _("Spam mail box"), + "gosaMailAlternateAddress" => _("Mail alternative addresses"), + + "gosaVacationMessage" => _("Vocation message"), + "gosaMailForwardingAddress" => _("Forwarding address"))); + + } } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: