Code

b4a2eae8090c42b72827a6f0d4d1a60369731ecd
[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/stop.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/search.png'));
511       $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
512       $smarty->assign("tree_image", get_template_path('images/tree.png'));
513       $smarty->assign("infoimage", get_template_path('images/info.png'));
514       $smarty->assign("launchimage", get_template_path('images/small_filter.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     }
943     $ldap->cd($this->config->current['BASE']);
944     $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=".$this->mail.")(gosaMailAlternateAddress=".$this->mail."))(!(uid=".$this->uid."))(!(cn=".$this->uid.")))", array("uid"));
945     if ($ldap->count() != 0){
946       $message[]= msgPool::duplicated(_("Mail address"));
947     }
949     /* Check quota */
950     if ($this->gosaMailQuota != '' && $this->acl_is_writeable("gosaMailQuota")){
951       if (!is_numeric($this->gosaMailQuota)) {
952         $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
953       } else {
954         $this->gosaMailQuota= (int) $this->gosaMailQuota;
955       }
956     }
958     /* Check rejectsize for integer */
959     if ($this->gosaMailMaxSize != '' && $this->acl_is_writeable("gosaMailMaxSize")){
960       if (!is_numeric($this->gosaMailMaxSize)){
961         $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
962       } else {
963         $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
964       }
965     }
967     /* Need gosaMailMaxSize if use_mailsize_limit is checked */
968     if (is_integer(strpos($this->gosaMailDeliveryMode, "R")) && $this->gosaMailMaxSize == ""){
969       $message[]= msgPool::required(_("Mail reject size"));
970     }
972     if((preg_match("/S/", $this->gosaMailDeliveryMode))&&(empty($this->gosaSpamMailbox))) {
973       $message[]= msgPool::required(_("Spam folder"));
974     }
976     if (preg_match('/V/', $this->gosaMailDeliveryMode) && $this->gosaVacationStart >= $this->gosaVacationStop){
977       $message[]= msgPool::invalid(_("Vacation interval"));
978     }
980     return ($message);
981   }
984   /* Adapt from template, using 'dn' */
985   function adapt_from_template($dn)
986   {
987     plugin::adapt_from_template($dn);
989     foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
990       $this->$val= array();
991       if (isset($this->attrs["$val"]["count"])){
992         for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
993           $value= $this->attrs["$val"][$i];
994           foreach (array("sn", "givenName", "uid") as $repl){
995             if (preg_match("/%$repl/i", $value)){
996               $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
997             }
998           }
999           array_push($this->$val, strtolower(rewrite($value)));
1000         }
1001       }
1002     }
1003     $this->mail= strtolower(rewrite($this->mail));
1004   }
1007   /* Add entry to forwarder list */
1008   function addForwarder($address)
1009   {
1010     if($this->acl_is_writeable("gosaMailForwardingAddress")){
1011       $this->gosaMailForwardingAddress[]= $address;
1012       $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
1013       sort ($this->gosaMailForwardingAddress);
1014       reset ($this->gosaMailForwardingAddress);
1015       $this->is_modified= TRUE;
1016     }else{
1017       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
1018     }
1019   }
1022   /* Remove list of addresses from forwarder list */
1023   function delForwarder($addresses)
1024   {
1025     if($this->acl_is_writeable("gosaMailForwardingAddress")){
1026       $this->gosaMailForwardingAddress= array_remove_entries ($addresses, $this->gosaMailForwardingAddress);
1027       $this->is_modified= TRUE;
1028     }else{
1029       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
1030     }
1031   }
1034   /* Add given mail address to the list of alternate adresses , 
1035      check if this mal address is used, skip adding in this case */
1036   function addAlternate($address)
1037   {
1038     if($this->acl_is_writeable("gosaMailAlternateAddress")){
1039       $ldap= $this->config->get_ldap_link();
1040       $address= strtolower($address);
1042       /* Is this address already assigned in LDAP? */
1043       $ldap->cd ($this->config->current['BASE']);
1044       $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)"."(gosaMailAlternateAddress=$address)))", array("uid"));
1045       $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=$address)"."(gosaMailAlternateAddress=$address)))", array("uid"));
1047       if ($ldap->count() > 0){
1048         $attrs= $ldap->fetch ();
1049         return ($attrs["uid"][0]);
1050       }
1052       /* Add to list of alternates */
1053       if (!in_array($address, $this->gosaMailAlternateAddress)){
1054         $this->gosaMailAlternateAddress[]= $address;
1055         $this->is_modified= TRUE;
1056       }
1058       sort ($this->gosaMailAlternateAddress);
1059       reset ($this->gosaMailAlternateAddress);
1060       return ("");
1061     }else{
1062       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
1063     }
1064   }
1067   function delAlternate($addresses)
1068   {
1069     if($this->acl_is_writeable("gosaMailAlternateAddress")){
1070       $this->gosaMailAlternateAddress= array_remove_entries ($addresses,$this->gosaMailAlternateAddress);
1071       $this->is_modified= TRUE;
1072     }else{
1073       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
1074     }
1075   }
1077   function make_name($attrs)
1078   {
1079     $name= "";
1080     if (isset($attrs['sn'][0])){
1081       $name= $attrs['sn'][0];
1082     }
1083     if (isset($attrs['givenName'][0])){
1084       if ($name != ""){
1085         $name.= ", ".$attrs['givenName'][0];
1086       } else {
1087         $name.= $attrs['givenName'][0];
1088       }
1089     }
1090     if ($name != ""){
1091       $name.= " ";
1092     }
1094     return ($name);
1095   }
1097   
1098   /* Create the mail part for the copy & paste dialog */
1099   function getCopyDialog()
1100   {
1101     if(!$this->is_account) return("");
1102     $smarty = get_smarty();
1103     $smarty->assign("mail",$this->mail); 
1104     $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress);
1105     $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress);
1106     $str = $smarty->fetch(get_template_path("copypaste.tpl",TRUE, dirname(__FILE__)));
1108     $ret = array();
1109     $ret['status'] = "";
1110     $ret['string'] = $str;
1111     return($ret);
1112   }
1114   function saveCopyDialog()
1115   {
1116     if(!$this->is_account) return;  
1118     /* Execute to save mailAlternateAddress && gosaMailForwardingAddress */
1119     $this->execute();
1120     
1121     if(isset($_POST['mail'])){
1122       $this->mail = $_POST['mail'];
1123     }
1125   }
1127   function allow_remove()
1128   {
1129     if (isset($this->config->current['MAILMETHOD'])){
1130       $method= $this->config->current['MAILMETHOD'];
1131       if(preg_match("/olab/i",$method)){
1132         $ldap = $this->config->get_ldap_link();
1133         $ldap->cd($this->config->current['BASE']);
1134         $ldap->cat($this->dn);
1135         if($ldap->count()){
1136           $attrs = $ldap->fetch();
1137           if(isset($attrs['kolabDeleteFlag'])){ 
1138             return(_("Waiting for kolab to remove mail properties..."));
1139           }elseif(in_array("gosaMailAccount",$attrs['objectClass'])){
1140             return(_("Please remove the mail settings first to allow kolab to call its remove methods!"));
1141           }
1142         }
1143       }
1144     }
1145   }
1147    
1148   function PrepareForCopyPaste($source)
1149   {
1150     plugin::PrepareForCopyPaste($source);
1152     /* Reset alternate mail addresses */
1153     $this->gosaMailAlternateAddress = array();    
1154    }
1157   static function plInfo()
1158   {
1159     return (array(
1160           "plShortName"     => _("Mail"),
1161           "plDescription"   => _("Mail settings"),
1162           "plSelfModify"    => TRUE,
1163           "plDepends"       => array("user"),                     // This plugin depends on
1164           "plPriority"      => 4,                                 // Position in tabs
1165           "plSection"     => array("personal" => _("My account")),
1166           "plCategory"    => array("users"),
1167           "plOptions"       => array(),
1168   
1169           "plProvidedAcls"  => array(
1170             "mail"                      =>  _("Mail address"),
1171             "gosaMailServer"            =>  _("Mail server"),
1172             "gosaMailQuota"             =>  _("Quota size"),
1174             "gosaMailDeliveryModeV"     =>  _("Add vacation information"),  // This is flag of gosaMailDeliveryMode
1175             "gosaVacationMessage"       =>  _("Vacation message"),
1177             "gosaMailDeliveryModeS"     =>  _("Use spam filter"),           // This is flag of gosaMailDeliveryMode
1178             "gosaSpamSortLevel"         =>  _("Spam level"),
1179             "gosaSpamMailbox"           =>  _("Spam mail box"),
1181             "sieveManagement"           =>  _("Sieve management"),
1183             "gosaMailDeliveryModeR"     =>  _("Reject due to mailsize"),    // This is flag of gosaMailDeliveryMode
1184             "gosaMailMaxSize"           =>  _("Mail max size"),
1186             "gosaMailForwardingAddress" =>  _("Forwarding address"),
1187             "gosaMailDeliveryModeL"     =>  _("Local delivery"),            // This is flag of gosaMailDeliveryMode
1188             "gosaMailDeliveryModeI"     =>  _("No delivery to own mailbox "),     // This is flag of gosaMailDeliveryMode
1189             "gosaMailAlternateAddress"  =>  _("Mail alternative addresses"),
1191             "gosaMailForwardingAddress" =>  _("Forwarding address"),
1192             "gosaMailDeliveryModeC"     =>  _("Use custom sieve script"))   // This is flag of gosaMailDeliveryMode
1193         ));
1194   }
1197   /*! \brief  Prepare importet vacation string. \
1198               Replace placeholder like %givenName a.s.o.
1199       @param  string  Vacation string
1200       @return string  Completed vacation string
1201    */  
1202   private function prepare_vacation_template($contents)
1203   {
1204     /* Replace attributes */
1205     $attrs = array();
1206     $obj   = NULL;
1207     if(isset($this->parent->by_object['user'])){
1208       $attrs  = $this->parent->by_object['user']->attributes;
1209       $obj    = $this->parent->by_object['user'];
1210     }else{
1211       $obj    = new user($this->config,$this->dn);
1212       $attrs  = $obj->attributes;
1213     }
1215     if($obj){
1216       foreach ($attrs as $val){
1217         if(preg_match("/dateOfBirth/",$val)){
1218           if($obj->use_dob){
1219             $contents= preg_replace("/%$val/",date("Y-d-m",$obj->dateOfBirth),$contents);
1220           }
1221         }else {
1222           $contents= preg_replace("/%$val/",
1223               $obj->$val, $contents);
1224         }
1226         /* Replace vacation start and end time */
1227         if(preg_match("/%start/",$contents)){
1228           $contents = preg_replace("/%start/",date("d.m.Y",$this->gosaVacationStart),$contents);
1229         }
1230         if(preg_match("/%end/",$contents)){
1231           $contents = preg_replace("/%end/",date("d.m.Y",$this->gosaVacationStop),$contents);
1232         }
1233       }
1234     }
1235     return($contents);
1236   }
1238   
1240   /* Upated shared folder ACLs 
1241    */
1242   function updateSharedFolder()
1243   {
1244     $ldap = $this->config->get_ldap_link();
1245     $ldap->cd($this->config->current['BASE']);
1246     $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array('dn','cn'));
1247     if(class_exists("grouptabs")){
1248       while($attrs = $ldap->fetch()){
1249         $tmp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
1250         if(isset($tmp->by_object['mailgroup'])){
1251           $tmp->by_object['mailgroup']->members= $tmp->by_object['group']->memberUid;
1252           if(!$this->is_account){
1253             $tmp->by_object['mailgroup']->removeUserAcl($this->uid);
1254             $tmp->by_object['mailgroup']->removeUserAcl($this->mail);
1255           }
1256           $tmp->by_object['mailgroup']->save();
1257         }
1258       }
1259     } 
1260   }
1262   /* Initialize plugin with given atribute arrays
1263    */
1264   function init_multiple_support($attrs,$all)
1265   {
1266     plugin::init_multiple_support($attrs,$all);
1268     if(isset($this->multi_attrs['gosaMailQuota'])){
1269       $this->gosaMailQuota = $this->multi_attrs['gosaMailQuota'];
1270     }
1271   }
1273   function get_multi_init_values()
1274   {
1275     $attrs = plugin::get_multi_init_values();
1276     $attrs['gosaMailQuota'] = $this->gosaMailQuota;
1277     return($attrs);
1278   }
1280   function multiple_execute()
1281   {
1282     return($this->execute());
1283   }
1285   function multiple_save_object()
1286   {
1287     plugin::multiple_save_object();
1289     $this->save_object();
1290     foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
1291       if(isset($_POST["use_".$attr])){
1292         $this->multi_boxes[] = $attr;
1293       }
1294     }
1295   }
1297   function get_multi_edit_values()
1298   {
1299     $ret = plugin::get_multi_edit_values();
1301     if(in_array("gosaMailQuota",$this->multi_boxes)){
1302       $ret['gosaMailQuota'] = $this->gosaMailQuota;
1303     }
1305     $flag_add = $flag_remove = array();
1306     $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1307     $opts = array(
1308         "R"   => "use_mailsize_limit",
1309         "S"   => "use_spam_filter",
1310         "L"   => "only_local",
1311         "V"   => "use_vacation",
1312         "C"   => "own_script",
1313         "I"   => "drop_own_mails");
1315     foreach($opts as $flag => $post){
1316       if(in_array($post, $this->multi_boxes)){
1317         if(preg_match("/".$flag."/",$tmp)){
1318           $flag_add[] = $flag;
1319         }else{
1320           $flag_remove[] = $flag;
1321         }
1322       }
1323     }
1324   
1325     $ret['flag_add'] = $flag_add;
1326     $ret['flag_remove'] = $flag_remove;
1327     return($ret);
1328   }
1331   function multiple_check()
1332   {
1333     $message = plugin::multiple_check();
1335     if(empty($this->gosaMailServer) && in_array("gosaMailServer",$this->multi_boxes)){
1336       $message[]= msgPool::noserver(_("Mail"));
1337     }
1339     /* Check quota */
1340     if ($this->gosaMailQuota != ''  && in_array("gosaMailQuota",$this->multi_boxes)){
1341       if (!is_numeric($this->gosaMailQuota)) {
1342         $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
1343       } else {
1344         $this->gosaMailQuota= (int) $this->gosaMailQuota;
1345       }
1346     }
1348     /* Check rejectsize for integer */
1349     if ($this->gosaMailMaxSize != '' && in_array("gosaMailMaxSize",$this->multi_boxes)){
1350       if (!is_numeric($this->gosaMailMaxSize)){
1351         $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
1352       } else {
1353         $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
1354       }
1355     }
1357     if(empty($this->gosaSpamMailbox) && in_array("gosaSpamMailbox",$this->multi_boxes)){
1358       $message[]= msgPool::required(_("Spam folder"));
1359     }
1361     if (  in_array("use_vacation",$this->multi_boxes) &&
1362           preg_match('/V/', $this->gosaMailDeliveryMode) && $this->gosaVacationStart > $this->gosaVacationStop){
1363       $message[]= msgPool::invalid(_("Vacation interval"));
1364     }
1365     return($message);
1366   }
1369   function set_multi_edit_values($values)
1370   {
1371     plugin::set_multi_edit_values($values);
1372     $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1373     if(isset($values['flag_add'])){
1374       foreach($values['flag_add'] as $flag){
1375         if(!preg_match("/".$flag."/",$tmp)){
1376           $tmp .= $flag;
1377         }
1378       }
1379     }
1380     if(isset($values['flag_remove'])){
1381       foreach($values['flag_remove'] as $flag){
1382         if(preg_match("/".$flag."/",$tmp)){
1383           $tmp = preg_replace("/".$flag."/","",$tmp);
1384         }
1385       }
1386     }
1387     $this->gosaMailDeliveryMode = "[".$tmp."]";
1389     /* Set vacation message and replace placeholder like %givenName 
1390      */
1391     if(isset($values['gosaVacationMessage'])){
1392       $this->gosaVacationMessage = $this->prepare_vacation_template($values['gosaVacationMessage']);
1393     }
1394   }
1397 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1398 ?>