Code

Updated multiple user edit && vacation range
[gosa.git] / gosa-plugins / mail / personal / mail / class_mailAccount.inc
1 <?php
2 /*! 
3   \brief   mail plugin
4   \author  Fabian Hicker  <Fabian.Hickert@GONICUS.de>
5   \version 2.6.2
6   \date    03.12.2007
8   This class provides the functionality to read and write all attributes
9   relevant for gosaMailAccounts from/to the LDAP. 
10   It does syntax checking and displays the formulars required.
11   Special handling like sieve or imap actions will be implemented 
12   by the mailMethods.
15 Functions :
17  - mailAccount (&$config, $dn= NULL)
18  - execute()
19  - save_object()
20  - get_vacation_templates()
21  - addForwarder($address)
22  - delForwarder($addresses)
23  - addAlternate($address)
24  - delAlternate($addresses)
25  - prepare_vacation_template($contents)
26  - display_forward_dialog()
27  - remove_from_parent()
28  - save()
29  - check()
30  - adapt_from_template($dn, $skip= array())
31  - getCopyDialog()
32  - saveCopyDialog()
33  - PrepareForCopyPaste($source)
34  - get_multi_edit_values()
35  - multiple_check()
36  - set_multi_edit_values($values)
37  - init_multiple_support($attrs,$all)
38  - get_multi_init_values()
39  - multiple_execute()
40  - multiple_save_object()
41  - make_name($attrs)
42  - plInfo()
45  */
47 class mailAccount extends plugin
48 {
49   /* Definitions */
50   var $plHeadline     = "Mail";
51   var $plDescription  = "This does something";
52   var $view_logged    = FALSE;
53   var $is_account     = FALSE;
54   var $initially_was_account = FALSE;
56   /* GOsa mail attributes */
57   var $mail                               = "";
58   var $gosaVacationStart                  = 0;
59   var $gosaVacationStop                   = 0;
60   var $gosaMailAlternateAddress           = array();
61   var $gosaMailForwardingAddress          = array();
62   var $gosaMailDeliveryMode               = "[L        ]";
63   var $gosaMailServer                     = "";
64   var $gosaMailQuota                      = "";
65   var $gosaMailMaxSize                    = "";
66   var $gosaVacationMessage                = "";
67   var $gosaSpamSortLevel                  = "";
68   var $gosaSpamMailbox                    = "";
70   /* The methods defaults */
71   var $quotaUsage     = -1; // Means unknown
73   var $mailMethod      = NULL;
74   var $MailDomain      = "";
75   var $sieveManagementUsed = FALSE;
76   var $vacationTemplates = array();
77   var $sieve_management = NULL;
78   var $forward_dialog = FALSE;
79   var $initial_uid    = "";
80   var $mailDomainPart = "";
81   var $mailDomainParts = array();
82   var $MailBoxes = array("INBOX");
84   /* Used LDAP attributes && classes */
85   var $attributes= array(
86       "mail", "gosaMailServer","gosaMailQuota", "gosaMailMaxSize","gosaMailForwardingAddress",
87       "gosaMailDeliveryMode", "gosaSpamSortLevel", "gosaSpamMailbox","gosaMailAlternateAddress",
88       "gosaVacationStart","gosaVacationStop", "gosaVacationMessage", "gosaMailAlternateAddress", 
89       "gosaMailForwardingAddress");
90   var $objectclasses= array("gosaMailAccount");
92   var $multiple_support = TRUE;
94   var $uid = "";
95   var $cn  = "";
98   /*! \brief  Initialize the mailAccount 
99    */
100   function __construct (&$config, $dn= NULL)
101   {
102     plugin::plugin($config,$dn); 
104     /* Get attributes from parent object 
105      */
106     foreach(array("uid","cn") as $attr){
107       if(isset($this->parent->by_object['group']) && isset($this->parent->by_object['group']->$attr)){
108         $this->$attr = &$this->parent->by_object['group']->$attr;
109       }elseif(isset($this->attrs[$attr])){
110         $this->$attr = $this->attrs[$attr][0];
111       }
112     }
114     /* Intialize the used mailMethod
115      */
116     $tmp = new mailMethod($config,$this);
117     $this->mailMethod       = $tmp->get_method();
118     $this->mailMethod->fixAttributesOnLoad();
119     $this->mailDomainParts  = $this->mailMethod->getMailDomains();
120     $this->SpamLevels = $this->mailMethod->getSpamLevels();
122     /* Remember account status 
123      */
124     $this->initially_was_account = $this->is_account;
126     /* Initialize vacation settings, if enabled.
127      */   
128     if(empty($this->gosaVacationStart) && $this->mailMethod->vacationRangeEnabled()){
129       $this->gosaVacationStart = time();
130       $this->gosaVacationStop = time();
131     }
133     /* Read vacation templates 
134      */
135     $this->vacationTemplates = $this->get_vacation_templates();
137     /* Initialize configured values 
138      */ 
139     if($this->is_account){
141       if($this->mailMethod->connect() && $this->mailMethod->account_exists()){
143         /* Read quota */
144         $this->gosaMailQuota = $this->mailMethod->getQuota($this->gosaMailQuota);
145         $this->quotaUsage    = $this->mailMethod->getQuotaUsage($this->quotaUsage);
146         if($this->mailMethod->is_error()){
147           msg_dialog::display(_("Mail error"), sprintf(_("Cannot read quota settings: %s"), 
148                 $this->mailMethod->get_error()), ERROR_DIALOG);
149         }
150         
151         /* Read mailboxes */
152         $this->MailBoxes = $this->mailMethod->getMailboxList($this->MailBoxes);
153         if($this->mailMethod->is_error()){
154           msg_dialog::display(_("Mail error"), sprintf(_("Cannot get list of mailboxes: %s"), 
155                 $this->mailMethod->get_error()), ERROR_DIALOG);
156         }
157           
158       }elseif(!$this->mailMethod->is_connected()){
159         msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"), 
160               $this->mailMethod->get_error()), ERROR_DIALOG);
161       }elseif(!$this->mailMethod->account_exists()){
162         msg_dialog::display(_("Mail error"), sprintf(_("Mailbox '%s' doesn't exists on mail server: %s"), 
163               $this->mailMethod->get_account_id(),$this->gosaMailServer), ERROR_DIALOG);
164       }
166       /* If the doamin part is selectable, we have to split the mail address
167        */
168       if(!(!$this->mailMethod->isModifyableMail() && $this->is_account)){
169         if($this->mailMethod->domainSelectionEnabled()){
170           $this->mailDomainPart = preg_replace("/^[^@]*+@/","",$this->mail);
171           $this->mail = preg_replace("/@.*$/","\\1",$this->mail);
172           if(!in_array($this->mailDomainPart,$this->mailDomainParts)){
173             $this->mailDomainParts[] = $this->mailDomainPart;
174           }
175         }
176       }
178       /* Load attributes containing arrays */
179       foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
180         $this->$val= array();
181         if (isset($this->attrs["$val"]["count"])){
182           for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
183             array_push($this->$val, $this->attrs["$val"][$i]);
184           }
185         }
186       }
187     }
189     /* Intialize sieveManagement if necessary */
190     if($this->mailMethod->allowSieveManagement()){
191       $this->mailboxList = &$this->MailBoxes;
192       $this->sieve_management = new sieveManagement($this->config,$this->dn,$this,$this->mailMethod->getUAttrib());
193     }
195     /* Get global filter config used in add local forward
196      */
197     if (!session::is_set("mailfilter")){
198       $ui= get_userinfo();
199       $base= get_base_from_people($ui->dn);
200       $mailfilter= array( "depselect"       => $base,
201           "muser"            => "",
202           "regex"           => "*");
203       session::set("mailfilter", $mailfilter);
204     }
206     /* Disconnect mailMethod. Connect on demand later. 
207      */
208     $this->mailMethod->disconnect();
209   }
212   function execute()
213   {
215     /* Call parent execute */
216     $display = plugin::execute();
218     /* Log view */
219     if($this->is_account && !$this->view_logged){
220       $this->view_logged = TRUE;
221       new log("view","users/".get_class($this),$this->dn);
222     }
225     /****************
226       Account status
227      ****************/
229     if(isset($_POST['modify_state'])){
230       if($this->is_account && $this->acl_is_removeable() && $this->mailMethod->accountRemoveAble()){
231         $this->is_account= FALSE;
232       }elseif(!$this->is_account && $this->acl_is_createable() && $this->mailMethod->accountCreateable()){
233         $this->is_account= TRUE;
234       }
235     }
236     if(!$this->multiple_support_active){
237       if (!$this->is_account && $this->parent === NULL){
238         $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\">&nbsp;<b>".
239           msgPool::noValidExtension(_("Mail"))."</b>";
240         $display.= back_to_main();
241         return ($display);
242       }
243       if ($this->parent !== NULL){
244         if ($this->is_account){ 
245           $reason = "";
246           if(!$this->mailMethod->accountRemoveable($reason)){
247             $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Mail")),$reason ,TRUE,TRUE);
248           }else{
249             $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Mail")),msgPool::featuresEnabled(_("Mail")));
250           }
251         } else {
252           $reason = "";
253           if(!$this->mailMethod->accountCreateable($reason)){
254             $display= $this->show_disable_header(msgPool::addFeaturesButton(_("Mail")),$reason ,TRUE,TRUE);
255           }else{
256             $display= $this->show_disable_header(msgPool::addFeaturesButton(_("Mail")),msgPool::featuresDisabled(_("Mail")));
257           }
258           return ($display);
259         }
260       }
261     }
263     /****************
264       Sieve Management Dialog
265      ****************/
266     if($this->mailMethod->allowSieveManagement()){
267       if(isset($_POST['sieveManagement'])
268           && preg_match("/C/",$this->gosaMailDeliveryMode)
269           && $this->acl_is_writeable("sieveManagement") 
270           && $this->mailMethod->allowSieveManagement()) {
271         $this->dialog = $this->sieve_management;
272       }
273       if(isset($_POST['sieve_cancel'])){
274         $this->dialog = FALSE;
275       }
276       if(isset($_POST['sieve_finish'])){
277         $this->sieve_management = $this->dialog;
278         $this->dialog = FALSE;
279       }
280       if(is_object($this->dialog)){
281         $this->dialog->save_object();
282         return($this->dialog->execute());
283       }
284     }
286     /****************
287       Forward addresses 
288      ****************/
289     if (isset($_POST['add_local_forwarder'])){
290       $this->forward_dialog= TRUE;
291       $this->dialog= TRUE;
292     }
293     if (isset($_POST['add_locals_cancel'])){
294       $this->forward_dialog= FALSE;
295       $this->dialog= FALSE;
296     }
297     if (isset($_POST['add_locals_finish'])){
298       if (isset($_POST['local_list'])){
299         if($this->acl_is_writeable("gosaMailForwardingAddress")){
300           foreach ($_POST['local_list'] as $val){
301             if (!in_array ($val, $this->gosaMailAlternateAddress) &&
302                 $val != $this->mail){
303               $this->addForwarder($val);
304               $this->is_modified= TRUE;
305             }
306           }
307         }
308         $this->forward_dialog= FALSE;
309         $this->dialog= FALSE;
310       } else {
311         msg_dialog::display(_("Error"), _("Please select an entry!"), ERROR_DIALOG);
312       }
313     }
314     if (isset($_POST['add_forwarder'])){
315       if ($_POST['forward_address'] != ""){
316         $address= $_POST['forward_address'];
317         $valid= FALSE;
318         if (!tests::is_email($address)){
319           if (!tests::is_email($address, TRUE)){
320             if ($this->is_template){
321               $valid= TRUE;
322             } else {
323               msg_dialog::display(_("Error"), msgPool::invalid(_("Mail address"),
324                     "","","your-address@your-domain.com"),ERROR_DIALOG);
325             }
326           }
327         } elseif ($address == $this->mail
328             || in_array($address, $this->gosaMailAlternateAddress)) {
329           msg_dialog::display(_("Error"),_("Cannot add primary address to the list of forwarders!") , ERROR_DIALOG);
330         } else {
331           $valid= TRUE;
332         }
333         if ($valid){
334           if($this->acl_is_writeable("gosaMailForwardingAddress")){
335             $this->addForwarder ($address);
336             $this->is_modified= TRUE;
337           }
338         }
339       }
340     }
341     if (isset($_POST['delete_forwarder'])){
342       $this->delForwarder ($_POST['forwarder_list']);
343     }
344     if ($this->forward_dialog){
345       return($this->display_forward_dialog());
346     }
349     /****************
350       Alternate addresses 
351      ****************/
353     if (isset($_POST['add_alternate'])){
354       $valid= FALSE;
355       if (!tests::is_email($_POST['alternate_address'])){
356         if ($this->is_template){
357           if (!(tests::is_email($_POST['alternate_address'], TRUE))){
358             msg_dialog::display(_("Error"),msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com"),ERROR_DIALOG);
359           } else {
360             $valid= TRUE;
361           }
362         } else {
363           msg_dialog::display(_("Error"),msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com"),ERROR_DIALOG);
364         }
365       } else {
366         $valid= TRUE;
367       }
368       if ($valid && ($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
369         $ui= get_userinfo();
370         if ($user != $ui->username){
371           msg_dialog::display(_("Error"), msgPool::duplicated(_("Mail address"))."&nbsp;".
372               sprintf(_("Address is already in use by user '%s'."), $user), ERROR_DIALOG);
373         }
374       }
375     }
376     if (isset($_POST['delete_alternate']) && isset($_POST['alternates_list'])){
377       $this->delAlternate ($_POST['alternates_list']);
378     }
380     /****************
381       SMARTY- Assign smarty variables 
382      ****************/
383     $smarty = get_smarty();
384     $smarty->assign("initially_was_account", $this->initially_was_account);
385     $smarty->assign("isModifyableMail"  , $this->mailMethod->isModifyableMail());
386     $smarty->assign("isModifyableServer", $this->mailMethod->isModifyableServer());
387     $smarty->assign("mailEqualsCN", $this->mailMethod->mailEqualsCN());
389     $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
390     $tmp  = $this->plInfo();
391     foreach($tmp['plProvidedAcls'] as $name => $transl){
392       $smarty->assign("$name"."ACL", $this->getacl($name,$SkipWrite));
393     }
394     foreach($this->attributes as $attr){
395       $smarty->assign($attr,$this->$attr);
396     }
397     $smarty->assign("quotaEnabled", $this->mailMethod->quotaEnabled());
398     if($this->mailMethod->quotaEnabled()){
399       $smarty->assign("quotaUsage",   mailMethod::quota_to_image($this->quotaUsage,$this->gosaMailQuota));
400       $smarty->assign("gosaMailQuota",$this->gosaMailQuota);
401     }
402     $smarty->assign("domainSelectionEnabled", $this->mailMethod->domainSelectionEnabled());
403     $smarty->assign("MailDomains", $this->mailDomainParts);
404     $smarty->assign("MailDomain" , $this->mailDomainPart);
405     $smarty->assign("MailServers", $this->mailMethod->getMailServers());
406     $smarty->assign("allowSieveManagement", $this->mailMethod->allowSieveManagement());
407     $smarty->assign("own_script",  $this->sieveManagementUsed);
409     print_a($this->multi_boxes);
411     /* _Multiple users vars_ */
412     foreach($this->attributes as $attr){
413       $u_attr = "use_".$attr;
414       $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
415     }
416     foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
417       $u_attr = "use_".$attr;
418       $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
419     }
422     /****************
423       SMARTY- Assign flags 
424      ****************/
426     $types = array(
427         "V"=>"use_vacation",
428         "S"=>"use_spam_filter",
429         "R"=>"use_mailsize_limit",
430         "I"=>"drop_own_mails",
431         "C"=>"own_script");
432     foreach($types as $option => $varname){
433       if (preg_match("/".$option."/", $this->gosaMailDeliveryMode)) {
434         $smarty->assign($varname, "checked");
435       } else {
436         $smarty->assign($varname, "");
437       }
438     }
439     if (!preg_match("/L/", $this->gosaMailDeliveryMode)) {
440       $smarty->assign("only_local", "checked");
441     } else {
442       $smarty->assign("only_local", "");
443     }
446     /****************
447       Smarty- Vacation settings 
448      ****************/
449     $smarty->assign("rangeEnabled", FALSE);
450     $smarty->assign("template", "");
451     if (count($this->vacationTemplates)){
452       $smarty->assign("show_templates", "true");
453       $smarty->assign("vacationtemplates", $this->vacationTemplates);
454       if (isset($_POST['vacation_template'])){
455         $smarty->assign("template", $_POST['vacation_template']);
456       }
457     } else {
458       $smarty->assign("show_templates", "false");
459     }
461     /* Vacation range assigments
462      */
463     if($this->mailMethod->vacationRangeEnabled()){
464       $smarty->assign("rangeEnabled", TRUE);
465       if($this->gosaVacationStop ==0){
466         $date= getdate(time());
467         $date["mday"]++;
468       }else{
469         $date= getdate($this->gosaVacationStop);
470       }
471       $smarty->assign("end_day", $date["mday"]);
472       $smarty->assign("end_month", $date["mon"]-1);
473       $smarty->assign("end_year", $date["year"]);
475       if($this->gosaVacationStart == 0){
476         $date= getdate(time());
477       }else{
478         $date= getdate($this->gosaVacationStart);
479       }
480       $smarty->assign("start_day", $date["mday"]);
481       $smarty->assign("start_month", $date["mon"]-1);
482       $smarty->assign("start_year", $date["year"]);
483       $days= array();
484       for($d= 1; $d<32; $d++){
485         $days[$d]= $d;
486       }
487       $years= array();
488       for($y= $date['year']-10; $y<$date['year']+10; $y++){
489         $years[]= $y;
490       }
491       $months= msgPool::months();
492       $smarty->assign("months", $months);
493       $smarty->assign("years", $years);
494       $smarty->assign("days", $days);
495     }
497     /* fill filter settings 
498      */
499     $smarty->assign("spamlevel", $this->SpamLevels);
500     $smarty->assign("spambox"  , $this->MailBoxes);
502     $smarty->assign("multiple_support",$this->multiple_support_active);  
503     return($display.$smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
504   }
508   /* Save data to object */
509   function save_object()
510   {
511     if (isset($_POST['mailTab'])){
513       /* Save ldap attributes */
514       $mail   = $this->mail;
515       $server = $this->gosaMailServer;
516       plugin::save_object();
518       if(!$this->mailMethod->isModifyableServer() && $this->initially_was_account){
519         $this->gosaMailServer = $server;
520       }
522       if(!$this->mailMethod->isModifyableMail() && $this->initially_was_account){
523         $this->mail = $mail;
524       }else{
526         /* Get posted mail domain part, if necessary  
527          */
528         if($this->mailMethod->domainSelectionEnabled() && isset($_POST['MailDomain'])){
529           if(in_array(get_post('MailDomain'), $this->mailDomainParts)){
530             $this->mailDomainPart = get_post('MailDomain');
531           }
532         }
533       }
535       /* Import vacation message? 
536        */
537       if (isset($_POST["import_vacation"]) && isset($this->vacationTemplates[$_POST["vacation_template"]])){
538         if($this->multiple_support_active){
539           $contents = ltrim(preg_replace("/^DESC:.*$/m","",file_get_contents($_POST["vacation_template"])));
540         }else{
541           $contents = $this->prepare_vacation_template(file_get_contents($_POST["vacation_template"]));
542         }
543         $this->gosaVacationMessage= htmlspecialchars($contents);
544       }
546       /* Handle flags 
547        */
548       if(isset($_POST['own_script'])){
549         if(!preg_match("/C/",$this->gosaMailDeliveryMode)){
550           $str= preg_replace("/[\[\]]/","",$this->gosaMailDeliveryMode);
551           $this->gosaMailDeliveryMode = "[".$str."C]";
552         }
553       }else{
555         /* Assemble mail delivery mode
556            The mode field in ldap consists of values between braces, this must
557            be called when 'mail' is set, because checkboxes may not be set when
558            we're in some other dialog.
560            Example for gosaMailDeliveryMode [LR        ]
561            L -  Local delivery
562            R -  Reject when exceeding mailsize limit
563            S -  Use spam filter
564            V -  Use vacation message
565            C -  Use custm sieve script
566            I -  Only insider delivery */
568         $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
571         /* Handle delivery flags */
572         if($this->acl_is_writeable("gosaMailDeliveryModeL")){
573           if(!preg_match("/L/",$tmp) && !isset($_POST['only_local'])){
574             $tmp.="L";
575           }elseif(preg_match("/L/",$tmp) && isset($_POST['only_local'])){
576             $tmp = preg_replace("/L/","",$tmp);
577           }
578         }
579         $opts = array(
580             "R"   => "use_mailsize_limit",
581             "S"   => "use_spam_filter",
582             "V"   => "use_vacation",
583             "C"   => "own_script",
584             "I"   => "drop_own_mails");
586         foreach($opts as $flag => $post){
587           if($this->acl_is_writeable("gosaMailDeliveryMode".$flag)){
588             if(!preg_match("/".$flag."/",$tmp) && isset($_POST[$post])){
589               $tmp.= $flag;
590             }elseif(preg_match("/".$flag."/",$tmp) && !isset($_POST[$post])){
591               $tmp = preg_replace("/".$flag."/","",$tmp);
592             }
593           }
594         }
596         $tmp= "[$tmp]";
597         if ($this->gosaMailDeliveryMode != $tmp){
598           $this->is_modified= TRUE;
599         }
600         $this->gosaMailDeliveryMode= $tmp;
602         /* Get start/stop values for vacation scope of application
603          */
604         if($this->mailMethod->vacationRangeEnabled()){
605           if($this->acl_is_writeable("gosaVacationMessage") && preg_match("/V/",$this->gosaMailDeliveryMode)){
606             if(isset($_POST['gosaVacationStart'])){
607               $this->gosaVacationStart = $_POST['gosaVacationStart'];
608             }
609             if(isset($_POST['gosaVacationStop'])){
610               $this->gosaVacationStop = $_POST['gosaVacationStop'];
611             }
612           }
613         }
614       }
615     }
616   }
619   /*! \brief  Parse vacation templates and build up an array
620     containing 'filename' => 'description'. 
621     Used to fill vacation dropdown box.
622     @return Array   All useable vacation templates.
623    */ 
624   function get_vacation_templates()
625   {
626     $vct = array();
627     if ($this->config->get_cfg_value("vacationTemplateDirectory") != ""){
628       $dir= $this->config->get_cfg_value("vacationTemplateDirectory");
629       if (is_dir($dir) && is_readable($dir)){
630         $dh = opendir($dir);
631         while($file = readdir($dh)){
632           $description= "";
633           if (is_file($dir."/".$file)){
634             $fh = fopen($dir."/".$file, "r");
635             $line= fgets($fh, 256);
636             if (!preg_match('/^DESC:/', $line)){
637               msg_dialog::display(_("Configuration error"), sprintf(_("No DESC tag in vacation template '%s'!"), $file), ERROR_DIALOG);
638             }else{
639               $description= trim(preg_replace('/^DESC:\s*/', '', $line));
640             }
641             fclose ($fh);
642           }
643           if ($description != ""){
644             $vct["$dir/$file"]= $description;
645           }
646         }
647         closedir($dh);
648       }
649     }
650     return($vct); 
651   }
654   /*! \brief  Adds the given mail address to the list of mail forwarders 
655    */ 
656   function addForwarder($address)
657   {
658     if(empty($address)) return;
659     if($this->acl_is_writeable("gosaMailForwardingAddress")){
660       $this->gosaMailForwardingAddress[]= $address;
661       $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
662       sort ($this->gosaMailForwardingAddress);
663       reset ($this->gosaMailForwardingAddress);
664       $this->is_modified= TRUE;
665     }else{
666       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
667     }
668   }
671   /*! \brief  Removes the given mail address from the list of mail forwarders 
672    */ 
673   function delForwarder($addresses)
674   {
675     if($this->acl_is_writeable("gosaMailForwardingAddress")){
676       $this->gosaMailForwardingAddress= array_remove_entries ($addresses, $this->gosaMailForwardingAddress);
677       $this->is_modified= TRUE;
678     }else{
679       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
680     }
681   }
684   /*! \brief  Add given mail address to the list of alternate adresses ,
685     .          check if this mal address is used, skip adding in this case 
686    */ 
687   function addAlternate($address)
688   {
689     if(empty($address)) return;
690     if($this->acl_is_writeable("gosaMailAlternateAddress")){
691       $ldap= $this->config->get_ldap_link();
692       $address= strtolower($address);
694       /* Is this address already assigned in LDAP? */
695       $ldap->cd ($this->config->current['BASE']);
696       $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=$address)".
697           "(alias=$address)(gosaMailAlternateAddress=$address)))", array("uid"));
698       if ($ldap->count() > 0){
699         $attrs= $ldap->fetch ();
700         return ($attrs["uid"][0]);
701       }
702       if (!in_array($address, $this->gosaMailAlternateAddress)){
703         $this->gosaMailAlternateAddress[]= $address;
704         $this->is_modified= TRUE;
705       }
706       sort ($this->gosaMailAlternateAddress);
707       reset ($this->gosaMailAlternateAddress);
708       return ("");
709     }else{
710       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
711     }
712   }
715   /*! \brief  Removes the given mail address from the alternate addresses list 
716    */ 
717   function delAlternate($addresses)
718   {
719     if($this->acl_is_writeable("gosaMailAlternateAddress")){
720       $this->gosaMailAlternateAddress= array_remove_entries ($addresses,$this->gosaMailAlternateAddress);
721       $this->is_modified= TRUE;
722     }else{
723       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
724     }
725   }
728   /*! \brief  Prepare importet vacation string. \
729     .         Replace placeholder like %givenName a.s.o.
730     @param  string  Vacation string
731     @return string  Completed vacation string
732    */
733   private function prepare_vacation_template($contents)
734   {
735     /* Replace attributes */
736     $attrs = array();
737     $obj   = NULL;
738     if(isset($this->parent->by_object['user'])){
739       $attrs  = $this->parent->by_object['user']->attributes;
740       $obj    = $this->parent->by_object['user'];
741     }else{
742       $obj    = new user($this->config,$this->dn);
743       $attrs  = $obj->attributes;
744     }
745     if($obj){
747       /* Replace vacation start and end time */
748       if($this->mailMethod->vacationRangeEnabled()){
749         if(preg_match("/%start/",$contents)){
750           $contents = preg_replace("/%start/",date("d.m.Y",$this->gosaVacationStart),$contents);
751         }
752         if(preg_match("/%end/",$contents)){
753           $contents = preg_replace("/%end/",date("d.m.Y",$this->gosaVacationStop),$contents);
754         }
755       }else{
756         if(preg_match("/%start/",$contents)){
757           $contents = preg_replace("/%start/", _("unknown"),$contents);
758         }
759         if(preg_match("/%end/",$contents)){
760           $contents = preg_replace("/%end/", _("unknown"), $contents);
761         }
762       }
764       foreach ($attrs as $val){
765         if(preg_match("/dateOfBirth/",$val)){
766           if($obj->use_dob){
767             $contents= preg_replace("/%$val/",date("Y-d-m",$obj->dateOfBirth),$contents);
768           }
769         }else {
770           $contents= preg_replace("/%$val/",
771               $obj->$val, $contents);
772         }
774       }
775     }
776     $contents = ltrim(preg_replace("/^DESC:.*$/m","",$contents),"\n ");
777     return($contents);
778   }
781   /*! \brief  Displays a dialog that allows mail address selection.
782    */ 
783   function display_forward_dialog()
784   {
785     restore_error_handler();
787     $smarty = get_smarty();
788     $ldap= $this->config->get_ldap_link();
790     /* Save data */
791     $mailfilter= session::get("mailfilter");
792     foreach( array("depselect", "muser", "regex") as $type){
793       if (isset($_POST[$type])){
794         $mailfilter[$type]= $_POST[$type];
795       }
796     }
797     if (isset($_GET['search'])){
798       $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
799       if ($s == "**"){
800         $s= "*";
801       }
802       $mailfilter['regex']= $s;
803     }
804     session::set("mailfilter", $mailfilter);
806     /* Get actual list */
807     $mailusers= array ();
808     if ($mailfilter['regex'] != '*' && $mailfilter['regex'] != ""){
809       $regex= $mailfilter['regex'];
810       $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
811     } else {
812       $filter= "";
813     }
814     if ($mailfilter['muser'] != ""){
815       $user= $mailfilter['muser'];
816       $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
817     }
819     /* Add already present people to the filter */
820     $exclude= "";
821     foreach ($this->gosaMailForwardingAddress as $mail){
822       $exclude.= "(mail=$mail)";
823     }
824     if ($exclude != ""){
825       $filter.= "(!(|$exclude))";
826     }
827     $res= get_list("(&(objectClass=gosaMailAccount)$filter)", "users", $mailfilter['depselect'],
828         array("sn", "mail", "givenName"), GL_SIZELIMIT | GL_SUBSEARCH);
829     $ldap->cd($mailfilter['depselect']);
830     $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
831     while ($attrs= $ldap->fetch()){
832       if(preg_match('/%/', $attrs['mail'][0])){
833         continue;
834       }
835       $name= $this->make_name($attrs);
836       $mailusers[$attrs['mail'][0]]= $name."&lt;".
837         $attrs['mail'][0]."&gt;";
838     }
839     natcasesort ($mailusers);
840     reset ($mailusers);
842     /* Show dialog */
843     $smarty->assign("search_image", get_template_path('images/lists/search.png'));
844     $smarty->assign("usearch_image", get_template_path('images/lists/search-user.png'));
845     $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
846     $smarty->assign("infoimage", get_template_path('images/info.png'));
847     $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
848     $smarty->assign("mailusers", $mailusers);
849     if (isset($_POST['depselect'])){
850       $smarty->assign("depselect", $_POST['depselect']);
851     }
852     $smarty->assign("deplist", $this->config->idepartments);
853     $smarty->assign("apply", apply_filter());
854     $smarty->assign("alphabet", generate_alphabet());
855     $smarty->assign("hint", print_sizelimit_warning());
856     foreach( array("depselect", "muser", "regex") as $type){
857       $smarty->assign("$type", $mailfilter[$type]);
858     }
859     $smarty->assign("hint", print_sizelimit_warning());
860     $display= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE, dirname(__FILE__)));
861     return ($display);
862   }
865   /*! \brief  Removes the mailAccount extension from ldap 
866    */  
867   function remove_from_parent()
868   {
869     /* Cancel if there's nothing to do here */
870     if (!$this->initially_was_account){
871       return;
872     }
874     /* If domain part was selectable, contruct mail address */
875     if($this->mailMethod->domainSelectionEnabled()){
876       $this->mail = $this->mail."@".$this->mailDomainPart;
877     }
879     /* Update sharedFolder dependencies. 
880        Open each shared folder and remove this account. 
881        Then Save the group to ensure that all necessary 
882         actions will be taken (imap acls updated aso.).
883      */
884     $ldap = $this->config->get_ldap_link();    
885     $ldap->cd($this->config->current['BASE']);
886     $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array("dn"));
887     while($attrs = $ldap->fetch()){
888       $grp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
889       if(isset($grp->by_object['mailgroup']) && isset($grp->by_object['group'])){
890         $grp->by_object['group']->removeUser($this->uid);
892         /* Do not save the complete group! This will quit the complete membership 
893          */
894         $grp->by_object['mailgroup']->save();
895       } 
896     }
898     /* Remove GOsa attributes */
899     plugin::remove_from_parent();
901     /* Zero arrays */
902     $this->attrs['gosaMailAlternateAddress'] = array();
903     $this->attrs['gosaMailForwardingAddress']= array();
906     $this->mailMethod->fixAttributesOnRemove();
907     $this->cleanup();
909     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
910     $ldap= $this->config->get_ldap_link();
911     $ldap->cd($this->dn);
912     $ldap->modify ($this->attrs);
914     /* Add "view" to logging class */
915     new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
916     if (!$ldap->success()){
917       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
918     }
919     
920     /* Let the mailMethod remove this mailbox, e.g. from imap and
921        update shared folder membership, ACL may need to be updated. 
922      */
923     if (!$this->is_template){
925       if(!$this->mailMethod->connect()){
926         msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"), 
927               $this->mailMethod->get_error()), ERROR_DIALOG);
928       }else{
929         if(!$this->mailMethod->deleteMailbox()){
930           msg_dialog::display(_("Mail error"), sprintf(_("Cannot remove mailbox: %s"), 
931                 $this->mailMethod->get_error()), ERROR_DIALOG);
932         }
933       }
934     }
935     $this->mailMethod->disconnect();
937     /* Optionally execute a command after we're done */
938     $this->handle_post_events("remove",array("uid" => $this->uid));
939   }
942   /*! \brief  Save the mailAccount settings to the ldap database.
943    */
944   function save()
945   {
946     $ldap= $this->config->get_ldap_link();
948     /* If domain part was selectable, contruct mail address */
949     if(!(!$this->mailMethod->isModifyableMail() && $this->initially_was_account)){
951       if($this->mailMethod->domainSelectionEnabled()){
952         $this->mail = $this->mail."@".$this->mailDomainPart;
953       }
955       /* Enforce lowercase mail address and trim whitespaces
956        */
957       $this->mail = trim(strtolower($this->mail));
958     }
961     /* Call parents save to prepare $this->attrs */
962     plugin::save();
964     /* Save arrays */
965     $this->attrs['gosaMailAlternateAddress'] = $this->gosaMailAlternateAddress;
966     $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
968     if(!$this->mailMethod->vacationRangeEnabled()){
969       $this->attrs['gosaVacationStart'] = $this->attrs['gosaVacationStop'] = array();
970     }elseif (!preg_match('/V/', $this->gosaMailDeliveryMode)){
971       unset($this->attrs['gosaVacationStart']);
972       unset($this->attrs['gosaVacationStop']);
973     }
975     /* Map method attributes */ 
976     $this->mailMethod->fixAttributesOnStore();
977     
978     /* Save data to LDAP */
979     $ldap->cd($this->dn);
980     $this->cleanup();
981     $ldap->modify ($this->attrs);
983     if (!$ldap->success()){
984       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
985     }
987     /* Log last action */
988     if($this->initially_was_account){
989       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
990     }else{
991       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
992     }
994     /* Only do IMAP actions if we are not a template */
995     if (!$this->is_template){
996       $this->mailMethod->connect();
997       if(!$this->mailMethod->is_connected()){
998         msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"), 
999               $this->mailMethod->get_error()), ERROR_DIALOG);
1000       }else{
1001         if(!$this->mailMethod->updateMailbox()){
1002           msg_dialog::display(_("Mail error"), sprintf(_("Cannot update mailbox: %s"), 
1003                 $this->mailMethod->get_error()), ERROR_DIALOG);
1004         }
1005         if(!$this->mailMethod->setQuota($this->gosaMailQuota)){
1006           msg_dialog::display(_("Mail error"), sprintf(_("Cannot write quota settings: %s"), 
1007                 $this->mailMethod->get_error()), ERROR_DIALOG);
1008         }
1010         if (!is_integer(strpos($this->gosaMailDeliveryMode, "C"))){
1012           /* Do not write sieve settings if this account is new and 
1013              doesn't seem to exist.
1014            */
1015           if(!$this->initially_was_account && !$this->mailMethod->account_exists()){
1016             @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,
1017                 "Skipping sieve settings, the account doesn't seem to be created already.</b>","");
1018           }else{
1019             if(!$this->mailMethod->saveSieveSettings()){
1020               msg_dialog::display(_("Mail error"), $this->mailMethod->get_error(), ERROR_DIALOG);
1021             }
1022           }
1023         }else{
1024          echo "Check sieve management here";
1025           @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, 
1026               "User uses an own sieve script, skipping sieve update.".$str."</b>","");
1027         }
1028       }
1029     }
1030     $this->mailMethod->disconnect();
1032     /* Update sharedFolder dependencies.
1033        Open each shared folder and remove this account.
1034        Then Save the group to ensure that all necessary
1035        actions will be taken (imap acls updated aso.).
1036      */
1037     if(!$this->initially_was_account){
1038       $ldap = $this->config->get_ldap_link();
1039       $ldap->cd($this->config->current['BASE']);
1040       $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array("dn"));
1041       while($attrs = $ldap->fetch()){
1042         $grp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
1043         if(isset($grp->by_object['mailgroup'])){
1044           /* Do not save the complete group! This will quit the complete membership
1045            */
1046           $grp->by_object['mailgroup']->save();
1047         }
1048       }
1049     }
1051     /* Optionally execute a command after we're done */
1052     if ($this->initially_was_account == $this->is_account){
1053       if ($this->is_modified){
1054         $this->handle_post_events("modify", array("uid" => $this->uid));
1055       }
1056     } else {
1057       $this->handle_post_events("add", array("uid" => $this->uid));
1058     }
1059   }
1062   /*! \brief  Check given values 
1063    */
1064   function check()
1065   {
1066     if(!$this->is_account){
1067       return(array());
1068     }
1070     $ldap= $this->config->get_ldap_link();
1072     /* Call common method to give check the hook */
1073     $message= plugin::check();
1075     if(empty($this->gosaMailServer)){
1076       $message[]= msgPool::noserver(_("Mail"));
1077     }
1079     /* Mail address checks */
1080     $mail = $this->mail;
1081     if(!(!$this->mailMethod->isModifyableMail() && $this->initially_was_account)){
1083       if($this->mailMethod->domainSelectionEnabled()){
1084         $mail.= "@".$this->mailDomainPart;
1085       }
1087       if (empty($mail)){
1088         $message[]= msgPool::required(_("Primary address"));
1089       }
1090       if ($this->is_template){
1091         if (!tests::is_email($mail, TRUE)){
1092           $message[]= msgPool::invalid(_("Mail address"),"","","%givenName.%sn@your-domain.com");
1093         }
1094       } else {
1095         if (!tests::is_email($mail)){
1096           $message[]= msgPool::invalid(_("Mail address"),"","","your-address@your-domain.com");
1097         }
1098       }
1100       /* Check if this mail address is already in use */
1101       $ldap->cd($this->config->current['BASE']);
1102       $filter = "(&(!(objectClass=gosaUserTemplate))(!(uid=".$this->uid."))".
1103         "(objectClass=gosaMailAccount)".
1104         "(|(mail=".$mail.")(alias=".$mail.")(gosaMailAlternateAddress=".$mail.")))";
1105       $ldap->search($filter,array("uid"));
1106       if ($ldap->count() != 0){
1107         $message[]= msgPool::duplicated(_("Mail address"));
1108       }
1109     }
1112     /* Check quota */
1113     if ($this->gosaMailQuota != '' && $this->acl_is_writeable("gosaMailQuota")){
1114       if (!is_numeric($this->gosaMailQuota)) {
1115         $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
1116       } else {
1117         $this->gosaMailQuota= (int) $this->gosaMailQuota;
1118       }
1119     }
1121     /* Check rejectsize for integer */
1122     if ($this->gosaMailMaxSize != '' && $this->acl_is_writeable("gosaMailMaxSize")){
1123       if (!is_numeric($this->gosaMailMaxSize)){
1124         $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
1125       } else {
1126         $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
1127       }
1128     }
1130     /* Need gosaMailMaxSize if use_mailsize_limit is checked */
1131     if (is_integer(strpos($this->gosaMailDeliveryMode, "R")) && $this->gosaMailMaxSize == ""){
1132       $message[]= msgPool::required(_("Mail reject size"));
1133     }
1135     if((preg_match("/S/", $this->gosaMailDeliveryMode))&&(empty($this->gosaSpamMailbox))) {
1136       $message[]= msgPool::required(_("Spam folder"));
1137     }
1139     if ($this->mailMethod->vacationRangeEnabled() 
1140         && preg_match('/V/', $this->gosaMailDeliveryMode) 
1141         && $this->gosaVacationStart > $this->gosaVacationStop){
1142       $message[]= msgPool::invalid(_("Vacation interval"));
1143     }
1144     return($message);
1145   }
1148   /*! \brief  Adapt from template, using 'dn' 
1149    */
1150   function adapt_from_template($dn, $skip= array())
1151   {
1152     plugin::adapt_from_template($dn, $skip);
1154     foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
1156       if (in_array($val, $skip)){
1157         continue;
1158       }
1160       $this->$val= array();
1161       if (isset($this->attrs["$val"]["count"])){
1162         for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
1163           $value= $this->attrs["$val"][$i];
1164           foreach (array("sn", "givenName", "uid") as $repl){
1165             if (preg_match("/%$repl/i", $value)){
1166               $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
1167             }
1168           }
1169           array_push($this->$val, strtolower(rewrite($value)));
1170         }
1171       }
1172     }
1173     $this->mail= strtolower(rewrite($this->mail));
1174   }
1177   /*! \brief  Creates the mail part for the copy & paste dialog 
1178    */ 
1179   function getCopyDialog()
1180   {
1181     if(!$this->is_account) return("");
1182     $smarty = get_smarty();
1183     $smarty->assign("mail",$this->mail);
1184     $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress);
1185     $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress);
1186     $str = $smarty->fetch(get_template_path("copypaste.tpl",TRUE, dirname(__FILE__)));
1188     $ret = array();
1189     $ret['status'] = "";
1190     $ret['string'] = $str;
1191     return($ret);
1192   }
1194     
1195   /*! \brief  save_object for copy&paste vars 
1196    */  
1197   function saveCopyDialog()
1198   {
1199     if(!$this->is_account) return;
1201     /* Execute to save mailAlternateAddress && gosaMailForwardingAddress */
1202     $this->execute();
1203     if(isset($_POST['mail'])){
1204       $this->mail = $_POST['mail'];
1205     }
1206   }
1208   
1209   /*! \brief  Prepare this account to be copied 
1210    */
1211   function PrepareForCopyPaste($source)
1212   {
1213     plugin::PrepareForCopyPaste($source);
1215     /* Reset alternate mail addresses */
1216     $this->gosaMailAlternateAddress = array();
1217   }
1220   /*! \brief  Prepare this class the be useable when editing multiple users at once 
1221    */
1222   function get_multi_edit_values()
1223   {
1224     $ret = plugin::get_multi_edit_values();
1225     if(in_array("gosaMailQuota",$this->multi_boxes)){
1226       $ret['gosaMailQuota'] = $this->gosaMailQuota;
1227     }
1228     $flag_add = $flag_remove = array();
1229     $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1230     $opts = array(
1231         "R"   => "use_mailsize_limit",
1232         "S"   => "use_spam_filter",
1233         "L"   => "only_local",
1234         "V"   => "use_vacation",
1235         "C"   => "own_script",
1236         "I"   => "drop_own_mails");
1237     foreach($opts as $flag => $post){
1238       if(in_array($post, $this->multi_boxes)){
1239         if(preg_match("/".$flag."/",$tmp)){
1240           $flag_add[] = $flag;
1241         }else{
1242           $flag_remove[] = $flag;
1243         }
1244       }
1245     }
1246     $ret['flag_add'] = $flag_add;
1247     $ret['flag_remove'] = $flag_remove;
1249     if($this->mailMethod->vacationRangeEnabled()){
1250       if(in_array("V",$flag_add)){
1251         $ret['gosaVacationStart'] =  $this->gosaVacationStart = $_POST['gosaVacationStart'];
1252         $ret['gosaVacationStop'] =  $this->gosaVacationStop = $_POST['gosaVacationStop'];
1253       }
1254     }
1255     return($ret);
1256   }
1259   /*! \brief  Check given input for multiple user edit 
1260    */
1261   function multiple_check()
1262   {
1263     $message = plugin::multiple_check();
1265     if(empty($this->gosaMailServer) && in_array("gosaMailServer",$this->multi_boxes)){
1266       $message[]= msgPool::noserver(_("Mail"));
1267     }
1269     /* Check quota */
1270     if ($this->gosaMailQuota != ''  && in_array("gosaMailQuota",$this->multi_boxes)){
1271       if (!is_numeric($this->gosaMailQuota)) {
1272         $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
1273       } else {
1274         $this->gosaMailQuota= (int) $this->gosaMailQuota;
1275       }
1276     }
1278     /* Check rejectsize for integer */
1279     if ($this->gosaMailMaxSize != '' && in_array("gosaMailMaxSize",$this->multi_boxes)){
1280       if (!is_numeric($this->gosaMailMaxSize)){
1281         $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
1282       } else {
1283         $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
1284       }
1285     }
1287     if(empty($this->gosaSpamMailbox) && in_array("gosaSpamMailbox",$this->multi_boxes)){
1288       $message[]= msgPool::required(_("Spam folder"));
1289     }
1291     if ($this->mailMethod->vacationRangeEnabled() && in_array("use_vacation",$this->multi_boxes) &&
1292         preg_match('/V/', $this->gosaMailDeliveryMode) && $this->gosaVacationStart > $this->gosaVacationStop){
1293       $message[]= msgPool::invalid(_("Vacation interval"));
1294     }
1295     return($message);
1296   }
1298   
1299   /*! \brief  ...
1300    */
1301   function set_multi_edit_values($values)
1302   {
1303     plugin::set_multi_edit_values($values);
1304     $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1305     if(isset($values['flag_add'])){
1306       foreach($values['flag_add'] as $flag){
1307         if(!preg_match("/".$flag."/",$tmp)){
1308           $tmp .= $flag;
1309         }
1310       }
1311     }
1312     if(isset($values['flag_remove'])){
1313       foreach($values['flag_remove'] as $flag){
1314         if(preg_match("/".$flag."/",$tmp)){
1315           $tmp = preg_replace("/".$flag."/","",$tmp);
1316         }
1317       }
1318     }
1319     $this->gosaMailDeliveryMode = "[".$tmp."]";
1321     /* Set vacation message and replace placeholder like %givenName
1322      */
1323     if(isset($values['gosaVacationMessage'])){
1324       $this->gosaVacationMessage = $this->prepare_vacation_template($values['gosaVacationMessage']);
1325     }
1326   }
1329   /*! \brief  Initialize plugin to be used as multiple edit class. 
1330    */
1331   function init_multiple_support($attrs,$all)
1332   {
1333     plugin::init_multiple_support($attrs,$all);
1334     if(isset($this->multi_attrs['gosaMailQuota'])){
1335       $this->gosaMailQuota = $this->multi_attrs['gosaMailQuota'];
1336     }
1337   }
1339  
1340   /*! \brief
1341    */
1342   function get_multi_init_values()
1343   {
1344     $attrs = plugin::get_multi_init_values();
1345     $attrs['gosaMailQuota'] = $this->gosaMailQuota;
1346     return($attrs);
1347   }
1350   /*! \brief  Display multiple edit dialog 
1351    */
1352   function multiple_execute()
1353   {
1354     return($this->execute());
1355   }
1357   
1358   /*! \brief  Save posts from multiple edit dialog 
1359    */
1360   function multiple_save_object()
1361   {
1362     plugin::multiple_save_object();
1364     $this->save_object();
1365     foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
1366       if(isset($_POST["use_".$attr])){
1367         $this->multi_boxes[] = $attr;
1368       }
1369     }
1370   }
1373   /*! \brief  Creates the user names for the add_local_forward dialog
1374    */
1375   function make_name($attrs)
1376   {
1377     $name= "";
1378     if (isset($attrs['sn'][0])){
1379       $name= $attrs['sn'][0];
1380     }
1381     if (isset($attrs['givenName'][0])){
1382       if ($name != ""){
1383         $name.= ", ".$attrs['givenName'][0];
1384       } else {
1385         $name.= $attrs['givenName'][0];
1386       }
1387     }
1388     if ($name != ""){
1389       $name.= " ";
1390     }
1392     return ($name);
1393   }
1396   function allow_remove()
1397   {
1398     $resason = "";
1399     if(!$this->mailMethod->allow_remove($reason)){
1400       return($reason);
1401     }
1402     return("");
1403   }
1407   /*! \brief  ACL settings 
1408    */
1409   static function plInfo()
1410   {
1411     return (array(
1412           "plShortName"     => _("Mail"),
1413           "plDescription"   => _("Mail settings"),
1414           "plSelfModify"    => TRUE,
1415           "plDepends"       => array("user"),                     // This plugin depends on
1416           "plPriority"      => 4,                                 // Position in tabs
1417           "plSection"     => array("personal" => _("My account")),
1418           "plCategory"    => array("users"),
1419           "plOptions"       => array(),
1421           "plProvidedAcls"  => array(
1422             "mail"                      =>  _("Mail address"),
1423             "gosaMailServer"            =>  _("Mail server"),
1424             "gosaMailQuota"             =>  _("Quota size"),
1426             "gosaMailDeliveryModeV"     =>  _("Add vacation information"),  // This is flag of gosaMailDeliveryMode
1427             "gosaVacationMessage"       =>  _("Vacation message"),
1429             "gosaMailDeliveryModeS"     =>  _("Use spam filter"),           // This is flag of gosaMailDeliveryMode
1430             "gosaSpamSortLevel"         =>  _("Spam level"),
1431             "gosaSpamMailbox"           =>  _("Spam mail box"),
1433             "sieveManagement"           =>  _("Sieve management"),
1435             "gosaMailDeliveryModeR"     =>  _("Reject due to mailsize"),    // This is flag of gosaMailDeliveryMode
1436             "gosaMailMaxSize"           =>  _("Mail max size"),
1438             "gosaMailForwardingAddress" =>  _("Forwarding address"),
1439             "gosaMailDeliveryModeL"     =>  _("Local delivery"),            // This is flag of gosaMailDeliveryMode
1440             "gosaMailDeliveryModeI"     =>  _("No delivery to own mailbox "),     // This is flag of gosaMailDeliveryMode
1441             "gosaMailAlternateAddress"  =>  _("Mail alternative addresses"),
1443             "gosaMailForwardingAddress" =>  _("Forwarding address"),
1444             "gosaMailDeliveryModeC"     =>  _("Use custom sieve script"))   // This is flag of gosaMailDeliveryMode
1445               ));
1446   }
1451 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1452 ?>