Code

Prepared mailAlternate selection, to use new dialogs
[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 $selectMailAddress = 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->selectMailAddress=  new selectMailAddress($this->config, get_userinfo());
285       $this->dialog= TRUE;
286     }
287     if (isset($_POST['selectMailAddress_cancel'])){
288       $this->selectMailAddress= FALSE;
289       $this->dialog= FALSE;
290     }
292     if (isset($_POST['selectMailAddress_save']) && $this->selectMailAddress instanceOf selectMailAddress){
294       if($this->acl_is_writeable("gosaMailForwardingAddress")){
295         $list = $this->selectMailAddress->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->selectMailAddress= FALSE;
304         $this->dialog= FALSE;
305       } else {
306         msg_dialog::display(_("Error"), _("Please select an entry!"), ERROR_DIALOG);
307       }
308     }
310     if($this->selectMailAddress instanceOf selectMailAddress){
311       $used  = array();
312       $used['mail'] = array_values($this->gosaMailAlternateAddress);  
313       $used['mail'][] = $this->mail;
314       return($this->selectMailAddress->execute());
315     }
317     if (isset($_POST['add_forwarder'])){
318       if ($_POST['forward_address'] != ""){
319         $address= $_POST['forward_address'];
320         $valid= FALSE;
321         if (!tests::is_email($address)){
322           if (!tests::is_email($address, TRUE)){
323             if ($this->is_template){
324               $valid= TRUE;
325             } else {
326               msg_dialog::display(_("Error"), msgPool::invalid(_("Mail address"),
327                     "","","your-address@your-domain.com"),ERROR_DIALOG);
328             }
329           }
330         } elseif ($address == $this->mail
331             || in_array($address, $this->gosaMailAlternateAddress)) {
332           msg_dialog::display(_("Error"),_("Cannot add primary address to the list of forwarders!") , ERROR_DIALOG);
333         } else {
334           $valid= TRUE;
335         }
336         if ($valid){
337           if($this->acl_is_writeable("gosaMailForwardingAddress")){
338             $this->addForwarder ($address);
339             $this->is_modified= TRUE;
340           }
341         }
342       }
343     }
344     if (isset($_POST['delete_forwarder'])){
345       $this->delForwarder ($_POST['forwarder_list']);
346     }
347     if ($this->selectMailAddress instanceOf selectMailAddress){
348     
349       return($this->selectMailAddress->execute());
350     }
353     /****************
354       Alternate addresses 
355      ****************/
357     if (isset($_POST['add_alternate'])){
358       $valid= FALSE;
359       if (!tests::is_email($_POST['alternate_address'])){
360         if ($this->is_template){
361           if (!(tests::is_email($_POST['alternate_address'], TRUE))){
362             msg_dialog::display(_("Error"),msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com"),ERROR_DIALOG);
363           } else {
364             $valid= TRUE;
365           }
366         } else {
367           msg_dialog::display(_("Error"),msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com"),ERROR_DIALOG);
368         }
369       } else {
370         $valid= TRUE;
371       }
372       if ($valid && ($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
373         $ui= get_userinfo();
374         $addon= "";
375         if ($user[0] == "!") {
376           $addon= sprintf(_("Address is already in use by group '%s'."), mb_substr($user, 1));
377         } else {
378           $addon= sprintf(_("Address is already in use by user '%s'."), $user);
379         }
380         msg_dialog::display(_("Error"), msgPool::duplicated(_("Mail address"))."<br><br><i>".
381             "$addon</i>", ERROR_DIALOG);
382       }
383     }
384     if (isset($_POST['delete_alternate']) && isset($_POST['alternates_list'])){
385       $this->delAlternate ($_POST['alternates_list']);
386     }
388     /****************
389       SMARTY- Assign smarty variables 
390      ****************/
391     $smarty = get_smarty();
392     $smarty->assign("usePrototype", "true");
393     $smarty->assign("initially_was_account", $this->initially_was_account);
394     $smarty->assign("isModifyableMail"  , $this->mailMethod->isModifyableMail());
395     $smarty->assign("isModifyableServer", $this->mailMethod->isModifyableServer());
396     $smarty->assign("mailEqualsCN", $this->mailMethod->mailEqualsCN());
398     $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
399     $tmp  = $this->plInfo();
400     foreach($tmp['plProvidedAcls'] as $name => $transl){
401       $smarty->assign("$name"."ACL", $this->getacl($name,$SkipWrite));
402     }
403     foreach($this->attributes as $attr){
404       $smarty->assign($attr,$this->$attr);
405     }
406     $smarty->assign("quotaEnabled", $this->mailMethod->quotaEnabled());
407     if($this->mailMethod->quotaEnabled()){
408       $smarty->assign("quotaUsage",   mailMethod::quota_to_image($this->quotaUsage,$this->gosaMailQuota));
409       $smarty->assign("gosaMailQuota",$this->gosaMailQuota);
410     }
411     $smarty->assign("domainSelectionEnabled", $this->mailMethod->domainSelectionEnabled());
412     $smarty->assign("MailDomains", $this->mailDomainParts);
413     $smarty->assign("MailDomain" , $this->mailDomainPart);
414     $smarty->assign("MailServers", $this->mailMethod->getMailServers());
415     $smarty->assign("allowSieveManagement", $this->mailMethod->allowSieveManagement());
416     $smarty->assign("own_script",  $this->sieveManagementUsed);
418     /* _Multiple users vars_ */
419     foreach($this->attributes as $attr){
420       $u_attr = "use_".$attr;
421       $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
422     }
423     foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
424       $u_attr = "use_".$attr;
425       $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
426     }
429     /****************
430       SMARTY- Assign flags 
431      ****************/
433     $types = array(
434         "V"=>"use_vacation",
435         "S"=>"use_spam_filter",
436         "R"=>"use_mailsize_limit",
437         "I"=>"drop_own_mails",
438         "C"=>"own_script");
439     foreach($types as $option => $varname){
440       if (preg_match("/".$option."/", $this->gosaMailDeliveryMode)) {
441         $smarty->assign($varname, "checked");
442       } else {
443         $smarty->assign($varname, "");
444       }
445     }
446     if (!preg_match("/L/", $this->gosaMailDeliveryMode)) {
447       $smarty->assign("only_local", "checked");
448     } else {
449       $smarty->assign("only_local", "");
450     }
453     /****************
454       Smarty- Vacation settings 
455      ****************/
456     $smarty->assign("rangeEnabled", FALSE);
457     $smarty->assign("template", "");
458     if (count($this->vacationTemplates)){
459       $smarty->assign("show_templates", "true");
460       $smarty->assign("vacationtemplates", $this->vacationTemplates);
461       if (isset($_POST['vacation_template'])){
462         $smarty->assign("template", $_POST['vacation_template']);
463       }
464     } else {
465       $smarty->assign("show_templates", "false");
466     }
468     /* Vacation range assigments
469      */
470     if($this->mailMethod->vacationRangeEnabled()){
471       $smarty->assign("rangeEnabled", TRUE);
472     }
474     /* fill filter settings 
475      */
476     $smarty->assign("spamlevel", $this->SpamLevels);
477     $smarty->assign("spambox"  , $this->MailBoxes);
479     $smarty->assign("multiple_support",$this->multiple_support_active);  
480     return($display.$smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
481   }
485   /* Save data to object */
486   function save_object()
487   {
488     if (isset($_POST['mailTab'])){
490       /* Save ldap attributes */
491       $mail   = $this->mail;
492       $server = $this->gosaMailServer;
493       plugin::save_object();
495       if(!$this->mailMethod->isModifyableServer() && $this->initially_was_account){
496         $this->gosaMailServer = $server;
497       }
499       if(!$this->mailMethod->isModifyableMail() && $this->initially_was_account){
500         $this->mail = $mail;
501       }else{
503         /* Get posted mail domain part, if necessary  
504          */
505         if($this->mailMethod->domainSelectionEnabled() && isset($_POST['MailDomain'])){
506           if(in_array(get_post('MailDomain'), $this->mailDomainParts)){
507             $this->mailDomainPart = get_post('MailDomain');
508           }
509         }
510       }
512       /* Import vacation message? 
513        */
514       if (isset($_POST["import_vacation"]) && isset($this->vacationTemplates[$_POST["vacation_template"]])){
515         if($this->multiple_support_active){
516           $contents = ltrim(preg_replace("/^DESC:.*$/m","",file_get_contents($_POST["vacation_template"])));
517         }else{
518           $contents = $this->prepare_vacation_template(file_get_contents($_POST["vacation_template"]));
519         }
520         $this->gosaVacationMessage= htmlspecialchars($contents);
521       }
523       /* Handle flags 
524        */
525       if(isset($_POST['own_script'])){
526         if(!preg_match("/C/",$this->gosaMailDeliveryMode)){
527           $str= preg_replace("/[\[\]]/","",$this->gosaMailDeliveryMode);
528           $this->gosaMailDeliveryMode = "[".$str."C]";
529         }
530       }else{
532         /* Assemble mail delivery mode
533            The mode field in ldap consists of values between braces, this must
534            be called when 'mail' is set, because checkboxes may not be set when
535            we're in some other dialog.
537            Example for gosaMailDeliveryMode [LR        ]
538            L -  Local delivery
539            R -  Reject when exceeding mailsize limit
540            S -  Use spam filter
541            V -  Use vacation message
542            C -  Use custm sieve script
543            I -  Only insider delivery */
545         $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
548         /* Handle delivery flags */
549         if($this->acl_is_writeable("gosaMailDeliveryModeL")){
550           if(!preg_match("/L/",$tmp) && !isset($_POST['only_local'])){
551             $tmp.="L";
552           }elseif(preg_match("/L/",$tmp) && isset($_POST['only_local'])){
553             $tmp = preg_replace("/L/","",$tmp);
554           }
555         }
556         $opts = array(
557             "R"   => "use_mailsize_limit",
558             "S"   => "use_spam_filter",
559             "V"   => "use_vacation",
560             "C"   => "own_script",
561             "I"   => "drop_own_mails");
563         foreach($opts as $flag => $post){
564           if($this->acl_is_writeable("gosaMailDeliveryMode".$flag)){
565             if(!preg_match("/".$flag."/",$tmp) && isset($_POST[$post])){
566               $tmp.= $flag;
567             }elseif(preg_match("/".$flag."/",$tmp) && !isset($_POST[$post])){
568               $tmp = preg_replace("/".$flag."/","",$tmp);
569             }
570           }
571         }
573         $tmp= "[$tmp]";
574         if ($this->gosaMailDeliveryMode != $tmp){
575           $this->is_modified= TRUE;
576         }
577         $this->gosaMailDeliveryMode= $tmp;
579         /* Get start/stop values for vacation scope of application
580          */
581         if($this->mailMethod->vacationRangeEnabled()){
582           if($this->acl_is_writeable("gosaVacationMessage") && preg_match("/V/",$this->gosaMailDeliveryMode)){
583             if(isset($_POST['gosaVacationStart'])){
584               $this->gosaVacationStart = $_POST['gosaVacationStart'];
585             }
586             if(isset($_POST['gosaVacationStop'])){
587               $this->gosaVacationStop = $_POST['gosaVacationStop'];
588             }
589           }
590         }
591       }
592     }
593   }
596   /*! \brief  Parse vacation templates and build up an array
597     containing 'filename' => 'description'. 
598     Used to fill vacation dropdown box.
599     @return Array   All useable vacation templates.
600    */ 
601   function get_vacation_templates()
602   {
603     $vct = array();
604     if ($this->config->get_cfg_value("vacationTemplateDirectory") != ""){
605       $dir= $this->config->get_cfg_value("vacationTemplateDirectory");
606       if (is_dir($dir) && is_readable($dir)){
607         $dh = opendir($dir);
608         while($file = readdir($dh)){
609           $description= "";
610           if (is_file($dir."/".$file)){
611             $fh = fopen($dir."/".$file, "r");
612             $line= fgets($fh, 256);
613             if (!preg_match('/^DESC:/', $line)){
614               msg_dialog::display(_("Configuration error"), sprintf(_("No DESC tag in vacation template '%s'!"), $file), ERROR_DIALOG);
615             }else{
616               $description= trim(preg_replace('/^DESC:\s*/', '', $line));
617             }
618             fclose ($fh);
619           }
620           if ($description != ""){
621             $vct["$dir/$file"]= $description;
622           }
623         }
624         closedir($dh);
625       }
626     }
627     return($vct); 
628   }
631   /*! \brief  Adds the given mail address to the list of mail forwarders 
632    */ 
633   function addForwarder($address)
634   {
635     if(empty($address)) return;
636     if($this->acl_is_writeable("gosaMailForwardingAddress")){
637       $this->gosaMailForwardingAddress[]= $address;
638       $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
639       sort ($this->gosaMailForwardingAddress);
640       reset ($this->gosaMailForwardingAddress);
641       $this->is_modified= TRUE;
642     }else{
643       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
644     }
645   }
648   /*! \brief  Removes the given mail address from the list of mail forwarders 
649    */ 
650   function delForwarder($addresses)
651   {
652     if($this->acl_is_writeable("gosaMailForwardingAddress")){
653       $this->gosaMailForwardingAddress= array_remove_entries ($addresses, $this->gosaMailForwardingAddress);
654       $this->is_modified= TRUE;
655     }else{
656       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
657     }
658   }
661   /*! \brief  Add given mail address to the list of alternate adresses ,
662     .          check if this mal address is used, skip adding in this case 
663    */ 
664   function addAlternate($address)
665   {
666     if(empty($address)) return;
667     if($this->acl_is_writeable("gosaMailAlternateAddress")){
668       $ldap= $this->config->get_ldap_link();
669       $address= strtolower($address);
671       /* Is this address already assigned in LDAP? */
672       $ldap->cd ($this->config->current['BASE']);
673       $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=$address)".
674           "(alias=$address)(gosaMailAlternateAddress=$address)))", array("uid", "cn"));
675       if ($ldap->count() > 0){
676         $attrs= $ldap->fetch ();
677         if (!isset($attrs["uid"])) {
678           return ("!".$attrs["cn"][0]);
679         }
680         return ($attrs["uid"][0]);
681       }
682       if (!in_array($address, $this->gosaMailAlternateAddress)){
683         $this->gosaMailAlternateAddress[]= $address;
684         $this->is_modified= TRUE;
685       }
686       sort ($this->gosaMailAlternateAddress);
687       reset ($this->gosaMailAlternateAddress);
688       return ("");
689     }else{
690       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
691     }
692   }
695   /*! \brief  Removes the given mail address from the alternate addresses list 
696    */ 
697   function delAlternate($addresses)
698   {
699     if($this->acl_is_writeable("gosaMailAlternateAddress")){
700       $this->gosaMailAlternateAddress= array_remove_entries ($addresses,$this->gosaMailAlternateAddress);
701       $this->is_modified= TRUE;
702     }else{
703       msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
704     }
705   }
708   /*! \brief  Prepare importet vacation string. \
709     .         Replace placeholder like %givenName a.s.o.
710     @param  string  Vacation string
711     @return string  Completed vacation string
712    */
713   private function prepare_vacation_template($contents)
714   {
715     /* Replace attributes */
716     $attrs = array();
717     $obj   = NULL;
718     if(isset($this->parent->by_object['user'])){
719       $attrs  = $this->parent->by_object['user']->attributes;
720       $obj    = $this->parent->by_object['user'];
721     }else{
722       $obj    = new user($this->config,$this->dn);
723       $attrs  = $obj->attributes;
724     }
725     if($obj){
727       /* Replace vacation start and end time */
728       if($this->mailMethod->vacationRangeEnabled()){
729         if(preg_match("/%start/",$contents)){
730           $contents = preg_replace("/%start/",$this->gosaVacationStart,$contents);
731         }
732         if(preg_match("/%end/",$contents)){
733           $contents = preg_replace("/%end/",$this->gosaVacationStop,$contents);
734         }
735       }else{
736         if(preg_match("/%start/",$contents)){
737           $contents = preg_replace("/%start/", _("unknown"),$contents);
738         }
739         if(preg_match("/%end/",$contents)){
740           $contents = preg_replace("/%end/", _("unknown"), $contents);
741         }
742       }
744       foreach ($attrs as $val){
745         if(preg_match("/dateOfBirth/",$val)){
746           if($obj->use_dob){
747             $contents= preg_replace("/%$val/",date("Y-d-m",$obj->dateOfBirth),$contents);
748           }
749         }else {
750           $contents= preg_replace("/%$val/",
751               $obj->$val, $contents);
752         }
754       }
755     }
756     $contents = ltrim(preg_replace("/^DESC:.*$/m","",$contents),"\n ");
757     return($contents);
758   }
761   /*! \brief  Removes the mailAccount extension from ldap 
762    */  
763   function remove_from_parent()
764   {
765     /* Cancel if there's nothing to do here */
766     if (!$this->initially_was_account){
767       return;
768     }
770     /* If domain part was selectable, contruct mail address */
771     if($this->mailMethod->domainSelectionEnabled()){
772       $this->mail = $this->mail."@".$this->mailDomainPart;
773     }
775     /* Update sharedFolder dependencies. 
776        Open each shared folder and remove this account. 
777        Then Save the group to ensure that all necessary 
778         actions will be taken (imap acls updated aso.).
779      */
780     $ldap = $this->config->get_ldap_link();    
781     $ldap->cd($this->config->current['BASE']);
782     $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array("dn"));
783     while($attrs = $ldap->fetch()){
784       $grp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
785       if(isset($grp->by_object['mailgroup']) && isset($grp->by_object['group'])){
786         $grp->by_object['group']->removeUser($this->uid);
788         /* Do not save the complete group! This will quit the complete membership 
789          */
790         $grp->by_object['mailgroup']->save();
791       } 
792     }
794     /* Remove GOsa attributes */
795     plugin::remove_from_parent();
797     /* Zero arrays */
798     $this->attrs['gosaMailAlternateAddress'] = array();
799     $this->attrs['gosaMailForwardingAddress']= array();
802     $this->mailMethod->fixAttributesOnRemove();
803     $this->cleanup();
805     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
806     $ldap= $this->config->get_ldap_link();
807     $ldap->cd($this->dn);
808     $ldap->modify ($this->attrs);
810     /* Add "view" to logging class */
811     new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
812     if (!$ldap->success()){
813       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
814     }
815     
816     /* Let the mailMethod remove this mailbox, e.g. from imap and
817        update shared folder membership, ACL may need to be updated. 
818      */
819     if (!$this->is_template){
821       if(!$this->mailMethod->connect()){
822         msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"), 
823               $this->mailMethod->get_error()), ERROR_DIALOG);
824       }else{
825         if(!$this->mailMethod->deleteMailbox()){
826           msg_dialog::display(_("Mail error"), sprintf(_("Cannot remove mailbox: %s"), 
827                 $this->mailMethod->get_error()), ERROR_DIALOG);
828         }
829       }
830     }
831     $this->mailMethod->disconnect();
833     /* Optionally execute a command after we're done */
834     $this->handle_post_events("remove",array("uid" => $this->uid));
835   }
838   /*! \brief  Save the mailAccount settings to the ldap database.
839    */
840   function save()
841   {
842     $ldap= $this->config->get_ldap_link();
844     /* If domain part was selectable, contruct mail address */
845     if(!(!$this->mailMethod->isModifyableMail() && $this->initially_was_account)){
847       if($this->mailMethod->domainSelectionEnabled()){
848         $this->mail = $this->mail."@".$this->mailDomainPart;
849       }
851       /* Enforce lowercase mail address and trim whitespaces
852        */
853       $this->mail = trim(strtolower($this->mail));
854     }
857     /* Call parents save to prepare $this->attrs */
858     plugin::save();
860     /* Save arrays */
861     $this->attrs['gosaMailAlternateAddress'] = $this->gosaMailAlternateAddress;
862     $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
864     if(!$this->mailMethod->vacationRangeEnabled()){
865       $this->attrs['gosaVacationStart'] = $this->attrs['gosaVacationStop'] = array();
866     }elseif (!preg_match('/V/', $this->gosaMailDeliveryMode)){
867       unset($this->attrs['gosaVacationStart']);
868       unset($this->attrs['gosaVacationStop']);
869     } else {
870       /* Adapt values to be timestamps */
871       list($day, $month, $year)= explode('.', $this->gosaVacationStart);
872       $this->attrs['gosaVacationStart']= mktime(0,0,0,$month, $day, $year);
873       list($day, $month, $year)= explode('.', $this->gosaVacationStop);
874       $this->attrs['gosaVacationStop']= mktime(0,0,0,$month, $day, $year);
875     }
877     /* Map method attributes */ 
878     $this->mailMethod->fixAttributesOnStore();
879     
880     /* Save data to LDAP */
881     $ldap->cd($this->dn);
882     $this->cleanup();
883     $ldap->modify ($this->attrs);
885     if (!$ldap->success()){
886       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
887     }
889     /* Log last action */
890     if($this->initially_was_account){
891       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
892     }else{
893       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
894     }
896     /* Only do IMAP actions if we are not a template */
897     if (!$this->is_template){
898       $this->mailMethod->connect();
899       if(!$this->mailMethod->is_connected()){
900         msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"), 
901               $this->mailMethod->get_error()), ERROR_DIALOG);
902       }else{
903         if(!$this->mailMethod->updateMailbox()){
904           msg_dialog::display(_("Mail error"), sprintf(_("Cannot update mailbox: %s"), 
905                 $this->mailMethod->get_error()), ERROR_DIALOG);
906         }
907         if(!$this->mailMethod->setQuota($this->gosaMailQuota)){
908           msg_dialog::display(_("Mail error"), sprintf(_("Cannot write quota settings: %s"), 
909                 $this->mailMethod->get_error()), ERROR_DIALOG);
910         }
912         if (!is_integer(strpos($this->gosaMailDeliveryMode, "C"))){
914           /* Do not write sieve settings if this account is new and 
915              doesn't seem to exist.
916            */
917           if(!$this->initially_was_account && !$this->mailMethod->account_exists()){
918             @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,
919                 "Skipping sieve settings, the account doesn't seem to be created already.</b>","");
920           }else{
921             if(!$this->mailMethod->saveSieveSettings()){
922               msg_dialog::display(_("Mail error saving sieve settings"), $this->mailMethod->get_error(), ERROR_DIALOG);
923             }
924           }
925         }else{
926           if ($this->sieve_management) {
927             @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, 
928                 "User uses an own sieve script, skipping sieve update.".$str."</b>","");
929             $this->sieve_management->save();
930           }
931         }
932       }
933     }
934     $this->mailMethod->disconnect();
936     /* Update sharedFolder dependencies.
937        Open each shared folder and remove this account.
938        Then Save the group to ensure that all necessary
939        actions will be taken (imap acls updated aso.).
940      */
941     if(!$this->initially_was_account){
942       $ldap = $this->config->get_ldap_link();
943       $ldap->cd($this->config->current['BASE']);
944       $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array("dn"));
945       while($attrs = $ldap->fetch()){
946         $grp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
947         if(isset($grp->by_object['mailgroup'])){
948           /* Do not save the complete group! This will quit the complete membership
949            */
950           $grp->by_object['mailgroup']->save();
951         }
952       }
953     }
955     /* Optionally execute a command after we're done */
956     if ($this->initially_was_account == $this->is_account){
957       if ($this->is_modified){
958         $this->handle_post_events("modify", array("uid" => $this->uid));
959       }
960     } else {
961       $this->handle_post_events("add", array("uid" => $this->uid));
962     }
963   }
966   /*! \brief  Check given values 
967    */
968   function check()
969   {
970     if(!$this->is_account){
971       return(array());
972     }
974     $ldap= $this->config->get_ldap_link();
976     /* Call common method to give check the hook */
977     $message= plugin::check();
979     if(empty($this->gosaMailServer)){
980       $message[]= msgPool::noserver(_("Mail"));
981     }
983     /* Mail address checks */
984     $mail = $this->mail;
985     if(!(!$this->mailMethod->isModifyableMail() && $this->initially_was_account)){
987       if($this->mailMethod->domainSelectionEnabled()){
988         $mail.= "@".$this->mailDomainPart;
989       }
991       if (empty($mail)){
992         $message[]= msgPool::required(_("Primary address"));
993       }
994       if ($this->is_template){
995         if (!tests::is_email($mail, TRUE)){
996           $message[]= msgPool::invalid(_("Mail address"),"","","%givenName.%sn@your-domain.com");
997         }
998       } else {
999         if (!tests::is_email($mail)){
1000           $message[]= msgPool::invalid(_("Mail address"),"","","your-address@your-domain.com");
1001         }
1002       }
1004       /* Check if this mail address is already in use */
1005       $ldap->cd($this->config->current['BASE']);
1006       $filter = "(&(!(objectClass=gosaUserTemplate))(!(uid=".$this->uid."))".
1007         "(objectClass=gosaMailAccount)".
1008         "(|(mail=".$mail.")(alias=".$mail.")(gosaMailAlternateAddress=".$mail.")))";
1009       $ldap->search($filter,array("uid", "cn"));
1010       if ($ldap->count() != 0){
1011         $entry= $ldap->fetch();
1012         $addon= "";
1013         if (!isset($entry['uid'])) {
1014            $addon= sprintf(_("Address is already in use by group '%s'."), $entry['cn'][0]);
1015         } else {
1016            $addon= sprintf(_("Address is already in use by user '%s'."), $entry['uid'][0]);
1017         }
1018         $message[]= msgPool::duplicated(_("Mail address"))."<br><br><i>$addon</i>";
1019       }
1020     }
1023     /* Check quota */
1024     if ($this->gosaMailQuota != '' && $this->acl_is_writeable("gosaMailQuota")){
1025       if (!is_numeric($this->gosaMailQuota)) {
1026         $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
1027       } else {
1028         $this->gosaMailQuota= (int) $this->gosaMailQuota;
1029       }
1030     }
1032     /* Check rejectsize for integer */
1033     if ($this->gosaMailMaxSize != '' && $this->acl_is_writeable("gosaMailMaxSize")){
1034       if (!is_numeric($this->gosaMailMaxSize)){
1035         $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
1036       } else {
1037         $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
1038       }
1039     }
1041     /* Need gosaMailMaxSize if use_mailsize_limit is checked */
1042     if (is_integer(strpos($this->gosaMailDeliveryMode, "R")) && $this->gosaMailMaxSize == ""){
1043       $message[]= msgPool::required(_("Mail reject size"));
1044     }
1046     if((preg_match("/S/", $this->gosaMailDeliveryMode))&&(empty($this->gosaSpamMailbox))) {
1047       $message[]= msgPool::required(_("Spam folder"));
1048     }
1050     if ($this->mailMethod->vacationRangeEnabled() && preg_match('/V/', $this->gosaMailDeliveryMode)){ 
1052       /* Check date strings */
1053       $state= true;
1054       if ($this->gosaVacationStart == "" || !tests::is_date($this->gosaVacationStart)) {
1055         $message[]= msgPool::invalid(_("from"),$this->gosaVacationStart);
1056         $state= false;
1057       }
1058       if ($this->gosaVacationStart == "" || !tests::is_date($this->gosaVacationStop)) {
1059         $message[]= msgPool::invalid(_("to"),$this->gosaVacationStop);
1060         $state= false;
1061       }
1063       #TODO: take care of date format
1064       if ($state) {
1065         list($day, $month, $year)= explode('.', $this->gosaVacationStart);
1066         $start= mktime(0,0,0,$month, $day, $year);
1067         list($day, $month, $year)= explode('.', $this->gosaVacationStop);
1068         $stop= mktime(0,0,0,$month, $day, $year);
1069         if($start > $stop){
1070           $message[]= msgPool::invalid(_("Vacation interval"));
1071         }
1072       }
1073     }
1074     return($message);
1075   }
1078   /*! \brief  Adapt from template, using 'dn' 
1079    */
1080   function adapt_from_template($dn, $skip= array())
1081   {
1082     plugin::adapt_from_template($dn, $skip);
1084     foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
1086       if (in_array($val, $skip)){
1087         continue;
1088       }
1090       $this->$val= array();
1091       if (isset($this->attrs["$val"]["count"])){
1092         for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
1093           $value= $this->attrs["$val"][$i];
1094           foreach (array("sn", "givenName", "uid") as $repl){
1095             if (preg_match("/%$repl/i", $value)){
1096               $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
1097             }
1098           }
1099           array_push($this->$val, strtolower(rewrite($value)));
1100         }
1101       }
1102     }
1103     $this->mail= strtolower(rewrite($this->mail));
1105     // Fix mail address when using templates
1106     if($this->is_account && $this->mailMethod->domainSelectionEnabled()){
1107       $this->mailDomainPart = preg_replace("/^[^@]*+@/","",$this->mail);
1108       $this->mail = preg_replace("/@.*$/","\\1",$this->mail);
1109       if(!in_array($this->mailDomainPart,$this->mailDomainParts)){
1110         $this->mailDomainParts[] = $this->mailDomainPart;
1111       }
1112     }
1113   }
1116   /*! \brief  Creates the mail part for the copy & paste dialog 
1117    */ 
1118   function getCopyDialog()
1119   {
1120     if(!$this->is_account) return("");
1121     $smarty = get_smarty();
1122     $smarty->assign("mail",$this->mail);
1123     $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress);
1124     $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress);
1125     $str = $smarty->fetch(get_template_path("copypaste.tpl",TRUE, dirname(__FILE__)));
1127     $ret = array();
1128     $ret['status'] = "";
1129     $ret['string'] = $str;
1130     return($ret);
1131   }
1133     
1134   /*! \brief  save_object for copy&paste vars 
1135    */  
1136   function saveCopyDialog()
1137   {
1138     if(!$this->is_account) return;
1140     /* Execute to save mailAlternateAddress && gosaMailForwardingAddress */
1141     $this->execute();
1142     if(isset($_POST['mail'])){
1143       $this->mail = $_POST['mail'];
1144     }
1145   }
1147   
1148   /*! \brief  Prepare this account to be copied 
1149    */
1150   function PrepareForCopyPaste($source)
1151   {
1152     plugin::PrepareForCopyPaste($source);
1154     /* Reset alternate mail addresses */
1155     $this->gosaMailAlternateAddress = array();
1156   }
1159   /*! \brief  Prepare this class the be useable when editing multiple users at once 
1160    */
1161   function get_multi_edit_values()
1162   {
1163     $ret = plugin::get_multi_edit_values();
1164     if(in_array("gosaMailQuota",$this->multi_boxes)){
1165       $ret['gosaMailQuota'] = $this->gosaMailQuota;
1166     }
1167     $flag_add = $flag_remove = array();
1168     $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1169     $opts = array(
1170         "R"   => "use_mailsize_limit",
1171         "S"   => "use_spam_filter",
1172         "L"   => "only_local",
1173         "V"   => "use_vacation",
1174         "C"   => "own_script",
1175         "I"   => "drop_own_mails");
1176     foreach($opts as $flag => $post){
1177       if(in_array($post, $this->multi_boxes)){
1178         if(preg_match("/".$flag."/",$tmp)){
1179           $flag_add[] = $flag;
1180         }else{
1181           $flag_remove[] = $flag;
1182         }
1183       }
1184     }
1185     $ret['flag_add'] = $flag_add;
1186     $ret['flag_remove'] = $flag_remove;
1188     if($this->mailMethod->vacationRangeEnabled()){
1189       if(in_array("V",$flag_add)){
1190         $ret['gosaVacationStart'] =  $this->gosaVacationStart = $_POST['gosaVacationStart'];
1191         $ret['gosaVacationStop'] =  $this->gosaVacationStop = $_POST['gosaVacationStop'];
1192       }
1193     }
1194     return($ret);
1195   }
1198   /*! \brief  Check given input for multiple user edit 
1199    */
1200   function multiple_check()
1201   {
1202     $message = plugin::multiple_check();
1204     if(empty($this->gosaMailServer) && in_array("gosaMailServer",$this->multi_boxes)){
1205       $message[]= msgPool::noserver(_("Mail"));
1206     }
1208     /* Check quota */
1209     if ($this->gosaMailQuota != ''  && in_array("gosaMailQuota",$this->multi_boxes)){
1210       if (!is_numeric($this->gosaMailQuota)) {
1211         $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
1212       } else {
1213         $this->gosaMailQuota= (int) $this->gosaMailQuota;
1214       }
1215     }
1217     /* Check rejectsize for integer */
1218     if ($this->gosaMailMaxSize != '' && in_array("gosaMailMaxSize",$this->multi_boxes)){
1219       if (!is_numeric($this->gosaMailMaxSize)){
1220         $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
1221       } else {
1222         $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
1223       }
1224     }
1226     if(empty($this->gosaSpamMailbox) && in_array("gosaSpamMailbox",$this->multi_boxes)){
1227       $message[]= msgPool::required(_("Spam folder"));
1228     }
1230     if ($this->mailMethod->vacationRangeEnabled() && preg_match('/V/', $this->gosaMailDeliveryMode)){ 
1232       /* Check date strings */
1233       $state= true;
1234       if ($this->gosaVacationStart == "" || !tests::is_date($this->gosaVacationStart)) {
1235         $message[]= msgPool::invalid(_("from"),$this->gosaVacationStart);
1236         $state= false;
1237       }
1238       if ($this->gosaVacationStart == "" || !tests::is_date($this->gosaVacationStop)) {
1239         $message[]= msgPool::invalid(_("to"),$this->gosaVacationStop);
1240         $state= false;
1241       }
1243       #TODO: take care of date format
1244       if ($state) {
1245         list($day, $month, $year)= explode('.', $this->gosaVacationStart);
1246         $start= mktime(0,0,0,$month, $day, $year);
1247         list($day, $month, $year)= explode('.', $this->gosaVacationStop);
1248         $stop= mktime(0,0,0,$month, $day, $year);
1249         if($start > $stop){
1250           $message[]= msgPool::invalid(_("Vacation interval"));
1251         }
1252       }
1253     }
1254     return($message);
1255   }
1257   
1258   /*! \brief  ...
1259    */
1260   function set_multi_edit_values($values)
1261   {
1262     plugin::set_multi_edit_values($values);
1263     $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1264     if(isset($values['flag_add'])){
1265       foreach($values['flag_add'] as $flag){
1266         if(!preg_match("/".$flag."/",$tmp)){
1267           $tmp .= $flag;
1268         }
1269       }
1270     }
1271     if(isset($values['flag_remove'])){
1272       foreach($values['flag_remove'] as $flag){
1273         if(preg_match("/".$flag."/",$tmp)){
1274           $tmp = preg_replace("/".$flag."/","",$tmp);
1275         }
1276       }
1277     }
1278     $this->gosaMailDeliveryMode = "[".$tmp."]";
1280     /* Set vacation message and replace placeholder like %givenName
1281      */
1282     if(isset($values['gosaVacationMessage'])){
1283       $this->gosaVacationMessage = $this->prepare_vacation_template($values['gosaVacationMessage']);
1284     }
1285   }
1288   /*! \brief  Initialize plugin to be used as multiple edit class. 
1289    */
1290   function init_multiple_support($attrs,$all)
1291   {
1292     plugin::init_multiple_support($attrs,$all);
1293     if(isset($this->multi_attrs['gosaMailQuota'])){
1294       $this->gosaMailQuota = $this->multi_attrs['gosaMailQuota'];
1295     }
1296   }
1298  
1299   /*! \brief
1300    */
1301   function get_multi_init_values()
1302   {
1303     $attrs = plugin::get_multi_init_values();
1304     $attrs['gosaMailQuota'] = $this->gosaMailQuota;
1305     return($attrs);
1306   }
1309   /*! \brief  Display multiple edit dialog 
1310    */
1311   function multiple_execute()
1312   {
1313     return($this->execute());
1314   }
1316   
1317   /*! \brief  Save posts from multiple edit dialog 
1318    */
1319   function multiple_save_object()
1320   {
1321     plugin::multiple_save_object();
1323     $this->save_object();
1324     foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
1325       if(isset($_POST["use_".$attr])){
1326         $this->multi_boxes[] = $attr;
1327       }
1328     }
1329   }
1332   /*! \brief  Creates the user names for the add_local_forward dialog
1333    */
1334   function make_name($attrs)
1335   {
1336     $name= "";
1337     if (isset($attrs['sn'][0])){
1338       $name= $attrs['sn'][0];
1339     }
1340     if (isset($attrs['givenName'][0])){
1341       if ($name != ""){
1342         $name.= ", ".$attrs['givenName'][0];
1343       } else {
1344         $name.= $attrs['givenName'][0];
1345       }
1346     }
1347     if ($name != ""){
1348       $name.= " ";
1349     }
1351     return ($name);
1352   }
1355   function allow_remove()
1356   {
1357     $resason = "";
1358     if(!$this->mailMethod->allow_remove($reason)){
1359       return($reason);
1360     }
1361     return("");
1362   }
1366   /*! \brief  ACL settings 
1367    */
1368   static function plInfo()
1369   {
1370     return (array(
1371           "plShortName"     => _("Mail"),
1372           "plDescription"   => _("Mail settings"),
1373           "plSelfModify"    => TRUE,
1374           "plDepends"       => array("user"),                     // This plugin depends on
1375           "plPriority"      => 4,                                 // Position in tabs
1376           "plSection"     => array("personal" => _("My account")),
1377           "plCategory"    => array("users"),
1378           "plOptions"       => array(),
1380           "plProvidedAcls"  => array(
1381             "mail"                      =>  _("Mail address"),
1382             "gosaMailServer"            =>  _("Mail server"),
1383             "gosaMailQuota"             =>  _("Quota size"),
1385             "gosaMailDeliveryModeV"     =>  _("Add vacation information"),  // This is flag of gosaMailDeliveryMode
1386             "gosaVacationMessage"       =>  _("Vacation message"),
1388             "gosaMailDeliveryModeS"     =>  _("Use spam filter"),           // This is flag of gosaMailDeliveryMode
1389             "gosaSpamSortLevel"         =>  _("Spam level"),
1390             "gosaSpamMailbox"           =>  _("Spam mail box"),
1392             "sieveManagement"           =>  _("Sieve management"),
1394             "gosaMailDeliveryModeR"     =>  _("Reject due to mailsize"),    // This is flag of gosaMailDeliveryMode
1395             "gosaMailMaxSize"           =>  _("Mail max size"),
1397             "gosaMailForwardingAddress" =>  _("Forwarding address"),
1398             "gosaMailDeliveryModeL"     =>  _("Local delivery"),            // This is flag of gosaMailDeliveryMode
1399             "gosaMailDeliveryModeI"     =>  _("No delivery to own mailbox "),     // This is flag of gosaMailDeliveryMode
1400             "gosaMailAlternateAddress"  =>  _("Mail alternative addresses"),
1402             "gosaMailForwardingAddress" =>  _("Forwarding address"),
1403             "gosaMailDeliveryModeC"     =>  _("Use custom sieve script"))   // This is flag of gosaMailDeliveryMode
1404               ));
1405   }
1410 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1411 ?>