"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",
"gosaMailAlternateAddress", "gosaMailForwardingAddress",
"gosaMailDeliveryMode", "gosaSpamSortLevel", "gosaSpamMailbox",
"acl","gosaSharedFolderTarget", "gosaVacationMessage");
var $objectclasses= array("gosaMailAccount");
function mailgroup ($config, $dn= NULL, $ui= NULL)
{
/* Initialise all available attributes ... if possible
*/
plugin::plugin($config, $dn);
/* Set mailMethod to the one defined in gosa.conf
*/
if (isset($this->config->current['MAILMETHOD'])){
$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));
}
/* 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 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]);
}
}
}
/* 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])){
/* Maybe the entry is not saved in new style, get
permissions from IMAP and convert them to acl attributes */
if (!isset($this->attrs['acl'])){
$this->imapacl= $method->getSharedFolderPermissions($this->uid);
/* Need to filter what a member acl could be... */
$vote= array();
$peak= 0;
$leader= "";
foreach ($this->imapacl as $user => $acl){
if ($user != "anyone" ){
if (!isset($vote[$acl])){
$vote[$acl]= 1;
} else {
$vote[$acl]++;
}
if ($vote[$acl] > $peak){
$leader= $acl;
$peek= $vote[$acl];
}
}
}
/* Highest count wins as %members%, remove all members
with the same acl */
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(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"
/* Get global filter config */
if (!is_global("gmailfilter")){
$ui= get_userinfo();
$base= get_base_from_people($ui->dn);
$gmailfilter= array( "depselect" => $base,
"muser" => "",
"regex" => "*");
register_global("gmailfilter", $gmailfilter);
}
/* Load permissions */
$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");
$this->perms["p"]= _("external post");
$this->perms["lrsip"]= _("append");
$this->perms["lrswipcd"]= _("write");
}
function execute()
{
/* Call parent execute */
//plugin::execute();
/* Load templating engine */
$smarty= get_smarty();
if ($_SESSION['js']==FALSE){
$smarty->assign("javascript", "false");
} else {
$smarty->assign("javascript", "true");
}
/* Do we need to flip is_account state? */
if (isset($_POST['modify_state'])){
$this->is_account= !$this->is_account;
}
/* Do we represent a valid account? */
if (!$this->is_account && $this->parent == NULL){
$display= " ".
_("This 'dn' has no valid mail extensions.")."";
return ($display);
}
/* Show tab dialog headers */
$display= "";
if ($this->parent != NULL){
if ($this->is_account){
$display= $this->show_header(_("Remove mail account"),
_("This account has mail features enabled. You can disable them by clicking below."));
} else {
$display= $this->show_header(_("Create mail account"),
_("This account has mail features disabled. You can enable them by clicking below."));
return ($display);
}
}
/* Add ACL? */
foreach ($this->indexed_user as $nr => $user){
if (isset($_POST["add_$nr"])){
$this->imapacl[""]= "l";
}
if (isset($_POST["del_$nr"])){
unset ($this->imapacl[$user]);
}
}
/* Trigger forward add dialog? */
if (isset($_POST['add_local_forwarder'])){
$this->forward_dialog= TRUE;
$this->dialog= TRUE;
}
/* Cancel forward add dialog? */
if (isset($_POST['add_locals_cancel'])){
$this->forward_dialog= FALSE;
$this->dialog= FALSE;
}
/* Finished adding of locals? */
if (isset($_POST['add_locals_finish'])){
if (count ($_POST['local_list']) &&
chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
/* Walk through list of forwarders, ignore own addresses */
foreach ($_POST['local_list'] as $val){
if (!in_array ($val, $this->gosaMailAlternateAddress) &&
$val != $this->mail){
$this->addForwarder($val);
}
}
}
$this->forward_dialog= FALSE;
$this->dialog= FALSE;
}
/* Add forward email addresses */
if (isset($_POST['add_forwarder'])){
if ($_POST['forward_address'] != ""){
/* Valid email address specified? */
$address= $_POST['forward_address'];
if (!is_email($address)){
print_red (_("You're trying to add an invalid email address ".
"to the list of forwarders."));
} elseif ($address == $this->mail
|| in_array($address, $this->gosaMailAlternateAddress)) {
print_red (_("Adding your one of your own addresses to the forwarders makes no sense."));
} else {
/* Add it */
if (chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
$this->addForwarder ($address);
}
}
}
}
/* Delete forward email addresses */
if (isset($_POST['delete_forwarder'])){
if (count($_POST['forwarder_list'])
&& chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
$this->delForwarder ($_POST['forwarder_list']);
}
}
/* Add alternate email addresses */
if (isset($_POST['add_alternate'])){
if ($_POST['alternate_address'] != "" &&
chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
if (!is_email($_POST['alternate_address'])){
print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
} elseif (($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
$ui= get_userinfo();
if ($user != $ui->username){
print_red (_("The address you're trying to add is already used by user")." '$user'.");
}
}
}
}
/* Delete alternate email addresses */
if (isset($_POST['delete_alternate']) && isset ($_POST['alternates_list'])){
if (count($_POST['alternates_list']) &&
chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
$this->delAlternate ($_POST['alternates_list']);
}
}
/* Show forward add dialog */
if ($this->forward_dialog){
$ldap= $this->config->get_ldap_link();
/* Save data */
$gmailfilter= get_global("gmailfilter");
foreach( array("depselect", "muser", "regex") as $type){
if (isset($_POST[$type])){
$gmailfilter[$type]= $_POST[$type];
}
}
if (isset($_GET['search'])){
$s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
if ($s == "**"){
$s= "*";
}
$gmailfilter['regex']= $s;
}
register_global("gmailfilter", $gmailfilter);
/* Get actual list */
$mailusers= array ();
if ($gmailfilter['regex'] != '*' && $gmailfilter['regex'] != ""){
$regex= $gmailfilter['regex'];
$filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
} else {
$filter= "";
}
if ($gmailfilter['muser'] != ""){
$user= $gmailfilter['muser'];
$filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
}
/* Add already present people to the filter */
$exclude= "";
foreach ($this->gosaMailForwardingAddress as $mail){
$exclude.= "(mail=$mail)";
}
if ($exclude != ""){
$filter.= "(!(|$exclude))";
}
$acl= array($this->config->current['BASE'] => ":all");
$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);
while ($attrs= $ldap->fetch()){
if(preg_match('/%/', $attrs['mail'][0])){
continue;
}
$name= $this->make_name($attrs);
$mailusers[$attrs['mail'][0]]= $name."<".
$attrs['mail'][0].">";
}
error_reporting (E_ALL);
natcasesort ($mailusers);
reset ($mailusers);
/* Show dialog */
$smarty->assign("search_image", get_template_path('images/search.png'));
$smarty->assign("usearch_image", get_template_path('images/search_user.png'));
$smarty->assign("tree_image", get_template_path('images/tree.png'));
$smarty->assign("infoimage", get_template_path('images/info.png'));
$smarty->assign("launchimage", get_template_path('images/small_filter.png'));
$smarty->assign("mailusers", $mailusers);
$smarty->assign("deplist", $this->config->idepartments);
$smarty->assign("apply", apply_filter());
$smarty->assign("alphabet", generate_alphabet());
$smarty->assign("hint", print_sizelimit_warning());
foreach( array("depselect", "muser", "regex") as $type){
$smarty->assign("$type", $gmailfilter[$type]);
}
$smarty->assign("hint", print_sizelimit_warning());
$display.= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE));
return ($display);
}
/* Assemble normal permissions */
$smarty->assign("permissionsACL", chkacl($this->acl, "permissions"));
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%']);
}
/* Assemble extra attributes */
$perm= chkacl($this->acl, "permissions");
$tmp= "";
$nr= 0;
$count= count($this->imapacl);
$this->indexed_user= array();
$this->indexed_acl= array();
foreach($this->imapacl as $user => $acl){
if ($user != "anyone" && $user != "%members%"){
$tmp.= "