Code

f2f332f208a8f62b2b430e1c73a0631c951f194e
[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     foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
245       $mailserver[]= $key;
246     }
248     /* 
249      * Sieve Management 
250      */
251     if(isset($_POST['sieveManagement']) 
252         && preg_match("/C/",$this->gosaMailDeliveryMode)
253         && $this->acl_is_writeable("sieveManagement")) {
255       $this->dialog = $this->sieve_management;
256     }
257    
258     /* Cancel sieve edit */
259     if(isset($_POST['sieve_cancel'])){
260       $this->dialog = FALSE;
261     }
262  
263     /* Save sieve changes */
264     if(isset($_POST['sieve_finish'])){
265       $this->sieve_management = $this->dialog;
266       $this->dialog = FALSE;
267     }
268  
269     if(is_object($this->dialog)){
270       $this->dialog->save_object();
271       return($this->dialog->execute());
272     } 
275     /* Handle account state */
276     /* Do we need to flip is_account state? */
277     if(isset($_POST['modify_state'])){
278       if($this->is_account && $this->acl_is_removeable()){
279         $this->is_account= FALSE;
280       }elseif(!$this->is_account && $this->acl_is_createable()){
281         $this->is_account= TRUE;
282       }
283     }
285     /* Do we represent a valid account? */
286     if(!$this->multiple_support_active){
287       if (!$this->is_account && $this->parent === NULL){
288         $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\">&nbsp;<b>".
289           msgPool::noValidExtension(_("Mail"))."</b>";
291         $display.= back_to_main();
292         return ($display);
293       }
295       /* Show tab dialog headers */
296       if ($this->parent !== NULL){
297         if ($this->is_account){
298           if($this->accountDelegationsConfigured()){
299             $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Mail")),
300                 _("Mail settings cannot be removed while there are delegations configured!"),TRUE,TRUE);
301           }else{
302             $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Mail")),
303                 msgPool::featuresEnabled(_("Mail")));
304           }
305         } else {
306           $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Mail")),
307                 msgPool::featuresDisabled(_("Mail")));
308           return ($display);
309         }
310       }
311     }
313     /* Forwarder  subdialog */
315     /* Trigger forward add dialog? */
316     if (isset($_POST['add_local_forwarder'])){
317       $this->forward_dialog= TRUE;
318       $this->dialog= TRUE;
319     }
321     /* Cancel forward add dialog? */
322     if (isset($_POST['add_locals_cancel'])){
323       $this->forward_dialog= FALSE;
324       $this->dialog= FALSE;
325     }
327     /* Finished adding of locals? */
328     if (isset($_POST['add_locals_finish'])){
330       if (isset($_POST['local_list'])){
332         /* Check if we are able to write gosaMailForwardingAddress */
333         if($this->acl_is_writeable("gosaMailForwardingAddress")){
335           /* Walk through list of forwarders, ignore own addresses */
336           foreach ($_POST['local_list'] as $val){
337             if (!in_array ($val, $this->gosaMailAlternateAddress) &&
338                 $val != $this->mail){
340               $this->addForwarder($val);
341               $this->is_modified= TRUE;
342             }
343           }
344         }
345         $this->forward_dialog= FALSE;
346         $this->dialog= FALSE;
347       } else {
348         msg_dialog::display(_("Error"), _("Please select an entry!"), ERROR_DIALOG);
349       }
350     }
352     /* Add forward email addresses */
353     if (isset($_POST['add_forwarder'])){
354       if ($_POST['forward_address'] != ""){
356         /* Valid email address specified? */
357         $address= $_POST['forward_address'];
358         $valid= FALSE;
359         if (!tests::is_email($address)){
360           if (!tests::is_email($address, TRUE)){
361             if ($this->is_template){
362               $valid= TRUE;
363             } else {
364               msg_dialog::display(_("Error"), 
365                   msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com"),
366                   ERROR_DIALOG);
367             }
368           }
369         } elseif ($address == $this->mail
370             || in_array($address, $this->gosaMailAlternateAddress)) {
371           msg_dialog::display(_("Error"),_("Cannot add primary address to the list of forwarders!") , ERROR_DIALOG);
372         } else {
373           $valid= TRUE;
374         }
376         if ($valid){
378           /* Add it, if we are able to write gosaMailForwardingAddress */
379           if($this->acl_is_writeable("gosaMailForwardingAddress")){
380             $this->addForwarder ($address);
381             $this->is_modified= TRUE;
382           }
383         }
384       }
385     }
387     /* Delete forward email addresses */
388     if (isset($_POST['delete_forwarder'])){
389       $this->delForwarder ($_POST['forwarder_list']);
390     }
393     /* Add alternate email addresses */
394     if (isset($_POST['add_alternate'])){
396       $valid= FALSE;
397       if (!tests::is_email($_POST['alternate_address'])){
398         if ($this->is_template){
399           if (!(tests::is_email($_POST['alternate_address'], TRUE))){
400             msg_dialog::display(_("Error"), 
401                 msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com"),
402                 ERROR_DIALOG);
404           } else {
405             $valid= TRUE;
406           }
407         } else {
408           msg_dialog::display(_("Error"), 
409               msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com"),
410               ERROR_DIALOG);
411         }
413       } else {
414         $valid= TRUE;
415       }
417       if ($valid && ($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
418         $ui= get_userinfo();
419         if ($user != $ui->username){
420           msg_dialog::display(_("Error"), msgPool::duplicated(_("Mail address"))."&nbsp;".
421             sprintf(_("Address is already in use by user '%s'."), $user), ERROR_DIALOG);
422         }
423       }
424     }
426     /* Delete alternate email addresses */
427     if (isset($_POST['delete_alternate']) && isset($_POST['alternates_list'])){
428       $this->delAlternate ($_POST['alternates_list']);
429     }
431   
432     /* Vacation message */
433   
434     /* Import vacation message? */
435     if (isset($_POST["import_vacation"]) && isset($this->vacation[$_POST["vacation_template"]])){
437       
438       /* Save message */
439       if($this->multiple_support_active){
440         $contents = file_get_contents($_POST["vacation_template"]);
441       }else{
442         $contents = $this->prepare_vacation_template(file_get_contents($_POST["vacation_template"]));
443       }
444       $this->gosaVacationMessage= htmlspecialchars($contents);
445     }
447   
448     /* Display forward dialog if requested above */
450     /* Show forward add dialog */
451     if ($this->forward_dialog){
452       $ldap= $this->config->get_ldap_link();
454       /* Save data */
455       $mailfilter= session::get("mailfilter");
456       foreach( array("depselect", "muser", "regex") as $type){
457         if (isset($_POST[$type])){
458           $mailfilter[$type]= $_POST[$type];
459         }
460       }
461       if (isset($_GET['search'])){
462         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
463         if ($s == "**"){
464           $s= "*";
465         }
466         $mailfilter['regex']= $s;
467       }
468       session::set("mailfilter", $mailfilter);
470       /* Get actual list */
471       $mailusers= array ();
472       if ($mailfilter['regex'] != '*' && $mailfilter['regex'] != ""){
473         $regex= $mailfilter['regex'];
474         $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
475       } else {
476         $filter= "";
477       }
478       if ($mailfilter['muser'] != ""){
479         $user= $mailfilter['muser'];
480         $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
481       }
483       /* Add already present people to the filter */
484       $exclude= "";
485       foreach ($this->gosaMailForwardingAddress as $mail){
486         $exclude.= "(mail=$mail)";
487       }
488       if ($exclude != ""){
489         $filter.= "(!(|$exclude))";
490       }
492       $res= get_list("(&(objectClass=gosaMailAccount)$filter)", "users", $mailfilter['depselect'], 
493                      array("sn", "mail", "givenName"), GL_SIZELIMIT | GL_SUBSEARCH);
494       $ldap->cd($mailfilter['depselect']);
495       $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
496       error_reporting (0);
497       while ($attrs= $ldap->fetch()){
498         if(preg_match('/%/', $attrs['mail'][0])){
499           continue;
500         }
501         $name= $this->make_name($attrs);
502         $mailusers[$attrs['mail'][0]]= $name."&lt;".
503           $attrs['mail'][0]."&gt;";
504       }
505       error_reporting (E_ALL | E_STRICT);
506       natcasesort ($mailusers);
507       reset ($mailusers);
509       /* Show dialog */
510       $smarty->assign("search_image", get_template_path('images/lists/search.png'));
511       $smarty->assign("usearch_image", get_template_path('images/lists/search-user.png'));
512       $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
513       $smarty->assign("infoimage", get_template_path('images/info.png'));
514       $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
515       $smarty->assign("mailusers", $mailusers);
516       if (isset($_POST['depselect'])){
517         $smarty->assign("depselect", $_POST['depselect']);
518       }
519       $smarty->assign("deplist", $this->config->idepartments);
520       $smarty->assign("apply", apply_filter());
521       $smarty->assign("alphabet", generate_alphabet());
522       $smarty->assign("hint", print_sizelimit_warning());
523       foreach( array("depselect", "muser", "regex") as $type){
524         $smarty->assign("$type", $mailfilter[$type]);
525       }
526       $smarty->assign("hint", print_sizelimit_warning());
528       $display.= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE, dirname(__FILE__)));
529       return ($display);
530     }
532     /* Display mail account tab */
534     $smarty->assign("mailServers", $mailserver);
535     $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
537     $tmp  = $this->plInfo();
538     foreach($tmp['plProvidedAcls'] as $name => $transl){
539       $smarty->assign("$name"."ACL", $this->getacl($name,$SkipWrite));
540     }
542     foreach(array("gosaMailServer", "gosaMailQuota", "perms", "mail",
543           "gosaMailAlternateAddress", "gosaMailForwardingAddress",
544           "gosaVacationMessage", "gosaMailDeliveryMode", "gosaVacationStart",
545           "gosaVacationStop", "gosaMailMaxSize", "gosaSpamSortLevel", "gosaSpamMailbox") as $val){
546       $smarty->assign("$val", $this->$val);
547     }
549     if (is_numeric($this->gosaMailQuota) && $this->gosaMailQuota != 0){
550       $smarty->assign("quotausage", progressbar(round(($this->quotaUsage * 100)/ $this->gosaMailQuota),100,15,true));
551       $smarty->assign("quotadefined", "true");
552     } else {
553       $smarty->assign("quotadefined", "false");
554     }
556     /* Disable mail field if needed */
557     $method= new $this->method($this->config);
558     if ($method->uattrib == "mail" && $this->initially_was_account){
559       $smarty->assign("mailACL", preg_replace("/w/","",$this->getacl("mail",$SkipWrite)));
560     }
562     /* Disable/Enable range select, but do not disable them twice 
563      *  if they are already diabled by "use own sieve script"
564      */
565     if (preg_match('/V/', $this->gosaMailDeliveryMode) || preg_match("/C/",$this->gosaMailDeliveryMode)){
566       $smarty->assign('rangeEnabled', "");
567     } else {
568       $smarty->assign('rangeEnabled', "disabled");
569     }
571     if (!preg_match("/L/", $this->gosaMailDeliveryMode)) {
572       $smarty->assign("only_local", "checked");
573     } else {
574       $smarty->assign("only_local", "");
575     }
577     $types = array(
578           "V"=>"use_vacation",
579           "S"=>"use_spam_filter",
580           "R"=>"use_mailsize_limit",
581           "I"=>"drop_own_mails",
582           "C"=>"own_script");
584     /* Fill checkboxes */
585     foreach($types as $option => $varname){
586       if (preg_match("/".$option."/", $this->gosaMailDeliveryMode)) {
587         $smarty->assign($varname, "checked");
588       } else {
589         $smarty->assign($varname, "");
590       }
591     }
592    
593     /* Display mail account tab */
594     if($this->gosaVacationStart ==0){
595       $date= getdate(time());
596     }else{
597       $date= getdate($this->gosaVacationStart);
598     }
599     $days= array();
600     for($d= 1; $d<32; $d++){
601       $days[$d]= $d;
602     }
603     $years= array();
604     for($y= $date['year']-10; $y<$date['year']+10; $y++){
605       $years[]= $y;
606     }
607     $months= msgPool::months();
608     $smarty->assign("start_day", $date["mday"]);
609     $smarty->assign("days", $days);
610     $smarty->assign("months", $months);
611     $smarty->assign("start_month", $date["mon"]-1);
612     $smarty->assign("years", $years);
613     $smarty->assign("start_year", $date["year"]);
615     if($this->gosaVacationStop ==0){
616       $date= getdate(time());
617       $date["mday"]++;
618     }else{
619       $date= getdate($this->gosaVacationStop);
620     }
621     $smarty->assign("end_day", $date["mday"]);
622     $smarty->assign("end_month", $date["mon"]-1);
623     $smarty->assign("end_year", $date["year"]);
626  
627     /* Have vacation templates? */
628     $smarty->assign("template", "");
629     if (count($this->vacation)){
630       $smarty->assign("show_templates", "true");
631       $smarty->assign("vacationtemplates", $this->vacation);
632       if (isset($_POST['vacation_template'])){
633         $smarty->assign("template", $_POST['vacation_template']);
634       }
635     } else {
636       $smarty->assign("show_templates", "false");
637     }
639     /* Fill spam selector */
640     $spamlevel= array();
641     for ($i= 0; $i<21; $i++){
642       $spamlevel[]= $i;
643     }
644     $smarty->assign("spamlevel", $spamlevel);
645     $smarty->assign("spambox", $this->mailboxList);
647     foreach($this->attributes as $attr){
648       $u_attr = "use_".$attr;
649       $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
650     }
652     foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
653       $u_attr = "use_".$attr;
654       $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
655     }
657     $smarty->assign("multiple_support",$this->multiple_support_active);
658     $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
659     return ($display);
660   }
663   /* remove object from parent */
664   function remove_from_parent()
665   {
666     /* Cancel if there's nothing to do here */
667     if (!$this->initially_was_account){
668       return;
669     }
670     
671     /* include global link_info */
672     $ldap= $this->config->get_ldap_link();
674     /* Remove and write to LDAP */
675     plugin::remove_from_parent();
677     /* Zero arrays */
678     $this->attrs['gosaMailAlternateAddress']= array();
679     $this->attrs['gosaMailForwardingAddress']= array();
681     /* Adapt attributes if needed */
682     $method= new $this->method($this->config);
683     $method->fixAttributesOnRemove($this);
685     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
686     $ldap->cd($this->dn);
687     $this->cleanup();
689     $ldap->modify ($this->attrs); 
691     /* Add "view" to logging class */ 
692     new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
694     if (!$ldap->success()){
695       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
696     }
698     /* Connect to IMAP server for account deletion */
699     if ($this->gosaMailServer != ""){
700       $method= new $this->method($this->config);
701       $id= $method->uattrib;
702       if ($method->connect($this->gosaMailServer)){
704         /* Remove account from IMAP server */
705         $method->deleteMailbox($this->folder_prefix.$this->$id);
706         $method->disconnect();
707       }
708     }
710     /* Update shared folder membership, ACL may need to be updated */
711     $this->updateSharedFolder(); 
713     /* Optionally execute a command after we're done */
714     $this->handle_post_events("remove",array("uid" => $this->uid));
715   }
717   
718   /* check if we have some delegations configured, those delegations must be removed first */
719   function accountDelegationsConfigured()
720   { 
721     /* We are in administrational edit mode.
722         Check tab configurations directly */
723     if(isset($this->attrs)){
724       $checkArray  = array("kolabInvitationPolicy","unrestrictedMailSize", "calFBURL","kolabDelegate","kolabFreeBusyFuture");
725       foreach($checkArray as $index){
726         if(isset($this->attrs[$index])){
727            return(true);
728         }
729       }
730     }
731     return(false); 
732   }
733  
735   /* Save data to object */
736   function save_object()
737   {
738     if (isset($_POST['mailTab'])){
740       /* Save ldap attributes */
741       plugin::save_object();
744       if(isset($_POST['own_script'])){
746         if(!preg_match("/C/",$this->gosaMailDeliveryMode)){
747           $str= preg_replace("/[\[\]]/","",$this->gosaMailDeliveryMode);
748           $this->gosaMailDeliveryMode = "[".$str."C]";
749         }
751       }else{
753         /* Assemble mail delivery mode
754            The mode field in ldap consists of values between braces, this must
755            be called when 'mail' is set, because checkboxes may not be set when
756            we're in some other dialog.
758           Example for gosaMailDeliveryMode [LR        ]
759           L: Local delivery
760           R: Reject when exceeding mailsize limit
761           S: Use spam filter
762           V: Use vacation message
763           C: Use custm sieve script
764           I: Only insider delivery */
766         $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
769         /* Handle delivery flags */
770         if($this->acl_is_writeable("gosaMailDeliveryModeL")){
771           if(!preg_match("/L/",$tmp) && !isset($_POST['only_local'])){
772             $tmp.="L";
773           }elseif(preg_match("/L/",$tmp) && isset($_POST['only_local'])){
774             $tmp = preg_replace("/L/","",$tmp);
775           }
776         }
778         $opts = array(     
779             "R"   => "use_mailsize_limit",
780             "S"   => "use_spam_filter",
781             "V"   => "use_vacation",
782             "C"   => "own_script",
783             "I"   => "drop_own_mails");
785         foreach($opts as $flag => $post){
786           if($this->acl_is_writeable("gosaMailDeliveryMode".$flag)){
787             if(!preg_match("/".$flag."/",$tmp) && isset($_POST[$post])){
788               $tmp.= $flag;
789             }elseif(preg_match("/".$flag."/",$tmp) && !isset($_POST[$post])){
790               $tmp = preg_replace("/".$flag."/","",$tmp);
791             }
792           }
793         }
795         $tmp= "[$tmp]";
796         if ($this->gosaMailDeliveryMode != $tmp){
797           $this->is_modified= TRUE;
798         }
799         $this->gosaMailDeliveryMode= $tmp;
802         if($this->acl_is_writeable("gosaVacationMessage") && preg_match("/V/",$this->gosaMailDeliveryMode)){
803           if(isset($_POST['gosaVacationStart'])){
804             $this->gosaVacationStart = $_POST['gosaVacationStart'];
805           }
806           if(isset($_POST['gosaVacationStop'])){
807             $this->gosaVacationStop = $_POST['gosaVacationStop'];
808           }
809         }
810       }
811     }
812   }
815   /* Save data to LDAP, depending on is_account we save or delete */
816   function save()
817   {
818     $ldap= $this->config->get_ldap_link();
820     /* Call parents save to prepare $this->attrs */
821     plugin::save();
823     /* Save arrays */
824     $this->attrs['gosaMailAlternateAddress']= $this->gosaMailAlternateAddress;
825     $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
827     /* Adapt attributes if needed */
828     $method= new $this->method($this->config);
829     $id= $method->uattrib;
831     $method->fixAttributesOnStore($this);
833     /* Remove Mailquota if = "" or "0"  */
834     if((isset($this->attrs['gosaMailQuota']))&&(!$this->attrs['gosaMailQuota'])) {
835       $this->attrs['gosaMailQuota']=0;
836     }
838     if(empty($this->attrs['gosaSpamMailbox'])){
839       unset($this->attrs['gosaSpamMailbox']);
840     }
842     $this->attrs['mail'] = strtolower($this->attrs['mail']); 
844         /* Remove attributes - if not needed */
845     if (!preg_match('/V/', $this->gosaMailDeliveryMode)){
846       unset($this->attrs['gosaVacationStart']);
847       unset($this->attrs['gosaVacationStop']);
848     }
851     /* Remove attributes - if not needed */
852     if (!preg_match('/V/', $this->gosaMailDeliveryMode)){
853       unset($this->attrs['gosaVacationStart']);
854       unset($this->attrs['gosaVacationStop']);
855     }
857     /* Save data to LDAP */
858     $ldap->cd($this->dn);
859     $this->cleanup();
860     $ldap->modify ($this->attrs); 
862     if (!$ldap->success()){
863       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
864     }
866     /* Log last action */ 
867     if($this->initially_was_account){
868       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
869     }else{
870       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
871     }
873     /* Only do IMAP actions if we are not a template */
874     if (!$this->is_template){
876       if ($method->connect($this->gosaMailServer)){
877         $method->updateMailbox($this->folder_prefix.$this->$id);
878         
879         $method->setQuota($this->folder_prefix.$this->$id, $this->gosaMailQuota);
880         $method->disconnect();
882         /* Ensure that this is an existing account */
883         if(1==1 || $this->initially_was_account){
885           /* Write sieve information only if not in C mode */
886           if (!is_integer(strpos($this->gosaMailDeliveryMode, "C"))){
887             $method->configureFilter($this->$id,
888                 $this->gosaMailDeliveryMode,
889                 $this->mail,
890                 $this->gosaMailAlternateAddress,
891                 $this->gosaMailMaxSize,
892                 $this->gosaSpamMailbox,
893                 $this->gosaSpamSortLevel,
894                 $this->gosaVacationMessage);
895             $this->is_modified = TRUE;
896           }else{
897             $this->sieve_management->save();
898           }
899         }
900       }
901     }
903     /* Optionally execute a command after we're done */
904     if ($this->initially_was_account == $this->is_account){
905       if ($this->is_modified){
906         $this->handle_post_events("modify", array("uid" => $this->uid));
907       }
908     } else {
909       $this->handle_post_events("add", array("uid" => $this->uid));
910     }
912     $this->updateSharedFolder();
913   }
916   /* Check formular input */
917   function check()
918   {
919     if(!$this->is_account) return(array());
921     $ldap= $this->config->get_ldap_link();
923     /* Call common method to give check the hook */
924     $message= plugin::check();
926     if(empty($this->gosaMailServer)){
927       $message[]= msgPool::noserver(_("Mail"));
928     }
930     /* must: mail */
931     if ($this->mail == ""){
932       $message[]= msgPool::required(_("Primary address"));
933     }
934     if ($this->is_template){
935       if (!tests::is_email($this->mail, TRUE)){
936         $message[]= msgPool::invalid(_("Mail address"),"","","%givenName.%sn@your-domain.com");
937       }
938     } else {
939       if (!tests::is_email($this->mail)){
940         $message[]= msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com");
941       }
942     }
944     $ldap->cd($this->config->current['BASE']);
945     $filter = "(&(!(objectClass=gosaUserTemplate))(!(uid=".$this->uid."))".
946       "(objectClass=gosaMailAccount)".
947       "(|(mail=".$this->mail.")(alias=".$this->mail.")(gosaMailAlternateAddress=".$this->mail.")))";
949     $ldap->search($filter,array("uid"));
950     if ($ldap->count() != 0){
951       $message[]= msgPool::duplicated(_("Mail address"));
952     }
955     /* Check quota */
956     if ($this->gosaMailQuota != '' && $this->acl_is_writeable("gosaMailQuota")){
957       if (!is_numeric($this->gosaMailQuota)) {
958         $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
959       } else {
960         $this->gosaMailQuota= (int) $this->gosaMailQuota;
961       }
962     }
964     /* Check rejectsize for integer */
965     if ($this->gosaMailMaxSize != '' && $this->acl_is_writeable("gosaMailMaxSize")){
966       if (!is_numeric($this->gosaMailMaxSize)){
967         $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
968       } else {
969         $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
970       }
971     }
973     /* Need gosaMailMaxSize if use_mailsize_limit is checked */
974     if (is_integer(strpos($this->gosaMailDeliveryMode, "R")) && $this->gosaMailMaxSize == ""){
975       $message[]= msgPool::required(_("Mail reject size"));
976     }
978     if((preg_match("/S/", $this->gosaMailDeliveryMode))&&(empty($this->gosaSpamMailbox))) {
979       $message[]= msgPool::required(_("Spam folder"));
980     }
982     if (preg_match('/V/', $this->gosaMailDeliveryMode) && $this->gosaVacationStart >= $this->gosaVacationStop){
983       $message[]= msgPool::invalid(_("Vacation interval"));
984     }
986     return ($message);
987   }
990   /* Adapt from template, using 'dn' */
991   function adapt_from_template($dn, $skip= array())
992   {
993     plugin::adapt_from_template($dn, $skip);
995     foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
997       if (in_array($val, $skip)){
998         continue;
999       }
1001       $this->$val= array();
1002       if (isset($this->attrs["$val"]["count"])){
1003         for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
1004           $value= $this->attrs["$val"][$i];
1005           foreach (array("sn", "givenName", "uid") as $repl){
1006             if (preg_match("/%$repl/i", $value)){
1007               $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
1008             }
1009           }
1010           array_push($this->$val, strtolower(rewrite($value)));
1011         }
1012       }
1013     }
1014     $this->mail= strtolower(rewrite($this->mail));
1015   }
1018   /* Add entry to forwarder list */
1019   function addForwarder($address)
1020   {
1021     if($this->acl_is_writeable("gosaMailForwardingAddress")){
1022       $this->gosaMailForwardingAddress[]= $address;
1023       $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
1024       sort ($this->gosaMailForwardingAddress);
1025       reset ($this->gosaMailForwardingAddress);
1026       $this->is_modified= TRUE;
1027     }else{
1028       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
1029     }
1030   }
1033   /* Remove list of addresses from forwarder list */
1034   function delForwarder($addresses)
1035   {
1036     if($this->acl_is_writeable("gosaMailForwardingAddress")){
1037       $this->gosaMailForwardingAddress= array_remove_entries ($addresses, $this->gosaMailForwardingAddress);
1038       $this->is_modified= TRUE;
1039     }else{
1040       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
1041     }
1042   }
1045   /* Add given mail address to the list of alternate adresses , 
1046      check if this mal address is used, skip adding in this case */
1047   function addAlternate($address)
1048   {
1049     if($this->acl_is_writeable("gosaMailAlternateAddress")){
1050       $ldap= $this->config->get_ldap_link();
1051       $address= strtolower($address);
1053       /* Is this address already assigned in LDAP? */
1054       $ldap->cd ($this->config->current['BASE']);
1055       $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=$address)".
1056           "(alias=$address)(gosaMailAlternateAddress=$address)))", array("uid"));
1058       if ($ldap->count() > 0){
1059         $attrs= $ldap->fetch ();
1060         return ($attrs["uid"][0]);
1061       }
1063       /* Add to list of alternates */
1064       if (!in_array($address, $this->gosaMailAlternateAddress)){
1065         $this->gosaMailAlternateAddress[]= $address;
1066         $this->is_modified= TRUE;
1067       }
1069       sort ($this->gosaMailAlternateAddress);
1070       reset ($this->gosaMailAlternateAddress);
1071       return ("");
1072     }else{
1073       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
1074     }
1075   }
1078   function delAlternate($addresses)
1079   {
1080     if($this->acl_is_writeable("gosaMailAlternateAddress")){
1081       $this->gosaMailAlternateAddress= array_remove_entries ($addresses,$this->gosaMailAlternateAddress);
1082       $this->is_modified= TRUE;
1083     }else{
1084       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
1085     }
1086   }
1088   function make_name($attrs)
1089   {
1090     $name= "";
1091     if (isset($attrs['sn'][0])){
1092       $name= $attrs['sn'][0];
1093     }
1094     if (isset($attrs['givenName'][0])){
1095       if ($name != ""){
1096         $name.= ", ".$attrs['givenName'][0];
1097       } else {
1098         $name.= $attrs['givenName'][0];
1099       }
1100     }
1101     if ($name != ""){
1102       $name.= " ";
1103     }
1105     return ($name);
1106   }
1108   
1109   /* Create the mail part for the copy & paste dialog */
1110   function getCopyDialog()
1111   {
1112     if(!$this->is_account) return("");
1113     $smarty = get_smarty();
1114     $smarty->assign("mail",$this->mail); 
1115     $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress);
1116     $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress);
1117     $str = $smarty->fetch(get_template_path("copypaste.tpl",TRUE, dirname(__FILE__)));
1119     $ret = array();
1120     $ret['status'] = "";
1121     $ret['string'] = $str;
1122     return($ret);
1123   }
1125   function saveCopyDialog()
1126   {
1127     if(!$this->is_account) return;  
1129     /* Execute to save mailAlternateAddress && gosaMailForwardingAddress */
1130     $this->execute();
1131     
1132     if(isset($_POST['mail'])){
1133       $this->mail = $_POST['mail'];
1134     }
1136   }
1138   function allow_remove()
1139   {
1140     if (isset($this->config->current['MAILMETHOD'])){
1141       $method= $this->config->current['MAILMETHOD'];
1142       if(preg_match("/olab/i",$method)){
1143         $ldap = $this->config->get_ldap_link();
1144         $ldap->cd($this->config->current['BASE']);
1145         $ldap->cat($this->dn);
1146         if($ldap->count()){
1147           $attrs = $ldap->fetch();
1148           if(isset($attrs['kolabDeleteFlag'])){ 
1149             return(_("Waiting for kolab to remove mail properties..."));
1150           }elseif(in_array("gosaMailAccount",$attrs['objectClass'])){
1151             return(_("Please remove the mail settings first to allow kolab to call its remove methods!"));
1152           }
1153         }
1154       }
1155     }
1156   }
1158    
1159   function PrepareForCopyPaste($source)
1160   {
1161     plugin::PrepareForCopyPaste($source);
1163     /* Reset alternate mail addresses */
1164     $this->gosaMailAlternateAddress = array();    
1165    }
1168   static function plInfo()
1169   {
1170     return (array(
1171           "plShortName"     => _("Mail"),
1172           "plDescription"   => _("Mail settings"),
1173           "plSelfModify"    => TRUE,
1174           "plDepends"       => array("user"),                     // This plugin depends on
1175           "plPriority"      => 4,                                 // Position in tabs
1176           "plSection"     => array("personal" => _("My account")),
1177           "plCategory"    => array("users"),
1178           "plOptions"       => array(),
1179   
1180           "plProvidedAcls"  => array(
1181             "mail"                      =>  _("Mail address"),
1182             "gosaMailServer"            =>  _("Mail server"),
1183             "gosaMailQuota"             =>  _("Quota size"),
1185             "gosaMailDeliveryModeV"     =>  _("Add vacation information"),  // This is flag of gosaMailDeliveryMode
1186             "gosaVacationMessage"       =>  _("Vacation message"),
1188             "gosaMailDeliveryModeS"     =>  _("Use spam filter"),           // This is flag of gosaMailDeliveryMode
1189             "gosaSpamSortLevel"         =>  _("Spam level"),
1190             "gosaSpamMailbox"           =>  _("Spam mail box"),
1192             "sieveManagement"           =>  _("Sieve management"),
1194             "gosaMailDeliveryModeR"     =>  _("Reject due to mailsize"),    // This is flag of gosaMailDeliveryMode
1195             "gosaMailMaxSize"           =>  _("Mail max size"),
1197             "gosaMailForwardingAddress" =>  _("Forwarding address"),
1198             "gosaMailDeliveryModeL"     =>  _("Local delivery"),            // This is flag of gosaMailDeliveryMode
1199             "gosaMailDeliveryModeI"     =>  _("No delivery to own mailbox "),     // This is flag of gosaMailDeliveryMode
1200             "gosaMailAlternateAddress"  =>  _("Mail alternative addresses"),
1202             "gosaMailForwardingAddress" =>  _("Forwarding address"),
1203             "gosaMailDeliveryModeC"     =>  _("Use custom sieve script"))   // This is flag of gosaMailDeliveryMode
1204         ));
1205   }
1208   /*! \brief  Prepare importet vacation string. \
1209               Replace placeholder like %givenName a.s.o.
1210       @param  string  Vacation string
1211       @return string  Completed vacation string
1212    */  
1213   private function prepare_vacation_template($contents)
1214   {
1215     /* Replace attributes */
1216     $attrs = array();
1217     $obj   = NULL;
1218     if(isset($this->parent->by_object['user'])){
1219       $attrs  = $this->parent->by_object['user']->attributes;
1220       $obj    = $this->parent->by_object['user'];
1221     }else{
1222       $obj    = new user($this->config,$this->dn);
1223       $attrs  = $obj->attributes;
1224     }
1226     if($obj){
1227       foreach ($attrs as $val){
1228         if(preg_match("/dateOfBirth/",$val)){
1229           if($obj->use_dob){
1230             $contents= preg_replace("/%$val/",date("Y-d-m",$obj->dateOfBirth),$contents);
1231           }
1232         }else {
1233           $contents= preg_replace("/%$val/",
1234               $obj->$val, $contents);
1235         }
1237         /* Replace vacation start and end time */
1238         if(preg_match("/%start/",$contents)){
1239           $contents = preg_replace("/%start/",date("d.m.Y",$this->gosaVacationStart),$contents);
1240         }
1241         if(preg_match("/%end/",$contents)){
1242           $contents = preg_replace("/%end/",date("d.m.Y",$this->gosaVacationStop),$contents);
1243         }
1244       }
1245     }
1246     return($contents);
1247   }
1249   
1251   /* Upated shared folder ACLs 
1252    */
1253   function updateSharedFolder()
1254   {
1255     $ldap = $this->config->get_ldap_link();
1256     $ldap->cd($this->config->current['BASE']);
1257     $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array('dn','cn'));
1258     if(class_exists("grouptabs")){
1259       while($attrs = $ldap->fetch()){
1260         $tmp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
1261         if(isset($tmp->by_object['mailgroup'])){
1262           $tmp->by_object['mailgroup']->members= $tmp->by_object['group']->memberUid;
1263           if(!$this->is_account){
1264             $tmp->by_object['mailgroup']->removeUserAcl($this->uid);
1265             $tmp->by_object['mailgroup']->removeUserAcl($this->mail);
1266           }
1267           $tmp->by_object['mailgroup']->save();
1268         }
1269       }
1270     } 
1271   }
1273   /* Initialize plugin with given atribute arrays
1274    */
1275   function init_multiple_support($attrs,$all)
1276   {
1277     plugin::init_multiple_support($attrs,$all);
1279     if(isset($this->multi_attrs['gosaMailQuota'])){
1280       $this->gosaMailQuota = $this->multi_attrs['gosaMailQuota'];
1281     }
1282   }
1284   function get_multi_init_values()
1285   {
1286     $attrs = plugin::get_multi_init_values();
1287     $attrs['gosaMailQuota'] = $this->gosaMailQuota;
1288     return($attrs);
1289   }
1291   function multiple_execute()
1292   {
1293     return($this->execute());
1294   }
1296   function multiple_save_object()
1297   {
1298     plugin::multiple_save_object();
1300     $this->save_object();
1301     foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
1302       if(isset($_POST["use_".$attr])){
1303         $this->multi_boxes[] = $attr;
1304       }
1305     }
1306   }
1308   function get_multi_edit_values()
1309   {
1310     $ret = plugin::get_multi_edit_values();
1312     if(in_array("gosaMailQuota",$this->multi_boxes)){
1313       $ret['gosaMailQuota'] = $this->gosaMailQuota;
1314     }
1316     $flag_add = $flag_remove = array();
1317     $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1318     $opts = array(
1319         "R"   => "use_mailsize_limit",
1320         "S"   => "use_spam_filter",
1321         "L"   => "only_local",
1322         "V"   => "use_vacation",
1323         "C"   => "own_script",
1324         "I"   => "drop_own_mails");
1326     foreach($opts as $flag => $post){
1327       if(in_array($post, $this->multi_boxes)){
1328         if(preg_match("/".$flag."/",$tmp)){
1329           $flag_add[] = $flag;
1330         }else{
1331           $flag_remove[] = $flag;
1332         }
1333       }
1334     }
1335   
1336     $ret['flag_add'] = $flag_add;
1337     $ret['flag_remove'] = $flag_remove;
1338     return($ret);
1339   }
1342   function multiple_check()
1343   {
1344     $message = plugin::multiple_check();
1346     if(empty($this->gosaMailServer) && in_array("gosaMailServer",$this->multi_boxes)){
1347       $message[]= msgPool::noserver(_("Mail"));
1348     }
1350     /* Check quota */
1351     if ($this->gosaMailQuota != ''  && in_array("gosaMailQuota",$this->multi_boxes)){
1352       if (!is_numeric($this->gosaMailQuota)) {
1353         $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
1354       } else {
1355         $this->gosaMailQuota= (int) $this->gosaMailQuota;
1356       }
1357     }
1359     /* Check rejectsize for integer */
1360     if ($this->gosaMailMaxSize != '' && in_array("gosaMailMaxSize",$this->multi_boxes)){
1361       if (!is_numeric($this->gosaMailMaxSize)){
1362         $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
1363       } else {
1364         $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
1365       }
1366     }
1368     if(empty($this->gosaSpamMailbox) && in_array("gosaSpamMailbox",$this->multi_boxes)){
1369       $message[]= msgPool::required(_("Spam folder"));
1370     }
1372     if (  in_array("use_vacation",$this->multi_boxes) &&
1373           preg_match('/V/', $this->gosaMailDeliveryMode) && $this->gosaVacationStart > $this->gosaVacationStop){
1374       $message[]= msgPool::invalid(_("Vacation interval"));
1375     }
1376     return($message);
1377   }
1380   function set_multi_edit_values($values)
1381   {
1382     plugin::set_multi_edit_values($values);
1383     $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1384     if(isset($values['flag_add'])){
1385       foreach($values['flag_add'] as $flag){
1386         if(!preg_match("/".$flag."/",$tmp)){
1387           $tmp .= $flag;
1388         }
1389       }
1390     }
1391     if(isset($values['flag_remove'])){
1392       foreach($values['flag_remove'] as $flag){
1393         if(preg_match("/".$flag."/",$tmp)){
1394           $tmp = preg_replace("/".$flag."/","",$tmp);
1395         }
1396       }
1397     }
1398     $this->gosaMailDeliveryMode = "[".$tmp."]";
1400     /* Set vacation message and replace placeholder like %givenName 
1401      */
1402     if(isset($values['gosaVacationMessage'])){
1403       $this->gosaVacationMessage = $this->prepare_vacation_template($values['gosaVacationMessage']);
1404     }
1405   }
1408 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1409 ?>