Code

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