Code

4918868bec066c7ef7ed8eb2e8952063e03a5ba2
[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 ($this->config->get_cfg_value("mailmethod") != ""){
86       $method= $this->config->get_cfg_value("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 ($this->config->get_cfg_value("cyrusunixstyle") == "true"){
101       $this->folder_prefix= "user/";
102     } else {
103       $this->folder_prefix= "user.";
104     }
105     
106     /* This is not a new account, parse additional attributes */
107     if (($dn !== NULL) && ($dn != "new") && $this->is_account){
109       /* Load attributes containing arrays */
110       foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
111         $this->$val= array();
112         if (isset($this->attrs["$val"]["count"])){
113           for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
114             array_push($this->$val, $this->attrs["$val"][$i]);
115           }
116         }
117       }
120       /* Only do IMAP actions if gosaMailServer attribute is set */
121       if (isset ($this->attrs["gosaMailServer"][0])){
123         $method = new $this->method($this->config);
124         $id     = $method->uattrib;
126         /* Adapt attributes if needed */
127         $method->fixAttributesOnLoad($this);
129         /* FixAttributesOnLoad possibly creates an array out of gosaMailServer.
130             If the mail tab wasn't opened once before saving, the account can't be saved */
131         if(is_array($this->gosaMailServer)){
132           $this->gosaMailServer = $this->gosaMailServer[0];
133         }
135         if ($method->connect($this->attrs["gosaMailServer"][0])){
137           /* Update quota values */
138           $quota= $method->getQuota($this->folder_prefix.$this->$id);
139          
140           if($quota){
141             if ($quota['gosaMailQuota'] == 2147483647){
142               $this->quotaUsage     = "";
143               $this->gosaMailQuota  = "";
144             } else {
145               $this->quotaUsage     = $quota['quotaUsage'];
146               $this->gosaMailQuota  = $quota['gosaMailQuota'];
147             }
148           }else{
149             $this->quotaUsage     = "";
150             $this->gosaMailQuota  = "";
151           }
153           /* Get mailboxes / folder like INBOX ..*/
154           $this->mailboxList= $method->getMailboxList($this->folder_prefix.$this->$id,$this->$id);
155           
156           $method->disconnect();
157         }else{
158           /* Could not connect to ldap.
159            */
160           if (isset($this->attrs['gosaMailQuota'][0])){
161             $this->gosaMailQuota = $this->attrs['gosaMailQuota'][0];
162           }
163         }
164       }
165     }
167     /* Fill vacation array */
168     $this->vacation= array();
169     if ($this->config->get_cfg_value("vacationdir") != ""){
170       $dir= $this->config->get_cfg_value("vacationdir");
171       if (is_dir($dir) && is_readable($dir)){
173         /* Look for files and build the vacation array */
174         $dh= opendir($dir);
175         while ($file = readdir($dh)){
176           $description= $this->parse_vacation("$dir/$file");
177           if ($description != ""){
178             $this->vacation["$dir/$file"]= $description;
179           }
180         }
181         closedir($dh);
182       }
183     }
185     /* Create sieve management class */
186     $method = new $this->method($this->config);
187     $id     = $method->uattrib;
188     $this->sieve_management = new sieveManagement($this->config,$this->dn,$this,$id);
190     /* Get global filter config */
191     if (!session::is_set("mailfilter")){
192       $ui= get_userinfo();
193       $base= get_base_from_people($ui->dn);
194       $mailfilter= array( "depselect"       => $base,
195           "muser"            => "",
196           "regex"           => "*");
197       session::set("mailfilter", $mailfilter);
198     }
199   }
202   function parse_vacation($file)
203   {
204     $desc= "";
206     if (is_file($file)){
207       $fh = fopen($file, "r");
208       $line= fgets($fh, 256);
210       if (!preg_match('/^DESC:/', $line)){
211         msg_dialog::display(_("Configuration error"), sprintf(_("No DESC tag in vacation template '%s'!"), $file), ERROR_DIALOG);
212         return $desc;
213       }
214       fclose ($fh);
216       $desc= trim(preg_replace('/^DESC:\s*/', '', $line));
217     }
219     return $desc;
220   }
223   function execute()
224   {
225     /* Call parent execute */
226     plugin::execute();
228     /* Log view */
229     if($this->is_account && !$this->view_logged){
230       $this->view_logged = TRUE;
231       new log("view","users/".get_class($this),$this->dn);
232     }
234     /* Initialise vars */
236     /* Load templating engine */
237     $smarty= get_smarty();
238     $display= "";
240     /* Get available mailserver */
241     $mailserver= array();
242     $ui = get_userinfo();
243     foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
244       if( $this->gosaMailServer == $key || 
245           preg_match("/r/",$ui->get_permissions($val['server_dn'],"server/goImapServer",""))){
246         $mailserver[]= $key;
247       }
248     }
250     /* 
251      * Sieve Management 
252      */
253     if(isset($_POST['sieveManagement']) 
254         && preg_match("/C/",$this->gosaMailDeliveryMode)
255         && $this->acl_is_writeable("sieveManagement")) {
257       $this->dialog = $this->sieve_management;
258     }
259    
260     /* Cancel sieve edit */
261     if(isset($_POST['sieve_cancel'])){
262       $this->dialog = FALSE;
263     }
264  
265     /* Save sieve changes */
266     if(isset($_POST['sieve_finish'])){
267       $this->sieve_management = $this->dialog;
268       $this->dialog = FALSE;
269     }
270  
271     if(is_object($this->dialog)){
272       $this->dialog->save_object();
273       return($this->dialog->execute());
274     } 
277     /* Handle account state */
278     /* Do we need to flip is_account state? */
279     if(isset($_POST['modify_state'])){
280       if($this->is_account && $this->acl_is_removeable()){
281         $this->is_account= FALSE;
282       }elseif(!$this->is_account && $this->acl_is_createable()){
283         $this->is_account= TRUE;
284       }
285     }
287     /* Do we represent a valid account? */
288     if(!$this->multiple_support_active){
289       if (!$this->is_account && $this->parent === NULL){
290         $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\">&nbsp;<b>".
291           msgPool::noValidExtension(_("Mail"))."</b>";
293         $display.= back_to_main();
294         return ($display);
295       }
297       /* Show tab dialog headers */
298       if ($this->parent !== NULL){
299         if ($this->is_account){
300           if($this->accountDelegationsConfigured()){
301             $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Mail")),
302                 _("Mail settings cannot be removed while there are delegations configured!"),TRUE,TRUE);
303           }else{
304             $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Mail")),
305                 msgPool::featuresEnabled(_("Mail")));
306           }
307         } else {
308           $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Mail")),
309                 msgPool::featuresDisabled(_("Mail")));
310           return ($display);
311         }
312       }
313     }
315     /* Forwarder  subdialog */
317     /* Trigger forward add dialog? */
318     if (isset($_POST['add_local_forwarder'])){
319       $this->forward_dialog= TRUE;
320       $this->dialog= TRUE;
321     }
323     /* Cancel forward add dialog? */
324     if (isset($_POST['add_locals_cancel'])){
325       $this->forward_dialog= FALSE;
326       $this->dialog= FALSE;
327     }
329     /* Finished adding of locals? */
330     if (isset($_POST['add_locals_finish'])){
332       if (isset($_POST['local_list'])){
334         /* Check if we are able to write gosaMailForwardingAddress */
335         if($this->acl_is_writeable("gosaMailForwardingAddress")){
337           /* Walk through list of forwarders, ignore own addresses */
338           foreach ($_POST['local_list'] as $val){
339             if (!in_array ($val, $this->gosaMailAlternateAddress) &&
340                 $val != $this->mail){
342               $this->addForwarder($val);
343               $this->is_modified= TRUE;
344             }
345           }
346         }
347         $this->forward_dialog= FALSE;
348         $this->dialog= FALSE;
349       } else {
350         msg_dialog::display(_("Error"), _("Please select an entry!"), ERROR_DIALOG);
351       }
352     }
354     /* Add forward email addresses */
355     if (isset($_POST['add_forwarder'])){
356       if ($_POST['forward_address'] != ""){
358         /* Valid email address specified? */
359         $address= $_POST['forward_address'];
360         $valid= FALSE;
361         if (!tests::is_email($address)){
362           if (!tests::is_email($address, TRUE)){
363             if ($this->is_template){
364               $valid= TRUE;
365             } else {
366               msg_dialog::display(_("Error"), 
367                   msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com"),
368                   ERROR_DIALOG);
369             }
370           }
371         } elseif ($address == $this->mail
372             || in_array($address, $this->gosaMailAlternateAddress)) {
373           msg_dialog::display(_("Error"),_("Cannot add primary address to the list of forwarders!") , ERROR_DIALOG);
374         } else {
375           $valid= TRUE;
376         }
378         if ($valid){
380           /* Add it, if we are able to write gosaMailForwardingAddress */
381           if($this->acl_is_writeable("gosaMailForwardingAddress")){
382             $this->addForwarder ($address);
383             $this->is_modified= TRUE;
384           }
385         }
386       }
387     }
389     /* Delete forward email addresses */
390     if (isset($_POST['delete_forwarder'])){
391       $this->delForwarder ($_POST['forwarder_list']);
392     }
395     /* Add alternate email addresses */
396     if (isset($_POST['add_alternate'])){
398       $valid= FALSE;
399       if (!tests::is_email($_POST['alternate_address'])){
400         if ($this->is_template){
401           if (!(tests::is_email($_POST['alternate_address'], TRUE))){
402             msg_dialog::display(_("Error"), 
403                 msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com"),
404                 ERROR_DIALOG);
406           } else {
407             $valid= TRUE;
408           }
409         } else {
410           msg_dialog::display(_("Error"), 
411               msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com"),
412               ERROR_DIALOG);
413         }
415       } else {
416         $valid= TRUE;
417       }
419       if ($valid && ($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
420         $ui= get_userinfo();
421         if ($user != $ui->username){
422           msg_dialog::display(_("Error"), msgPool::duplicated(_("Mail address"))."&nbsp;".
423             sprintf(_("Address is already in use by user '%s'."), $user), ERROR_DIALOG);
424         }
425       }
426     }
428     /* Delete alternate email addresses */
429     if (isset($_POST['delete_alternate']) && isset($_POST['alternates_list'])){
430       $this->delAlternate ($_POST['alternates_list']);
431     }
433   
434     /* Vacation message */
435   
436     /* Import vacation message? */
437     if (isset($_POST["import_vacation"]) && isset($this->vacation[$_POST["vacation_template"]])){
439       
440       /* Save message */
441       if($this->multiple_support_active){
442         $contents = file_get_contents($_POST["vacation_template"]);
443       }else{
444         $contents = $this->prepare_vacation_template(file_get_contents($_POST["vacation_template"]));
445       }
446       $this->gosaVacationMessage= htmlspecialchars($contents);
447     }
449   
450     /* Display forward dialog if requested above */
452     /* Show forward add dialog */
453     if ($this->forward_dialog){
454       $ldap= $this->config->get_ldap_link();
456       /* Save data */
457       $mailfilter= session::get("mailfilter");
458       foreach( array("depselect", "muser", "regex") as $type){
459         if (isset($_POST[$type])){
460           $mailfilter[$type]= $_POST[$type];
461         }
462       }
463       if (isset($_GET['search'])){
464         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
465         if ($s == "**"){
466           $s= "*";
467         }
468         $mailfilter['regex']= $s;
469       }
470       session::set("mailfilter", $mailfilter);
472       /* Get actual list */
473       $mailusers= array ();
474       if ($mailfilter['regex'] != '*' && $mailfilter['regex'] != ""){
475         $regex= $mailfilter['regex'];
476         $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
477       } else {
478         $filter= "";
479       }
480       if ($mailfilter['muser'] != ""){
481         $user= $mailfilter['muser'];
482         $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
483       }
485       /* Add already present people to the filter */
486       $exclude= "";
487       foreach ($this->gosaMailForwardingAddress as $mail){
488         $exclude.= "(mail=$mail)";
489       }
490       if ($exclude != ""){
491         $filter.= "(!(|$exclude))";
492       }
494       $res= get_list("(&(objectClass=gosaMailAccount)$filter)", "users", $mailfilter['depselect'], 
495                      array("sn", "mail", "givenName"), GL_SIZELIMIT | GL_SUBSEARCH);
496       $ldap->cd($mailfilter['depselect']);
497       $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
498       error_reporting (0);
499       while ($attrs= $ldap->fetch()){
500         if(preg_match('/%/', $attrs['mail'][0])){
501           continue;
502         }
503         $name= $this->make_name($attrs);
504         $mailusers[$attrs['mail'][0]]= $name."&lt;".
505           $attrs['mail'][0]."&gt;";
506       }
507       error_reporting (E_ALL | E_STRICT);
508       natcasesort ($mailusers);
509       reset ($mailusers);
511       /* Show dialog */
512       $smarty->assign("search_image", get_template_path('images/lists/search.png'));
513       $smarty->assign("usearch_image", get_template_path('images/lists/search-user.png'));
514       $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
515       $smarty->assign("infoimage", get_template_path('images/info.png'));
516       $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
517       $smarty->assign("mailusers", $mailusers);
518       if (isset($_POST['depselect'])){
519         $smarty->assign("depselect", $_POST['depselect']);
520       }
521       $smarty->assign("deplist", $this->config->idepartments);
522       $smarty->assign("apply", apply_filter());
523       $smarty->assign("alphabet", generate_alphabet());
524       $smarty->assign("hint", print_sizelimit_warning());
525       foreach( array("depselect", "muser", "regex") as $type){
526         $smarty->assign("$type", $mailfilter[$type]);
527       }
528       $smarty->assign("hint", print_sizelimit_warning());
530       $display.= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE, dirname(__FILE__)));
531       return ($display);
532     }
534     /* Display mail account tab */
536     $smarty->assign("mailServers", $mailserver);
537     $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
539     $tmp  = $this->plInfo();
540     foreach($tmp['plProvidedAcls'] as $name => $transl){
541       $smarty->assign("$name"."ACL", $this->getacl($name,$SkipWrite));
542     }
544     foreach(array("gosaMailServer", "gosaMailQuota", "perms", "mail",
545           "gosaMailAlternateAddress", "gosaMailForwardingAddress",
546           "gosaVacationMessage", "gosaMailDeliveryMode", "gosaVacationStart",
547           "gosaVacationStop", "gosaMailMaxSize", "gosaSpamSortLevel", "gosaSpamMailbox") as $val){
548       $smarty->assign("$val", $this->$val);
549     }
551     if (is_numeric($this->gosaMailQuota) && $this->gosaMailQuota != 0){
552       $smarty->assign("quotausage", progressbar(round(($this->quotaUsage * 100)/ $this->gosaMailQuota),100,15,true));
553       $smarty->assign("quotadefined", "true");
554     } else {
555       $smarty->assign("quotadefined", "false");
556     }
558     /* Disable mail field if needed */
559     $method= new $this->method($this->config);
560     if ($method->uattrib == "mail" && $this->initially_was_account){
561       $smarty->assign("mailACL", preg_replace("/w/","",$this->getacl("mail",$SkipWrite)));
562     }
564     /* Disable/Enable range select, but do not disable them twice 
565      *  if they are already diabled by "use own sieve script"
566      */
567     if (preg_match('/V/', $this->gosaMailDeliveryMode) || preg_match("/C/",$this->gosaMailDeliveryMode)){
568       $smarty->assign('rangeEnabled', "");
569     } else {
570       $smarty->assign('rangeEnabled', "disabled");
571     }
573     if (!preg_match("/L/", $this->gosaMailDeliveryMode)) {
574       $smarty->assign("only_local", "checked");
575     } else {
576       $smarty->assign("only_local", "");
577     }
579     $types = array(
580           "V"=>"use_vacation",
581           "S"=>"use_spam_filter",
582           "R"=>"use_mailsize_limit",
583           "I"=>"drop_own_mails",
584           "C"=>"own_script");
586     /* Fill checkboxes */
587     foreach($types as $option => $varname){
588       if (preg_match("/".$option."/", $this->gosaMailDeliveryMode)) {
589         $smarty->assign($varname, "checked");
590       } else {
591         $smarty->assign($varname, "");
592       }
593     }
594    
595     /* Display mail account tab */
596     if($this->gosaVacationStart ==0){
597       $date= getdate(time());
598     }else{
599       $date= getdate($this->gosaVacationStart);
600     }
601     $days= array();
602     for($d= 1; $d<32; $d++){
603       $days[$d]= $d;
604     }
605     $years= array();
606     for($y= $date['year']-10; $y<$date['year']+10; $y++){
607       $years[]= $y;
608     }
609     $months= msgPool::months();
610     $smarty->assign("start_day", $date["mday"]);
611     $smarty->assign("days", $days);
612     $smarty->assign("months", $months);
613     $smarty->assign("start_month", $date["mon"]-1);
614     $smarty->assign("years", $years);
615     $smarty->assign("start_year", $date["year"]);
617     if($this->gosaVacationStop ==0){
618       $date= getdate(time());
619       $date["mday"]++;
620     }else{
621       $date= getdate($this->gosaVacationStop);
622     }
623     $smarty->assign("end_day", $date["mday"]);
624     $smarty->assign("end_month", $date["mon"]-1);
625     $smarty->assign("end_year", $date["year"]);
628  
629     /* Have vacation templates? */
630     $smarty->assign("template", "");
631     if (count($this->vacation)){
632       $smarty->assign("show_templates", "true");
633       $smarty->assign("vacationtemplates", $this->vacation);
634       if (isset($_POST['vacation_template'])){
635         $smarty->assign("template", $_POST['vacation_template']);
636       }
637     } else {
638       $smarty->assign("show_templates", "false");
639     }
641     /* Fill spam selector */
642     $spamlevel= array();
643     for ($i= 0; $i<21; $i++){
644       $spamlevel[]= $i;
645     }
646     $smarty->assign("spamlevel", $spamlevel);
647     $smarty->assign("spambox", $this->mailboxList);
649     foreach($this->attributes as $attr){
650       $u_attr = "use_".$attr;
651       $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
652     }
654     foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
655       $u_attr = "use_".$attr;
656       $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
657     }
659     $smarty->assign("multiple_support",$this->multiple_support_active);
660     $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
661     return ($display);
662   }
665   /* remove object from parent */
666   function remove_from_parent()
667   {
668     /* Cancel if there's nothing to do here */
669     if (!$this->initially_was_account){
670       return;
671     }
672     
673     /* include global link_info */
674     $ldap= $this->config->get_ldap_link();
676     /* Remove and write to LDAP */
677     plugin::remove_from_parent();
679     /* Zero arrays */
680     $this->attrs['gosaMailAlternateAddress']= array();
681     $this->attrs['gosaMailForwardingAddress']= array();
683     /* Adapt attributes if needed */
684     $method= new $this->method($this->config);
685     $method->fixAttributesOnRemove($this);
687     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
688     $ldap->cd($this->dn);
689     $this->cleanup();
691     $ldap->modify ($this->attrs); 
693     /* Add "view" to logging class */ 
694     new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
696     if (!$ldap->success()){
697       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
698     }
700     /* Connect to IMAP server for account deletion */
701     if ($this->gosaMailServer != ""){
702       $method= new $this->method($this->config);
703       $id= $method->uattrib;
704       if ($method->connect($this->gosaMailServer)){
706         /* Remove account from IMAP server */
707         $method->deleteMailbox($this->folder_prefix.$this->$id);
708         $method->disconnect();
709       }
710     }
712     /* Update shared folder membership, ACL may need to be updated */
713     $this->updateSharedFolder(); 
715     /* Optionally execute a command after we're done */
716     $this->handle_post_events("remove",array("uid" => $this->uid));
717   }
719   
720   /* check if we have some delegations configured, those delegations must be removed first */
721   function accountDelegationsConfigured()
722   { 
723     /* We are in administrational edit mode.
724         Check tab configurations directly */
725     if(isset($this->attrs)){
726       $checkArray  = array("kolabInvitationPolicy","unrestrictedMailSize", "calFBURL","kolabDelegate","kolabFreeBusyFuture");
727       foreach($checkArray as $index){
728         if(isset($this->attrs[$index])){
729            return(true);
730         }
731       }
732     }
733     return(false); 
734   }
735  
737   /* Save data to object */
738   function save_object()
739   {
740     if (isset($_POST['mailTab'])){
742       /* Save ldap attributes */
743       plugin::save_object();
746       if(isset($_POST['own_script'])){
748         if(!preg_match("/C/",$this->gosaMailDeliveryMode)){
749           $str= preg_replace("/[\[\]]/","",$this->gosaMailDeliveryMode);
750           $this->gosaMailDeliveryMode = "[".$str."C]";
751         }
753       }else{
755         /* Assemble mail delivery mode
756            The mode field in ldap consists of values between braces, this must
757            be called when 'mail' is set, because checkboxes may not be set when
758            we're in some other dialog.
760           Example for gosaMailDeliveryMode [LR        ]
761           L: Local delivery
762           R: Reject when exceeding mailsize limit
763           S: Use spam filter
764           V: Use vacation message
765           C: Use custm sieve script
766           I: Only insider delivery */
768         $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
771         /* Handle delivery flags */
772         if($this->acl_is_writeable("gosaMailDeliveryModeL")){
773           if(!preg_match("/L/",$tmp) && !isset($_POST['only_local'])){
774             $tmp.="L";
775           }elseif(preg_match("/L/",$tmp) && isset($_POST['only_local'])){
776             $tmp = preg_replace("/L/","",$tmp);
777           }
778         }
780         $opts = array(     
781             "R"   => "use_mailsize_limit",
782             "S"   => "use_spam_filter",
783             "V"   => "use_vacation",
784             "C"   => "own_script",
785             "I"   => "drop_own_mails");
787         foreach($opts as $flag => $post){
788           if($this->acl_is_writeable("gosaMailDeliveryMode".$flag)){
789             if(!preg_match("/".$flag."/",$tmp) && isset($_POST[$post])){
790               $tmp.= $flag;
791             }elseif(preg_match("/".$flag."/",$tmp) && !isset($_POST[$post])){
792               $tmp = preg_replace("/".$flag."/","",$tmp);
793             }
794           }
795         }
797         $tmp= "[$tmp]";
798         if ($this->gosaMailDeliveryMode != $tmp){
799           $this->is_modified= TRUE;
800         }
801         $this->gosaMailDeliveryMode= $tmp;
804         if($this->acl_is_writeable("gosaVacationMessage") && preg_match("/V/",$this->gosaMailDeliveryMode)){
805           if(isset($_POST['gosaVacationStart'])){
806             $this->gosaVacationStart = $_POST['gosaVacationStart'];
807           }
808           if(isset($_POST['gosaVacationStop'])){
809             $this->gosaVacationStop = $_POST['gosaVacationStop'];
810           }
811         }
812       }
813     }
814   }
817   /* Save data to LDAP, depending on is_account we save or delete */
818   function save()
819   {
820     $ldap= $this->config->get_ldap_link();
822     /* Call parents save to prepare $this->attrs */
823     plugin::save();
825     /* Save arrays */
826     $this->attrs['gosaMailAlternateAddress']= $this->gosaMailAlternateAddress;
827     $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
829     /* Adapt attributes if needed */
830     $method= new $this->method($this->config);
831     $id= $method->uattrib;
833     $method->fixAttributesOnStore($this);
835     /* Remove Mailquota if = "" or "0"  */
836     if((isset($this->attrs['gosaMailQuota']))&&(!$this->attrs['gosaMailQuota'])) {
837       $this->attrs['gosaMailQuota']=0;
838     }
840     if(empty($this->attrs['gosaSpamMailbox'])){
841       unset($this->attrs['gosaSpamMailbox']);
842     }
844     $this->attrs['mail'] = strtolower($this->attrs['mail']); 
846         /* Remove attributes - if not needed */
847     if (!preg_match('/V/', $this->gosaMailDeliveryMode)){
848       unset($this->attrs['gosaVacationStart']);
849       unset($this->attrs['gosaVacationStop']);
850     }
853     /* Remove attributes - if not needed */
854     if (!preg_match('/V/', $this->gosaMailDeliveryMode)){
855       unset($this->attrs['gosaVacationStart']);
856       unset($this->attrs['gosaVacationStop']);
857     }
859     /* Save data to LDAP */
860     $ldap->cd($this->dn);
861     $this->cleanup();
862     $ldap->modify ($this->attrs); 
864     if (!$ldap->success()){
865       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
866     }
868     /* Log last action */ 
869     if($this->initially_was_account){
870       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
871     }else{
872       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
873     }
875     /* Only do IMAP actions if we are not a template */
876     if (!$this->is_template){
878       if ($method->connect($this->gosaMailServer)){
879         $method->updateMailbox($this->folder_prefix.$this->$id);
880         
881         $method->setQuota($this->folder_prefix.$this->$id, $this->gosaMailQuota);
882         $method->disconnect();
884         /* Ensure that this is an existing account */
885         if(1==1 || $this->initially_was_account){
887           /* Write sieve information only if not in C mode */
888           if (!is_integer(strpos($this->gosaMailDeliveryMode, "C"))){
889             $method->configureFilter($this->$id,
890                 $this->gosaMailDeliveryMode,
891                 $this->mail,
892                 $this->gosaMailAlternateAddress,
893                 $this->gosaMailMaxSize,
894                 $this->gosaSpamMailbox,
895                 $this->gosaSpamSortLevel,
896                 $this->gosaVacationMessage);
897             $this->is_modified = TRUE;
898           }else{
899             $this->sieve_management->save();
900           }
901         }
902       }
903     }
905     /* Optionally execute a command after we're done */
906     if ($this->initially_was_account == $this->is_account){
907       if ($this->is_modified){
908         $this->handle_post_events("modify", array("uid" => $this->uid));
909       }
910     } else {
911       $this->handle_post_events("add", array("uid" => $this->uid));
912     }
914     $this->updateSharedFolder();
915   }
918   /* Check formular input */
919   function check()
920   {
921     if(!$this->is_account) return(array());
923     $ldap= $this->config->get_ldap_link();
925     /* Call common method to give check the hook */
926     $message= plugin::check();
928     if(empty($this->gosaMailServer)){
929       $message[]= msgPool::noserver(_("Mail"));
930     }
932     /* must: mail */
933     if ($this->mail == ""){
934       $message[]= msgPool::required(_("Primary address"));
935     }
936     if ($this->is_template){
937       if (!tests::is_email($this->mail, TRUE)){
938         $message[]= msgPool::invalid(_("Mail address"),"","","%givenName.%sn@your-domain.com");
939       }
940     } else {
941       if (!tests::is_email($this->mail)){
942         $message[]= msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com");
943       }
944     }
946     $ldap->cd($this->config->current['BASE']);
947     $filter = "(&(!(objectClass=gosaUserTemplate))(!(uid=".$this->uid."))".
948       "(objectClass=gosaMailAccount)".
949       "(|(mail=".$this->mail.")(alias=".$this->mail.")(gosaMailAlternateAddress=".$this->mail.")))";
951     $ldap->search($filter,array("uid"));
952     if ($ldap->count() != 0){
953       $message[]= msgPool::duplicated(_("Mail address"));
954     }
957     /* Check quota */
958     if ($this->gosaMailQuota != '' && $this->acl_is_writeable("gosaMailQuota")){
959       if (!is_numeric($this->gosaMailQuota)) {
960         $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
961       } else {
962         $this->gosaMailQuota= (int) $this->gosaMailQuota;
963       }
964     }
966     /* Check rejectsize for integer */
967     if ($this->gosaMailMaxSize != '' && $this->acl_is_writeable("gosaMailMaxSize")){
968       if (!is_numeric($this->gosaMailMaxSize)){
969         $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
970       } else {
971         $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
972       }
973     }
975     /* Need gosaMailMaxSize if use_mailsize_limit is checked */
976     if (is_integer(strpos($this->gosaMailDeliveryMode, "R")) && $this->gosaMailMaxSize == ""){
977       $message[]= msgPool::required(_("Mail reject size"));
978     }
980     if((preg_match("/S/", $this->gosaMailDeliveryMode))&&(empty($this->gosaSpamMailbox))) {
981       $message[]= msgPool::required(_("Spam folder"));
982     }
984     if (preg_match('/V/', $this->gosaMailDeliveryMode) && $this->gosaVacationStart >= $this->gosaVacationStop){
985       $message[]= msgPool::invalid(_("Vacation interval"));
986     }
988     return ($message);
989   }
992   /* Adapt from template, using 'dn' */
993   function adapt_from_template($dn, $skip= array())
994   {
995     plugin::adapt_from_template($dn, $skip);
997     foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
999       if (in_array($val, $skip)){
1000         continue;
1001       }
1003       $this->$val= array();
1004       if (isset($this->attrs["$val"]["count"])){
1005         for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
1006           $value= $this->attrs["$val"][$i];
1007           foreach (array("sn", "givenName", "uid") as $repl){
1008             if (preg_match("/%$repl/i", $value)){
1009               $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
1010             }
1011           }
1012           array_push($this->$val, strtolower(rewrite($value)));
1013         }
1014       }
1015     }
1016     $this->mail= strtolower(rewrite($this->mail));
1017   }
1020   /* Add entry to forwarder list */
1021   function addForwarder($address)
1022   {
1023     if($this->acl_is_writeable("gosaMailForwardingAddress")){
1024       $this->gosaMailForwardingAddress[]= $address;
1025       $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
1026       sort ($this->gosaMailForwardingAddress);
1027       reset ($this->gosaMailForwardingAddress);
1028       $this->is_modified= TRUE;
1029     }else{
1030       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
1031     }
1032   }
1035   /* Remove list of addresses from forwarder list */
1036   function delForwarder($addresses)
1037   {
1038     if($this->acl_is_writeable("gosaMailForwardingAddress")){
1039       $this->gosaMailForwardingAddress= array_remove_entries ($addresses, $this->gosaMailForwardingAddress);
1040       $this->is_modified= TRUE;
1041     }else{
1042       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
1043     }
1044   }
1047   /* Add given mail address to the list of alternate adresses , 
1048      check if this mal address is used, skip adding in this case */
1049   function addAlternate($address)
1050   {
1051     if($this->acl_is_writeable("gosaMailAlternateAddress")){
1052       $ldap= $this->config->get_ldap_link();
1053       $address= strtolower($address);
1055       /* Is this address already assigned in LDAP? */
1056       $ldap->cd ($this->config->current['BASE']);
1057       $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=$address)".
1058           "(alias=$address)(gosaMailAlternateAddress=$address)))", array("uid"));
1060       if ($ldap->count() > 0){
1061         $attrs= $ldap->fetch ();
1062         return ($attrs["uid"][0]);
1063       }
1065       /* Add to list of alternates */
1066       if (!in_array($address, $this->gosaMailAlternateAddress)){
1067         $this->gosaMailAlternateAddress[]= $address;
1068         $this->is_modified= TRUE;
1069       }
1071       sort ($this->gosaMailAlternateAddress);
1072       reset ($this->gosaMailAlternateAddress);
1073       return ("");
1074     }else{
1075       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
1076     }
1077   }
1080   function delAlternate($addresses)
1081   {
1082     if($this->acl_is_writeable("gosaMailAlternateAddress")){
1083       $this->gosaMailAlternateAddress= array_remove_entries ($addresses,$this->gosaMailAlternateAddress);
1084       $this->is_modified= TRUE;
1085     }else{
1086       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
1087     }
1088   }
1090   function make_name($attrs)
1091   {
1092     $name= "";
1093     if (isset($attrs['sn'][0])){
1094       $name= $attrs['sn'][0];
1095     }
1096     if (isset($attrs['givenName'][0])){
1097       if ($name != ""){
1098         $name.= ", ".$attrs['givenName'][0];
1099       } else {
1100         $name.= $attrs['givenName'][0];
1101       }
1102     }
1103     if ($name != ""){
1104       $name.= " ";
1105     }
1107     return ($name);
1108   }
1110   
1111   /* Create the mail part for the copy & paste dialog */
1112   function getCopyDialog()
1113   {
1114     if(!$this->is_account) return("");
1115     $smarty = get_smarty();
1116     $smarty->assign("mail",$this->mail); 
1117     $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress);
1118     $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress);
1119     $str = $smarty->fetch(get_template_path("copypaste.tpl",TRUE, dirname(__FILE__)));
1121     $ret = array();
1122     $ret['status'] = "";
1123     $ret['string'] = $str;
1124     return($ret);
1125   }
1127   function saveCopyDialog()
1128   {
1129     if(!$this->is_account) return;  
1131     /* Execute to save mailAlternateAddress && gosaMailForwardingAddress */
1132     $this->execute();
1133     
1134     if(isset($_POST['mail'])){
1135       $this->mail = $_POST['mail'];
1136     }
1138   }
1140   function allow_remove()
1141   {
1142     if ($this->config->get_cfg_value("mailmethod") != ""){
1143       $method= $this->config->get_cfg_value("mailmethod");
1144       if(preg_match("/olab/i",$method)){
1145         $ldap = $this->config->get_ldap_link();
1146         $ldap->cd($this->config->current['BASE']);
1147         $ldap->cat($this->dn);
1148         if($ldap->count()){
1149           $attrs = $ldap->fetch();
1150           if(isset($attrs['kolabDeleteFlag'])){ 
1151             return(_("Waiting for kolab to remove mail properties..."));
1152           }elseif(in_array("gosaMailAccount",$attrs['objectClass'])){
1153             return(_("Please remove the mail settings first to allow kolab to call its remove methods!"));
1154           }
1155         }
1156       }
1157     }
1158   }
1160    
1161   function PrepareForCopyPaste($source)
1162   {
1163     plugin::PrepareForCopyPaste($source);
1165     /* Reset alternate mail addresses */
1166     $this->gosaMailAlternateAddress = array();    
1167    }
1170   static function plInfo()
1171   {
1172     return (array(
1173           "plShortName"     => _("Mail"),
1174           "plDescription"   => _("Mail settings"),
1175           "plSelfModify"    => TRUE,
1176           "plDepends"       => array("user"),                     // This plugin depends on
1177           "plPriority"      => 4,                                 // Position in tabs
1178           "plSection"     => array("personal" => _("My account")),
1179           "plCategory"    => array("users"),
1180           "plOptions"       => array(),
1181   
1182           "plProvidedAcls"  => array(
1183             "mail"                      =>  _("Mail address"),
1184             "gosaMailServer"            =>  _("Mail server"),
1185             "gosaMailQuota"             =>  _("Quota size"),
1187             "gosaMailDeliveryModeV"     =>  _("Add vacation information"),  // This is flag of gosaMailDeliveryMode
1188             "gosaVacationMessage"       =>  _("Vacation message"),
1190             "gosaMailDeliveryModeS"     =>  _("Use spam filter"),           // This is flag of gosaMailDeliveryMode
1191             "gosaSpamSortLevel"         =>  _("Spam level"),
1192             "gosaSpamMailbox"           =>  _("Spam mail box"),
1194             "sieveManagement"           =>  _("Sieve management"),
1196             "gosaMailDeliveryModeR"     =>  _("Reject due to mailsize"),    // This is flag of gosaMailDeliveryMode
1197             "gosaMailMaxSize"           =>  _("Mail max size"),
1199             "gosaMailForwardingAddress" =>  _("Forwarding address"),
1200             "gosaMailDeliveryModeL"     =>  _("Local delivery"),            // This is flag of gosaMailDeliveryMode
1201             "gosaMailDeliveryModeI"     =>  _("No delivery to own mailbox "),     // This is flag of gosaMailDeliveryMode
1202             "gosaMailAlternateAddress"  =>  _("Mail alternative addresses"),
1204             "gosaMailForwardingAddress" =>  _("Forwarding address"),
1205             "gosaMailDeliveryModeC"     =>  _("Use custom sieve script"))   // This is flag of gosaMailDeliveryMode
1206         ));
1207   }
1210   /*! \brief  Prepare importet vacation string. \
1211               Replace placeholder like %givenName a.s.o.
1212       @param  string  Vacation string
1213       @return string  Completed vacation string
1214    */  
1215   private function prepare_vacation_template($contents)
1216   {
1217     /* Replace attributes */
1218     $attrs = array();
1219     $obj   = NULL;
1220     if(isset($this->parent->by_object['user'])){
1221       $attrs  = $this->parent->by_object['user']->attributes;
1222       $obj    = $this->parent->by_object['user'];
1223     }else{
1224       $obj    = new user($this->config,$this->dn);
1225       $attrs  = $obj->attributes;
1226     }
1228     if($obj){
1229       foreach ($attrs as $val){
1230         if(preg_match("/dateOfBirth/",$val)){
1231           if($obj->use_dob){
1232             $contents= preg_replace("/%$val/",date("Y-d-m",$obj->dateOfBirth),$contents);
1233           }
1234         }else {
1235           $contents= preg_replace("/%$val/",
1236               $obj->$val, $contents);
1237         }
1239         /* Replace vacation start and end time */
1240         if(preg_match("/%start/",$contents)){
1241           $contents = preg_replace("/%start/",date("d.m.Y",$this->gosaVacationStart),$contents);
1242         }
1243         if(preg_match("/%end/",$contents)){
1244           $contents = preg_replace("/%end/",date("d.m.Y",$this->gosaVacationStop),$contents);
1245         }
1246       }
1247     }
1248     return($contents);
1249   }
1251   
1253   /* Upated shared folder ACLs 
1254    */
1255   function updateSharedFolder()
1256   {
1257     $ldap = $this->config->get_ldap_link();
1258     $ldap->cd($this->config->current['BASE']);
1259     $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array('dn','cn'));
1260     if(class_exists("grouptabs")){
1261       while($attrs = $ldap->fetch()){
1262         $tmp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
1263         if(isset($tmp->by_object['mailgroup'])){
1264           $tmp->by_object['mailgroup']->members= $tmp->by_object['group']->memberUid;
1265           if(!$this->is_account){
1266             $tmp->by_object['mailgroup']->removeUserAcl($this->uid);
1267             $tmp->by_object['mailgroup']->removeUserAcl($this->mail);
1268           }
1269           $tmp->by_object['mailgroup']->save();
1270         }
1271       }
1272     } 
1273   }
1275   /* Initialize plugin with given atribute arrays
1276    */
1277   function init_multiple_support($attrs,$all)
1278   {
1279     plugin::init_multiple_support($attrs,$all);
1281     if(isset($this->multi_attrs['gosaMailQuota'])){
1282       $this->gosaMailQuota = $this->multi_attrs['gosaMailQuota'];
1283     }
1284   }
1286   function get_multi_init_values()
1287   {
1288     $attrs = plugin::get_multi_init_values();
1289     $attrs['gosaMailQuota'] = $this->gosaMailQuota;
1290     return($attrs);
1291   }
1293   function multiple_execute()
1294   {
1295     return($this->execute());
1296   }
1298   function multiple_save_object()
1299   {
1300     plugin::multiple_save_object();
1302     $this->save_object();
1303     foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
1304       if(isset($_POST["use_".$attr])){
1305         $this->multi_boxes[] = $attr;
1306       }
1307     }
1308   }
1310   function get_multi_edit_values()
1311   {
1312     $ret = plugin::get_multi_edit_values();
1314     if(in_array("gosaMailQuota",$this->multi_boxes)){
1315       $ret['gosaMailQuota'] = $this->gosaMailQuota;
1316     }
1318     $flag_add = $flag_remove = array();
1319     $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1320     $opts = array(
1321         "R"   => "use_mailsize_limit",
1322         "S"   => "use_spam_filter",
1323         "L"   => "only_local",
1324         "V"   => "use_vacation",
1325         "C"   => "own_script",
1326         "I"   => "drop_own_mails");
1328     foreach($opts as $flag => $post){
1329       if(in_array($post, $this->multi_boxes)){
1330         if(preg_match("/".$flag."/",$tmp)){
1331           $flag_add[] = $flag;
1332         }else{
1333           $flag_remove[] = $flag;
1334         }
1335       }
1336     }
1337   
1338     $ret['flag_add'] = $flag_add;
1339     $ret['flag_remove'] = $flag_remove;
1340     return($ret);
1341   }
1344   function multiple_check()
1345   {
1346     $message = plugin::multiple_check();
1348     if(empty($this->gosaMailServer) && in_array("gosaMailServer",$this->multi_boxes)){
1349       $message[]= msgPool::noserver(_("Mail"));
1350     }
1352     /* Check quota */
1353     if ($this->gosaMailQuota != ''  && in_array("gosaMailQuota",$this->multi_boxes)){
1354       if (!is_numeric($this->gosaMailQuota)) {
1355         $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
1356       } else {
1357         $this->gosaMailQuota= (int) $this->gosaMailQuota;
1358       }
1359     }
1361     /* Check rejectsize for integer */
1362     if ($this->gosaMailMaxSize != '' && in_array("gosaMailMaxSize",$this->multi_boxes)){
1363       if (!is_numeric($this->gosaMailMaxSize)){
1364         $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
1365       } else {
1366         $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
1367       }
1368     }
1370     if(empty($this->gosaSpamMailbox) && in_array("gosaSpamMailbox",$this->multi_boxes)){
1371       $message[]= msgPool::required(_("Spam folder"));
1372     }
1374     if (  in_array("use_vacation",$this->multi_boxes) &&
1375           preg_match('/V/', $this->gosaMailDeliveryMode) && $this->gosaVacationStart > $this->gosaVacationStop){
1376       $message[]= msgPool::invalid(_("Vacation interval"));
1377     }
1378     return($message);
1379   }
1382   function set_multi_edit_values($values)
1383   {
1384     plugin::set_multi_edit_values($values);
1385     $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1386     if(isset($values['flag_add'])){
1387       foreach($values['flag_add'] as $flag){
1388         if(!preg_match("/".$flag."/",$tmp)){
1389           $tmp .= $flag;
1390         }
1391       }
1392     }
1393     if(isset($values['flag_remove'])){
1394       foreach($values['flag_remove'] as $flag){
1395         if(preg_match("/".$flag."/",$tmp)){
1396           $tmp = preg_replace("/".$flag."/","",$tmp);
1397         }
1398       }
1399     }
1400     $this->gosaMailDeliveryMode = "[".$tmp."]";
1402     /* Set vacation message and replace placeholder like %givenName 
1403      */
1404     if(isset($values['gosaVacationMessage'])){
1405       $this->gosaVacationMessage = $this->prepare_vacation_template($values['gosaVacationMessage']);
1406     }
1407   }
1410 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1411 ?>