Code

Added ACL check to personal mail account-
[gosa.git] / gosa-plugins / mail / personal / mail / class_mailAccount.inc
1 <?php
2 /*! \brief   mail plugin
3   \author  Cajus Pollmeier <pollmeier@gonicus.de>
4   \version 2.00
5   \date    24.07.2003
7   This class provides the functionality to read and write all attributes
8   relevant for gosaMailAccounts from/to the LDAP. It does syntax checking
9   and displays the formulars required.
10  */
12 class mailAccount extends plugin
13 {
14   /* Definitions */
15   var $plHeadline         = "Mail";
16   var $plDescription      = "This does something";
17   var $method             = "mailMethod";
19   var $gosaVacationStart                  = 0;
20   var $gosaVacationStop                   = 0;
21   var $view_logged = FALSE;
23   /* plugin specific values */
24   var $mail                               = "";
25   var $gosaMailAlternateAddress           = array();
26   var $gosaMailForwardingAddress          = array();
27   var $gosaMailDeliveryMode               = "[L        ]";
28   var $gosaMailServer                     = "";
29   var $gosaMailQuota                      = "";
30   var $gosaMailMaxSize                    = "";
31   var $gosaVacationMessage                = "";
32   var $gosaSpamSortLevel                  = "";
33   var $gosaSpamMailbox                    = "";
35   var $quotaUsage                         = 0;
36   var $forward_dialog                     = FALSE;
37   var $folder_prefix                      = "";
38   var $mailboxList                        = array("INBOX");
39   var $default_permissions                = "none";
40   var $member_permissions                 = "post";
41   var $members                            = array();
42   var $admins                             = array();
43   var $vacations                          = array();
44   var $perms                              = array(  "lrs"       => "read", 
45                                                     "lrsp"      => "post", 
46                                                     "lrsip"     => "append",
47                                                     "lrswipcd"  => "write", 
48                                                     "lrswipcda" => "all" );
50   /* attribute list for save action */
51   var $attributes= array("mail", "gosaMailServer", "gosaMailQuota", "gosaMailMaxSize","gosaMailForwardingAddress",
52       "gosaMailDeliveryMode", "gosaSpamSortLevel", "gosaSpamMailbox","gosaMailAlternateAddress","gosaVacationStart","gosaVacationStop",
53       "gosaVacationMessage", "gosaMailAlternateAddress", "gosaMailForwardingAddress");
54   var $objectclasses= array("gosaMailAccount");
55   var $uid              = "";
57   var $sieve_management = NULL;
58   var $multiple_support = TRUE;
60   /* constructor, if 'dn' is set, the node loads the given
61      'dn' from LDAP */
62   function mailAccount (&$config, $dn= NULL)
63   {
64     global $class_mapping;
66     $this->gosaVacationStart = time();
67     $this->gosaVacationStop = time();
69     /* Load bases attributes */
70     plugin::plugin($config, $dn);
72     /* Set uid */
73     if(isset($this->attrs['uid'])){
74       $this->uid = $this->attrs['uid'][0];
75     }
76  
77     if(is_array($this->gosaMailServer) && isset($this->gosaMailServer[0])){
78       $this->gosaMailServer = $this->gosaMailServer[0];
79     }
81     /* Save initial account state */
82     $this->initially_was_account= $this->is_account;
84     /*  Set mailMethod to the one defined in gosa.conf */
85     if (isset($this->config->current['MAILMETHOD'])){
86       $method= $this->config->current['MAILMETHOD'];
88       $cls = get_correct_class_name("mailMethod$method");
89       if ($cls && class_exists($cls)){
90         $this->method= $cls;
91       } else {
92         msg_dialog::display(_("Configuration error"), sprintf(_("Mail method '%s' is unknown!"), $method), ERROR_DIALOG);
93       }
94     }
96     
97     /* Create the account prefix  user. user/ 
98        Preset folder prefix. Will change it later to respect
99        altnamespace. */
100     if (isset($this->config->current['CYRUSUNIXSTYLE']) && $this->config->current['CYRUSUNIXSTYLE'] == "true"){
101       $this->folder_prefix= "user/";
102     }elseif (isset($this->config->data['MAIN']['CYRUSUNIXSTYLE']) && $this->config->data['MAIN']['CYRUSUNIXSTYLE'] == "true"){
103       $this->folder_prefix= "user/";
104     } else {
105       $this->folder_prefix= "user.";
106     }
107     
108     /* This is not a new account, parse additional attributes */
109     if (($dn !== NULL) && ($dn != "new") && $this->is_account){
111       /* Load attributes containing arrays */
112       foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
113         $this->$val= array();
114         if (isset($this->attrs["$val"]["count"])){
115           for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
116             array_push($this->$val, $this->attrs["$val"][$i]);
117           }
118         }
119       }
122       /* Only do IMAP actions if gosaMailServer attribute is set */
123       if (isset ($this->attrs["gosaMailServer"][0])){
125         $method = new $this->method($this->config);
126         $id     = $method->uattrib;
128         /* Adapt attributes if needed */
129         $method->fixAttributesOnLoad($this);
131         /* FixAttributesOnLoad possibly creates an array out of gosaMailServer.
132             If the mail tab wasn't opened once before saving, the account can't be saved */
133         if(is_array($this->gosaMailServer)){
134           $this->gosaMailServer = $this->gosaMailServer[0];
135         }
137         if ($method->connect($this->attrs["gosaMailServer"][0])){
139           /* Update quota values */
140           $quota= $method->getQuota($this->folder_prefix.$this->$id);
141          
142           if($quota){
143             if ($quota['gosaMailQuota'] == 2147483647){
144               $this->quotaUsage     = "";
145               $this->gosaMailQuota  = "";
146             } else {
147               $this->quotaUsage     = $quota['quotaUsage'];
148               $this->gosaMailQuota  = $quota['gosaMailQuota'];
149             }
150           }else{
151             $this->quotaUsage     = "";
152             $this->gosaMailQuota  = "";
153           }
155           /* Get mailboxes / folder like INBOX ..*/
156           $this->mailboxList= $method->getMailboxList($this->folder_prefix.$this->$id,$this->$id);
157           
158           $method->disconnect();
159         }else{
160           /* Could not connect to ldap.
161            */
162           if (isset($this->attrs['gosaMailQuota'][0])){
163             $this->gosaMailQuota = $this->attrs['gosaMailQuota'][0];
164           }
165         }
166       }
167     }
169     /* Fill vacation array */
170     $this->vacation= array();
171     if (isset($this->config->current['VACATIONDIR'])){
172       $dir= $this->config->current['VACATIONDIR'];
173       if (is_dir($dir) && is_readable($dir)){
175         /* Look for files and build the vacation array */
176         $dh= opendir($dir);
177         while ($file = readdir($dh)){
178           $description= $this->parse_vacation("$dir/$file");
179           if ($description != ""){
180             $this->vacation["$dir/$file"]= $description;
181           }
182         }
183         closedir($dh);
184       }
185     }
187     /* Create sieve management class */
188     $method = new $this->method($this->config);
189     $id     = $method->uattrib;
190     $this->sieve_management = new sieveManagement($this->config,$this->dn,$this,$id);
192     /* Get global filter config */
193     if (!session::is_set("mailfilter")){
194       $ui= get_userinfo();
195       $base= get_base_from_people($ui->dn);
196       $mailfilter= array( "depselect"       => $base,
197           "muser"            => "",
198           "regex"           => "*");
199       session::set("mailfilter", $mailfilter);
200     }
201   }
204   function parse_vacation($file)
205   {
206     $desc= "";
208     if (is_file($file)){
209       $fh = fopen($file, "r");
210       $line= fgets($fh, 256);
212       if (!preg_match('/^DESC:/', $line)){
213         msg_dialog::display(_("Configuration error"), sprintf(_("No DESC tag in vacation template '%s'!"), $file), ERROR_DIALOG);
214         return $desc;
215       }
216       fclose ($fh);
218       $desc= trim(preg_replace('/^DESC:\s*/', '', $line));
219     }
221     return $desc;
222   }
225   function execute()
226   {
227     /* Call parent execute */
228     plugin::execute();
230     /* Log view */
231     if($this->is_account && !$this->view_logged){
232       $this->view_logged = TRUE;
233       new log("view","users/".get_class($this),$this->dn);
234     }
236     /* Initialise vars */
238     /* Load templating engine */
239     $smarty= get_smarty();
240     $display= "";
242     /* Get available mailserver */
243     $mailserver= array();
244     $ui = get_userinfo();
245     foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
246       if( $this->gosaMailServer == $key || 
247           preg_match("/r/",$ui->get_permissions($val['server_dn'],"server/goImapServer",""))){
248         $mailserver[]= $key;
249       }
250     }
252     /* 
253      * Sieve Management 
254      */
255     if(isset($_POST['sieveManagement']) 
256         && preg_match("/C/",$this->gosaMailDeliveryMode)
257         && $this->acl_is_writeable("sieveManagement")) {
259       $this->dialog = $this->sieve_management;
260     }
261    
262     /* Cancel sieve edit */
263     if(isset($_POST['sieve_cancel'])){
264       $this->dialog = FALSE;
265     }
266  
267     /* Save sieve changes */
268     if(isset($_POST['sieve_finish'])){
269       $this->sieve_management = $this->dialog;
270       $this->dialog = FALSE;
271     }
272  
273     if(is_object($this->dialog)){
274       $this->dialog->save_object();
275       return($this->dialog->execute());
276     } 
279     /* Handle account state */
280     /* Do we need to flip is_account state? */
281     if(isset($_POST['modify_state'])){
282       if($this->is_account && $this->acl_is_removeable()){
283         $this->is_account= FALSE;
284       }elseif(!$this->is_account && $this->acl_is_createable()){
285         $this->is_account= TRUE;
286       }
287     }
289     /* Do we represent a valid account? */
290     if(!$this->multiple_support_active){
291       if (!$this->is_account && $this->parent === NULL){
292         $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\">&nbsp;<b>".
293           msgPool::noValidExtension(_("Mail"))."</b>";
295         $display.= back_to_main();
296         return ($display);
297       }
299       /* Show tab dialog headers */
300       if ($this->parent !== NULL){
301         if ($this->is_account){
302           if($this->accountDelegationsConfigured()){
303             $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Mail")),
304                 _("Mail settings cannot be removed while there are delegations configured!"),TRUE,TRUE);
305           }else{
306             $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Mail")),
307                 msgPool::featuresEnabled(_("Mail")));
308           }
309         } else {
310           $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Mail")),
311                 msgPool::featuresDisabled(_("Mail")));
312           return ($display);
313         }
314       }
315     }
317     /* Forwarder  subdialog */
319     /* Trigger forward add dialog? */
320     if (isset($_POST['add_local_forwarder'])){
321       $this->forward_dialog= TRUE;
322       $this->dialog= TRUE;
323     }
325     /* Cancel forward add dialog? */
326     if (isset($_POST['add_locals_cancel'])){
327       $this->forward_dialog= FALSE;
328       $this->dialog= FALSE;
329     }
331     /* Finished adding of locals? */
332     if (isset($_POST['add_locals_finish'])){
334       if (isset($_POST['local_list'])){
336         /* Check if we are able to write gosaMailForwardingAddress */
337         if($this->acl_is_writeable("gosaMailForwardingAddress")){
339           /* Walk through list of forwarders, ignore own addresses */
340           foreach ($_POST['local_list'] as $val){
341             if (!in_array ($val, $this->gosaMailAlternateAddress) &&
342                 $val != $this->mail){
344               $this->addForwarder($val);
345               $this->is_modified= TRUE;
346             }
347           }
348         }
349         $this->forward_dialog= FALSE;
350         $this->dialog= FALSE;
351       } else {
352         msg_dialog::display(_("Error"), _("Please select an entry!"), ERROR_DIALOG);
353       }
354     }
356     /* Add forward email addresses */
357     if (isset($_POST['add_forwarder'])){
358       if ($_POST['forward_address'] != ""){
360         /* Valid email address specified? */
361         $address= $_POST['forward_address'];
362         $valid= FALSE;
363         if (!tests::is_email($address)){
364           if (!tests::is_email($address, TRUE)){
365             if ($this->is_template){
366               $valid= TRUE;
367             } else {
368               msg_dialog::display(_("Error"), 
369                   msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com"),
370                   ERROR_DIALOG);
371             }
372           }
373         } elseif ($address == $this->mail
374             || in_array($address, $this->gosaMailAlternateAddress)) {
375           msg_dialog::display(_("Error"),_("Cannot add primary address to the list of forwarders!") , ERROR_DIALOG);
376         } else {
377           $valid= TRUE;
378         }
380         if ($valid){
382           /* Add it, if we are able to write gosaMailForwardingAddress */
383           if($this->acl_is_writeable("gosaMailForwardingAddress")){
384             $this->addForwarder ($address);
385             $this->is_modified= TRUE;
386           }
387         }
388       }
389     }
391     /* Delete forward email addresses */
392     if (isset($_POST['delete_forwarder'])){
393       $this->delForwarder ($_POST['forwarder_list']);
394     }
397     /* Add alternate email addresses */
398     if (isset($_POST['add_alternate'])){
400       $valid= FALSE;
401       if (!tests::is_email($_POST['alternate_address'])){
402         if ($this->is_template){
403           if (!(tests::is_email($_POST['alternate_address'], TRUE))){
404             msg_dialog::display(_("Error"), 
405                 msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com"),
406                 ERROR_DIALOG);
408           } else {
409             $valid= TRUE;
410           }
411         } else {
412           msg_dialog::display(_("Error"), 
413               msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com"),
414               ERROR_DIALOG);
415         }
417       } else {
418         $valid= TRUE;
419       }
421       if ($valid && ($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
422         $ui= get_userinfo();
423         if ($user != $ui->username){
424           msg_dialog::display(_("Error"), msgPool::duplicated(_("Mail address"))."&nbsp;".
425             sprintf(_("Address is already in use by user '%s'."), $user), ERROR_DIALOG);
426         }
427       }
428     }
430     /* Delete alternate email addresses */
431     if (isset($_POST['delete_alternate']) && isset($_POST['alternates_list'])){
432       $this->delAlternate ($_POST['alternates_list']);
433     }
435   
436     /* Vacation message */
437   
438     /* Import vacation message? */
439     if (isset($_POST["import_vacation"]) && isset($this->vacation[$_POST["vacation_template"]])){
441       
442       /* Save message */
443       if($this->multiple_support_active){
444         $contents = file_get_contents($_POST["vacation_template"]);
445       }else{
446         $contents = $this->prepare_vacation_template(file_get_contents($_POST["vacation_template"]));
447       }
448       $this->gosaVacationMessage= htmlspecialchars($contents);
449     }
451   
452     /* Display forward dialog if requested above */
454     /* Show forward add dialog */
455     if ($this->forward_dialog){
456       $ldap= $this->config->get_ldap_link();
458       /* Save data */
459       $mailfilter= session::get("mailfilter");
460       foreach( array("depselect", "muser", "regex") as $type){
461         if (isset($_POST[$type])){
462           $mailfilter[$type]= $_POST[$type];
463         }
464       }
465       if (isset($_GET['search'])){
466         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
467         if ($s == "**"){
468           $s= "*";
469         }
470         $mailfilter['regex']= $s;
471       }
472       session::set("mailfilter", $mailfilter);
474       /* Get actual list */
475       $mailusers= array ();
476       if ($mailfilter['regex'] != '*' && $mailfilter['regex'] != ""){
477         $regex= $mailfilter['regex'];
478         $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
479       } else {
480         $filter= "";
481       }
482       if ($mailfilter['muser'] != ""){
483         $user= $mailfilter['muser'];
484         $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
485       }
487       /* Add already present people to the filter */
488       $exclude= "";
489       foreach ($this->gosaMailForwardingAddress as $mail){
490         $exclude.= "(mail=$mail)";
491       }
492       if ($exclude != ""){
493         $filter.= "(!(|$exclude))";
494       }
496       $res= get_list("(&(objectClass=gosaMailAccount)$filter)", "users", $mailfilter['depselect'], 
497                      array("sn", "mail", "givenName"), GL_SIZELIMIT | GL_SUBSEARCH);
498       $ldap->cd($mailfilter['depselect']);
499       $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
500       error_reporting (0);
501       while ($attrs= $ldap->fetch()){
502         if(preg_match('/%/', $attrs['mail'][0])){
503           continue;
504         }
505         $name= $this->make_name($attrs);
506         $mailusers[$attrs['mail'][0]]= $name."&lt;".
507           $attrs['mail'][0]."&gt;";
508       }
509       error_reporting (E_ALL | E_STRICT);
510       natcasesort ($mailusers);
511       reset ($mailusers);
513       /* Show dialog */
514       $smarty->assign("search_image", get_template_path('images/lists/search.png'));
515       $smarty->assign("usearch_image", get_template_path('images/lists/search-user.png'));
516       $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
517       $smarty->assign("infoimage", get_template_path('images/info.png'));
518       $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
519       $smarty->assign("mailusers", $mailusers);
520       if (isset($_POST['depselect'])){
521         $smarty->assign("depselect", $_POST['depselect']);
522       }
523       $smarty->assign("deplist", $this->config->idepartments);
524       $smarty->assign("apply", apply_filter());
525       $smarty->assign("alphabet", generate_alphabet());
526       $smarty->assign("hint", print_sizelimit_warning());
527       foreach( array("depselect", "muser", "regex") as $type){
528         $smarty->assign("$type", $mailfilter[$type]);
529       }
530       $smarty->assign("hint", print_sizelimit_warning());
532       $display.= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE, dirname(__FILE__)));
533       return ($display);
534     }
536     /* Display mail account tab */
538     $smarty->assign("mailServers", $mailserver);
539     $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
541     $tmp  = $this->plInfo();
542     foreach($tmp['plProvidedAcls'] as $name => $transl){
543       $smarty->assign("$name"."ACL", $this->getacl($name,$SkipWrite));
544     }
546     foreach(array("gosaMailServer", "gosaMailQuota", "perms", "mail",
547           "gosaMailAlternateAddress", "gosaMailForwardingAddress",
548           "gosaVacationMessage", "gosaMailDeliveryMode", "gosaVacationStart",
549           "gosaVacationStop", "gosaMailMaxSize", "gosaSpamSortLevel", "gosaSpamMailbox") as $val){
550       $smarty->assign("$val", $this->$val);
551     }
553     if (is_numeric($this->gosaMailQuota) && $this->gosaMailQuota != 0){
554       $smarty->assign("quotausage", progressbar(round(($this->quotaUsage * 100)/ $this->gosaMailQuota),100,15,true));
555       $smarty->assign("quotadefined", "true");
556     } else {
557       $smarty->assign("quotadefined", "false");
558     }
560     /* Disable mail field if needed */
561     $method= new $this->method($this->config);
562     if ($method->uattrib == "mail" && $this->initially_was_account){
563       $smarty->assign("mailACL", preg_replace("/w/","",$this->getacl("mail",$SkipWrite)));
564     }
566     /* Disable/Enable range select, but do not disable them twice 
567      *  if they are already diabled by "use own sieve script"
568      */
569     if (preg_match('/V/', $this->gosaMailDeliveryMode) || preg_match("/C/",$this->gosaMailDeliveryMode)){
570       $smarty->assign('rangeEnabled', "");
571     } else {
572       $smarty->assign('rangeEnabled', "disabled");
573     }
575     if (!preg_match("/L/", $this->gosaMailDeliveryMode)) {
576       $smarty->assign("only_local", "checked");
577     } else {
578       $smarty->assign("only_local", "");
579     }
581     $types = array(
582           "V"=>"use_vacation",
583           "S"=>"use_spam_filter",
584           "R"=>"use_mailsize_limit",
585           "I"=>"drop_own_mails",
586           "C"=>"own_script");
588     /* Fill checkboxes */
589     foreach($types as $option => $varname){
590       if (preg_match("/".$option."/", $this->gosaMailDeliveryMode)) {
591         $smarty->assign($varname, "checked");
592       } else {
593         $smarty->assign($varname, "");
594       }
595     }
596    
597     /* Display mail account tab */
598     if($this->gosaVacationStart ==0){
599       $date= getdate(time());
600     }else{
601       $date= getdate($this->gosaVacationStart);
602     }
603     $days= array();
604     for($d= 1; $d<32; $d++){
605       $days[$d]= $d;
606     }
607     $years= array();
608     for($y= $date['year']-10; $y<$date['year']+10; $y++){
609       $years[]= $y;
610     }
611     $months= msgPool::months();
612     $smarty->assign("start_day", $date["mday"]);
613     $smarty->assign("days", $days);
614     $smarty->assign("months", $months);
615     $smarty->assign("start_month", $date["mon"]-1);
616     $smarty->assign("years", $years);
617     $smarty->assign("start_year", $date["year"]);
619     if($this->gosaVacationStop ==0){
620       $date= getdate(time());
621       $date["mday"]++;
622     }else{
623       $date= getdate($this->gosaVacationStop);
624     }
625     $smarty->assign("end_day", $date["mday"]);
626     $smarty->assign("end_month", $date["mon"]-1);
627     $smarty->assign("end_year", $date["year"]);
630  
631     /* Have vacation templates? */
632     $smarty->assign("template", "");
633     if (count($this->vacation)){
634       $smarty->assign("show_templates", "true");
635       $smarty->assign("vacationtemplates", $this->vacation);
636       if (isset($_POST['vacation_template'])){
637         $smarty->assign("template", $_POST['vacation_template']);
638       }
639     } else {
640       $smarty->assign("show_templates", "false");
641     }
643     /* Fill spam selector */
644     $spamlevel= array();
645     for ($i= 0; $i<21; $i++){
646       $spamlevel[]= $i;
647     }
648     $smarty->assign("spamlevel", $spamlevel);
649     $smarty->assign("spambox", $this->mailboxList);
651     foreach($this->attributes as $attr){
652       $u_attr = "use_".$attr;
653       $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
654     }
656     foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
657       $u_attr = "use_".$attr;
658       $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
659     }
661     $smarty->assign("multiple_support",$this->multiple_support_active);
662     $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
663     return ($display);
664   }
667   /* remove object from parent */
668   function remove_from_parent()
669   {
670     /* Cancel if there's nothing to do here */
671     if (!$this->initially_was_account){
672       return;
673     }
674     
675     /* include global link_info */
676     $ldap= $this->config->get_ldap_link();
678     /* Remove and write to LDAP */
679     plugin::remove_from_parent();
681     /* Zero arrays */
682     $this->attrs['gosaMailAlternateAddress']= array();
683     $this->attrs['gosaMailForwardingAddress']= array();
685     /* Adapt attributes if needed */
686     $method= new $this->method($this->config);
687     $method->fixAttributesOnRemove($this);
689     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
690     $ldap->cd($this->dn);
691     $this->cleanup();
693     $ldap->modify ($this->attrs); 
695     /* Add "view" to logging class */ 
696     new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
698     if (!$ldap->success()){
699       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
700     }
702     /* Connect to IMAP server for account deletion */
703     if ($this->gosaMailServer != ""){
704       $method= new $this->method($this->config);
705       $id= $method->uattrib;
706       if ($method->connect($this->gosaMailServer)){
708         /* Remove account from IMAP server */
709         $method->deleteMailbox($this->folder_prefix.$this->$id);
710         $method->disconnect();
711       }
712     }
714     /* Update shared folder membership, ACL may need to be updated */
715     $this->updateSharedFolder(); 
717     /* Optionally execute a command after we're done */
718     $this->handle_post_events("remove",array("uid" => $this->uid));
719   }
721   
722   /* check if we have some delegations configured, those delegations must be removed first */
723   function accountDelegationsConfigured()
724   { 
725     /* We are in administrational edit mode.
726         Check tab configurations directly */
727     if(isset($this->attrs)){
728       $checkArray  = array("kolabInvitationPolicy","unrestrictedMailSize", "calFBURL","kolabDelegate","kolabFreeBusyFuture");
729       foreach($checkArray as $index){
730         if(isset($this->attrs[$index])){
731            return(true);
732         }
733       }
734     }
735     return(false); 
736   }
737  
739   /* Save data to object */
740   function save_object()
741   {
742     if (isset($_POST['mailTab'])){
744       /* Save ldap attributes */
745       plugin::save_object();
748       if(isset($_POST['own_script'])){
750         if(!preg_match("/C/",$this->gosaMailDeliveryMode)){
751           $str= preg_replace("/[\[\]]/","",$this->gosaMailDeliveryMode);
752           $this->gosaMailDeliveryMode = "[".$str."C]";
753         }
755       }else{
757         /* Assemble mail delivery mode
758            The mode field in ldap consists of values between braces, this must
759            be called when 'mail' is set, because checkboxes may not be set when
760            we're in some other dialog.
762           Example for gosaMailDeliveryMode [LR        ]
763           L: Local delivery
764           R: Reject when exceeding mailsize limit
765           S: Use spam filter
766           V: Use vacation message
767           C: Use custm sieve script
768           I: Only insider delivery */
770         $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
773         /* Handle delivery flags */
774         if($this->acl_is_writeable("gosaMailDeliveryModeL")){
775           if(!preg_match("/L/",$tmp) && !isset($_POST['only_local'])){
776             $tmp.="L";
777           }elseif(preg_match("/L/",$tmp) && isset($_POST['only_local'])){
778             $tmp = preg_replace("/L/","",$tmp);
779           }
780         }
782         $opts = array(     
783             "R"   => "use_mailsize_limit",
784             "S"   => "use_spam_filter",
785             "V"   => "use_vacation",
786             "C"   => "own_script",
787             "I"   => "drop_own_mails");
789         foreach($opts as $flag => $post){
790           if($this->acl_is_writeable("gosaMailDeliveryMode".$flag)){
791             if(!preg_match("/".$flag."/",$tmp) && isset($_POST[$post])){
792               $tmp.= $flag;
793             }elseif(preg_match("/".$flag."/",$tmp) && !isset($_POST[$post])){
794               $tmp = preg_replace("/".$flag."/","",$tmp);
795             }
796           }
797         }
799         $tmp= "[$tmp]";
800         if ($this->gosaMailDeliveryMode != $tmp){
801           $this->is_modified= TRUE;
802         }
803         $this->gosaMailDeliveryMode= $tmp;
806         if($this->acl_is_writeable("gosaVacationMessage") && preg_match("/V/",$this->gosaMailDeliveryMode)){
807           if(isset($_POST['gosaVacationStart'])){
808             $this->gosaVacationStart = $_POST['gosaVacationStart'];
809           }
810           if(isset($_POST['gosaVacationStop'])){
811             $this->gosaVacationStop = $_POST['gosaVacationStop'];
812           }
813         }
814       }
815     }
816   }
819   /* Save data to LDAP, depending on is_account we save or delete */
820   function save()
821   {
822     $ldap= $this->config->get_ldap_link();
824     /* Call parents save to prepare $this->attrs */
825     plugin::save();
827     /* Save arrays */
828     $this->attrs['gosaMailAlternateAddress']= $this->gosaMailAlternateAddress;
829     $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
831     /* Adapt attributes if needed */
832     $method= new $this->method($this->config);
833     $id= $method->uattrib;
835     $method->fixAttributesOnStore($this);
837     /* Remove Mailquota if = "" or "0"  */
838     if((isset($this->attrs['gosaMailQuota']))&&(!$this->attrs['gosaMailQuota'])) {
839       $this->attrs['gosaMailQuota']=0;
840     }
842     if(empty($this->attrs['gosaSpamMailbox'])){
843       unset($this->attrs['gosaSpamMailbox']);
844     }
846     $this->attrs['mail'] = strtolower($this->attrs['mail']); 
848         /* Remove attributes - if not needed */
849     if (!preg_match('/V/', $this->gosaMailDeliveryMode)){
850       unset($this->attrs['gosaVacationStart']);
851       unset($this->attrs['gosaVacationStop']);
852     }
855     /* Remove attributes - if not needed */
856     if (!preg_match('/V/', $this->gosaMailDeliveryMode)){
857       unset($this->attrs['gosaVacationStart']);
858       unset($this->attrs['gosaVacationStop']);
859     }
861     /* Save data to LDAP */
862     $ldap->cd($this->dn);
863     $this->cleanup();
864     $ldap->modify ($this->attrs); 
866     if (!$ldap->success()){
867       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
868     }
870     /* Log last action */ 
871     if($this->initially_was_account){
872       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
873     }else{
874       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
875     }
877     /* Only do IMAP actions if we are not a template */
878     if (!$this->is_template){
880       if ($method->connect($this->gosaMailServer)){
881         $method->updateMailbox($this->folder_prefix.$this->$id);
882         
883         $method->setQuota($this->folder_prefix.$this->$id, $this->gosaMailQuota);
884         $method->disconnect();
886         /* Ensure that this is an existing account */
887         if(1==1 || $this->initially_was_account){
889           /* Write sieve information only if not in C mode */
890           if (!is_integer(strpos($this->gosaMailDeliveryMode, "C"))){
891             $method->configureFilter($this->$id,
892                 $this->gosaMailDeliveryMode,
893                 $this->mail,
894                 $this->gosaMailAlternateAddress,
895                 $this->gosaMailMaxSize,
896                 $this->gosaSpamMailbox,
897                 $this->gosaSpamSortLevel,
898                 $this->gosaVacationMessage);
899             $this->is_modified = TRUE;
900           }else{
901             $this->sieve_management->save();
902           }
903         }
904       }
905     }
907     /* Optionally execute a command after we're done */
908     if ($this->initially_was_account == $this->is_account){
909       if ($this->is_modified){
910         $this->handle_post_events("modify", array("uid" => $this->uid));
911       }
912     } else {
913       $this->handle_post_events("add", array("uid" => $this->uid));
914     }
916     $this->updateSharedFolder();
917   }
920   /* Check formular input */
921   function check()
922   {
923     if(!$this->is_account) return(array());
925     $ldap= $this->config->get_ldap_link();
927     /* Call common method to give check the hook */
928     $message= plugin::check();
930     if(empty($this->gosaMailServer)){
931       $message[]= msgPool::noserver(_("Mail"));
932     }
934     /* must: mail */
935     if ($this->mail == ""){
936       $message[]= msgPool::required(_("Primary address"));
937     }
938     if ($this->is_template){
939       if (!tests::is_email($this->mail, TRUE)){
940         $message[]= msgPool::invalid(_("Mail address"),"","","%givenName.%sn@your-domain.com");
941       }
942     } else {
943       if (!tests::is_email($this->mail)){
944         $message[]= msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com");
945       }
946     }
948     $ldap->cd($this->config->current['BASE']);
949     $filter = "(&(!(objectClass=gosaUserTemplate))(!(uid=".$this->uid."))".
950       "(objectClass=gosaMailAccount)".
951       "(|(mail=".$this->mail.")(alias=".$this->mail.")(gosaMailAlternateAddress=".$this->mail.")))";
953     $ldap->search($filter,array("uid"));
954     if ($ldap->count() != 0){
955       $message[]= msgPool::duplicated(_("Mail address"));
956     }
959     /* Check quota */
960     if ($this->gosaMailQuota != '' && $this->acl_is_writeable("gosaMailQuota")){
961       if (!is_numeric($this->gosaMailQuota)) {
962         $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
963       } else {
964         $this->gosaMailQuota= (int) $this->gosaMailQuota;
965       }
966     }
968     /* Check rejectsize for integer */
969     if ($this->gosaMailMaxSize != '' && $this->acl_is_writeable("gosaMailMaxSize")){
970       if (!is_numeric($this->gosaMailMaxSize)){
971         $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
972       } else {
973         $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
974       }
975     }
977     /* Need gosaMailMaxSize if use_mailsize_limit is checked */
978     if (is_integer(strpos($this->gosaMailDeliveryMode, "R")) && $this->gosaMailMaxSize == ""){
979       $message[]= msgPool::required(_("Mail reject size"));
980     }
982     if((preg_match("/S/", $this->gosaMailDeliveryMode))&&(empty($this->gosaSpamMailbox))) {
983       $message[]= msgPool::required(_("Spam folder"));
984     }
986     if (preg_match('/V/', $this->gosaMailDeliveryMode) && $this->gosaVacationStart >= $this->gosaVacationStop){
987       $message[]= msgPool::invalid(_("Vacation interval"));
988     }
990     return ($message);
991   }
994   /* Adapt from template, using 'dn' */
995   function adapt_from_template($dn, $skip= array())
996   {
997     plugin::adapt_from_template($dn, $skip);
999     foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
1001       if (in_array($val, $skip)){
1002         continue;
1003       }
1005       $this->$val= array();
1006       if (isset($this->attrs["$val"]["count"])){
1007         for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
1008           $value= $this->attrs["$val"][$i];
1009           foreach (array("sn", "givenName", "uid") as $repl){
1010             if (preg_match("/%$repl/i", $value)){
1011               $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
1012             }
1013           }
1014           array_push($this->$val, strtolower(rewrite($value)));
1015         }
1016       }
1017     }
1018     $this->mail= strtolower(rewrite($this->mail));
1019   }
1022   /* Add entry to forwarder list */
1023   function addForwarder($address)
1024   {
1025     if($this->acl_is_writeable("gosaMailForwardingAddress")){
1026       $this->gosaMailForwardingAddress[]= $address;
1027       $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
1028       sort ($this->gosaMailForwardingAddress);
1029       reset ($this->gosaMailForwardingAddress);
1030       $this->is_modified= TRUE;
1031     }else{
1032       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
1033     }
1034   }
1037   /* Remove list of addresses from forwarder list */
1038   function delForwarder($addresses)
1039   {
1040     if($this->acl_is_writeable("gosaMailForwardingAddress")){
1041       $this->gosaMailForwardingAddress= array_remove_entries ($addresses, $this->gosaMailForwardingAddress);
1042       $this->is_modified= TRUE;
1043     }else{
1044       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
1045     }
1046   }
1049   /* Add given mail address to the list of alternate adresses , 
1050      check if this mal address is used, skip adding in this case */
1051   function addAlternate($address)
1052   {
1053     if($this->acl_is_writeable("gosaMailAlternateAddress")){
1054       $ldap= $this->config->get_ldap_link();
1055       $address= strtolower($address);
1057       /* Is this address already assigned in LDAP? */
1058       $ldap->cd ($this->config->current['BASE']);
1059       $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=$address)".
1060           "(alias=$address)(gosaMailAlternateAddress=$address)))", array("uid"));
1062       if ($ldap->count() > 0){
1063         $attrs= $ldap->fetch ();
1064         return ($attrs["uid"][0]);
1065       }
1067       /* Add to list of alternates */
1068       if (!in_array($address, $this->gosaMailAlternateAddress)){
1069         $this->gosaMailAlternateAddress[]= $address;
1070         $this->is_modified= TRUE;
1071       }
1073       sort ($this->gosaMailAlternateAddress);
1074       reset ($this->gosaMailAlternateAddress);
1075       return ("");
1076     }else{
1077       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
1078     }
1079   }
1082   function delAlternate($addresses)
1083   {
1084     if($this->acl_is_writeable("gosaMailAlternateAddress")){
1085       $this->gosaMailAlternateAddress= array_remove_entries ($addresses,$this->gosaMailAlternateAddress);
1086       $this->is_modified= TRUE;
1087     }else{
1088       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
1089     }
1090   }
1092   function make_name($attrs)
1093   {
1094     $name= "";
1095     if (isset($attrs['sn'][0])){
1096       $name= $attrs['sn'][0];
1097     }
1098     if (isset($attrs['givenName'][0])){
1099       if ($name != ""){
1100         $name.= ", ".$attrs['givenName'][0];
1101       } else {
1102         $name.= $attrs['givenName'][0];
1103       }
1104     }
1105     if ($name != ""){
1106       $name.= " ";
1107     }
1109     return ($name);
1110   }
1112   
1113   /* Create the mail part for the copy & paste dialog */
1114   function getCopyDialog()
1115   {
1116     if(!$this->is_account) return("");
1117     $smarty = get_smarty();
1118     $smarty->assign("mail",$this->mail); 
1119     $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress);
1120     $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress);
1121     $str = $smarty->fetch(get_template_path("copypaste.tpl",TRUE, dirname(__FILE__)));
1123     $ret = array();
1124     $ret['status'] = "";
1125     $ret['string'] = $str;
1126     return($ret);
1127   }
1129   function saveCopyDialog()
1130   {
1131     if(!$this->is_account) return;  
1133     /* Execute to save mailAlternateAddress && gosaMailForwardingAddress */
1134     $this->execute();
1135     
1136     if(isset($_POST['mail'])){
1137       $this->mail = $_POST['mail'];
1138     }
1140   }
1142   function allow_remove()
1143   {
1144     if (isset($this->config->current['MAILMETHOD'])){
1145       $method= $this->config->current['MAILMETHOD'];
1146       if(preg_match("/olab/i",$method)){
1147         $ldap = $this->config->get_ldap_link();
1148         $ldap->cd($this->config->current['BASE']);
1149         $ldap->cat($this->dn);
1150         if($ldap->count()){
1151           $attrs = $ldap->fetch();
1152           if(isset($attrs['kolabDeleteFlag'])){ 
1153             return(_("Waiting for kolab to remove mail properties..."));
1154           }elseif(in_array("gosaMailAccount",$attrs['objectClass'])){
1155             return(_("Please remove the mail settings first to allow kolab to call its remove methods!"));
1156           }
1157         }
1158       }
1159     }
1160   }
1162    
1163   function PrepareForCopyPaste($source)
1164   {
1165     plugin::PrepareForCopyPaste($source);
1167     /* Reset alternate mail addresses */
1168     $this->gosaMailAlternateAddress = array();    
1169    }
1172   static function plInfo()
1173   {
1174     return (array(
1175           "plShortName"     => _("Mail"),
1176           "plDescription"   => _("Mail settings"),
1177           "plSelfModify"    => TRUE,
1178           "plDepends"       => array("user"),                     // This plugin depends on
1179           "plPriority"      => 4,                                 // Position in tabs
1180           "plSection"     => array("personal" => _("My account")),
1181           "plCategory"    => array("users"),
1182           "plOptions"       => array(),
1183   
1184           "plProvidedAcls"  => array(
1185             "mail"                      =>  _("Mail address"),
1186             "gosaMailServer"            =>  _("Mail server"),
1187             "gosaMailQuota"             =>  _("Quota size"),
1189             "gosaMailDeliveryModeV"     =>  _("Add vacation information"),  // This is flag of gosaMailDeliveryMode
1190             "gosaVacationMessage"       =>  _("Vacation message"),
1192             "gosaMailDeliveryModeS"     =>  _("Use spam filter"),           // This is flag of gosaMailDeliveryMode
1193             "gosaSpamSortLevel"         =>  _("Spam level"),
1194             "gosaSpamMailbox"           =>  _("Spam mail box"),
1196             "sieveManagement"           =>  _("Sieve management"),
1198             "gosaMailDeliveryModeR"     =>  _("Reject due to mailsize"),    // This is flag of gosaMailDeliveryMode
1199             "gosaMailMaxSize"           =>  _("Mail max size"),
1201             "gosaMailForwardingAddress" =>  _("Forwarding address"),
1202             "gosaMailDeliveryModeL"     =>  _("Local delivery"),            // This is flag of gosaMailDeliveryMode
1203             "gosaMailDeliveryModeI"     =>  _("No delivery to own mailbox "),     // This is flag of gosaMailDeliveryMode
1204             "gosaMailAlternateAddress"  =>  _("Mail alternative addresses"),
1206             "gosaMailForwardingAddress" =>  _("Forwarding address"),
1207             "gosaMailDeliveryModeC"     =>  _("Use custom sieve script"))   // This is flag of gosaMailDeliveryMode
1208         ));
1209   }
1212   /*! \brief  Prepare importet vacation string. \
1213               Replace placeholder like %givenName a.s.o.
1214       @param  string  Vacation string
1215       @return string  Completed vacation string
1216    */  
1217   private function prepare_vacation_template($contents)
1218   {
1219     /* Replace attributes */
1220     $attrs = array();
1221     $obj   = NULL;
1222     if(isset($this->parent->by_object['user'])){
1223       $attrs  = $this->parent->by_object['user']->attributes;
1224       $obj    = $this->parent->by_object['user'];
1225     }else{
1226       $obj    = new user($this->config,$this->dn);
1227       $attrs  = $obj->attributes;
1228     }
1230     if($obj){
1231       foreach ($attrs as $val){
1232         if(preg_match("/dateOfBirth/",$val)){
1233           if($obj->use_dob){
1234             $contents= preg_replace("/%$val/",date("Y-d-m",$obj->dateOfBirth),$contents);
1235           }
1236         }else {
1237           $contents= preg_replace("/%$val/",
1238               $obj->$val, $contents);
1239         }
1241         /* Replace vacation start and end time */
1242         if(preg_match("/%start/",$contents)){
1243           $contents = preg_replace("/%start/",date("d.m.Y",$this->gosaVacationStart),$contents);
1244         }
1245         if(preg_match("/%end/",$contents)){
1246           $contents = preg_replace("/%end/",date("d.m.Y",$this->gosaVacationStop),$contents);
1247         }
1248       }
1249     }
1250     return($contents);
1251   }
1253   
1255   /* Upated shared folder ACLs 
1256    */
1257   function updateSharedFolder()
1258   {
1259     $ldap = $this->config->get_ldap_link();
1260     $ldap->cd($this->config->current['BASE']);
1261     $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array('dn','cn'));
1262     if(class_exists("grouptabs")){
1263       while($attrs = $ldap->fetch()){
1264         $tmp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
1265         if(isset($tmp->by_object['mailgroup'])){
1266           $tmp->by_object['mailgroup']->members= $tmp->by_object['group']->memberUid;
1267           if(!$this->is_account){
1268             $tmp->by_object['mailgroup']->removeUserAcl($this->uid);
1269             $tmp->by_object['mailgroup']->removeUserAcl($this->mail);
1270           }
1271           $tmp->by_object['mailgroup']->save();
1272         }
1273       }
1274     } 
1275   }
1277   /* Initialize plugin with given atribute arrays
1278    */
1279   function init_multiple_support($attrs,$all)
1280   {
1281     plugin::init_multiple_support($attrs,$all);
1283     if(isset($this->multi_attrs['gosaMailQuota'])){
1284       $this->gosaMailQuota = $this->multi_attrs['gosaMailQuota'];
1285     }
1286   }
1288   function get_multi_init_values()
1289   {
1290     $attrs = plugin::get_multi_init_values();
1291     $attrs['gosaMailQuota'] = $this->gosaMailQuota;
1292     return($attrs);
1293   }
1295   function multiple_execute()
1296   {
1297     return($this->execute());
1298   }
1300   function multiple_save_object()
1301   {
1302     plugin::multiple_save_object();
1304     $this->save_object();
1305     foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
1306       if(isset($_POST["use_".$attr])){
1307         $this->multi_boxes[] = $attr;
1308       }
1309     }
1310   }
1312   function get_multi_edit_values()
1313   {
1314     $ret = plugin::get_multi_edit_values();
1316     if(in_array("gosaMailQuota",$this->multi_boxes)){
1317       $ret['gosaMailQuota'] = $this->gosaMailQuota;
1318     }
1320     $flag_add = $flag_remove = array();
1321     $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1322     $opts = array(
1323         "R"   => "use_mailsize_limit",
1324         "S"   => "use_spam_filter",
1325         "L"   => "only_local",
1326         "V"   => "use_vacation",
1327         "C"   => "own_script",
1328         "I"   => "drop_own_mails");
1330     foreach($opts as $flag => $post){
1331       if(in_array($post, $this->multi_boxes)){
1332         if(preg_match("/".$flag."/",$tmp)){
1333           $flag_add[] = $flag;
1334         }else{
1335           $flag_remove[] = $flag;
1336         }
1337       }
1338     }
1339   
1340     $ret['flag_add'] = $flag_add;
1341     $ret['flag_remove'] = $flag_remove;
1342     return($ret);
1343   }
1346   function multiple_check()
1347   {
1348     $message = plugin::multiple_check();
1350     if(empty($this->gosaMailServer) && in_array("gosaMailServer",$this->multi_boxes)){
1351       $message[]= msgPool::noserver(_("Mail"));
1352     }
1354     /* Check quota */
1355     if ($this->gosaMailQuota != ''  && in_array("gosaMailQuota",$this->multi_boxes)){
1356       if (!is_numeric($this->gosaMailQuota)) {
1357         $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
1358       } else {
1359         $this->gosaMailQuota= (int) $this->gosaMailQuota;
1360       }
1361     }
1363     /* Check rejectsize for integer */
1364     if ($this->gosaMailMaxSize != '' && in_array("gosaMailMaxSize",$this->multi_boxes)){
1365       if (!is_numeric($this->gosaMailMaxSize)){
1366         $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
1367       } else {
1368         $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
1369       }
1370     }
1372     if(empty($this->gosaSpamMailbox) && in_array("gosaSpamMailbox",$this->multi_boxes)){
1373       $message[]= msgPool::required(_("Spam folder"));
1374     }
1376     if (  in_array("use_vacation",$this->multi_boxes) &&
1377           preg_match('/V/', $this->gosaMailDeliveryMode) && $this->gosaVacationStart > $this->gosaVacationStop){
1378       $message[]= msgPool::invalid(_("Vacation interval"));
1379     }
1380     return($message);
1381   }
1384   function set_multi_edit_values($values)
1385   {
1386     plugin::set_multi_edit_values($values);
1387     $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1388     if(isset($values['flag_add'])){
1389       foreach($values['flag_add'] as $flag){
1390         if(!preg_match("/".$flag."/",$tmp)){
1391           $tmp .= $flag;
1392         }
1393       }
1394     }
1395     if(isset($values['flag_remove'])){
1396       foreach($values['flag_remove'] as $flag){
1397         if(preg_match("/".$flag."/",$tmp)){
1398           $tmp = preg_replace("/".$flag."/","",$tmp);
1399         }
1400       }
1401     }
1402     $this->gosaMailDeliveryMode = "[".$tmp."]";
1404     /* Set vacation message and replace placeholder like %givenName 
1405      */
1406     if(isset($values['gosaVacationMessage'])){
1407       $this->gosaVacationMessage = $this->prepare_vacation_template($values['gosaVacationMessage']);
1408     }
1409   }
1412 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1413 ?>