Code

d346f242aa82923661de7e7e04f65501cc461e34
[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 $mailMethod      = NULL;
72   var $MailDomain      = "";
73   var $sieveManagementUsed = FALSE;
74   var $vacationTemplates = array();
75   var $sieve_management = NULL;
76   var $forward_dialog = FALSE;
77   var $initial_uid    = "";
78   var $mailDomainPart = "";
79   var $mailDomainParts = array();
80   var $MailBoxes = array("INBOX");
82   /* Used LDAP attributes && classes */
83   var $attributes= array(
84       "mail", "gosaMailServer","gosaMailQuota", "gosaMailMaxSize","gosaMailForwardingAddress",
85       "gosaMailDeliveryMode", "gosaSpamSortLevel", "gosaSpamMailbox","gosaMailAlternateAddress",
86       "gosaVacationStart","gosaVacationStop", "gosaVacationMessage", "gosaMailAlternateAddress", 
87       "gosaMailForwardingAddress");
88   var $objectclasses= array("gosaMailAccount");
90   var $multiple_support = TRUE;
92   var $uid = "";
93   var $cn  = "";
96   /*! \brief  Initialize the mailAccount 
97    */
98   function __construct (&$config, $dn= NULL)
99   {
100     plugin::plugin($config,$dn); 
102     /* Get attributes from parent object 
103      */
104     foreach(array("uid","cn") as $attr){
105       if(isset($this->parent->by_object['group']) && isset($this->parent->by_object['group']->$attr)){
106         $this->$attr = &$this->parent->by_object['group']->$attr;
107       }elseif(isset($this->attrs[$attr])){
108         $this->$attr = $this->attrs[$attr][0];
109       }
110     }
112     /* Intialize the used mailMethod
113      */
114     $tmp = new mailMethod($config,$this);
115     $this->mailMethod       = $tmp->get_method();
116     $this->mailMethod->fixAttributesOnLoad();
117     $this->mailDomainParts  = $this->mailMethod->getMailDomains();
118     $this->SpamLevels = $this->mailMethod->getSpamLevels();
120     /* Remember account status 
121      */
122     $this->initially_was_account = $this->is_account;
124     /* Initialize vacation settings 
125      */   
126     if(empty($this->gosaVacationStart)){
127       $this->gosaVacationStart = time();
128       $this->gosaVacationStop = time();
129     }
131     /* Read vacation templates 
132      */
133     $this->vacationTemplates = $this->get_vacation_templates();
135     /* Initialize configured values 
136      */ 
137     if($this->is_account){
139       if($this->mailMethod->connect() && $this->mailMethod->account_exists()){
141         /* Read quota */
142         $this->gosaMailQuota = $this->mailMethod->getQuota($this->gosaMailQuota);
143         if($this->mailMethod->is_error()){
144           msg_dialog::display(_("Mail error"), sprintf(_("Cannot read quota settings: %s"), 
145                 $this->mailMethod->get_error()), ERROR_DIALOG);
146         }
147         
148         /* Read mailboxes */
149         $this->MailBoxes = $this->mailMethod->getMailboxList($this->MailBoxes);
150         if($this->mailMethod->is_error()){
151           msg_dialog::display(_("Mail error"), sprintf(_("Cannot get list of mailboxes: %s"), 
152                 $this->mailMethod->get_error()), ERROR_DIALOG);
153         }
154           
155       }elseif(!$this->mailMethod->is_connected()){
156         msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"), 
157               $this->mailMethod->get_error()), ERROR_DIALOG);
158       }elseif(!$this->mailMethod->account_exists()){
159         msg_dialog::display(_("Mail error"), sprintf(_("Mailbox '%s' doesn't exists on mail server: %s"), 
160               $this->mailMethod->get_account_id(),$this->gosaMailServer), ERROR_DIALOG);
161       }
163       /* If the doamin part is selectable, we have to split the mail address
164        */
165       if(!(!$this->mailMethod->isModifyableMail() && $this->is_account)){
166         if($this->mailMethod->domainSelectionEnabled()){
167           $this->mailDomainPart = preg_replace("/^[^@]*+@/","",$this->mail);
168           $this->mail = preg_replace("/@.*$/","\\1",$this->mail);
169           if(!in_array($this->mailDomainPart,$this->mailDomainParts)){
170             $this->mailDomainParts[] = $this->mailDomainPart;
171           }
172         }
173       }
175       /* Load attributes containing arrays */
176       foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
177         $this->$val= array();
178         if (isset($this->attrs["$val"]["count"])){
179           for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
180             array_push($this->$val, $this->attrs["$val"][$i]);
181           }
182         }
183       }
184     }
186     /* Intialize sieveManagement if necessary */
187     if($this->mailMethod->allowSieveManagement()){
188       $this->mailboxList = &$this->MailBoxes;
189       $this->sieve_management = new sieveManagement($this->config,$this->dn,$this,$this->mailMethod->getUAttrib());
190     }
192     /* Get global filter config used in add local forward
193      */
194     if (!session::is_set("mailfilter")){
195       $ui= get_userinfo();
196       $base= get_base_from_people($ui->dn);
197       $mailfilter= array( "depselect"       => $base,
198           "muser"            => "",
199           "regex"           => "*");
200       session::set("mailfilter", $mailfilter);
201     }
203     /* Disconnect mailMethod. Connect on demand later. 
204      */
205     $this->mailMethod->disconnect();
206   }
209   function execute()
210   {
212     /* Call parent execute */
213     $display = plugin::execute();
215     /* Log view */
216     if($this->is_account && !$this->view_logged){
217       $this->view_logged = TRUE;
218       new log("view","users/".get_class($this),$this->dn);
219     }
222     /****************
223       Account status
224      ****************/
226     if(isset($_POST['modify_state'])){
227       if($this->is_account && $this->acl_is_removeable() && $this->mailMethod->accountRemoveAble()){
228         $this->is_account= FALSE;
229       }elseif(!$this->is_account && $this->acl_is_createable() && $this->mailMethod->accountCreateable()){
230         $this->is_account= TRUE;
231       }
232     }
233     if(!$this->multiple_support_active){
234       if (!$this->is_account && $this->parent === NULL){
235         $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\">&nbsp;<b>".
236           msgPool::noValidExtension(_("Mail"))."</b>";
237         $display.= back_to_main();
238         return ($display);
239       }
240       if ($this->parent !== NULL){
241         if ($this->is_account){ 
242           $reason = "";
243           if(!$this->mailMethod->accountRemoveable($reason)){
244             $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Mail")),$reason ,TRUE,TRUE);
245           }else{
246             $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Mail")),msgPool::featuresEnabled(_("Mail")));
247           }
248         } else {
249           $reason = "";
250           if(!$this->mailMethod->accountCreateable($reason)){
251             $display= $this->show_disable_header(msgPool::addFeaturesButton(_("Mail")),$reason ,TRUE,TRUE);
252           }else{
253             $display= $this->show_disable_header(msgPool::addFeaturesButton(_("Mail")),msgPool::featuresDisabled(_("Mail")));
254           }
255           return ($display);
256         }
257       }
258     }
260     /****************
261       Sieve Management Dialog
262      ****************/
263     if($this->mailMethod->allowSieveManagement()){
264       if(isset($_POST['sieveManagement'])
265           && preg_match("/C/",$this->gosaMailDeliveryMode)
266           && $this->acl_is_writeable("sieveManagement") 
267           && $this->mailMethod->allowSieveManagement()) {
268         $this->dialog = $this->sieve_management;
269       }
270       if(isset($_POST['sieve_cancel'])){
271         $this->dialog = FALSE;
272       }
273       if(isset($_POST['sieve_finish'])){
274         $this->sieve_management = $this->dialog;
275         $this->dialog = FALSE;
276       }
277       if(is_object($this->dialog)){
278         $this->dialog->save_object();
279         return($this->dialog->execute());
280       }
281     }
283     /****************
284       Forward addresses 
285      ****************/
286     if (isset($_POST['add_local_forwarder'])){
287       $this->forward_dialog= TRUE;
288       $this->dialog= TRUE;
289     }
290     if (isset($_POST['add_locals_cancel'])){
291       $this->forward_dialog= FALSE;
292       $this->dialog= FALSE;
293     }
294     if (isset($_POST['add_locals_finish'])){
295       if (isset($_POST['local_list'])){
296         if($this->acl_is_writeable("gosaMailForwardingAddress")){
297           foreach ($_POST['local_list'] as $val){
298             if (!in_array ($val, $this->gosaMailAlternateAddress) &&
299                 $val != $this->mail){
300               $this->addForwarder($val);
301               $this->is_modified= TRUE;
302             }
303           }
304         }
305         $this->forward_dialog= FALSE;
306         $this->dialog= FALSE;
307       } else {
308         msg_dialog::display(_("Error"), _("Please select an entry!"), ERROR_DIALOG);
309       }
310     }
311     if (isset($_POST['add_forwarder'])){
312       if ($_POST['forward_address'] != ""){
313         $address= $_POST['forward_address'];
314         $valid= FALSE;
315         if (!tests::is_email($address)){
316           if (!tests::is_email($address, TRUE)){
317             if ($this->is_template){
318               $valid= TRUE;
319             } else {
320               msg_dialog::display(_("Error"), msgPool::invalid(_("Mail address"),
321                     "","","your-address@your-domain.com"),ERROR_DIALOG);
322             }
323           }
324         } elseif ($address == $this->mail
325             || in_array($address, $this->gosaMailAlternateAddress)) {
326           msg_dialog::display(_("Error"),_("Cannot add primary address to the list of forwarders!") , ERROR_DIALOG);
327         } else {
328           $valid= TRUE;
329         }
330         if ($valid){
331           if($this->acl_is_writeable("gosaMailForwardingAddress")){
332             $this->addForwarder ($address);
333             $this->is_modified= TRUE;
334           }
335         }
336       }
337     }
338     if (isset($_POST['delete_forwarder'])){
339       $this->delForwarder ($_POST['forwarder_list']);
340     }
341     if ($this->forward_dialog){
342       return($this->display_forward_dialog());
343     }
346     /****************
347       Alternate addresses 
348      ****************/
350     if (isset($_POST['add_alternate'])){
351       $valid= FALSE;
352       if (!tests::is_email($_POST['alternate_address'])){
353         if ($this->is_template){
354           if (!(tests::is_email($_POST['alternate_address'], TRUE))){
355             msg_dialog::display(_("Error"),msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com"),ERROR_DIALOG);
356           } else {
357             $valid= TRUE;
358           }
359         } else {
360           msg_dialog::display(_("Error"),msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com"),ERROR_DIALOG);
361         }
362       } else {
363         $valid= TRUE;
364       }
365       if ($valid && ($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
366         $ui= get_userinfo();
367         if ($user != $ui->username){
368           msg_dialog::display(_("Error"), msgPool::duplicated(_("Mail address"))."&nbsp;".
369               sprintf(_("Address is already in use by user '%s'."), $user), ERROR_DIALOG);
370         }
371       }
372     }
373     if (isset($_POST['delete_alternate']) && isset($_POST['alternates_list'])){
374       $this->delAlternate ($_POST['alternates_list']);
375     }
377     /****************
378       SMARTY- Assign smarty variables 
379      ****************/
380     $smarty = get_smarty();
381     $smarty->assign("initially_was_account", $this->initially_was_account);
382     $smarty->assign("isModifyableMail"  , $this->mailMethod->isModifyableMail());
383     $smarty->assign("isModifyableServer", $this->mailMethod->isModifyableServer());
384     $smarty->assign("mailEqualsCN", $this->mailMethod->mailEqualsCN());
386     $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
387     $tmp  = $this->plInfo();
388     foreach($tmp['plProvidedAcls'] as $name => $transl){
389       $smarty->assign("$name"."ACL", $this->getacl($name,$SkipWrite));
390     }
391     foreach($this->attributes as $attr){
392       $smarty->assign($attr,$this->$attr);
393     }
394     $smarty->assign("quotaEnabled", $this->mailMethod->quotaEnabled());
395     if($this->mailMethod->is_connected()){
396       $smarty->assign("quotaUsage",   $this->mailMethod->getQuotaUsage());
397     }else{
398       $smarty->assign("quotaUsage",   _("Unknown"));
399     }
400     $smarty->assign("gosaMailQuota",$this->gosaMailQuota);
401     $smarty->assign("domainSelectionEnabled", $this->mailMethod->domainSelectionEnabled());
402     $smarty->assign("MailDomains", $this->mailDomainParts);
403     $smarty->assign("MailDomain" , $this->mailDomainPart);
404     $smarty->assign("MailServers", $this->mailMethod->getMailServers());
405     $smarty->assign("allowSieveManagement", $this->mailMethod->allowSieveManagement());
406     $smarty->assign("own_script",  $this->sieveManagementUsed);
408     print_a($this->multi_boxes);
410     /* _Multiple users vars_ */
411     foreach($this->attributes as $attr){
412       $u_attr = "use_".$attr;
413       $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
414     }
415     foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
416       $u_attr = "use_".$attr;
417       $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
418     }
421     /****************
422       SMARTY- Assign flags 
423      ****************/
425     $types = array(
426         "V"=>"use_vacation",
427         "S"=>"use_spam_filter",
428         "R"=>"use_mailsize_limit",
429         "I"=>"drop_own_mails",
430         "C"=>"own_script");
431     foreach($types as $option => $varname){
432       if (preg_match("/".$option."/", $this->gosaMailDeliveryMode)) {
433         $smarty->assign($varname, "checked");
434       } else {
435         $smarty->assign($varname, "");
436       }
437     }
438     if (!preg_match("/L/", $this->gosaMailDeliveryMode)) {
439       $smarty->assign("only_local", "checked");
440     } else {
441       $smarty->assign("only_local", "");
442     }
445     /****************
446       Smarty- Vacation settings 
447      ****************/
448     $smarty->assign("rangeEnabled", FALSE);
449     $smarty->assign("template", "");
450     if (count($this->vacationTemplates)){
451       $smarty->assign("show_templates", "true");
452       $smarty->assign("vacationtemplates", $this->vacationTemplates);
453       if (isset($_POST['vacation_template'])){
454         $smarty->assign("template", $_POST['vacation_template']);
455       }
456     } else {
457       $smarty->assign("show_templates", "false");
458     }
460     /* Vacation range assigments
461      */
462     if($this->mailMethod->vacationRangeEnabled()){
463       $smarty->assign("rangeEnabled", TRUE);
464       if($this->gosaVacationStop ==0){
465         $date= getdate(time());
466         $date["mday"]++;
467       }else{
468         $date= getdate($this->gosaVacationStop);
469       }
470       $smarty->assign("end_day", $date["mday"]);
471       $smarty->assign("end_month", $date["mon"]-1);
472       $smarty->assign("end_year", $date["year"]);
474       if($this->gosaVacationStart == 0){
475         $date= getdate(time());
476       }else{
477         $date= getdate($this->gosaVacationStart);
478       }
479       $smarty->assign("start_day", $date["mday"]);
480       $smarty->assign("start_month", $date["mon"]-1);
481       $smarty->assign("start_year", $date["year"]);
482       $days= array();
483       for($d= 1; $d<32; $d++){
484         $days[$d]= $d;
485       }
486       $years= array();
487       for($y= $date['year']-10; $y<$date['year']+10; $y++){
488         $years[]= $y;
489       }
490       $months= msgPool::months();
491       $smarty->assign("months", $months);
492       $smarty->assign("years", $years);
493       $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;
601         if($this->mailMethod->vacationRangeEnabled()){
602           if($this->acl_is_writeable("gosaVacationMessage") && preg_match("/V/",$this->gosaMailDeliveryMode)){
603             if(isset($_POST['gosaVacationStart'])){
604               $this->gosaVacationStart = $_POST['gosaVacationStart'];
605             }
606             if(isset($_POST['gosaVacationStop'])){
607               $this->gosaVacationStop = $_POST['gosaVacationStop'];
608             }
609           }
610         }
611       }
612     }
613   }
616   /*! \brief  Parse vacation templates and build up an array
617     containing 'filename' => 'description'. 
618     Used to fill vacation dropdown box.
619     @return Array   All useable vacation templates.
620    */ 
621   function get_vacation_templates()
622   {
623     $vct = array();
624     if ($this->config->get_cfg_value("vacationTemplateDirectory") != ""){
625       $dir= $this->config->get_cfg_value("vacationTemplateDirectory");
626       if (is_dir($dir) && is_readable($dir)){
627         $dh = opendir($dir);
628         while($file = readdir($dh)){
629           $description= "";
630           if (is_file($dir."/".$file)){
631             $fh = fopen($dir."/".$file, "r");
632             $line= fgets($fh, 256);
633             if (!preg_match('/^DESC:/', $line)){
634               msg_dialog::display(_("Configuration error"), sprintf(_("No DESC tag in vacation template '%s'!"), $file), ERROR_DIALOG);
635             }else{
636               $description= trim(preg_replace('/^DESC:\s*/', '', $line));
637             }
638             fclose ($fh);
639           }
640           if ($description != ""){
641             $vct["$dir/$file"]= $description;
642           }
643         }
644         closedir($dh);
645       }
646     }
647     return($vct); 
648   }
651   /*! \brief  Adds the given mail address to the list of mail forwarders 
652    */ 
653   function addForwarder($address)
654   {
655     if(empty($address)) return;
656     if($this->acl_is_writeable("gosaMailForwardingAddress")){
657       $this->gosaMailForwardingAddress[]= $address;
658       $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
659       sort ($this->gosaMailForwardingAddress);
660       reset ($this->gosaMailForwardingAddress);
661       $this->is_modified= TRUE;
662     }else{
663       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
664     }
665   }
668   /*! \brief  Removes the given mail address from the list of mail forwarders 
669    */ 
670   function delForwarder($addresses)
671   {
672     if($this->acl_is_writeable("gosaMailForwardingAddress")){
673       $this->gosaMailForwardingAddress= array_remove_entries ($addresses, $this->gosaMailForwardingAddress);
674       $this->is_modified= TRUE;
675     }else{
676       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
677     }
678   }
681   /*! \brief  Add given mail address to the list of alternate adresses ,
682     .          check if this mal address is used, skip adding in this case 
683    */ 
684   function addAlternate($address)
685   {
686     if(empty($address)) return;
687     if($this->acl_is_writeable("gosaMailAlternateAddress")){
688       $ldap= $this->config->get_ldap_link();
689       $address= strtolower($address);
691       /* Is this address already assigned in LDAP? */
692       $ldap->cd ($this->config->current['BASE']);
693       $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=$address)".
694           "(alias=$address)(gosaMailAlternateAddress=$address)))", array("uid"));
695       if ($ldap->count() > 0){
696         $attrs= $ldap->fetch ();
697         return ($attrs["uid"][0]);
698       }
699       if (!in_array($address, $this->gosaMailAlternateAddress)){
700         $this->gosaMailAlternateAddress[]= $address;
701         $this->is_modified= TRUE;
702       }
703       sort ($this->gosaMailAlternateAddress);
704       reset ($this->gosaMailAlternateAddress);
705       return ("");
706     }else{
707       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
708     }
709   }
712   /*! \brief  Removes the given mail address from the alternate addresses list 
713    */ 
714   function delAlternate($addresses)
715   {
716     if($this->acl_is_writeable("gosaMailAlternateAddress")){
717       $this->gosaMailAlternateAddress= array_remove_entries ($addresses,$this->gosaMailAlternateAddress);
718       $this->is_modified= TRUE;
719     }else{
720       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
721     }
722   }
725   /*! \brief  Prepare importet vacation string. \
726     .         Replace placeholder like %givenName a.s.o.
727     @param  string  Vacation string
728     @return string  Completed vacation string
729    */
730   private function prepare_vacation_template($contents)
731   {
732     /* Replace attributes */
733     $attrs = array();
734     $obj   = NULL;
735     if(isset($this->parent->by_object['user'])){
736       $attrs  = $this->parent->by_object['user']->attributes;
737       $obj    = $this->parent->by_object['user'];
738     }else{
739       $obj    = new user($this->config,$this->dn);
740       $attrs  = $obj->attributes;
741     }
742     if($obj){
743       foreach ($attrs as $val){
744         if(preg_match("/dateOfBirth/",$val)){
745           if($obj->use_dob){
746             $contents= preg_replace("/%$val/",date("Y-d-m",$obj->dateOfBirth),$contents);
747           }
748         }else {
749           $contents= preg_replace("/%$val/",
750               $obj->$val, $contents);
751         }
753         /* Replace vacation start and end time */
754         if(preg_match("/%start/",$contents)){
755           $contents = preg_replace("/%start/",date("d.m.Y",$this->gosaVacationStart),$contents);
756         }
757         if(preg_match("/%end/",$contents)){
758           $contents = preg_replace("/%end/",date("d.m.Y",$this->gosaVacationStop),$contents);
759         }
760       }
761     }
762     $contents = ltrim(preg_replace("/^DESC:.*$/m","",$contents),"\n ");
763     return($contents);
764   }
767   /*! \brief  Displays a dialog that allows mail address selection.
768    */ 
769   function display_forward_dialog()
770   {
771     restore_error_handler();
773     $smarty = get_smarty();
774     $ldap= $this->config->get_ldap_link();
776     /* Save data */
777     $mailfilter= session::get("mailfilter");
778     foreach( array("depselect", "muser", "regex") as $type){
779       if (isset($_POST[$type])){
780         $mailfilter[$type]= $_POST[$type];
781       }
782     }
783     if (isset($_GET['search'])){
784       $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
785       if ($s == "**"){
786         $s= "*";
787       }
788       $mailfilter['regex']= $s;
789     }
790     session::set("mailfilter", $mailfilter);
792     /* Get actual list */
793     $mailusers= array ();
794     if ($mailfilter['regex'] != '*' && $mailfilter['regex'] != ""){
795       $regex= $mailfilter['regex'];
796       $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
797     } else {
798       $filter= "";
799     }
800     if ($mailfilter['muser'] != ""){
801       $user= $mailfilter['muser'];
802       $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
803     }
805     /* Add already present people to the filter */
806     $exclude= "";
807     foreach ($this->gosaMailForwardingAddress as $mail){
808       $exclude.= "(mail=$mail)";
809     }
810     if ($exclude != ""){
811       $filter.= "(!(|$exclude))";
812     }
813     $res= get_list("(&(objectClass=gosaMailAccount)$filter)", "users", $mailfilter['depselect'],
814         array("sn", "mail", "givenName"), GL_SIZELIMIT | GL_SUBSEARCH);
815     $ldap->cd($mailfilter['depselect']);
816     $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
817     while ($attrs= $ldap->fetch()){
818       if(preg_match('/%/', $attrs['mail'][0])){
819         continue;
820       }
821       $name= $this->make_name($attrs);
822       $mailusers[$attrs['mail'][0]]= $name."&lt;".
823         $attrs['mail'][0]."&gt;";
824     }
825     natcasesort ($mailusers);
826     reset ($mailusers);
828     /* Show dialog */
829     $smarty->assign("search_image", get_template_path('images/lists/search.png'));
830     $smarty->assign("usearch_image", get_template_path('images/lists/search-user.png'));
831     $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
832     $smarty->assign("infoimage", get_template_path('images/info.png'));
833     $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
834     $smarty->assign("mailusers", $mailusers);
835     if (isset($_POST['depselect'])){
836       $smarty->assign("depselect", $_POST['depselect']);
837     }
838     $smarty->assign("deplist", $this->config->idepartments);
839     $smarty->assign("apply", apply_filter());
840     $smarty->assign("alphabet", generate_alphabet());
841     $smarty->assign("hint", print_sizelimit_warning());
842     foreach( array("depselect", "muser", "regex") as $type){
843       $smarty->assign("$type", $mailfilter[$type]);
844     }
845     $smarty->assign("hint", print_sizelimit_warning());
846     $display= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE, dirname(__FILE__)));
847     return ($display);
848   }
851   /*! \brief  Removes the mailAccount extension from ldap 
852    */  
853   function remove_from_parent()
854   {
855     /* Cancel if there's nothing to do here */
856     if (!$this->initially_was_account){
857       return;
858     }
860     /* If domain part was selectable, contruct mail address */
861     if($this->mailMethod->domainSelectionEnabled()){
862       $this->mail = $this->mail."@".$this->mailDomainPart;
863     }
865     /* Update sharedFolder dependencies. 
866        Open each shared folder and remove this account. 
867        Then Save the group to ensure that all necessary 
868         actions will be taken (imap acls updated aso.).
869      */
870     $ldap = $this->config->get_ldap_link();    
871     $ldap->cd($this->config->current['BASE']);
872     $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array("dn"));
873     while($attrs = $ldap->fetch()){
874       $grp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
875       if(isset($grp->by_object['mailgroup']) && isset($grp->by_object['group'])){
876         $grp->by_object['group']->removeUser($this->uid);
878         /* Do not save the complete group! This will quit the complete membership 
879          */
880         $grp->by_object['mailgroup']->save();
881       } 
882     }
884     /* Remove GOsa attributes */
885     plugin::remove_from_parent();
887     /* Zero arrays */
888     $this->attrs['gosaMailAlternateAddress'] = array();
889     $this->attrs['gosaMailForwardingAddress']= array();
892     $this->mailMethod->fixAttributesOnRemove();
893     $this->cleanup();
895     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
896     $ldap= $this->config->get_ldap_link();
897     $ldap->cd($this->dn);
898     $ldap->modify ($this->attrs);
900     /* Add "view" to logging class */
901     new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
902     if (!$ldap->success()){
903       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
904     }
905     
906     /* Let the mailMethod remove this mailbox, e.g. from imap and
907        update shared folder membership, ACL may need to be updated. 
908      */
909     if (!$this->is_template){
911       if(!$this->mailMethod->connect()){
912         msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"), 
913               $this->mailMethod->get_error()), ERROR_DIALOG);
914       }else{
915         if(!$this->mailMethod->deleteMailbox()){
916           msg_dialog::display(_("Mail error"), sprintf(_("Cannot remove mailbox: %s"), 
917                 $this->mailMethod->get_error()), ERROR_DIALOG);
918         }
919       }
920     }
921     $this->mailMethod->disconnect();
923     /* Optionally execute a command after we're done */
924     $this->handle_post_events("remove",array("uid" => $this->uid));
925   }
928   /*! \brief  Save the mailAccount settings to the ldap database.
929    */
930   function save()
931   {
932     $ldap= $this->config->get_ldap_link();
934     /* If domain part was selectable, contruct mail address */
935     if(!(!$this->mailMethod->isModifyableMail() && $this->initially_was_account)){
937       if($this->mailMethod->domainSelectionEnabled()){
938         $this->mail = $this->mail."@".$this->mailDomainPart;
939       }
941       /* Enforce lowercase mail address and trim whitespaces
942        */
943       $this->mail = trim(strtolower($this->mail));
944     }
947     /* Call parents save to prepare $this->attrs */
948     plugin::save();
950     /* Save arrays */
951     $this->attrs['gosaMailAlternateAddress'] = $this->gosaMailAlternateAddress;
952     $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
954     if(!$this->mailMethod->vacationRangeEnabled()){
955       $this->attrs['gosaVacationStart'] = $this->attrs['gosaVacationStop'] = array();
956     }elseif (!preg_match('/V/', $this->gosaMailDeliveryMode)){
957       unset($this->attrs['gosaVacationStart']);
958       unset($this->attrs['gosaVacationStop']);
959     }
961     /* Map method attributes */ 
962     $this->mailMethod->fixAttributesOnStore();
963     
964     /* Save data to LDAP */
965     $ldap->cd($this->dn);
966     $this->cleanup();
967     $ldap->modify ($this->attrs);
969     if (!$ldap->success()){
970       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
971     }
973     /* Log last action */
974     if($this->initially_was_account){
975       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
976     }else{
977       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
978     }
980     /* Only do IMAP actions if we are not a template */
981     if (!$this->is_template){
982       $this->mailMethod->connect();
983       if(!$this->mailMethod->is_connected()){
984         msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"), 
985               $this->mailMethod->get_error()), ERROR_DIALOG);
986       }else{
987         if(!$this->mailMethod->updateMailbox()){
988           msg_dialog::display(_("Mail error"), sprintf(_("Cannot update mailbox: %s"), 
989                 $this->mailMethod->get_error()), ERROR_DIALOG);
990         }
991         if(!$this->mailMethod->setQuota($this->gosaMailQuota)){
992           msg_dialog::display(_("Mail error"), sprintf(_("Cannot write quota settings: %s"), 
993                 $this->mailMethod->get_error()), ERROR_DIALOG);
994         }
996         if (!is_integer(strpos($this->gosaMailDeliveryMode, "C"))){
998           /* Do not write sieve settings if this account is new and 
999              doesn't seem to exist.
1000            */
1001           if(!$this->initially_was_account && !$this->mailMethod->account_exists()){
1002             @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,
1003                 "Skipping sieve settings, the account doesn't seem to be created already.</b>","");
1004           }else{
1005             if(!$this->mailMethod->saveSieveSettings()){
1006               msg_dialog::display(_("Mail error"), $this->mailMethod->get_error(), ERROR_DIALOG);
1007             }
1008           }
1009         }else{
1010          echo "Check sieve management here";
1011           @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, 
1012               "User uses an own sieve script, skipping sieve update.".$str."</b>","");
1013         }
1014       }
1015     }
1016     $this->mailMethod->disconnect();
1018     /* Update sharedFolder dependencies.
1019        Open each shared folder and remove this account.
1020        Then Save the group to ensure that all necessary
1021        actions will be taken (imap acls updated aso.).
1022      */
1023     if(!$this->initially_was_account){
1024       $ldap = $this->config->get_ldap_link();
1025       $ldap->cd($this->config->current['BASE']);
1026       $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array("dn"));
1027       while($attrs = $ldap->fetch()){
1028         $grp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
1029         if(isset($grp->by_object['mailgroup'])){
1030           /* Do not save the complete group! This will quit the complete membership
1031            */
1032           $grp->by_object['mailgroup']->save();
1033         }
1034       }
1035     }
1037     /* Optionally execute a command after we're done */
1038     if ($this->initially_was_account == $this->is_account){
1039       if ($this->is_modified){
1040         $this->handle_post_events("modify", array("uid" => $this->uid));
1041       }
1042     } else {
1043       $this->handle_post_events("add", array("uid" => $this->uid));
1044     }
1045   }
1048   /*! \brief  Check given values 
1049    */
1050   function check()
1051   {
1052     if(!$this->is_account){
1053       return(array());
1054     }
1056     $ldap= $this->config->get_ldap_link();
1058     /* Call common method to give check the hook */
1059     $message= plugin::check();
1061     if(empty($this->gosaMailServer)){
1062       $message[]= msgPool::noserver(_("Mail"));
1063     }
1065     /* Mail address checks */
1066     $mail = $this->mail;
1067     if(!(!$this->mailMethod->isModifyableMail() && $this->initially_was_account)){
1069       if($this->mailMethod->domainSelectionEnabled()){
1070         $mail.= "@".$this->mailDomainPart;
1071       }
1073       if (empty($mail)){
1074         $message[]= msgPool::required(_("Primary address"));
1075       }
1076       if ($this->is_template){
1077         if (!tests::is_email($mail, TRUE)){
1078           $message[]= msgPool::invalid(_("Mail address"),"","","%givenName.%sn@your-domain.com");
1079         }
1080       } else {
1081         if (!tests::is_email($mail)){
1082           $message[]= msgPool::invalid(_("Mail address"),"","","your-address@your-domain.com");
1083         }
1084       }
1086       /* Check if this mail address is already in use */
1087       $ldap->cd($this->config->current['BASE']);
1088       $filter = "(&(!(objectClass=gosaUserTemplate))(!(uid=".$this->uid."))".
1089         "(objectClass=gosaMailAccount)".
1090         "(|(mail=".$mail.")(alias=".$mail.")(gosaMailAlternateAddress=".$mail.")))";
1091       $ldap->search($filter,array("uid"));
1092       if ($ldap->count() != 0){
1093         $message[]= msgPool::duplicated(_("Mail address"));
1094       }
1095     }
1098     /* Check quota */
1099     if ($this->gosaMailQuota != '' && $this->acl_is_writeable("gosaMailQuota")){
1100       if (!is_numeric($this->gosaMailQuota)) {
1101         $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
1102       } else {
1103         $this->gosaMailQuota= (int) $this->gosaMailQuota;
1104       }
1105     }
1107     /* Check rejectsize for integer */
1108     if ($this->gosaMailMaxSize != '' && $this->acl_is_writeable("gosaMailMaxSize")){
1109       if (!is_numeric($this->gosaMailMaxSize)){
1110         $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
1111       } else {
1112         $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
1113       }
1114     }
1116     /* Need gosaMailMaxSize if use_mailsize_limit is checked */
1117     if (is_integer(strpos($this->gosaMailDeliveryMode, "R")) && $this->gosaMailMaxSize == ""){
1118       $message[]= msgPool::required(_("Mail reject size"));
1119     }
1121     if((preg_match("/S/", $this->gosaMailDeliveryMode))&&(empty($this->gosaSpamMailbox))) {
1122       $message[]= msgPool::required(_("Spam folder"));
1123     }
1125     if ($this->mailMethod->vacationRangeEnabled() 
1126         && preg_match('/V/', $this->gosaMailDeliveryMode) 
1127         && $this->gosaVacationStart > $this->gosaVacationStop){
1128       $message[]= msgPool::invalid(_("Vacation interval"));
1129     }
1130     return($message);
1131   }
1134   /*! \brief  Adapt from template, using 'dn' 
1135    */
1136   function adapt_from_template($dn, $skip= array())
1137   {
1138     plugin::adapt_from_template($dn, $skip);
1140     foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
1142       if (in_array($val, $skip)){
1143         continue;
1144       }
1146       $this->$val= array();
1147       if (isset($this->attrs["$val"]["count"])){
1148         for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
1149           $value= $this->attrs["$val"][$i];
1150           foreach (array("sn", "givenName", "uid") as $repl){
1151             if (preg_match("/%$repl/i", $value)){
1152               $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
1153             }
1154           }
1155           array_push($this->$val, strtolower(rewrite($value)));
1156         }
1157       }
1158     }
1159     $this->mail= strtolower(rewrite($this->mail));
1160   }
1163   /*! \brief  Creates the mail part for the copy & paste dialog 
1164    */ 
1165   function getCopyDialog()
1166   {
1167     if(!$this->is_account) return("");
1168     $smarty = get_smarty();
1169     $smarty->assign("mail",$this->mail);
1170     $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress);
1171     $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress);
1172     $str = $smarty->fetch(get_template_path("copypaste.tpl",TRUE, dirname(__FILE__)));
1174     $ret = array();
1175     $ret['status'] = "";
1176     $ret['string'] = $str;
1177     return($ret);
1178   }
1180     
1181   /*! \brief  save_object for copy&paste vars 
1182    */  
1183   function saveCopyDialog()
1184   {
1185     if(!$this->is_account) return;
1187     /* Execute to save mailAlternateAddress && gosaMailForwardingAddress */
1188     $this->execute();
1189     if(isset($_POST['mail'])){
1190       $this->mail = $_POST['mail'];
1191     }
1192   }
1194   
1195   /*! \brief  Prepare this account to be copied 
1196    */
1197   function PrepareForCopyPaste($source)
1198   {
1199     plugin::PrepareForCopyPaste($source);
1201     /* Reset alternate mail addresses */
1202     $this->gosaMailAlternateAddress = array();
1203   }
1206   /*! \brief  Prepare this class the be useable when editing multiple users at once 
1207    */
1208   function get_multi_edit_values()
1209   {
1210     $ret = plugin::get_multi_edit_values();
1211     if(in_array("gosaMailQuota",$this->multi_boxes)){
1212       $ret['gosaMailQuota'] = $this->gosaMailQuota;
1213     }
1214     $flag_add = $flag_remove = array();
1215     $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1216     $opts = array(
1217         "R"   => "use_mailsize_limit",
1218         "S"   => "use_spam_filter",
1219         "L"   => "only_local",
1220         "V"   => "use_vacation",
1221         "C"   => "own_script",
1222         "I"   => "drop_own_mails");
1223     foreach($opts as $flag => $post){
1224       if(in_array($post, $this->multi_boxes)){
1225         if(preg_match("/".$flag."/",$tmp)){
1226           $flag_add[] = $flag;
1227         }else{
1228           $flag_remove[] = $flag;
1229         }
1230       }
1231     }
1232     $ret['flag_add'] = $flag_add;
1233     $ret['flag_remove'] = $flag_remove;
1235     echo "1";
1236     if($this->mailMethod->vacationRangeEnabled()){
1237       echo "2";
1238       if(in_array("V",$flag_add)){
1239         $ret['gosaVacationStart'] =  $this->gosaVacationStart = $_POST['gosaVacationStart'];
1240         $ret['gosaVacationStop'] =  $this->gosaVacationStop = $_POST['gosaVacationStop'];
1241       }
1242     }
1243     return($ret);
1244   }
1247   /*! \brief  Check given input for multiple user edit 
1248    */
1249   function multiple_check()
1250   {
1251     $message = plugin::multiple_check();
1253     if(empty($this->gosaMailServer) && in_array("gosaMailServer",$this->multi_boxes)){
1254       $message[]= msgPool::noserver(_("Mail"));
1255     }
1257     /* Check quota */
1258     if ($this->gosaMailQuota != ''  && in_array("gosaMailQuota",$this->multi_boxes)){
1259       if (!is_numeric($this->gosaMailQuota)) {
1260         $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
1261       } else {
1262         $this->gosaMailQuota= (int) $this->gosaMailQuota;
1263       }
1264     }
1266     /* Check rejectsize for integer */
1267     if ($this->gosaMailMaxSize != '' && in_array("gosaMailMaxSize",$this->multi_boxes)){
1268       if (!is_numeric($this->gosaMailMaxSize)){
1269         $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
1270       } else {
1271         $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
1272       }
1273     }
1275     if(empty($this->gosaSpamMailbox) && in_array("gosaSpamMailbox",$this->multi_boxes)){
1276       $message[]= msgPool::required(_("Spam folder"));
1277     }
1279     if (  in_array("use_vacation",$this->multi_boxes) &&
1280         preg_match('/V/', $this->gosaMailDeliveryMode) && $this->gosaVacationStart > $this->gosaVacationStop){
1281       $message[]= msgPool::invalid(_("Vacation interval"));
1282     }
1283     return($message);
1284   }
1286   
1287   /*! \brief  ...
1288    */
1289   function set_multi_edit_values($values)
1290   {
1291     plugin::set_multi_edit_values($values);
1292     $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1293     if(isset($values['flag_add'])){
1294       foreach($values['flag_add'] as $flag){
1295         if(!preg_match("/".$flag."/",$tmp)){
1296           $tmp .= $flag;
1297         }
1298       }
1299     }
1300     if(isset($values['flag_remove'])){
1301       foreach($values['flag_remove'] as $flag){
1302         if(preg_match("/".$flag."/",$tmp)){
1303           $tmp = preg_replace("/".$flag."/","",$tmp);
1304         }
1305       }
1306     }
1307     $this->gosaMailDeliveryMode = "[".$tmp."]";
1309     /* Set vacation message and replace placeholder like %givenName
1310      */
1311     if(isset($values['gosaVacationMessage'])){
1312       $this->gosaVacationMessage = $this->prepare_vacation_template($values['gosaVacationMessage']);
1313     }
1314   }
1317   /*! \brief  Initialize plugin to be used as multiple edit class. 
1318    */
1319   function init_multiple_support($attrs,$all)
1320   {
1321     plugin::init_multiple_support($attrs,$all);
1322     if(isset($this->multi_attrs['gosaMailQuota'])){
1323       $this->gosaMailQuota = $this->multi_attrs['gosaMailQuota'];
1324     }
1325   }
1327  
1328   /*! \brief
1329    */
1330   function get_multi_init_values()
1331   {
1332     $attrs = plugin::get_multi_init_values();
1333     $attrs['gosaMailQuota'] = $this->gosaMailQuota;
1334     return($attrs);
1335   }
1338   /*! \brief  Display multiple edit dialog 
1339    */
1340   function multiple_execute()
1341   {
1342     return($this->execute());
1343   }
1345   
1346   /*! \brief  Save posts from multiple edit dialog 
1347    */
1348   function multiple_save_object()
1349   {
1350     plugin::multiple_save_object();
1352     $this->save_object();
1353     foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
1354       if(isset($_POST["use_".$attr])){
1355         $this->multi_boxes[] = $attr;
1356       }
1357     }
1358   }
1361   /*! \brief  Creates the user names for the add_local_forward dialog
1362    */
1363   function make_name($attrs)
1364   {
1365     $name= "";
1366     if (isset($attrs['sn'][0])){
1367       $name= $attrs['sn'][0];
1368     }
1369     if (isset($attrs['givenName'][0])){
1370       if ($name != ""){
1371         $name.= ", ".$attrs['givenName'][0];
1372       } else {
1373         $name.= $attrs['givenName'][0];
1374       }
1375     }
1376     if ($name != ""){
1377       $name.= " ";
1378     }
1380     return ($name);
1381   }
1384   function allow_remove()
1385   {
1386     $resason = "";
1387     if(!$this->mailMethod->allow_remove($reason)){
1388       return($reason);
1389     }
1390     return("");
1391   }
1395   /*! \brief  ACL settings 
1396    */
1397   static function plInfo()
1398   {
1399     return (array(
1400           "plShortName"     => _("Mail"),
1401           "plDescription"   => _("Mail settings"),
1402           "plSelfModify"    => TRUE,
1403           "plDepends"       => array("user"),                     // This plugin depends on
1404           "plPriority"      => 4,                                 // Position in tabs
1405           "plSection"     => array("personal" => _("My account")),
1406           "plCategory"    => array("users"),
1407           "plOptions"       => array(),
1409           "plProvidedAcls"  => array(
1410             "mail"                      =>  _("Mail address"),
1411             "gosaMailServer"            =>  _("Mail server"),
1412             "gosaMailQuota"             =>  _("Quota size"),
1414             "gosaMailDeliveryModeV"     =>  _("Add vacation information"),  // This is flag of gosaMailDeliveryMode
1415             "gosaVacationMessage"       =>  _("Vacation message"),
1417             "gosaMailDeliveryModeS"     =>  _("Use spam filter"),           // This is flag of gosaMailDeliveryMode
1418             "gosaSpamSortLevel"         =>  _("Spam level"),
1419             "gosaSpamMailbox"           =>  _("Spam mail box"),
1421             "sieveManagement"           =>  _("Sieve management"),
1423             "gosaMailDeliveryModeR"     =>  _("Reject due to mailsize"),    // This is flag of gosaMailDeliveryMode
1424             "gosaMailMaxSize"           =>  _("Mail max size"),
1426             "gosaMailForwardingAddress" =>  _("Forwarding address"),
1427             "gosaMailDeliveryModeL"     =>  _("Local delivery"),            // This is flag of gosaMailDeliveryMode
1428             "gosaMailDeliveryModeI"     =>  _("No delivery to own mailbox "),     // This is flag of gosaMailDeliveryMode
1429             "gosaMailAlternateAddress"  =>  _("Mail alternative addresses"),
1431             "gosaMailForwardingAddress" =>  _("Forwarding address"),
1432             "gosaMailDeliveryModeC"     =>  _("Use custom sieve script"))   // This is flag of gosaMailDeliveryMode
1433               ));
1434   }
1439 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1440 ?>