Code

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