X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fadmin%2Fgroups%2Fclass_groupMail.inc;h=31557a6c4c12aa858266cacd3f4ca4826feddfa5;hb=4f507bf6c24fd9a5c50928b3a0c334ba5529c42d;hp=f7744376383a24247d20379ec9bb82c810835ec2;hpb=0b0ba2643acbe53011db1b3307397cb38adb0c36;p=gosa.git diff --git a/plugins/admin/groups/class_groupMail.inc b/plugins/admin/groups/class_groupMail.inc index f77443763..31557a6c4 100644 --- a/plugins/admin/groups/class_groupMail.inc +++ b/plugins/admin/groups/class_groupMail.inc @@ -3,72 +3,99 @@ class mailgroup extends plugin { /* CLI vars */ - var $cli_summary= "Manage mail groups/shared folders"; - var $cli_description= "Some longer text\nfor help"; - var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser"); - var $method= "mailMethod"; - - /* plugin specific values */ - var $mail= ""; - var $uid= ""; - var $cn= ""; - 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 $members= array(); - var $mailusers= array(); - var $perms= array(); - var $imapacl= array('anyone' => 'p', '%members%' => 'lrsp', '' => 'p'); + var $cli_summary = "Manage mail groups/shared folders"; + var $cli_description = "Some longer text\nfor help"; + var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser"); + + var $uid = ""; // User id + var $cn = ""; // cn + + var $method = "mailMethod"; // Used Mail method + var $mmethod = ""; // Contains the gosa.conf MAILMETHOD + var $mail = ""; // Default mail address + + var $gosaMailAlternateAddress = array(); // Set default Alternate Mail Adresses to empty array + var $gosaMailForwardingAddress = array(); // Forwarding also empty + + var $gosaMailServer = ""; // Selected mailserver + var $gosaMailQuota = ""; // Defined Quota + var $quotaUsage = 0; // Currently used quota + + var $gosaVacationMessage = ""; // Vocation message + + var $imapacl = array('anyone' => 'p', // Set acls for everyone + '%members%' => 'lrsp', // %members% are all group-members + '' => 'p'); // Every user added gets this right + + + var $gosaSpamSortLevel = ""; + var $gosaSpamMailbox = ""; + var $gosaSharedFolderTarget ; + + var $forward_dialog = FALSE; + + var $members = array(); // Group members + + var $mailusers = array(); + var $perms = array(); + var $gosaMailDeliveryMode = "[L ]"; // + var $gosaMailMaxSize = ""; // + /* Helper */ var $indexed_acl= array(); var $indexed_user= array(); /* attribute list for save action */ - var $attributes= array("mail", "gosaMailServer", "gosaMailQuota", "gosaMailMaxSize", + var $attributes= array( "mail", "gosaMailServer", "gosaMailQuota", "gosaMailMaxSize", + "gosaMailAlternateAddress", "gosaMailForwardingAddress", "gosaMailDeliveryMode", "gosaSpamSortLevel", "gosaSpamMailbox", - "gosaVacationMessage"); + "acl","gosaSharedFolderTarget", "gosaVacationMessage"); + var $objectclasses= array("gosaMailAccount"); - /* constructor, if 'dn' is set, the node loads the given - 'dn' from LDAP */ - function mailgroup ($config, $dn= NULL, $ui= NULL) + function mailgroup ($config, $dn= NULL, $parent= NULL) { - /* Configuration is fine, allways */ - $this->config= $config; - - /* Load bases attributes */ - plugin::plugin($config, $dn); + /* Initialise all available attributes ... if possible + */ + plugin::plugin($config, $dn, $parent); - /* Set mailMethod to the one defined in gosa.conf */ + /* 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")){ - $this->method= "mailMethod$method"; - } else { - print_red(sprintf(_("There is no mail method '%s' specified in your gosa.conf available."), $method)); - } + $this->mmethod= $this->config->current['MAILMETHOD']; + } + + /* Check if selected mail method exists + */ + if (class_exists("mailMethod$this->mmethod")){ + $this->method= "mailMethod$this->mmethod"; + } else { + print_red(sprintf(_("There is no mail method '%s' specified in your gosa.conf available."), $this->mmethod)); } - /* Convert cn to uid in case of existing entries */ + /* Load Mailserver + */ + if(isset($this->attrs['gosaMailServer'][0])){ + $this->gosaMailServer = $this->attrs['gosaMailServer'][0]; + } + + /* Convert cn to uid in case of existing entry + */ if (isset($this->attrs['cn'][0])){ $this->uid= $this->attrs['cn'][0]; } - if ($dn != NULL){ - /* Load attributes containing arrays */ + /* If this ins't new mailgroup, read all required data from ldap + */ + if (($dn != "new")&&($dn != NULL)){ + + /* Load attributes which represent multiple entries + */ foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){ + $this->$val = array(); if (isset($this->attrs["$val"]["count"])){ for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){ array_push($this->$val, $this->attrs["$val"][$i]); @@ -76,11 +103,16 @@ class mailgroup extends plugin } } - /* Only do IMAP actions if gosaMailServer attribute is set */ + /* Only do IMAP actions if gosaMailServer attribute is set + */ if (isset ($this->attrs["gosaMailServer"][0])){ + + /* Create new instance of our defined mailclass + */ $method= new $this->method($this->config); + if ($method->connect($this->attrs["gosaMailServer"][0])){ - $quota= $method->getQuota($this->uid); + /* Maybe the entry is not saved in new style, get permissions from IMAP and convert them to acl attributes */ @@ -109,31 +141,44 @@ class mailgroup extends plugin /* Highest count wins as %members%, remove all members with the same acl */ - $this->imapacl['%members%']= $leader; + if(!empty($leader)){ + $this->imapacl['%members%']= $leader; + } foreach ($this->imapacl as $user => $acl){ if ($this->acl == $leader && in_array($user, $this->attrs['memberUid'])){ unset($this->imapacl[$user]); } } - - } + + } // ENDE ! isset ($this->attrs['acl']) + /* Adapt attributes if needed */ + $method->fixAttributesOnLoad($this); + + /* get Quota */ + $quota= $method->getQuota($this->uid); + /* Update quota values */ - if ($quota['gosaMailQuota'] == 2147483647){ - $this->quotaUsage= ""; - $this->gosaMailQuota= ""; - } else { - $this->quotaUsage= $quota['quotaUsage']; - $this->gosaMailQuota= $quota['gosaMailQuota']; + if(is_array($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->uid)); } $method->disconnect(); - } + } // ENDE $method->connect($this->attrs["gosaMailServer"][0])){ - } + } // ENDE gosaMailServer + + } // ENDE dn != "new" - /* Adapt attributes if needed */ - $method->fixAttributesOnLoad($this); - } /* Get global filter config */ if (!is_global("gmailfilter")){ @@ -146,16 +191,95 @@ class mailgroup extends plugin } /* Load permissions */ - if (isset($this->attrs['acl'])){ - for ($i= 0; $i<$this->attrs['acl']['count']; $i++){ - list($user, $permission)= split(' ', $this->attrs['acl'][$i]); - $this->imapacl[$user]= $permission; - if ($user != "anyone" && $user != "%members%"){ - unset($this->imapacl['']); + $tmp = array(); + if(preg_match("/kolab/i",$this->mmethod)){ + $ldap = $this->config->get_ldap_link(); + + if (isset($this->attrs['acl'])){ + + for ($i= 0; $i<$this->attrs['acl']['count']; $i++){ + list($user, $permission)= split(' ', $this->attrs['acl'][$i]); + + /* Add to list */ + $this->imapacl[$user]= $permission; + + /* Get all user permissions sorted by acl, to detect the most used acl + This acl is then used for %members% + */ + if ($user != "anyone" && $user != "%members%"){ + $tmp[$permission][] = $user; + } + + /* There is an entry in $this->imapacl like this this ... + $this->attrs['imapacl']['anyone'] = "p"; + $this->attrs['imapacl']['%members%'] = "lprs"; + $this->attrs['imapacl'][''] = ""; <------ This is used to diplay an empty + Field for special acls in our template. + If there is at least one special acl in out imapacl, + we don't need this entry anymore, because it is already displayed. + */ + if ($user != "anyone" && $user != "%members%"){ + unset($this->imapacl['']); + } + } + } + + /* In this section we dectect which acl is tho most used + This will be used as %members% acl + */ + $tmp2 = array(); + foreach($tmp as $acl => $user){ + $tmp2[count($tmp[$acl])]=$acl; + } + /* Most used at last + */ + ksort($tmp2); + + /* Assign last (most used acl) to %members% acl + */ + $str = array_pop($tmp2); + if(!empty($str)) { + $this->imapacl['%members%']=$str; + } + + /* Open ldap connection + */ + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + + /* Remove those users, that use %members% acl && are member of this group. */ + foreach($this->imapacl as $mail => $permission){ + $ldap->search("(&(objectClass=person)(mail=".$mail."))",array("uid")); + $atr = $ldap->fetch(); + if((isset($this->attrs['memberUid'])) && (is_array($this->attrs['memberUid']))){ + if((isset($atr['uid'][0]))&&(in_array($atr['uid'][0],$this->attrs['memberUid']))&&($permission == $this->imapacl['%members%'])){ + unset($this->imapacl[$mail]); + } + } + } + /* Append an empty entry, for special acl handling */ + if(count($this->imapacl)==2){ + $this->imapacl[''] =""; + } + + }else{ // Not kolab + /* Load permissions */ + if (isset($this->attrs['acl'])){ + for ($i= 0; $i<$this->attrs['acl']['count']; $i++){ + list($user, $permission)= split(' ', $this->attrs['acl'][$i]); + $this->imapacl[$user]= $permission; + if ($user != "anyone" && $user != "%members%"){ + unset($this->imapacl['']); + } } } } + /* Load Mailserver + */ + if(isset($this->attrs['gosaMailServer'][0])){ + $this->gosaMailServer = $this->attrs['gosaMailServer'][0]; + } /* Fill translations */ $this->perms["lrs"]= _("read"); $this->perms["lrsp"]= _("post"); @@ -164,11 +288,10 @@ class mailgroup extends plugin $this->perms["lrswipcd"]= _("write"); } - function execute() { - /* Call parent execute */ - plugin::execute(); + /* Call parent execute */ + //plugin::execute(); /* Load templating engine */ $smarty= get_smarty(); @@ -272,7 +395,7 @@ class mailgroup extends plugin /* Delete forward email addresses */ if (isset($_POST['delete_forwarder'])){ - if (count($_POST['forwarder_list']) + if (count($_POST['forwarder_list']) && chkacl ($this->acl, "gosaMailForwardingAddress") == ""){ $this->delForwarder ($_POST['forwarder_list']); @@ -348,7 +471,8 @@ class mailgroup extends plugin } $acl= array($this->config->current['BASE'] => ":all"); - $res= get_list($acl, "(&(objectClass=gosaMailAccount)$filter)", TRUE, $gmailfilter['depselect'], array("sn", "mail", "givenName"), TRUE); + $res= get_list("(&(objectClass=gosaMailAccount)$filter)", $acl, $gmailfilter['depselect'], + array("sn", "mail", "givenName"), GL_SUBSEARCH | GL_SIZELIMIT); $ldap->cd($gmailfilter['depselect']); $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName")); error_reporting (0); @@ -388,6 +512,7 @@ class mailgroup extends plugin if (isset($this->imapacl['anyone'])){ $smarty->assign("default_permissions", $this->imapacl['anyone']); } + $smarty->assign("member_permissions", "lrsp"); if (isset($this->imapacl['%members%'])){ $smarty->assign("member_permissions", $this->imapacl['%members%']); } @@ -402,7 +527,7 @@ class mailgroup extends plugin foreach($this->imapacl as $user => $acl){ if ($user != "anyone" && $user != "%members%"){ $tmp.= "