Code

Fixed problem with vacation import and replacement of arrays
[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_disable_header(msgPool::addFeaturesButton(_("Mail")),$reason ,TRUE,TRUE);
248           }else{
249             $display= $this->show_disable_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     $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
403     $tmp  = $this->plInfo();
404     foreach($tmp['plProvidedAcls'] as $name => $transl){
405       $smarty->assign("$name"."ACL", $this->getacl($name,$SkipWrite));
406     }
407     foreach($this->attributes as $attr){
408       $smarty->assign($attr,$this->$attr);
409     }
410     $smarty->assign("quotaEnabled", $this->mailMethod->quotaEnabled());
411     if($this->mailMethod->quotaEnabled()){
412       $smarty->assign("quotaUsage",   mailMethod::quota_to_image($this->quotaUsage,$this->gosaMailQuota));
413       $smarty->assign("gosaMailQuota",$this->gosaMailQuota);
414     }
415     $smarty->assign("domainSelectionEnabled", $this->mailMethod->domainSelectionEnabled());
416     $smarty->assign("MailDomains", $this->mailDomainParts);
417     $smarty->assign("MailDomain" , $this->mailDomainPart);
418     $smarty->assign("MailServers", $this->mailMethod->getMailServers());
419     $smarty->assign("allowSieveManagement", $this->mailMethod->allowSieveManagement());
420     $smarty->assign("own_script",  $this->sieveManagementUsed);
422     /* _Multiple users vars_ */
423     foreach($this->attributes as $attr){
424       $u_attr = "use_".$attr;
425       $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
426     }
427     foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
428       $u_attr = "use_".$attr;
429       $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
430     }
433     /****************
434       SMARTY- Assign flags 
435      ****************/
437     $types = array(
438         "V"=>"use_vacation",
439         "S"=>"use_spam_filter",
440         "R"=>"use_mailsize_limit",
441         "I"=>"drop_own_mails",
442         "C"=>"own_script");
443     foreach($types as $option => $varname){
444       if (preg_match("/".$option."/", $this->gosaMailDeliveryMode)) {
445         $smarty->assign($varname, "checked");
446       } else {
447         $smarty->assign($varname, "");
448       }
449     }
450     if (!preg_match("/L/", $this->gosaMailDeliveryMode)) {
451       $smarty->assign("only_local", "checked");
452     } else {
453       $smarty->assign("only_local", "");
454     }
457     /****************
458       Smarty- Vacation settings 
459      ****************/
460     $smarty->assign("rangeEnabled", FALSE);
461     $smarty->assign("template", "");
462     if (count($this->vacationTemplates)){
463       $smarty->assign("show_templates", "true");
464       $smarty->assign("vacationtemplates", $this->vacationTemplates);
465       if (isset($_POST['vacation_template'])){
466         $smarty->assign("template", $_POST['vacation_template']);
467       }
468     } else {
469       $smarty->assign("show_templates", "false");
470     }
472     /* Vacation range assigments
473      */
474     if($this->mailMethod->vacationRangeEnabled()){
475       $smarty->assign("rangeEnabled", TRUE);
476     }
478     /* fill filter settings 
479      */
480     $smarty->assign("spamlevel", $this->SpamLevels);
481     $smarty->assign("spambox"  , $this->MailBoxes);
483     $smarty->assign("multiple_support",$this->multiple_support_active);  
484     return($display.$smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
485   }
489   /* Save data to object */
490   function save_object()
491   {
492     if (isset($_POST['mailTab'])){
494       /* Save ldap attributes */
495       $mail   = $this->mail;
496       $server = $this->gosaMailServer;
497       plugin::save_object();
499       if(!$this->mailMethod->isModifyableServer() && $this->initially_was_account){
500         $this->gosaMailServer = $server;
501       }
503       if(!$this->mailMethod->isModifyableMail() && $this->initially_was_account){
504         $this->mail = $mail;
505       }else{
507         /* Get posted mail domain part, if necessary  
508          */
509         if($this->mailMethod->domainSelectionEnabled() && isset($_POST['MailDomain'])){
510           if(in_array(get_post('MailDomain'), $this->mailDomainParts)){
511             $this->mailDomainPart = get_post('MailDomain');
512           }
513         }
514       }
516       /* Import vacation message? 
517        */
518       if (isset($_POST["import_vacation"]) && isset($this->vacationTemplates[$_POST["vacation_template"]])){
519         if($this->multiple_support_active){
520           $contents = ltrim(preg_replace("/^DESC:.*$/m","",file_get_contents($_POST["vacation_template"])));
521         }else{
522           $contents = $this->prepare_vacation_template(file_get_contents($_POST["vacation_template"]));
523         }
524         $this->gosaVacationMessage= htmlspecialchars($contents);
525       }
527       /* Handle flags 
528        */
529       if(isset($_POST['own_script'])){
530         if(!preg_match("/C/",$this->gosaMailDeliveryMode)){
531           $str= preg_replace("/[\[\]]/","",$this->gosaMailDeliveryMode);
532           $this->gosaMailDeliveryMode = "[".$str."C]";
533         }
534       }else{
536         /* Assemble mail delivery mode
537            The mode field in ldap consists of values between braces, this must
538            be called when 'mail' is set, because checkboxes may not be set when
539            we're in some other dialog.
541            Example for gosaMailDeliveryMode [LR        ]
542            L -  Local delivery
543            R -  Reject when exceeding mailsize limit
544            S -  Use spam filter
545            V -  Use vacation message
546            C -  Use custm sieve script
547            I -  Only insider delivery */
549         $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
552         /* Handle delivery flags */
553         if($this->acl_is_writeable("gosaMailDeliveryModeL")){
554           if(!preg_match("/L/",$tmp) && !isset($_POST['only_local'])){
555             $tmp.="L";
556           }elseif(preg_match("/L/",$tmp) && isset($_POST['only_local'])){
557             $tmp = preg_replace("/L/","",$tmp);
558           }
559         }
560         $opts = array(
561             "R"   => "use_mailsize_limit",
562             "S"   => "use_spam_filter",
563             "V"   => "use_vacation",
564             "C"   => "own_script",
565             "I"   => "drop_own_mails");
567         foreach($opts as $flag => $post){
568           if($this->acl_is_writeable("gosaMailDeliveryMode".$flag)){
569             if(!preg_match("/".$flag."/",$tmp) && isset($_POST[$post])){
570               $tmp.= $flag;
571             }elseif(preg_match("/".$flag."/",$tmp) && !isset($_POST[$post])){
572               $tmp = preg_replace("/".$flag."/","",$tmp);
573             }
574           }
575         }
577         $tmp= "[$tmp]";
578         if ($this->gosaMailDeliveryMode != $tmp){
579           $this->is_modified= TRUE;
580         }
581         $this->gosaMailDeliveryMode= $tmp;
583         /* Get start/stop values for vacation scope of application
584          */
585         if($this->mailMethod->vacationRangeEnabled()){
586           if($this->acl_is_writeable("gosaVacationMessage") && preg_match("/V/",$this->gosaMailDeliveryMode)){
587             if(isset($_POST['gosaVacationStart'])){
588               $this->gosaVacationStart = $_POST['gosaVacationStart'];
589             }
590             if(isset($_POST['gosaVacationStop'])){
591               $this->gosaVacationStop = $_POST['gosaVacationStop'];
592             }
593           }
594         }
595       }
596     }
597   }
600   /*! \brief  Parse vacation templates and build up an array
601     containing 'filename' => 'description'. 
602     Used to fill vacation dropdown box.
603     @return Array   All useable vacation templates.
604    */ 
605   function get_vacation_templates()
606   {
607     $vct = array();
608     if ($this->config->get_cfg_value("vacationTemplateDirectory") != ""){
609       $dir= $this->config->get_cfg_value("vacationTemplateDirectory");
610       if (is_dir($dir) && is_readable($dir)){
611         $dh = opendir($dir);
612         while($file = readdir($dh)){
613           $description= "";
614           if (is_file($dir."/".$file)){
615             $fh = fopen($dir."/".$file, "r");
616             $line= fgets($fh, 256);
617             if (!preg_match('/^DESC:/', $line)){
618               msg_dialog::display(_("Configuration error"), sprintf(_("No DESC tag in vacation template '%s'!"), $file), ERROR_DIALOG);
619             }else{
620               $description= trim(preg_replace('/^DESC:\s*/', '', $line));
621             }
622             fclose ($fh);
623           }
624           if ($description != ""){
625             $vct["$dir/$file"]= $description;
626           }
627         }
628         closedir($dh);
629       }
630     }
631     return($vct); 
632   }
635   /*! \brief  Adds the given mail address to the list of mail forwarders 
636    */ 
637   function addForwarder($address)
638   {
639     if(empty($address)) return;
640     if($this->acl_is_writeable("gosaMailForwardingAddress")){
641       $this->gosaMailForwardingAddress[]= $address;
642       $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
643       sort ($this->gosaMailForwardingAddress);
644       reset ($this->gosaMailForwardingAddress);
645       $this->is_modified= TRUE;
646     }else{
647       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
648     }
649   }
652   /*! \brief  Removes the given mail address from the list of mail forwarders 
653    */ 
654   function delForwarder($addresses)
655   {
656     if($this->acl_is_writeable("gosaMailForwardingAddress")){
657       $this->gosaMailForwardingAddress= array_remove_entries ($addresses, $this->gosaMailForwardingAddress);
658       $this->is_modified= TRUE;
659     }else{
660       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
661     }
662   }
665   /*! \brief  Add given mail address to the list of alternate adresses ,
666     .          check if this mal address is used, skip adding in this case 
667    */ 
668   function addAlternate($address)
669   {
670     if(empty($address)) return;
671     if($this->acl_is_writeable("gosaMailAlternateAddress")){
672       $ldap= $this->config->get_ldap_link();
673       $address= strtolower($address);
675       /* Is this address already assigned in LDAP? */
676       $ldap->cd ($this->config->current['BASE']);
677       $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=$address)".
678           "(alias=$address)(gosaMailAlternateAddress=$address)))", array("uid", "cn"));
679       if ($ldap->count() > 0){
680         $attrs= $ldap->fetch ();
681         if (!isset($attrs["uid"])) {
682           return ("!".$attrs["cn"][0]);
683         }
684         return ($attrs["uid"][0]);
685       }
686       if (!in_array($address, $this->gosaMailAlternateAddress)){
687         $this->gosaMailAlternateAddress[]= $address;
688         $this->is_modified= TRUE;
689       }
690       sort ($this->gosaMailAlternateAddress);
691       reset ($this->gosaMailAlternateAddress);
692       return ("");
693     }else{
694       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
695     }
696   }
699   /*! \brief  Removes the given mail address from the alternate addresses list 
700    */ 
701   function delAlternate($addresses)
702   {
703     if($this->acl_is_writeable("gosaMailAlternateAddress")){
704       $this->gosaMailAlternateAddress= array_remove_entries ($addresses,$this->gosaMailAlternateAddress);
705       $this->is_modified= TRUE;
706     }else{
707       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
708     }
709   }
712   /*! \brief  Prepare importet vacation string. \
713     .         Replace placeholder like %givenName a.s.o.
714     @param  string  Vacation string
715     @return string  Completed vacation string
716    */
717   private function prepare_vacation_template($contents)
718   {
719     /* Replace attributes */
720     $attrs = array();
721     $obj   = NULL;
722     if(isset($this->parent->by_object['user'])){
723       $attrs  = $this->parent->by_object['user']->attributes;
724       $obj    = $this->parent->by_object['user'];
725     }else{
726       $obj    = new user($this->config,$this->dn);
727       $attrs  = $obj->attributes;
728     }
729     if($obj){
731       /* Replace vacation start and end time */
732       if($this->mailMethod->vacationRangeEnabled()){
733         if(preg_match("/%start/",$contents)){
734           $contents = preg_replace("/%start/",$this->gosaVacationStart,$contents);
735         }
736         if(preg_match("/%end/",$contents)){
737           $contents = preg_replace("/%end/",$this->gosaVacationStop,$contents);
738         }
739       }else{
740         if(preg_match("/%start/",$contents)){
741           $contents = preg_replace("/%start/", _("unknown"),$contents);
742         }
743         if(preg_match("/%end/",$contents)){
744           $contents = preg_replace("/%end/", _("unknown"), $contents);
745         }
746       }
748       foreach ($attrs as $val){
750         // We can only replace strings here
751         if(!is_string($obj->$val)) continue;
753         if(preg_match("/dateOfBirth/",$val)){
754           if($obj->use_dob){
755             $contents= preg_replace("/%$val/",date("Y-d-m",$obj->dateOfBirth),$contents);
756           }
757         }else {
758           $contents= preg_replace("/%$val/",
759               $obj->$val, $contents);
760         }
762       }
763     }
764     $contents = ltrim(preg_replace("/^DESC:.*$/m","",$contents),"\n ");
765     return($contents);
766   }
769   /*! \brief  Removes the mailAccount extension from ldap 
770    */  
771   function remove_from_parent()
772   {
773     /* Cancel if there's nothing to do here */
774     if (!$this->initially_was_account){
775       return;
776     }
778     /* If domain part was selectable, contruct mail address */
779     if($this->mailMethod->domainSelectionEnabled()){
780       $this->mail = $this->mail."@".$this->mailDomainPart;
781     }
783     /* Update sharedFolder dependencies. 
784        Open each shared folder and remove this account. 
785        Then Save the group to ensure that all necessary 
786         actions will be taken (imap acls updated aso.).
787      */
788     $ldap = $this->config->get_ldap_link();    
789     $ldap->cd($this->config->current['BASE']);
790     $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array("dn"));
791     while($attrs = $ldap->fetch()){
792       $grp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
793       if(isset($grp->by_object['mailgroup']) && isset($grp->by_object['group'])){
794         $grp->by_object['group']->removeUser($this->uid);
796         /* Do not save the complete group! This will quit the complete membership 
797          */
798         $grp->by_object['mailgroup']->save();
799       } 
800     }
802     /* Remove GOsa attributes */
803     plugin::remove_from_parent();
805     /* Zero arrays */
806     $this->attrs['gosaMailAlternateAddress'] = array();
807     $this->attrs['gosaMailForwardingAddress']= array();
810     $this->mailMethod->fixAttributesOnRemove();
811     $this->cleanup();
813     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
814     $ldap= $this->config->get_ldap_link();
815     $ldap->cd($this->dn);
816     $ldap->modify ($this->attrs);
818     /* Add "view" to logging class */
819     new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
820     if (!$ldap->success()){
821       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
822     }
823     
824     /* Let the mailMethod remove this mailbox, e.g. from imap and
825        update shared folder membership, ACL may need to be updated. 
826      */
827     if (!$this->is_template){
829       if(!$this->mailMethod->connect()){
830         msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"), 
831               $this->mailMethod->get_error()), ERROR_DIALOG);
832       }else{
833         if(!$this->mailMethod->deleteMailbox()){
834           msg_dialog::display(_("Mail error"), sprintf(_("Cannot remove mailbox: %s"), 
835                 $this->mailMethod->get_error()), ERROR_DIALOG);
836         }
837       }
838     }
839     $this->mailMethod->disconnect();
841     /* Optionally execute a command after we're done */
842     $this->handle_post_events("remove",array("uid" => $this->uid));
843   }
846   /*! \brief  Save the mailAccount settings to the ldap database.
847    */
848   function save()
849   {
850     $ldap= $this->config->get_ldap_link();
852     /* If domain part was selectable, contruct mail address */
853     if(!(!$this->mailMethod->isModifyableMail() && $this->initially_was_account)){
855       if($this->mailMethod->domainSelectionEnabled()){
856         $this->mail = $this->mail."@".$this->mailDomainPart;
857       }
859       /* Enforce lowercase mail address and trim whitespaces
860        */
861       $this->mail = trim(strtolower($this->mail));
862     }
865     /* Call parents save to prepare $this->attrs */
866     plugin::save();
868     /* Save arrays */
869     $this->attrs['gosaMailAlternateAddress'] = $this->gosaMailAlternateAddress;
870     $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
872     if(!$this->mailMethod->vacationRangeEnabled()){
873       $this->attrs['gosaVacationStart'] = $this->attrs['gosaVacationStop'] = array();
874     }elseif (!preg_match('/V/', $this->gosaMailDeliveryMode)){
875       unset($this->attrs['gosaVacationStart']);
876       unset($this->attrs['gosaVacationStop']);
877     } else {
878       /* Adapt values to be timestamps */
879       list($day, $month, $year)= explode('.', $this->gosaVacationStart);
880       $this->attrs['gosaVacationStart']= mktime(0,0,0,$month, $day, $year);
881       list($day, $month, $year)= explode('.', $this->gosaVacationStop);
882       $this->attrs['gosaVacationStop']= mktime(0,0,0,$month, $day, $year);
883     }
885     /* Map method attributes */ 
886     $this->mailMethod->fixAttributesOnStore();
887     
888     /* Save data to LDAP */
889     $ldap->cd($this->dn);
890     $this->cleanup();
891     $ldap->modify ($this->attrs);
893     if (!$ldap->success()){
894       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
895     }
897     /* Log last action */
898     if($this->initially_was_account){
899       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
900     }else{
901       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
902     }
904     /* Only do IMAP actions if we are not a template */
905     if (!$this->is_template){
906       $this->mailMethod->connect();
907       if(!$this->mailMethod->is_connected()){
908         msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"), 
909               $this->mailMethod->get_error()), ERROR_DIALOG);
910       }else{
911         if(!$this->mailMethod->updateMailbox()){
912           msg_dialog::display(_("Mail error"), sprintf(_("Cannot update mailbox: %s"), 
913                 $this->mailMethod->get_error()), ERROR_DIALOG);
914         }
915         if(!$this->mailMethod->setQuota($this->gosaMailQuota)){
916           msg_dialog::display(_("Mail error"), sprintf(_("Cannot write quota settings: %s"), 
917                 $this->mailMethod->get_error()), ERROR_DIALOG);
918         }
920         if (!is_integer(strpos($this->gosaMailDeliveryMode, "C"))){
922           /* Do not write sieve settings if this account is new and 
923              doesn't seem to exist.
924            */
925           if(!$this->initially_was_account && !$this->mailMethod->account_exists()){
926             @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,
927                 "Skipping sieve settings, the account doesn't seem to be created already.</b>","");
928           }else{
929             if(!$this->mailMethod->saveSieveSettings()){
930               msg_dialog::display(_("Mail error saving sieve settings"), $this->mailMethod->get_error(), ERROR_DIALOG);
931             }
932           }
933         }else{
934           if ($this->sieve_management) {
935             @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, 
936                 "User uses an own sieve script, skipping sieve update.".$str."</b>","");
937             $this->sieve_management->save();
938           }
939         }
940       }
941     }
942     $this->mailMethod->disconnect();
944     /* Update sharedFolder dependencies.
945        Open each shared folder and remove this account.
946        Then Save the group to ensure that all necessary
947        actions will be taken (imap acls updated aso.).
948      */
949     if(!$this->initially_was_account){
950       $ldap = $this->config->get_ldap_link();
951       $ldap->cd($this->config->current['BASE']);
952       $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array("dn"));
953       while($attrs = $ldap->fetch()){
954         $grp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
955         if(isset($grp->by_object['mailgroup'])){
956           /* Do not save the complete group! This will quit the complete membership
957            */
958           $grp->by_object['mailgroup']->save();
959         }
960       }
961     }
963     /* Optionally execute a command after we're done */
964     if ($this->initially_was_account == $this->is_account){
965       if ($this->is_modified){
966         $this->handle_post_events("modify", array("uid" => $this->uid));
967       }
968     } else {
969       $this->handle_post_events("add", array("uid" => $this->uid));
970     }
971   }
974   /*! \brief  Check given values 
975    */
976   function check()
977   {
978     if(!$this->is_account){
979       return(array());
980     }
982     $ldap= $this->config->get_ldap_link();
984     /* Call common method to give check the hook */
985     $message= plugin::check();
987     if(empty($this->gosaMailServer)){
988       $message[]= msgPool::noserver(_("Mail"));
989     }
991     /* Mail address checks */
992     $mail = $this->mail;
993     if(!(!$this->mailMethod->isModifyableMail() && $this->initially_was_account)){
995       if($this->mailMethod->domainSelectionEnabled()){
996         $mail.= "@".$this->mailDomainPart;
997       }
999       if (empty($mail)){
1000         $message[]= msgPool::required(_("Primary address"));
1001       }
1002       if ($this->is_template){
1003         if (!tests::is_email($mail, TRUE)){
1004           $message[]= msgPool::invalid(_("Mail address"),"","","%givenName.%sn@your-domain.com");
1005         }
1006       } else {
1007         if (!tests::is_email($mail)){
1008           $message[]= msgPool::invalid(_("Mail address"),"","","your-address@your-domain.com");
1009         }
1010       }
1012       /* Check if this mail address is already in use */
1013       $ldap->cd($this->config->current['BASE']);
1014       $filter = "(&(!(objectClass=gosaUserTemplate))(!(uid=".$this->uid."))".
1015         "(objectClass=gosaMailAccount)".
1016         "(|(mail=".$mail.")(alias=".$mail.")(gosaMailAlternateAddress=".$mail.")))";
1017       $ldap->search($filter,array("uid", "cn"));
1018       if ($ldap->count() != 0){
1019         $entry= $ldap->fetch();
1020         $addon= "";
1021         if (!isset($entry['uid'])) {
1022            $addon= sprintf(_("Address is already in use by group '%s'."), $entry['cn'][0]);
1023         } else {
1024            $addon= sprintf(_("Address is already in use by user '%s'."), $entry['uid'][0]);
1025         }
1026         $message[]= msgPool::duplicated(_("Mail address"))."<br><br><i>$addon</i>";
1027       }
1028     }
1031     /* Check quota */
1032     if ($this->gosaMailQuota != '' && $this->acl_is_writeable("gosaMailQuota")){
1033       if (!is_numeric($this->gosaMailQuota)) {
1034         $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
1035       } else {
1036         $this->gosaMailQuota= (int) $this->gosaMailQuota;
1037       }
1038     }
1040     /* Check rejectsize for integer */
1041     if ($this->gosaMailMaxSize != '' && $this->acl_is_writeable("gosaMailMaxSize")){
1042       if (!is_numeric($this->gosaMailMaxSize)){
1043         $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
1044       } else {
1045         $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
1046       }
1047     }
1049     /* Need gosaMailMaxSize if use_mailsize_limit is checked */
1050     if (is_integer(strpos($this->gosaMailDeliveryMode, "R")) && $this->gosaMailMaxSize == ""){
1051       $message[]= msgPool::required(_("Mail reject size"));
1052     }
1054     if((preg_match("/S/", $this->gosaMailDeliveryMode))&&(empty($this->gosaSpamMailbox))) {
1055       $message[]= msgPool::required(_("Spam folder"));
1056     }
1058     if ($this->mailMethod->vacationRangeEnabled() && preg_match('/V/', $this->gosaMailDeliveryMode)){ 
1060       /* Check date strings */
1061       $state= true;
1062       if ($this->gosaVacationStart == "" || !tests::is_date($this->gosaVacationStart)) {
1063         $message[]= msgPool::invalid(_("from"),$this->gosaVacationStart);
1064         $state= false;
1065       }
1066       if ($this->gosaVacationStart == "" || !tests::is_date($this->gosaVacationStop)) {
1067         $message[]= msgPool::invalid(_("to"),$this->gosaVacationStop);
1068         $state= false;
1069       }
1071       #TODO: take care of date format
1072       if ($state) {
1073         list($day, $month, $year)= explode('.', $this->gosaVacationStart);
1074         $start= mktime(0,0,0,$month, $day, $year);
1075         list($day, $month, $year)= explode('.', $this->gosaVacationStop);
1076         $stop= mktime(0,0,0,$month, $day, $year);
1077         if($start > $stop){
1078           $message[]= msgPool::invalid(_("Vacation interval"));
1079         }
1080       }
1081     }
1082     return($message);
1083   }
1086   /*! \brief  Adapt from template, using 'dn' 
1087    */
1088   function adapt_from_template($dn, $skip= array())
1089   {
1090     plugin::adapt_from_template($dn, $skip);
1092     foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
1094       if (in_array($val, $skip)){
1095         continue;
1096       }
1098       $this->$val= array();
1099       if (isset($this->attrs["$val"]["count"])){
1100         for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
1101           $value= $this->attrs["$val"][$i];
1102           foreach (array("sn", "givenName", "uid") as $repl){
1103             if (preg_match("/%$repl/i", $value)){
1104               $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
1105             }
1106           }
1107           array_push($this->$val, strtolower(rewrite($value)));
1108         }
1109       }
1110     }
1111     $this->mail= strtolower(rewrite($this->mail));
1113     // Fix mail address when using templates
1114     if($this->is_account && $this->mailMethod->domainSelectionEnabled()){
1115       $this->mailDomainPart = preg_replace("/^[^@]*+@/","",$this->mail);
1116       $this->mail = preg_replace("/@.*$/","\\1",$this->mail);
1117       if(!in_array($this->mailDomainPart,$this->mailDomainParts)){
1118         $this->mailDomainParts[] = $this->mailDomainPart;
1119       }
1120     }
1121   }
1124   /*! \brief  Creates the mail part for the copy & paste dialog 
1125    */ 
1126   function getCopyDialog()
1127   {
1128     if(!$this->is_account) return("");
1129     $smarty = get_smarty();
1130     $smarty->assign("mail",$this->mail);
1131     $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress);
1132     $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress);
1133     $str = $smarty->fetch(get_template_path("copypaste.tpl",TRUE, dirname(__FILE__)));
1135     $ret = array();
1136     $ret['status'] = "";
1137     $ret['string'] = $str;
1138     return($ret);
1139   }
1141     
1142   /*! \brief  save_object for copy&paste vars 
1143    */  
1144   function saveCopyDialog()
1145   {
1146     if(!$this->is_account) return;
1148     /* Execute to save mailAlternateAddress && gosaMailForwardingAddress */
1149     $this->execute();
1150     if(isset($_POST['mail'])){
1151       $this->mail = $_POST['mail'];
1152     }
1153   }
1155   
1156   /*! \brief  Prepare this account to be copied 
1157    */
1158   function PrepareForCopyPaste($source)
1159   {
1160     plugin::PrepareForCopyPaste($source);
1162     /* Reset alternate mail addresses */
1163     $this->gosaMailAlternateAddress = array();
1164   }
1167   /*! \brief  Prepare this class the be useable when editing multiple users at once 
1168    */
1169   function get_multi_edit_values()
1170   {
1171     $ret = plugin::get_multi_edit_values();
1172     if(in_array("gosaMailQuota",$this->multi_boxes)){
1173       $ret['gosaMailQuota'] = $this->gosaMailQuota;
1174     }
1175     $flag_add = $flag_remove = array();
1176     $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1177     $opts = array(
1178         "R"   => "use_mailsize_limit",
1179         "S"   => "use_spam_filter",
1180         "L"   => "only_local",
1181         "V"   => "use_vacation",
1182         "C"   => "own_script",
1183         "I"   => "drop_own_mails");
1184     foreach($opts as $flag => $post){
1185       if(in_array($post, $this->multi_boxes)){
1186         if(preg_match("/".$flag."/",$tmp)){
1187           $flag_add[] = $flag;
1188         }else{
1189           $flag_remove[] = $flag;
1190         }
1191       }
1192     }
1193     $ret['flag_add'] = $flag_add;
1194     $ret['flag_remove'] = $flag_remove;
1196     if($this->mailMethod->vacationRangeEnabled()){
1197       if(in_array("V",$flag_add)){
1198         $ret['gosaVacationStart'] =  $this->gosaVacationStart = $_POST['gosaVacationStart'];
1199         $ret['gosaVacationStop'] =  $this->gosaVacationStop = $_POST['gosaVacationStop'];
1200       }
1201     }
1202     return($ret);
1203   }
1206   /*! \brief  Check given input for multiple user edit 
1207    */
1208   function multiple_check()
1209   {
1210     $message = plugin::multiple_check();
1212     if(empty($this->gosaMailServer) && in_array("gosaMailServer",$this->multi_boxes)){
1213       $message[]= msgPool::noserver(_("Mail"));
1214     }
1216     /* Check quota */
1217     if ($this->gosaMailQuota != ''  && in_array("gosaMailQuota",$this->multi_boxes)){
1218       if (!is_numeric($this->gosaMailQuota)) {
1219         $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
1220       } else {
1221         $this->gosaMailQuota= (int) $this->gosaMailQuota;
1222       }
1223     }
1225     /* Check rejectsize for integer */
1226     if ($this->gosaMailMaxSize != '' && in_array("gosaMailMaxSize",$this->multi_boxes)){
1227       if (!is_numeric($this->gosaMailMaxSize)){
1228         $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
1229       } else {
1230         $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
1231       }
1232     }
1234     if(empty($this->gosaSpamMailbox) && in_array("gosaSpamMailbox",$this->multi_boxes)){
1235       $message[]= msgPool::required(_("Spam folder"));
1236     }
1238     if ($this->mailMethod->vacationRangeEnabled() && preg_match('/V/', $this->gosaMailDeliveryMode)){ 
1240       /* Check date strings */
1241       $state= true;
1242       if ($this->gosaVacationStart == "" || !tests::is_date($this->gosaVacationStart)) {
1243         $message[]= msgPool::invalid(_("from"),$this->gosaVacationStart);
1244         $state= false;
1245       }
1246       if ($this->gosaVacationStart == "" || !tests::is_date($this->gosaVacationStop)) {
1247         $message[]= msgPool::invalid(_("to"),$this->gosaVacationStop);
1248         $state= false;
1249       }
1251       #TODO: take care of date format
1252       if ($state) {
1253         list($day, $month, $year)= explode('.', $this->gosaVacationStart);
1254         $start= mktime(0,0,0,$month, $day, $year);
1255         list($day, $month, $year)= explode('.', $this->gosaVacationStop);
1256         $stop= mktime(0,0,0,$month, $day, $year);
1257         if($start > $stop){
1258           $message[]= msgPool::invalid(_("Vacation interval"));
1259         }
1260       }
1261     }
1262     return($message);
1263   }
1265   
1266   /*! \brief  ...
1267    */
1268   function set_multi_edit_values($values)
1269   {
1270     plugin::set_multi_edit_values($values);
1271     $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1272     if(isset($values['flag_add'])){
1273       foreach($values['flag_add'] as $flag){
1274         if(!preg_match("/".$flag."/",$tmp)){
1275           $tmp .= $flag;
1276         }
1277       }
1278     }
1279     if(isset($values['flag_remove'])){
1280       foreach($values['flag_remove'] as $flag){
1281         if(preg_match("/".$flag."/",$tmp)){
1282           $tmp = preg_replace("/".$flag."/","",$tmp);
1283         }
1284       }
1285     }
1286     $this->gosaMailDeliveryMode = "[".$tmp."]";
1288     /* Set vacation message and replace placeholder like %givenName
1289      */
1290     if(isset($values['gosaVacationMessage'])){
1291       $this->gosaVacationMessage = $this->prepare_vacation_template($values['gosaVacationMessage']);
1292     }
1293   }
1296   /*! \brief  Initialize plugin to be used as multiple edit class. 
1297    */
1298   function init_multiple_support($attrs,$all)
1299   {
1300     plugin::init_multiple_support($attrs,$all);
1301     if(isset($this->multi_attrs['gosaMailQuota'])){
1302       $this->gosaMailQuota = $this->multi_attrs['gosaMailQuota'];
1303     }
1304   }
1306  
1307   /*! \brief
1308    */
1309   function get_multi_init_values()
1310   {
1311     $attrs = plugin::get_multi_init_values();
1312     $attrs['gosaMailQuota'] = $this->gosaMailQuota;
1313     return($attrs);
1314   }
1317   /*! \brief  Display multiple edit dialog 
1318    */
1319   function multiple_execute()
1320   {
1321     return($this->execute());
1322   }
1324   
1325   /*! \brief  Save posts from multiple edit dialog 
1326    */
1327   function multiple_save_object()
1328   {
1329     plugin::multiple_save_object();
1331     $this->save_object();
1332     foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
1333       if(isset($_POST["use_".$attr])){
1334         $this->multi_boxes[] = $attr;
1335       }
1336     }
1337   }
1340   /*! \brief  Creates the user names for the add_local_forward dialog
1341    */
1342   function make_name($attrs)
1343   {
1344     $name= "";
1345     if (isset($attrs['sn'][0])){
1346       $name= $attrs['sn'][0];
1347     }
1348     if (isset($attrs['givenName'][0])){
1349       if ($name != ""){
1350         $name.= ", ".$attrs['givenName'][0];
1351       } else {
1352         $name.= $attrs['givenName'][0];
1353       }
1354     }
1355     if ($name != ""){
1356       $name.= " ";
1357     }
1359     return ($name);
1360   }
1363   function allow_remove()
1364   {
1365     $resason = "";
1366     if(!$this->mailMethod->allow_remove($reason)){
1367       return($reason);
1368     }
1369     return("");
1370   }
1374   /*! \brief  ACL settings 
1375    */
1376   static function plInfo()
1377   {
1378     return (array(
1379           "plShortName"     => _("Mail"),
1380           "plDescription"   => _("Mail settings"),
1381           "plSelfModify"    => TRUE,
1382           "plDepends"       => array("user"),                     // This plugin depends on
1383           "plPriority"      => 4,                                 // Position in tabs
1384           "plSection"     => array("personal" => _("My account")),
1385           "plCategory"    => array("users"),
1386           "plOptions"       => array(),
1388           "plProvidedAcls"  => array(
1389             "mail"                      =>  _("Mail address"),
1390             "gosaMailServer"            =>  _("Mail server"),
1391             "gosaMailQuota"             =>  _("Quota size"),
1393             "gosaMailDeliveryModeV"     =>  _("Add vacation information"),  // This is flag of gosaMailDeliveryMode
1394             "gosaVacationMessage"       =>  _("Vacation message"),
1396             "gosaMailDeliveryModeS"     =>  _("Use spam filter"),           // This is flag of gosaMailDeliveryMode
1397             "gosaSpamSortLevel"         =>  _("Spam level"),
1398             "gosaSpamMailbox"           =>  _("Spam mail box"),
1400             "sieveManagement"           =>  _("Sieve management"),
1402             "gosaMailDeliveryModeR"     =>  _("Reject due to mailsize"),    // This is flag of gosaMailDeliveryMode
1403             "gosaMailMaxSize"           =>  _("Mail max size"),
1405             "gosaMailForwardingAddress" =>  _("Forwarding address"),
1406             "gosaMailDeliveryModeL"     =>  _("Local delivery"),            // This is flag of gosaMailDeliveryMode
1407             "gosaMailDeliveryModeI"     =>  _("No delivery to own mailbox "),     // This is flag of gosaMailDeliveryMode
1408             "gosaMailAlternateAddress"  =>  _("Mail alternative addresses"),
1410             "gosaMailForwardingAddress" =>  _("Forwarding address"),
1411             "gosaMailDeliveryModeC"     =>  _("Use custom sieve script"))   // This is flag of gosaMailDeliveryMode
1412               ));
1413   }
1418 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1419 ?>