Code

Updated table summary
[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  - remove_from_parent()
27  - save()
28  - check()
29  - adapt_from_template($dn, $skip= array())
30  - getCopyDialog()
31  - saveCopyDialog()
32  - PrepareForCopyPaste($source)
33  - get_multi_edit_values()
34  - multiple_check()
35  - set_multi_edit_values($values)
36  - init_multiple_support($attrs,$all)
37  - get_multi_init_values()
38  - multiple_execute()
39  - multiple_save_object()
40  - make_name($attrs)
41  - plInfo()
44  */
46 class mailAccount extends plugin
47 {
48   /* Definitions */
49   var $plHeadline     = "Mail";
50   var $plDescription  = "This does something";
51   var $view_logged    = FALSE;
52   var $is_account     = FALSE;
53   var $initially_was_account = FALSE;
55   /* GOsa mail attributes */
56   var $mail                               = "";
57   var $gosaVacationStart                  = "";
58   var $gosaVacationStop                   = "";
59   var $gosaMailAlternateAddress           = array();
60   var $gosaMailForwardingAddress          = array();
61   var $gosaMailDeliveryMode               = "[L        ]";
62   var $gosaMailServer                     = "";
63   var $gosaMailQuota                      = "";
64   var $gosaMailMaxSize                    = "";
65   var $gosaVacationMessage                = "";
66   var $gosaSpamSortLevel                  = "";
67   var $gosaSpamMailbox                    = "";
69   /* The methods defaults */
70   var $quotaUsage     = -1; // Means unknown
72   var $mailMethod      = NULL;
73   var $MailDomain      = "";
74   var $sieveManagementUsed = FALSE;
75   var $vacationTemplates = array();
76   var $sieve_management = NULL;
77   var $mailAddressSelect = FALSE;
78   var $initial_uid    = "";
79   var $mailDomainPart = "";
80   var $mailDomainParts = array();
81   var $MailBoxes = array("INBOX");
83   /* Used LDAP attributes && classes */
84   var $attributes= array(
85       "mail", "gosaMailServer","gosaMailQuota", "gosaMailMaxSize","gosaMailForwardingAddress",
86       "gosaMailDeliveryMode", "gosaSpamSortLevel", "gosaSpamMailbox","gosaMailAlternateAddress",
87       "gosaVacationStart","gosaVacationStop", "gosaVacationMessage", "gosaMailAlternateAddress", 
88       "gosaMailForwardingAddress");
89   var $objectclasses= array("gosaMailAccount");
91   var $multiple_support = TRUE;
93   var $uid = "";
94   var $cn  = "";
97   /*! \brief  Initialize the mailAccount 
98    */
99   function __construct (&$config, $dn= NULL)
100   {
101     plugin::plugin($config,$dn); 
103     /* Get attributes from parent object 
104      */
105     foreach(array("uid","cn") as $attr){
106       if(isset($this->parent->by_object['group']) && isset($this->parent->by_object['group']->$attr)){
107         $this->$attr = &$this->parent->by_object['group']->$attr;
108       }elseif(isset($this->attrs[$attr])){
109         $this->$attr = $this->attrs[$attr][0];
110       }
111     }
113     /* Intialize the used mailMethod
114      */
115     $tmp = new mailMethod($config,$this);
116     $this->mailMethod       = $tmp->get_method();
117     $this->mailMethod->fixAttributesOnLoad();
118     $this->mailDomainParts  = $this->mailMethod->getMailDomains();
119     $this->SpamLevels = $this->mailMethod->getSpamLevels();
121     /* Remember account status 
122      */
123     $this->initially_was_account = $this->is_account;
125     /* Initialize vacation settings, if enabled.
126      */   
127     if(empty($this->gosaVacationStart) && $this->mailMethod->vacationRangeEnabled()){
128       $this->gosaVacationStart = time();
129       $this->gosaVacationStop = time();
130     }
132     /* Read vacation templates 
133      */
134     $this->vacationTemplates = $this->get_vacation_templates();
136     /* Initialize configured values 
137      */ 
138     if($this->is_account){
140       if($this->mailMethod->connect() && $this->mailMethod->account_exists()){
142         /* Read quota */
143         $this->gosaMailQuota = $this->mailMethod->getQuota($this->gosaMailQuota);
144         $this->quotaUsage    = $this->mailMethod->getQuotaUsage($this->quotaUsage);
145         if($this->mailMethod->is_error()){
146           msg_dialog::display(_("Mail error"), sprintf(_("Cannot read quota settings: %s"), 
147                 $this->mailMethod->get_error()), ERROR_DIALOG);
148         }
149         
150         /* Read mailboxes */
151         $this->MailBoxes = $this->mailMethod->getMailboxList($this->MailBoxes);
152         if($this->mailMethod->is_error()){
153           msg_dialog::display(_("Mail error"), sprintf(_("Cannot get list of mailboxes: %s"), 
154                 $this->mailMethod->get_error()), ERROR_DIALOG);
155         }
156           
157       }elseif(!$this->mailMethod->is_connected()){
158         msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"), 
159               $this->mailMethod->get_error()), ERROR_DIALOG);
160       }elseif(!$this->mailMethod->account_exists()){
161         msg_dialog::display(_("Mail error"), sprintf(_("Mailbox '%s' doesn't exists on mail server: %s"), 
162               $this->mailMethod->get_account_id(),$this->gosaMailServer), ERROR_DIALOG);
163       }
165       /* If the doamin part is selectable, we have to split the mail address
166        */
167       if(!(!$this->mailMethod->isModifyableMail() && $this->is_account)){
168         if($this->mailMethod->domainSelectionEnabled()){
169           $this->mailDomainPart = preg_replace("/^[^@]*+@/","",$this->mail);
170           $this->mail = preg_replace("/@.*$/","\\1",$this->mail);
171           if(!in_array($this->mailDomainPart,$this->mailDomainParts)){
172             $this->mailDomainParts[] = $this->mailDomainPart;
173           }
174         }
175       }
177       /* Load attributes containing arrays */
178       foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
179         $this->$val= array();
180         if (isset($this->attrs["$val"]["count"])){
181           for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
182             array_push($this->$val, $this->attrs["$val"][$i]);
183           }
184         }
185       }
186     }
188     /* Intialize sieveManagement if necessary */
189     if($this->mailMethod->allowSieveManagement()){
190       $this->mailboxList = &$this->MailBoxes;
191       $this->sieve_management = new sieveManagement($this->config,$this->dn,$this,$this->mailMethod->getUAttrib());
192     }
194     /* Disconnect mailMethod. Connect on demand later. 
195      */
196     $this->mailMethod->disconnect();
198     /* Convert start/stop dates */
199     #TODO: use date format
200     $this->gosaVacationStart= date('d.m.Y', $this->gosaVacationStart);
201     $this->gosaVacationStop= date('d.m.Y', $this->gosaVacationStop);
202   }
205   function execute()
206   {
208     /* Call parent execute */
209     $display = plugin::execute();
211     /* Log view */
212     if($this->is_account && !$this->view_logged){
213       $this->view_logged = TRUE;
214       new log("view","users/".get_class($this),$this->dn);
215     }
218     /****************
219       Account status
220      ****************/
222     if(isset($_POST['modify_state'])){
223       if($this->is_account && $this->acl_is_removeable() && $this->mailMethod->accountRemoveAble()){
224         $this->is_account= FALSE;
225       }elseif(!$this->is_account && $this->acl_is_createable() && $this->mailMethod->accountCreateable()){
226         $this->is_account= TRUE;
227       }
228     }
229     if(!$this->multiple_support_active){
230       if (!$this->is_account && $this->parent === NULL){
231         $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\">&nbsp;<b>".
232           msgPool::noValidExtension(_("Mail"))."</b>";
233         $display.= back_to_main();
234         return ($display);
235       }
236       if ($this->parent !== NULL){
237         if ($this->is_account){ 
238           $reason = "";
239           if(!$this->mailMethod->accountRemoveable($reason)){
240             $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Mail")),$reason ,TRUE,TRUE);
241           }else{
242             $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Mail")),msgPool::featuresEnabled(_("Mail")));
243           }
244         } else {
245           $reason = "";
246           if(!$this->mailMethod->accountCreateable($reason)){
247             $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Mail")),$reason ,TRUE,TRUE);
248           }else{
249             $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Mail")),msgPool::featuresDisabled(_("Mail")));
250           }
251           return ($display);
252         }
253       }
254     }
256     /****************
257       Sieve Management Dialog
258      ****************/
259     if($this->mailMethod->allowSieveManagement()){
260       if(isset($_POST['sieveManagement'])
261           && preg_match("/C/",$this->gosaMailDeliveryMode)
262           && $this->acl_is_writeable("sieveManagement") 
263           && $this->mailMethod->allowSieveManagement()) {
264         $this->dialog = $this->sieve_management;
265       }
266       if(isset($_POST['sieve_cancel'])){
267         $this->dialog = FALSE;
268       }
269       if(isset($_POST['sieve_finish'])){
270         $this->sieve_management = $this->dialog;
271         $this->dialog = FALSE;
272       }
273       if(is_object($this->dialog)){
274         $this->dialog->save_object();
275         return($this->dialog->execute());
276       }
277     }
279     /****************
280       Forward addresses 
281      ****************/
283     if (isset($_POST['add_local_forwarder'])){
284       $this->mailAddressSelect=  new mailAddressSelect($this->config, get_userinfo());
285       $this->dialog= TRUE;
286     }
287     if (isset($_POST['mailAddressSelect_cancel'])){
288       $this->mailAddressSelect= FALSE;
289       $this->dialog= FALSE;
290     }
292     if (isset($_POST['mailAddressSelect_save']) && $this->mailAddressSelect instanceOf mailAddressSelect){
294       if($this->acl_is_writeable("gosaMailForwardingAddress")){
295         $list = $this->mailAddressSelect->save();
296         foreach ($list as $entry){
297           $val = $entry['mail'][0];
298           if (!in_array ($val, $this->gosaMailAlternateAddress) && $val != $this->mail){
299             $this->addForwarder($val);
300             $this->is_modified= TRUE;
301           }
302         }
303         $this->mailAddressSelect= FALSE;
304         $this->dialog= FALSE;
305       } else {
306         msg_dialog::display(_("Error"), _("Please select an entry!"), ERROR_DIALOG);
307       }
308     }
310     if($this->mailAddressSelect instanceOf mailAddressSelect){
311       $used  = array();
312       $used['mail'] = array_values($this->gosaMailAlternateAddress);  
313       $used['mail'] = array_merge($used['mail'], array_values($this->gosaMailForwardingAddress));  
314       $used['mail'][] = $this->mail;
316       // Build up blocklist
317       session::set('filterBlacklist', $used);
318       return($this->mailAddressSelect->execute());
319     }
321     if (isset($_POST['add_forwarder'])){
322       if ($_POST['forward_address'] != ""){
323         $address= $_POST['forward_address'];
324         $valid= FALSE;
325         if (!tests::is_email($address)){
326           if (!tests::is_email($address, TRUE)){
327             if ($this->is_template){
328               $valid= TRUE;
329             } else {
330               msg_dialog::display(_("Error"), msgPool::invalid(_("Mail address"),
331                     "","","your-address@your-domain.com"),ERROR_DIALOG);
332             }
333           }
334         } elseif ($address == $this->mail
335             || in_array($address, $this->gosaMailAlternateAddress)) {
336           msg_dialog::display(_("Error"),_("Cannot add primary address to the list of forwarders!") , ERROR_DIALOG);
337         } else {
338           $valid= TRUE;
339         }
340         if ($valid){
341           if($this->acl_is_writeable("gosaMailForwardingAddress")){
342             $this->addForwarder ($address);
343             $this->is_modified= TRUE;
344           }
345         }
346       }
347     }
348     if (isset($_POST['delete_forwarder'])){
349       $this->delForwarder ($_POST['forwarder_list']);
350     }
351     if ($this->mailAddressSelect instanceOf mailAddressSelect){
352     
353       return($this->mailAddressSelect->execute());
354     }
357     /****************
358       Alternate addresses 
359      ****************/
361     if (isset($_POST['add_alternate'])){
362       $valid= FALSE;
363       if (!tests::is_email($_POST['alternate_address'])){
364         if ($this->is_template){
365           if (!(tests::is_email($_POST['alternate_address'], TRUE))){
366             msg_dialog::display(_("Error"),msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com"),ERROR_DIALOG);
367           } else {
368             $valid= TRUE;
369           }
370         } else {
371           msg_dialog::display(_("Error"),msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com"),ERROR_DIALOG);
372         }
373       } else {
374         $valid= TRUE;
375       }
376       if ($valid && ($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
377         $ui= get_userinfo();
378         $addon= "";
379         if ($user[0] == "!") {
380           $addon= sprintf(_("Address is already in use by group '%s'."), mb_substr($user, 1));
381         } else {
382           $addon= sprintf(_("Address is already in use by user '%s'."), $user);
383         }
384         msg_dialog::display(_("Error"), msgPool::duplicated(_("Mail address"))."<br><br><i>".
385             "$addon</i>", ERROR_DIALOG);
386       }
387     }
388     if (isset($_POST['delete_alternate']) && isset($_POST['alternates_list'])){
389       $this->delAlternate ($_POST['alternates_list']);
390     }
392     /****************
393       SMARTY- Assign smarty variables 
394      ****************/
395     $smarty = get_smarty();
396     $smarty->assign("usePrototype", "true");
397     $smarty->assign("initially_was_account", $this->initially_was_account);
398     $smarty->assign("isModifyableMail"  , $this->mailMethod->isModifyableMail());
399     $smarty->assign("isModifyableServer", $this->mailMethod->isModifyableServer());
400     $smarty->assign("mailEqualsCN", $this->mailMethod->mailEqualsCN());
402     $tmp  = $this->plInfo();
403     foreach($tmp['plProvidedAcls'] as $name => $transl){
404       $smarty->assign("$name"."ACL", $this->getacl($name));
405     }
406     foreach($this->attributes as $attr){
407       $smarty->assign($attr,$this->$attr);
408     }
409     $smarty->assign("quotaEnabled", $this->mailMethod->quotaEnabled());
410     if($this->mailMethod->quotaEnabled()){
411       $smarty->assign("quotaUsage",   mailMethod::quota_to_image($this->quotaUsage,$this->gosaMailQuota));
412       $smarty->assign("gosaMailQuota",$this->gosaMailQuota);
413     }
414     $smarty->assign("domainSelectionEnabled", $this->mailMethod->domainSelectionEnabled());
415     $smarty->assign("MailDomains", $this->mailDomainParts);
416     $smarty->assign("MailDomain" , $this->mailDomainPart);
417     $smarty->assign("MailServers", $this->mailMethod->getMailServers());
418     $smarty->assign("allowSieveManagement", $this->mailMethod->allowSieveManagement());
419     $smarty->assign("own_script",  $this->sieveManagementUsed);
421     /* _Multiple users vars_ */
422     foreach($this->attributes as $attr){
423       $u_attr = "use_".$attr;
424       $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
425     }
426     foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
427       $u_attr = "use_".$attr;
428       $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
429     }
432     /****************
433       SMARTY- Assign flags 
434      ****************/
436     $types = array(
437         "V"=>"use_vacation",
438         "S"=>"use_spam_filter",
439         "R"=>"use_mailsize_limit",
440         "I"=>"drop_own_mails",
441         "C"=>"own_script");
442     foreach($types as $option => $varname){
443       if (preg_match("/".$option."/", $this->gosaMailDeliveryMode)) {
444         $smarty->assign($varname, "checked");
445       } else {
446         $smarty->assign($varname, "");
447       }
448     }
449     if (!preg_match("/L/", $this->gosaMailDeliveryMode)) {
450       $smarty->assign("only_local", "checked");
451     } else {
452       $smarty->assign("only_local", "");
453     }
456     /****************
457       Smarty- Vacation settings 
458      ****************/
459     $smarty->assign("rangeEnabled", FALSE);
460     $smarty->assign("template", "");
461     if (count($this->vacationTemplates)){
462       $smarty->assign("show_templates", "true");
463       $smarty->assign("vacationtemplates", $this->vacationTemplates);
464       if (isset($_POST['vacation_template'])){
465         $smarty->assign("template", $_POST['vacation_template']);
466       }
467     } else {
468       $smarty->assign("show_templates", "false");
469     }
471     /* Vacation range assigments
472      */
473     if($this->mailMethod->vacationRangeEnabled()){
474       $smarty->assign("rangeEnabled", TRUE);
475     }
477     /* fill filter settings 
478      */
479     $smarty->assign("spamlevel", $this->SpamLevels);
480     $smarty->assign("spambox"  , $this->MailBoxes);
482     $smarty->assign("multiple_support",$this->multiple_support_active);  
483     return($display.$smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
484   }
488   /* Save data to object */
489   function save_object()
490   {
491     if (isset($_POST['mailTab'])){
493       /* Save ldap attributes */
494       $mail   = $this->mail;
495       $server = $this->gosaMailServer;
496       plugin::save_object();
498       if(!$this->mailMethod->isModifyableServer() && $this->initially_was_account){
499         $this->gosaMailServer = $server;
500       }
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;
582         /* Get start/stop values for vacation scope of application
583          */
584         if($this->mailMethod->vacationRangeEnabled()){
585           if($this->acl_is_writeable("gosaVacationMessage") && preg_match("/V/",$this->gosaMailDeliveryMode)){
586             if(isset($_POST['gosaVacationStart'])){
587               $this->gosaVacationStart = $_POST['gosaVacationStart'];
588             }
589             if(isset($_POST['gosaVacationStop'])){
590               $this->gosaVacationStop = $_POST['gosaVacationStop'];
591             }
592           }
593         }
594       }
595     }
596   }
599   /*! \brief  Parse vacation templates and build up an array
600     containing 'filename' => 'description'. 
601     Used to fill vacation dropdown box.
602     @return Array   All useable vacation templates.
603    */ 
604   function get_vacation_templates()
605   {
606     $vct = array();
607     if ($this->config->get_cfg_value("vacationTemplateDirectory") != ""){
608       $dir= $this->config->get_cfg_value("vacationTemplateDirectory");
609       if (is_dir($dir) && is_readable($dir)){
610         $dh = opendir($dir);
611         while($file = readdir($dh)){
612           $description= "";
613           if (is_file($dir."/".$file)){
614             $fh = fopen($dir."/".$file, "r");
615             $line= fgets($fh, 256);
616             if (!preg_match('/^DESC:/', $line)){
617               msg_dialog::display(_("Configuration error"), sprintf(_("No DESC tag in vacation template '%s'!"), $file), ERROR_DIALOG);
618             }else{
619               $description= trim(preg_replace('/^DESC:\s*/', '', $line));
620             }
621             fclose ($fh);
622           }
623           if ($description != ""){
624             $vct["$dir/$file"]= $description;
625           }
626         }
627         closedir($dh);
628       }
629     }
630     return($vct); 
631   }
634   /*! \brief  Adds the given mail address to the list of mail forwarders 
635    */ 
636   function addForwarder($address)
637   {
638     if(empty($address)) return;
639     if($this->acl_is_writeable("gosaMailForwardingAddress")){
640       $this->gosaMailForwardingAddress[]= $address;
641       $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
642       sort ($this->gosaMailForwardingAddress);
643       reset ($this->gosaMailForwardingAddress);
644       $this->is_modified= TRUE;
645     }else{
646       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
647     }
648   }
651   /*! \brief  Removes the given mail address from the list of mail forwarders 
652    */ 
653   function delForwarder($addresses)
654   {
655     if($this->acl_is_writeable("gosaMailForwardingAddress")){
656       $this->gosaMailForwardingAddress= array_remove_entries ($addresses, $this->gosaMailForwardingAddress);
657       $this->is_modified= TRUE;
658     }else{
659       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
660     }
661   }
664   /*! \brief  Add given mail address to the list of alternate adresses ,
665     .          check if this mal address is used, skip adding in this case 
666    */ 
667   function addAlternate($address)
668   {
669     if(empty($address)) return;
670     if($this->acl_is_writeable("gosaMailAlternateAddress")){
671       $ldap= $this->config->get_ldap_link();
672       $address= strtolower($address);
674       /* Is this address already assigned in LDAP? */
675       $ldap->cd ($this->config->current['BASE']);
676       $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=$address)".
677           "(alias=$address)(gosaMailAlternateAddress=$address)))", array("uid", "cn"));
678       if ($ldap->count() > 0){
679         $attrs= $ldap->fetch ();
680         if (!isset($attrs["uid"])) {
681           return ("!".$attrs["cn"][0]);
682         }
683         return ($attrs["uid"][0]);
684       }
685       if (!in_array($address, $this->gosaMailAlternateAddress)){
686         $this->gosaMailAlternateAddress[]= $address;
687         $this->is_modified= TRUE;
688       }
689       sort ($this->gosaMailAlternateAddress);
690       reset ($this->gosaMailAlternateAddress);
691       return ("");
692     }else{
693       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
694     }
695   }
698   /*! \brief  Removes the given mail address from the alternate addresses list 
699    */ 
700   function delAlternate($addresses)
701   {
702     if($this->acl_is_writeable("gosaMailAlternateAddress")){
703       $this->gosaMailAlternateAddress= array_remove_entries ($addresses,$this->gosaMailAlternateAddress);
704       $this->is_modified= TRUE;
705     }else{
706       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
707     }
708   }
711   /*! \brief  Prepare importet vacation string. \
712     .         Replace placeholder like %givenName a.s.o.
713     @param  string  Vacation string
714     @return string  Completed vacation string
715    */
716   private function prepare_vacation_template($contents)
717   {
718     /* Replace attributes */
719     $attrs = array();
720     $obj   = NULL;
721     if(isset($this->parent->by_object['user'])){
722       $attrs  = $this->parent->by_object['user']->attributes;
723       $obj    = $this->parent->by_object['user'];
724     }else{
725       $obj    = new user($this->config,$this->dn);
726       $attrs  = $obj->attributes;
727     }
728     if($obj){
730       /* Replace vacation start and end time */
731       if($this->mailMethod->vacationRangeEnabled()){
732         if(preg_match("/%start/",$contents)){
733           $contents = preg_replace("/%start/",$this->gosaVacationStart,$contents);
734         }
735         if(preg_match("/%end/",$contents)){
736           $contents = preg_replace("/%end/",$this->gosaVacationStop,$contents);
737         }
738       }else{
739         if(preg_match("/%start/",$contents)){
740           $contents = preg_replace("/%start/", _("unknown"),$contents);
741         }
742         if(preg_match("/%end/",$contents)){
743           $contents = preg_replace("/%end/", _("unknown"), $contents);
744         }
745       }
747       foreach ($attrs as $val){
749         // We can only replace strings here
750         if(!is_string($obj->$val)) continue;
752         if(preg_match("/dateOfBirth/",$val)){
753           if($obj->use_dob){
754             $contents= preg_replace("/%$val/",date("Y-d-m",$obj->dateOfBirth),$contents);
755           }
756         }else {
757           $contents= preg_replace("/%$val/",
758               $obj->$val, $contents);
759         }
761       }
762     }
763     $contents = ltrim(preg_replace("/^DESC:.*$/m","",$contents),"\n ");
764     return($contents);
765   }
768   /*! \brief  Removes the mailAccount extension from ldap 
769    */  
770   function remove_from_parent()
771   {
772     /* Cancel if there's nothing to do here */
773     if (!$this->initially_was_account){
774       return;
775     }
777     /* If domain part was selectable, contruct mail address */
778     if($this->mailMethod->domainSelectionEnabled()){
779       $this->mail = $this->mail."@".$this->mailDomainPart;
780     }
782     /* Update sharedFolder dependencies. 
783        Open each shared folder and remove this account. 
784        Then Save the group to ensure that all necessary 
785         actions will be taken (imap acls updated aso.).
786      */
787     $ldap = $this->config->get_ldap_link();    
788     $ldap->cd($this->config->current['BASE']);
789     $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array("dn"));
790     while($attrs = $ldap->fetch()){
791       $grp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
792       if(isset($grp->by_object['mailgroup']) && isset($grp->by_object['group'])){
793         $grp->by_object['group']->removeUser($this->uid);
795         /* Do not save the complete group! This will quit the complete membership 
796          */
797         $grp->by_object['mailgroup']->save();
798       } 
799     }
801     /* Remove GOsa attributes */
802     plugin::remove_from_parent();
804     /* Zero arrays */
805     $this->attrs['gosaMailAlternateAddress'] = array();
806     $this->attrs['gosaMailForwardingAddress']= array();
809     $this->mailMethod->fixAttributesOnRemove();
810     $this->cleanup();
812     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
813     $ldap= $this->config->get_ldap_link();
814     $ldap->cd($this->dn);
815     $ldap->modify ($this->attrs);
817     /* Add "view" to logging class */
818     new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
819     if (!$ldap->success()){
820       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
821     }
822     
823     /* Let the mailMethod remove this mailbox, e.g. from imap and
824        update shared folder membership, ACL may need to be updated. 
825      */
826     if (!$this->is_template){
828       if(!$this->mailMethod->connect()){
829         msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"), 
830               $this->mailMethod->get_error()), ERROR_DIALOG);
831       }else{
832         if(!$this->mailMethod->deleteMailbox()){
833           msg_dialog::display(_("Mail error"), sprintf(_("Cannot remove mailbox: %s"), 
834                 $this->mailMethod->get_error()), ERROR_DIALOG);
835         }
836       }
837     }
838     $this->mailMethod->disconnect();
840     /* Optionally execute a command after we're done */
841     $this->handle_post_events("remove",array("uid" => $this->uid));
842   }
845   /*! \brief  Save the mailAccount settings to the ldap database.
846    */
847   function save()
848   {
849     $ldap= $this->config->get_ldap_link();
851     /* If domain part was selectable, contruct mail address */
852     if(!(!$this->mailMethod->isModifyableMail() && $this->initially_was_account)){
854       if($this->mailMethod->domainSelectionEnabled()){
855         $this->mail = $this->mail."@".$this->mailDomainPart;
856       }
858       /* Enforce lowercase mail address and trim whitespaces
859        */
860       $this->mail = trim(strtolower($this->mail));
861     }
864     /* Call parents save to prepare $this->attrs */
865     plugin::save();
867     /* Save arrays */
868     $this->attrs['gosaMailAlternateAddress'] = $this->gosaMailAlternateAddress;
869     $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
871     if(!$this->mailMethod->vacationRangeEnabled()){
872       $this->attrs['gosaVacationStart'] = $this->attrs['gosaVacationStop'] = array();
873     }elseif (!preg_match('/V/', $this->gosaMailDeliveryMode)){
874       unset($this->attrs['gosaVacationStart']);
875       unset($this->attrs['gosaVacationStop']);
876     } else {
877       /* Adapt values to be timestamps */
878       list($day, $month, $year)= explode('.', $this->gosaVacationStart);
879       $this->attrs['gosaVacationStart']= mktime(0,0,0,$month, $day, $year);
880       list($day, $month, $year)= explode('.', $this->gosaVacationStop);
881       $this->attrs['gosaVacationStop']= mktime(0,0,0,$month, $day, $year);
882     }
884     /* Map method attributes */ 
885     $this->mailMethod->fixAttributesOnStore();
886     
887     /* Save data to LDAP */
888     $ldap->cd($this->dn);
889     $this->cleanup();
890     $ldap->modify ($this->attrs);
892     if (!$ldap->success()){
893       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
894     }
896     /* Log last action */
897     if($this->initially_was_account){
898       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
899     }else{
900       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
901     }
903     /* Only do IMAP actions if we are not a template */
904     if (!$this->is_template){
905       $this->mailMethod->connect();
906       if(!$this->mailMethod->is_connected()){
907         msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"), 
908               $this->mailMethod->get_error()), ERROR_DIALOG);
909       }else{
910         if(!$this->mailMethod->updateMailbox()){
911           msg_dialog::display(_("Mail error"), sprintf(_("Cannot update mailbox: %s"), 
912                 $this->mailMethod->get_error()), ERROR_DIALOG);
913         }
914         if(!$this->mailMethod->setQuota($this->gosaMailQuota)){
915           msg_dialog::display(_("Mail error"), sprintf(_("Cannot write quota settings: %s"), 
916                 $this->mailMethod->get_error()), ERROR_DIALOG);
917         }
919         if (!is_integer(strpos($this->gosaMailDeliveryMode, "C"))){
921           /* Do not write sieve settings if this account is new and 
922              doesn't seem to exist.
923            */
924           if(!$this->initially_was_account && !$this->mailMethod->account_exists()){
925             @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,
926                 "Skipping sieve settings, the account doesn't seem to be created already.</b>","");
927           }else{
928             if(!$this->mailMethod->saveSieveSettings()){
929               msg_dialog::display(_("Mail error saving sieve settings"), $this->mailMethod->get_error(), ERROR_DIALOG);
930             }
931           }
932         }else{
933           if ($this->sieve_management) {
934             @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, 
935                 "User uses an own sieve script, skipping sieve update.".$str."</b>","");
936             $this->sieve_management->save();
937           }
938         }
939       }
940     }
941     $this->mailMethod->disconnect();
943     /* Update sharedFolder dependencies.
944        Open each shared folder and remove this account.
945        Then Save the group to ensure that all necessary
946        actions will be taken (imap acls updated aso.).
947      */
948     if(!$this->initially_was_account){
949       $ldap = $this->config->get_ldap_link();
950       $ldap->cd($this->config->current['BASE']);
951       $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array("dn"));
952       while($attrs = $ldap->fetch()){
953         $grp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
954         if(isset($grp->by_object['mailgroup'])){
955           /* Do not save the complete group! This will quit the complete membership
956            */
957           $grp->by_object['mailgroup']->save();
958         }
959       }
960     }
962     /* Optionally execute a command after we're done */
963     if ($this->initially_was_account == $this->is_account){
964       if ($this->is_modified){
965         $this->handle_post_events("modify", array("uid" => $this->uid));
966       }
967     } else {
968       $this->handle_post_events("add", array("uid" => $this->uid));
969     }
970   }
973   /*! \brief  Check given values 
974    */
975   function check()
976   {
977     if(!$this->is_account){
978       return(array());
979     }
981     $ldap= $this->config->get_ldap_link();
983     /* Call common method to give check the hook */
984     $message= plugin::check();
986     if(empty($this->gosaMailServer)){
987       $message[]= msgPool::noserver(_("Mail"));
988     }
990     /* Mail address checks */
991     $mail = $this->mail;
992     if(!(!$this->mailMethod->isModifyableMail() && $this->initially_was_account)){
994       if($this->mailMethod->domainSelectionEnabled()){
995         $mail.= "@".$this->mailDomainPart;
996       }
998       if (empty($mail)){
999         $message[]= msgPool::required(_("Primary address"));
1000       }
1001       if ($this->is_template){
1002         if (!tests::is_email($mail, TRUE)){
1003           $message[]= msgPool::invalid(_("Mail address"),"","","%givenName.%sn@your-domain.com");
1004         }
1005       } else {
1006         if (!tests::is_email($mail)){
1007           $message[]= msgPool::invalid(_("Mail address"),"","","your-address@your-domain.com");
1008         }
1009       }
1011       /* Check if this mail address is already in use */
1012       $ldap->cd($this->config->current['BASE']);
1013       $filter = "(&(!(objectClass=gosaUserTemplate))(!(uid=".$this->uid."))".
1014         "(objectClass=gosaMailAccount)".
1015         "(|(mail=".$mail.")(alias=".$mail.")(gosaMailAlternateAddress=".$mail.")))";
1016       $ldap->search($filter,array("uid", "cn"));
1017       if ($ldap->count() != 0){
1018         $entry= $ldap->fetch();
1019         $addon= "";
1020         if (!isset($entry['uid'])) {
1021            $addon= sprintf(_("Address is already in use by group '%s'."), $entry['cn'][0]);
1022         } else {
1023            $addon= sprintf(_("Address is already in use by user '%s'."), $entry['uid'][0]);
1024         }
1025         $message[]= msgPool::duplicated(_("Mail address"))."<br><br><i>$addon</i>";
1026       }
1027     }
1030     /* Check quota */
1031     if ($this->gosaMailQuota != '' && $this->acl_is_writeable("gosaMailQuota")){
1032       if (!is_numeric($this->gosaMailQuota)) {
1033         $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
1034       } else {
1035         $this->gosaMailQuota= (int) $this->gosaMailQuota;
1036       }
1037     }
1039     /* Check rejectsize for integer */
1040     if ($this->gosaMailMaxSize != '' && $this->acl_is_writeable("gosaMailMaxSize")){
1041       if (!is_numeric($this->gosaMailMaxSize)){
1042         $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
1043       } else {
1044         $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
1045       }
1046     }
1048     /* Need gosaMailMaxSize if use_mailsize_limit is checked */
1049     if (is_integer(strpos($this->gosaMailDeliveryMode, "R")) && $this->gosaMailMaxSize == ""){
1050       $message[]= msgPool::required(_("Mail reject size"));
1051     }
1053     if((preg_match("/S/", $this->gosaMailDeliveryMode))&&(empty($this->gosaSpamMailbox))) {
1054       $message[]= msgPool::required(_("Spam folder"));
1055     }
1057     if ($this->mailMethod->vacationRangeEnabled() && preg_match('/V/', $this->gosaMailDeliveryMode)){ 
1059       /* Check date strings */
1060       $state= true;
1061       if ($this->gosaVacationStart == "" || !tests::is_date($this->gosaVacationStart)) {
1062         $message[]= msgPool::invalid(_("from"),$this->gosaVacationStart);
1063         $state= false;
1064       }
1065       if ($this->gosaVacationStart == "" || !tests::is_date($this->gosaVacationStop)) {
1066         $message[]= msgPool::invalid(_("to"),$this->gosaVacationStop);
1067         $state= false;
1068       }
1070       #TODO: take care of date format
1071       if ($state) {
1072         list($day, $month, $year)= explode('.', $this->gosaVacationStart);
1073         $start= mktime(0,0,0,$month, $day, $year);
1074         list($day, $month, $year)= explode('.', $this->gosaVacationStop);
1075         $stop= mktime(0,0,0,$month, $day, $year);
1076         if($start > $stop){
1077           $message[]= msgPool::invalid(_("Vacation interval"));
1078         }
1079       }
1080     }
1081     return($message);
1082   }
1085   /*! \brief  Adapt from template, using 'dn' 
1086    */
1087   function adapt_from_template($dn, $skip= array())
1088   {
1089     plugin::adapt_from_template($dn, $skip);
1091     foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
1093       if (in_array($val, $skip)){
1094         continue;
1095       }
1097       $this->$val= array();
1098       if (isset($this->attrs["$val"]["count"])){
1099         for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
1100           $value= $this->attrs["$val"][$i];
1101           foreach (array("sn", "givenName", "uid") as $repl){
1102             if (preg_match("/%$repl/i", $value)){
1103               $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
1104             }
1105           }
1106           array_push($this->$val, strtolower(rewrite($value)));
1107         }
1108       }
1109     }
1110     $this->mail= strtolower(rewrite($this->mail));
1112     // Fix mail address when using templates
1113     if($this->is_account && $this->mailMethod->domainSelectionEnabled()){
1114       $this->mailDomainPart = preg_replace("/^[^@]*+@/","",$this->mail);
1115       $this->mail = preg_replace("/@.*$/","\\1",$this->mail);
1116       if(!in_array($this->mailDomainPart,$this->mailDomainParts)){
1117         $this->mailDomainParts[] = $this->mailDomainPart;
1118       }
1119     }
1120   }
1123   /*! \brief  Creates the mail part for the copy & paste dialog 
1124    */ 
1125   function getCopyDialog()
1126   {
1127     if(!$this->is_account) return("");
1128     $smarty = get_smarty();
1129     $smarty->assign("mail",$this->mail);
1130     $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress);
1131     $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress);
1132     $str = $smarty->fetch(get_template_path("copypaste.tpl",TRUE, dirname(__FILE__)));
1134     $ret = array();
1135     $ret['status'] = "";
1136     $ret['string'] = $str;
1137     return($ret);
1138   }
1140     
1141   /*! \brief  save_object for copy&paste vars 
1142    */  
1143   function saveCopyDialog()
1144   {
1145     if(!$this->is_account) return;
1147     /* Execute to save mailAlternateAddress && gosaMailForwardingAddress */
1148     $this->execute();
1149     if(isset($_POST['mail'])){
1150       $this->mail = $_POST['mail'];
1151     }
1152   }
1154   
1155   /*! \brief  Prepare this account to be copied 
1156    */
1157   function PrepareForCopyPaste($source)
1158   {
1159     plugin::PrepareForCopyPaste($source);
1161     /* Reset alternate mail addresses */
1162     $this->gosaMailAlternateAddress = array();
1163   }
1166   /*! \brief  Prepare this class the be useable when editing multiple users at once 
1167    */
1168   function get_multi_edit_values()
1169   {
1170     $ret = plugin::get_multi_edit_values();
1171     if(in_array("gosaMailQuota",$this->multi_boxes)){
1172       $ret['gosaMailQuota'] = $this->gosaMailQuota;
1173     }
1174     $flag_add = $flag_remove = array();
1175     $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1176     $opts = array(
1177         "R"   => "use_mailsize_limit",
1178         "S"   => "use_spam_filter",
1179         "L"   => "only_local",
1180         "V"   => "use_vacation",
1181         "C"   => "own_script",
1182         "I"   => "drop_own_mails");
1183     foreach($opts as $flag => $post){
1184       if(in_array($post, $this->multi_boxes)){
1185         if(preg_match("/".$flag."/",$tmp)){
1186           $flag_add[] = $flag;
1187         }else{
1188           $flag_remove[] = $flag;
1189         }
1190       }
1191     }
1192     $ret['flag_add'] = $flag_add;
1193     $ret['flag_remove'] = $flag_remove;
1195     if($this->mailMethod->vacationRangeEnabled()){
1196       if(in_array("V",$flag_add)){
1197         $ret['gosaVacationStart'] =  $this->gosaVacationStart = $_POST['gosaVacationStart'];
1198         $ret['gosaVacationStop'] =  $this->gosaVacationStop = $_POST['gosaVacationStop'];
1199       }
1200     }
1201     return($ret);
1202   }
1205   /*! \brief  Check given input for multiple user edit 
1206    */
1207   function multiple_check()
1208   {
1209     $message = plugin::multiple_check();
1211     if(empty($this->gosaMailServer) && in_array("gosaMailServer",$this->multi_boxes)){
1212       $message[]= msgPool::noserver(_("Mail"));
1213     }
1215     /* Check quota */
1216     if ($this->gosaMailQuota != ''  && in_array("gosaMailQuota",$this->multi_boxes)){
1217       if (!is_numeric($this->gosaMailQuota)) {
1218         $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
1219       } else {
1220         $this->gosaMailQuota= (int) $this->gosaMailQuota;
1221       }
1222     }
1224     /* Check rejectsize for integer */
1225     if ($this->gosaMailMaxSize != '' && in_array("gosaMailMaxSize",$this->multi_boxes)){
1226       if (!is_numeric($this->gosaMailMaxSize)){
1227         $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
1228       } else {
1229         $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
1230       }
1231     }
1233     if(empty($this->gosaSpamMailbox) && in_array("gosaSpamMailbox",$this->multi_boxes)){
1234       $message[]= msgPool::required(_("Spam folder"));
1235     }
1237     if ($this->mailMethod->vacationRangeEnabled() && preg_match('/V/', $this->gosaMailDeliveryMode)){ 
1239       /* Check date strings */
1240       $state= true;
1241       if ($this->gosaVacationStart == "" || !tests::is_date($this->gosaVacationStart)) {
1242         $message[]= msgPool::invalid(_("from"),$this->gosaVacationStart);
1243         $state= false;
1244       }
1245       if ($this->gosaVacationStart == "" || !tests::is_date($this->gosaVacationStop)) {
1246         $message[]= msgPool::invalid(_("to"),$this->gosaVacationStop);
1247         $state= false;
1248       }
1250       #TODO: take care of date format
1251       if ($state) {
1252         list($day, $month, $year)= explode('.', $this->gosaVacationStart);
1253         $start= mktime(0,0,0,$month, $day, $year);
1254         list($day, $month, $year)= explode('.', $this->gosaVacationStop);
1255         $stop= mktime(0,0,0,$month, $day, $year);
1256         if($start > $stop){
1257           $message[]= msgPool::invalid(_("Vacation interval"));
1258         }
1259       }
1260     }
1261     return($message);
1262   }
1264   
1265   /*! \brief  ...
1266    */
1267   function set_multi_edit_values($values)
1268   {
1269     plugin::set_multi_edit_values($values);
1270     $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1271     if(isset($values['flag_add'])){
1272       foreach($values['flag_add'] as $flag){
1273         if(!preg_match("/".$flag."/",$tmp)){
1274           $tmp .= $flag;
1275         }
1276       }
1277     }
1278     if(isset($values['flag_remove'])){
1279       foreach($values['flag_remove'] as $flag){
1280         if(preg_match("/".$flag."/",$tmp)){
1281           $tmp = preg_replace("/".$flag."/","",$tmp);
1282         }
1283       }
1284     }
1285     $this->gosaMailDeliveryMode = "[".$tmp."]";
1287     /* Set vacation message and replace placeholder like %givenName
1288      */
1289     if(isset($values['gosaVacationMessage'])){
1290       $this->gosaVacationMessage = $this->prepare_vacation_template($values['gosaVacationMessage']);
1291     }
1292   }
1295   /*! \brief  Initialize plugin to be used as multiple edit class. 
1296    */
1297   function init_multiple_support($attrs,$all)
1298   {
1299     plugin::init_multiple_support($attrs,$all);
1300     if(isset($this->multi_attrs['gosaMailQuota'])){
1301       $this->gosaMailQuota = $this->multi_attrs['gosaMailQuota'];
1302     }
1303   }
1305  
1306   /*! \brief
1307    */
1308   function get_multi_init_values()
1309   {
1310     $attrs = plugin::get_multi_init_values();
1311     $attrs['gosaMailQuota'] = $this->gosaMailQuota;
1312     return($attrs);
1313   }
1316   /*! \brief  Display multiple edit dialog 
1317    */
1318   function multiple_execute()
1319   {
1320     return($this->execute());
1321   }
1323   
1324   /*! \brief  Save posts from multiple edit dialog 
1325    */
1326   function multiple_save_object()
1327   {
1328     plugin::multiple_save_object();
1330     $this->save_object();
1331     foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
1332       if(isset($_POST["use_".$attr])){
1333         $this->multi_boxes[] = $attr;
1334       }
1335     }
1336   }
1339   /*! \brief  Creates the user names for the add_local_forward dialog
1340    */
1341   function make_name($attrs)
1342   {
1343     $name= "";
1344     if (isset($attrs['sn'][0])){
1345       $name= $attrs['sn'][0];
1346     }
1347     if (isset($attrs['givenName'][0])){
1348       if ($name != ""){
1349         $name.= ", ".$attrs['givenName'][0];
1350       } else {
1351         $name.= $attrs['givenName'][0];
1352       }
1353     }
1354     if ($name != ""){
1355       $name.= " ";
1356     }
1358     return ($name);
1359   }
1362   function allow_remove()
1363   {
1364     $resason = "";
1365     if(!$this->mailMethod->allow_remove($reason)){
1366       return($reason);
1367     }
1368     return("");
1369   }
1373   /*! \brief  ACL settings 
1374    */
1375   static function plInfo()
1376   {
1377     return (array(
1378           "plShortName"     => _("Mail"),
1379           "plDescription"   => _("Mail settings"),
1380           "plSelfModify"    => TRUE,
1381           "plDepends"       => array("user"),                     // This plugin depends on
1382           "plPriority"      => 4,                                 // Position in tabs
1383           "plSection"     => array("personal" => _("My account")),
1384           "plCategory"    => array("users"),
1385           "plOptions"       => array(),
1387           "plProvidedAcls"  => array(
1388             "mail"                      =>  _("Mail address"),
1389             "gosaMailServer"            =>  _("Mail server"),
1390             "gosaMailQuota"             =>  _("Quota size"),
1392             "gosaMailDeliveryModeV"     =>  _("Add vacation information"),  // This is flag of gosaMailDeliveryMode
1393             "gosaVacationMessage"       =>  _("Vacation message"),
1395             "gosaMailDeliveryModeS"     =>  _("Use spam filter"),           // This is flag of gosaMailDeliveryMode
1396             "gosaSpamSortLevel"         =>  _("Spam level"),
1397             "gosaSpamMailbox"           =>  _("Spam mail box"),
1399             "sieveManagement"           =>  _("Sieve management"),
1401             "gosaMailDeliveryModeR"     =>  _("Reject due to mailsize"),    // This is flag of gosaMailDeliveryMode
1402             "gosaMailMaxSize"           =>  _("Mail max size"),
1404             "gosaMailForwardingAddress" =>  _("Forwarding address"),
1405             "gosaMailDeliveryModeL"     =>  _("Local delivery"),            // This is flag of gosaMailDeliveryMode
1406             "gosaMailDeliveryModeI"     =>  _("No delivery to own mailbox "),     // This is flag of gosaMailDeliveryMode
1407             "gosaMailAlternateAddress"  =>  _("Mail alternative addresses"),
1409             "gosaMailForwardingAddress" =>  _("Forwarding address"),
1410             "gosaMailDeliveryModeC"     =>  _("Use custom sieve script"))   // This is flag of gosaMailDeliveryMode
1411               ));
1412   }
1417 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1418 ?>