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
127 */
128 if(empty($this->gosaVacationStart)){
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 }
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 }
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\"> <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 if ($user != $ui->username){
371 msg_dialog::display(_("Error"), msgPool::duplicated(_("Mail address"))." ".
372 sprintf(_("Address is already in use by user '%s'."), $user), ERROR_DIALOG);
373 }
374 }
375 }
376 if (isset($_POST['delete_alternate']) && isset($_POST['alternates_list'])){
377 $this->delAlternate ($_POST['alternates_list']);
378 }
380 /****************
381 SMARTY- Assign smarty variables
382 ****************/
383 $smarty = get_smarty();
384 $smarty->assign("initially_was_account", $this->initially_was_account);
385 $smarty->assign("isModifyableMail" , $this->mailMethod->isModifyableMail());
386 $smarty->assign("isModifyableServer", $this->mailMethod->isModifyableServer());
387 $smarty->assign("mailEqualsCN", $this->mailMethod->mailEqualsCN());
389 $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
390 $tmp = $this->plInfo();
391 foreach($tmp['plProvidedAcls'] as $name => $transl){
392 $smarty->assign("$name"."ACL", $this->getacl($name,$SkipWrite));
393 }
394 foreach($this->attributes as $attr){
395 $smarty->assign($attr,$this->$attr);
396 }
397 $smarty->assign("quotaEnabled", $this->mailMethod->quotaEnabled());
398 if($this->mailMethod->quotaEnabled()){
399 $smarty->assign("quotaUsage", mailMethod::quota_to_image($this->quotaUsage,$this->gosaMailQuota));
400 $smarty->assign("gosaMailQuota",$this->gosaMailQuota);
401 }
402 $smarty->assign("domainSelectionEnabled", $this->mailMethod->domainSelectionEnabled());
403 $smarty->assign("MailDomains", $this->mailDomainParts);
404 $smarty->assign("MailDomain" , $this->mailDomainPart);
405 $smarty->assign("MailServers", $this->mailMethod->getMailServers());
406 $smarty->assign("allowSieveManagement", $this->mailMethod->allowSieveManagement());
407 $smarty->assign("own_script", $this->sieveManagementUsed);
409 print_a($this->multi_boxes);
411 /* _Multiple users vars_ */
412 foreach($this->attributes as $attr){
413 $u_attr = "use_".$attr;
414 $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
415 }
416 foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
417 $u_attr = "use_".$attr;
418 $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
419 }
422 /****************
423 SMARTY- Assign flags
424 ****************/
426 $types = array(
427 "V"=>"use_vacation",
428 "S"=>"use_spam_filter",
429 "R"=>"use_mailsize_limit",
430 "I"=>"drop_own_mails",
431 "C"=>"own_script");
432 foreach($types as $option => $varname){
433 if (preg_match("/".$option."/", $this->gosaMailDeliveryMode)) {
434 $smarty->assign($varname, "checked");
435 } else {
436 $smarty->assign($varname, "");
437 }
438 }
439 if (!preg_match("/L/", $this->gosaMailDeliveryMode)) {
440 $smarty->assign("only_local", "checked");
441 } else {
442 $smarty->assign("only_local", "");
443 }
446 /****************
447 Smarty- Vacation settings
448 ****************/
449 $smarty->assign("rangeEnabled", FALSE);
450 $smarty->assign("template", "");
451 if (count($this->vacationTemplates)){
452 $smarty->assign("show_templates", "true");
453 $smarty->assign("vacationtemplates", $this->vacationTemplates);
454 if (isset($_POST['vacation_template'])){
455 $smarty->assign("template", $_POST['vacation_template']);
456 }
457 } else {
458 $smarty->assign("show_templates", "false");
459 }
461 /* Vacation range assigments
462 */
463 if($this->mailMethod->vacationRangeEnabled()){
464 $smarty->assign("rangeEnabled", TRUE);
465 if($this->gosaVacationStop ==0){
466 $date= getdate(time());
467 $date["mday"]++;
468 }else{
469 $date= getdate($this->gosaVacationStop);
470 }
471 $smarty->assign("end_day", $date["mday"]);
472 $smarty->assign("end_month", $date["mon"]-1);
473 $smarty->assign("end_year", $date["year"]);
475 if($this->gosaVacationStart == 0){
476 $date= getdate(time());
477 }else{
478 $date= getdate($this->gosaVacationStart);
479 }
480 $smarty->assign("start_day", $date["mday"]);
481 $smarty->assign("start_month", $date["mon"]-1);
482 $smarty->assign("start_year", $date["year"]);
483 $days= array();
484 for($d= 1; $d<32; $d++){
485 $days[$d]= $d;
486 }
487 $years= array();
488 for($y= $date['year']-10; $y<$date['year']+10; $y++){
489 $years[]= $y;
490 }
491 $months= msgPool::months();
492 $smarty->assign("months", $months);
493 $smarty->assign("years", $years);
494 $smarty->assign("days", $days);
496 }
498 /* fill filter settings
499 */
500 $smarty->assign("spamlevel", $this->SpamLevels);
501 $smarty->assign("spambox" , $this->MailBoxes);
503 $smarty->assign("multiple_support",$this->multiple_support_active);
504 return($display.$smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
505 }
509 /* Save data to object */
510 function save_object()
511 {
512 if (isset($_POST['mailTab'])){
514 /* Save ldap attributes */
515 $mail = $this->mail;
516 $server = $this->gosaMailServer;
517 plugin::save_object();
519 if(!$this->mailMethod->isModifyableServer() && $this->initially_was_account){
520 $this->gosaMailServer = $server;
521 }
523 if(!$this->mailMethod->isModifyableMail() && $this->initially_was_account){
524 $this->mail = $mail;
525 }else{
527 /* Get posted mail domain part, if necessary
528 */
529 if($this->mailMethod->domainSelectionEnabled() && isset($_POST['MailDomain'])){
530 if(in_array(get_post('MailDomain'), $this->mailDomainParts)){
531 $this->mailDomainPart = get_post('MailDomain');
532 }
533 }
534 }
536 /* Import vacation message?
537 */
538 if (isset($_POST["import_vacation"]) && isset($this->vacationTemplates[$_POST["vacation_template"]])){
539 if($this->multiple_support_active){
540 $contents = ltrim(preg_replace("/^DESC:.*$/m","",file_get_contents($_POST["vacation_template"])));
541 }else{
542 $contents = $this->prepare_vacation_template(file_get_contents($_POST["vacation_template"]));
543 }
544 $this->gosaVacationMessage= htmlspecialchars($contents);
545 }
547 /* Handle flags
548 */
549 if(isset($_POST['own_script'])){
550 if(!preg_match("/C/",$this->gosaMailDeliveryMode)){
551 $str= preg_replace("/[\[\]]/","",$this->gosaMailDeliveryMode);
552 $this->gosaMailDeliveryMode = "[".$str."C]";
553 }
554 }else{
556 /* Assemble mail delivery mode
557 The mode field in ldap consists of values between braces, this must
558 be called when 'mail' is set, because checkboxes may not be set when
559 we're in some other dialog.
561 Example for gosaMailDeliveryMode [LR ]
562 L - Local delivery
563 R - Reject when exceeding mailsize limit
564 S - Use spam filter
565 V - Use vacation message
566 C - Use custm sieve script
567 I - Only insider delivery */
569 $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
572 /* Handle delivery flags */
573 if($this->acl_is_writeable("gosaMailDeliveryModeL")){
574 if(!preg_match("/L/",$tmp) && !isset($_POST['only_local'])){
575 $tmp.="L";
576 }elseif(preg_match("/L/",$tmp) && isset($_POST['only_local'])){
577 $tmp = preg_replace("/L/","",$tmp);
578 }
579 }
580 $opts = array(
581 "R" => "use_mailsize_limit",
582 "S" => "use_spam_filter",
583 "V" => "use_vacation",
584 "C" => "own_script",
585 "I" => "drop_own_mails");
587 foreach($opts as $flag => $post){
588 if($this->acl_is_writeable("gosaMailDeliveryMode".$flag)){
589 if(!preg_match("/".$flag."/",$tmp) && isset($_POST[$post])){
590 $tmp.= $flag;
591 }elseif(preg_match("/".$flag."/",$tmp) && !isset($_POST[$post])){
592 $tmp = preg_replace("/".$flag."/","",$tmp);
593 }
594 }
595 }
597 $tmp= "[$tmp]";
598 if ($this->gosaMailDeliveryMode != $tmp){
599 $this->is_modified= TRUE;
600 }
601 $this->gosaMailDeliveryMode= $tmp;
602 if($this->mailMethod->vacationRangeEnabled()){
603 if($this->acl_is_writeable("gosaVacationMessage") && preg_match("/V/",$this->gosaMailDeliveryMode)){
604 if(isset($_POST['gosaVacationStart'])){
605 $this->gosaVacationStart = $_POST['gosaVacationStart'];
606 }
607 if(isset($_POST['gosaVacationStop'])){
608 $this->gosaVacationStop = $_POST['gosaVacationStop'];
609 }
610 }
611 }
612 }
613 }
614 }
617 /*! \brief Parse vacation templates and build up an array
618 containing 'filename' => 'description'.
619 Used to fill vacation dropdown box.
620 @return Array All useable vacation templates.
621 */
622 function get_vacation_templates()
623 {
624 $vct = array();
625 if ($this->config->get_cfg_value("vacationTemplateDirectory") != ""){
626 $dir= $this->config->get_cfg_value("vacationTemplateDirectory");
627 if (is_dir($dir) && is_readable($dir)){
628 $dh = opendir($dir);
629 while($file = readdir($dh)){
630 $description= "";
631 if (is_file($dir."/".$file)){
632 $fh = fopen($dir."/".$file, "r");
633 $line= fgets($fh, 256);
634 if (!preg_match('/^DESC:/', $line)){
635 msg_dialog::display(_("Configuration error"), sprintf(_("No DESC tag in vacation template '%s'!"), $file), ERROR_DIALOG);
636 }else{
637 $description= trim(preg_replace('/^DESC:\s*/', '', $line));
638 }
639 fclose ($fh);
640 }
641 if ($description != ""){
642 $vct["$dir/$file"]= $description;
643 }
644 }
645 closedir($dh);
646 }
647 }
648 return($vct);
649 }
652 /*! \brief Adds the given mail address to the list of mail forwarders
653 */
654 function addForwarder($address)
655 {
656 if(empty($address)) return;
657 if($this->acl_is_writeable("gosaMailForwardingAddress")){
658 $this->gosaMailForwardingAddress[]= $address;
659 $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
660 sort ($this->gosaMailForwardingAddress);
661 reset ($this->gosaMailForwardingAddress);
662 $this->is_modified= TRUE;
663 }else{
664 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
665 }
666 }
669 /*! \brief Removes the given mail address from the list of mail forwarders
670 */
671 function delForwarder($addresses)
672 {
673 if($this->acl_is_writeable("gosaMailForwardingAddress")){
674 $this->gosaMailForwardingAddress= array_remove_entries ($addresses, $this->gosaMailForwardingAddress);
675 $this->is_modified= TRUE;
676 }else{
677 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
678 }
679 }
682 /*! \brief Add given mail address to the list of alternate adresses ,
683 . check if this mal address is used, skip adding in this case
684 */
685 function addAlternate($address)
686 {
687 if(empty($address)) return;
688 if($this->acl_is_writeable("gosaMailAlternateAddress")){
689 $ldap= $this->config->get_ldap_link();
690 $address= strtolower($address);
692 /* Is this address already assigned in LDAP? */
693 $ldap->cd ($this->config->current['BASE']);
694 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=$address)".
695 "(alias=$address)(gosaMailAlternateAddress=$address)))", array("uid"));
696 if ($ldap->count() > 0){
697 $attrs= $ldap->fetch ();
698 return ($attrs["uid"][0]);
699 }
700 if (!in_array($address, $this->gosaMailAlternateAddress)){
701 $this->gosaMailAlternateAddress[]= $address;
702 $this->is_modified= TRUE;
703 }
704 sort ($this->gosaMailAlternateAddress);
705 reset ($this->gosaMailAlternateAddress);
706 return ("");
707 }else{
708 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
709 }
710 }
713 /*! \brief Removes the given mail address from the alternate addresses list
714 */
715 function delAlternate($addresses)
716 {
717 if($this->acl_is_writeable("gosaMailAlternateAddress")){
718 $this->gosaMailAlternateAddress= array_remove_entries ($addresses,$this->gosaMailAlternateAddress);
719 $this->is_modified= TRUE;
720 }else{
721 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
722 }
723 }
726 /*! \brief Prepare importet vacation string. \
727 . Replace placeholder like %givenName a.s.o.
728 @param string Vacation string
729 @return string Completed vacation string
730 */
731 private function prepare_vacation_template($contents)
732 {
733 /* Replace attributes */
734 $attrs = array();
735 $obj = NULL;
736 if(isset($this->parent->by_object['user'])){
737 $attrs = $this->parent->by_object['user']->attributes;
738 $obj = $this->parent->by_object['user'];
739 }else{
740 $obj = new user($this->config,$this->dn);
741 $attrs = $obj->attributes;
742 }
743 if($obj){
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 /* Replace vacation start and end time */
755 if(preg_match("/%start/",$contents)){
756 $contents = preg_replace("/%start/",date("d.m.Y",$this->gosaVacationStart),$contents);
757 }
758 if(preg_match("/%end/",$contents)){
759 $contents = preg_replace("/%end/",date("d.m.Y",$this->gosaVacationStop),$contents);
760 }
761 }
762 }
763 $contents = ltrim(preg_replace("/^DESC:.*$/m","",$contents),"\n ");
764 return($contents);
765 }
768 /*! \brief Displays a dialog that allows mail address selection.
769 */
770 function display_forward_dialog()
771 {
772 restore_error_handler();
774 $smarty = get_smarty();
775 $ldap= $this->config->get_ldap_link();
777 /* Save data */
778 $mailfilter= session::get("mailfilter");
779 foreach( array("depselect", "muser", "regex") as $type){
780 if (isset($_POST[$type])){
781 $mailfilter[$type]= $_POST[$type];
782 }
783 }
784 if (isset($_GET['search'])){
785 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
786 if ($s == "**"){
787 $s= "*";
788 }
789 $mailfilter['regex']= $s;
790 }
791 session::set("mailfilter", $mailfilter);
793 /* Get actual list */
794 $mailusers= array ();
795 if ($mailfilter['regex'] != '*' && $mailfilter['regex'] != ""){
796 $regex= $mailfilter['regex'];
797 $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
798 } else {
799 $filter= "";
800 }
801 if ($mailfilter['muser'] != ""){
802 $user= $mailfilter['muser'];
803 $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
804 }
806 /* Add already present people to the filter */
807 $exclude= "";
808 foreach ($this->gosaMailForwardingAddress as $mail){
809 $exclude.= "(mail=$mail)";
810 }
811 if ($exclude != ""){
812 $filter.= "(!(|$exclude))";
813 }
814 $res= get_list("(&(objectClass=gosaMailAccount)$filter)", "users", $mailfilter['depselect'],
815 array("sn", "mail", "givenName"), GL_SIZELIMIT | GL_SUBSEARCH);
816 $ldap->cd($mailfilter['depselect']);
817 $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
818 while ($attrs= $ldap->fetch()){
819 if(preg_match('/%/', $attrs['mail'][0])){
820 continue;
821 }
822 $name= $this->make_name($attrs);
823 $mailusers[$attrs['mail'][0]]= $name."<".
824 $attrs['mail'][0].">";
825 }
826 natcasesort ($mailusers);
827 reset ($mailusers);
829 /* Show dialog */
830 $smarty->assign("search_image", get_template_path('images/lists/search.png'));
831 $smarty->assign("usearch_image", get_template_path('images/lists/search-user.png'));
832 $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
833 $smarty->assign("infoimage", get_template_path('images/info.png'));
834 $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
835 $smarty->assign("mailusers", $mailusers);
836 if (isset($_POST['depselect'])){
837 $smarty->assign("depselect", $_POST['depselect']);
838 }
839 $smarty->assign("deplist", $this->config->idepartments);
840 $smarty->assign("apply", apply_filter());
841 $smarty->assign("alphabet", generate_alphabet());
842 $smarty->assign("hint", print_sizelimit_warning());
843 foreach( array("depselect", "muser", "regex") as $type){
844 $smarty->assign("$type", $mailfilter[$type]);
845 }
846 $smarty->assign("hint", print_sizelimit_warning());
847 $display= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE, dirname(__FILE__)));
848 return ($display);
849 }
852 /*! \brief Removes the mailAccount extension from ldap
853 */
854 function remove_from_parent()
855 {
856 /* Cancel if there's nothing to do here */
857 if (!$this->initially_was_account){
858 return;
859 }
861 /* If domain part was selectable, contruct mail address */
862 if($this->mailMethod->domainSelectionEnabled()){
863 $this->mail = $this->mail."@".$this->mailDomainPart;
864 }
866 /* Update sharedFolder dependencies.
867 Open each shared folder and remove this account.
868 Then Save the group to ensure that all necessary
869 actions will be taken (imap acls updated aso.).
870 */
871 $ldap = $this->config->get_ldap_link();
872 $ldap->cd($this->config->current['BASE']);
873 $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array("dn"));
874 while($attrs = $ldap->fetch()){
875 $grp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
876 if(isset($grp->by_object['mailgroup']) && isset($grp->by_object['group'])){
877 $grp->by_object['group']->removeUser($this->uid);
879 /* Do not save the complete group! This will quit the complete membership
880 */
881 $grp->by_object['mailgroup']->save();
882 }
883 }
885 /* Remove GOsa attributes */
886 plugin::remove_from_parent();
888 /* Zero arrays */
889 $this->attrs['gosaMailAlternateAddress'] = array();
890 $this->attrs['gosaMailForwardingAddress']= array();
893 $this->mailMethod->fixAttributesOnRemove();
894 $this->cleanup();
896 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
897 $ldap= $this->config->get_ldap_link();
898 $ldap->cd($this->dn);
899 $ldap->modify ($this->attrs);
901 /* Add "view" to logging class */
902 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
903 if (!$ldap->success()){
904 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
905 }
907 /* Let the mailMethod remove this mailbox, e.g. from imap and
908 update shared folder membership, ACL may need to be updated.
909 */
910 if (!$this->is_template){
912 if(!$this->mailMethod->connect()){
913 msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"),
914 $this->mailMethod->get_error()), ERROR_DIALOG);
915 }else{
916 if(!$this->mailMethod->deleteMailbox()){
917 msg_dialog::display(_("Mail error"), sprintf(_("Cannot remove mailbox: %s"),
918 $this->mailMethod->get_error()), ERROR_DIALOG);
919 }
920 }
921 }
922 $this->mailMethod->disconnect();
924 /* Optionally execute a command after we're done */
925 $this->handle_post_events("remove",array("uid" => $this->uid));
926 }
929 /*! \brief Save the mailAccount settings to the ldap database.
930 */
931 function save()
932 {
933 $ldap= $this->config->get_ldap_link();
935 /* If domain part was selectable, contruct mail address */
936 if(!(!$this->mailMethod->isModifyableMail() && $this->initially_was_account)){
938 if($this->mailMethod->domainSelectionEnabled()){
939 $this->mail = $this->mail."@".$this->mailDomainPart;
940 }
942 /* Enforce lowercase mail address and trim whitespaces
943 */
944 $this->mail = trim(strtolower($this->mail));
945 }
948 /* Call parents save to prepare $this->attrs */
949 plugin::save();
951 /* Save arrays */
952 $this->attrs['gosaMailAlternateAddress'] = $this->gosaMailAlternateAddress;
953 $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
955 if(!$this->mailMethod->vacationRangeEnabled()){
956 $this->attrs['gosaVacationStart'] = $this->attrs['gosaVacationStop'] = array();
957 }elseif (!preg_match('/V/', $this->gosaMailDeliveryMode)){
958 unset($this->attrs['gosaVacationStart']);
959 unset($this->attrs['gosaVacationStop']);
960 }
962 /* Map method attributes */
963 $this->mailMethod->fixAttributesOnStore();
965 /* Save data to LDAP */
966 $ldap->cd($this->dn);
967 $this->cleanup();
968 $ldap->modify ($this->attrs);
970 if (!$ldap->success()){
971 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
972 }
974 /* Log last action */
975 if($this->initially_was_account){
976 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
977 }else{
978 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
979 }
981 /* Only do IMAP actions if we are not a template */
982 if (!$this->is_template){
983 $this->mailMethod->connect();
984 if(!$this->mailMethod->is_connected()){
985 msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"),
986 $this->mailMethod->get_error()), ERROR_DIALOG);
987 }else{
988 if(!$this->mailMethod->updateMailbox()){
989 msg_dialog::display(_("Mail error"), sprintf(_("Cannot update mailbox: %s"),
990 $this->mailMethod->get_error()), ERROR_DIALOG);
991 }
992 if(!$this->mailMethod->setQuota($this->gosaMailQuota)){
993 msg_dialog::display(_("Mail error"), sprintf(_("Cannot write quota settings: %s"),
994 $this->mailMethod->get_error()), ERROR_DIALOG);
995 }
997 if (!is_integer(strpos($this->gosaMailDeliveryMode, "C"))){
999 /* Do not write sieve settings if this account is new and
1000 doesn't seem to exist.
1001 */
1002 if(!$this->initially_was_account && !$this->mailMethod->account_exists()){
1003 @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,
1004 "Skipping sieve settings, the account doesn't seem to be created already.</b>","");
1005 }else{
1006 if(!$this->mailMethod->saveSieveSettings()){
1007 msg_dialog::display(_("Mail error"), $this->mailMethod->get_error(), ERROR_DIALOG);
1008 }
1009 }
1010 }else{
1011 echo "Check sieve management here";
1012 @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,
1013 "User uses an own sieve script, skipping sieve update.".$str."</b>","");
1014 }
1015 }
1016 }
1017 $this->mailMethod->disconnect();
1019 /* Update sharedFolder dependencies.
1020 Open each shared folder and remove this account.
1021 Then Save the group to ensure that all necessary
1022 actions will be taken (imap acls updated aso.).
1023 */
1024 if(!$this->initially_was_account){
1025 $ldap = $this->config->get_ldap_link();
1026 $ldap->cd($this->config->current['BASE']);
1027 $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array("dn"));
1028 while($attrs = $ldap->fetch()){
1029 $grp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
1030 if(isset($grp->by_object['mailgroup'])){
1031 /* Do not save the complete group! This will quit the complete membership
1032 */
1033 $grp->by_object['mailgroup']->save();
1034 }
1035 }
1036 }
1038 /* Optionally execute a command after we're done */
1039 if ($this->initially_was_account == $this->is_account){
1040 if ($this->is_modified){
1041 $this->handle_post_events("modify", array("uid" => $this->uid));
1042 }
1043 } else {
1044 $this->handle_post_events("add", array("uid" => $this->uid));
1045 }
1046 }
1049 /*! \brief Check given values
1050 */
1051 function check()
1052 {
1053 if(!$this->is_account){
1054 return(array());
1055 }
1057 $ldap= $this->config->get_ldap_link();
1059 /* Call common method to give check the hook */
1060 $message= plugin::check();
1062 if(empty($this->gosaMailServer)){
1063 $message[]= msgPool::noserver(_("Mail"));
1064 }
1066 /* Mail address checks */
1067 $mail = $this->mail;
1068 if(!(!$this->mailMethod->isModifyableMail() && $this->initially_was_account)){
1070 if($this->mailMethod->domainSelectionEnabled()){
1071 $mail.= "@".$this->mailDomainPart;
1072 }
1074 if (empty($mail)){
1075 $message[]= msgPool::required(_("Primary address"));
1076 }
1077 if ($this->is_template){
1078 if (!tests::is_email($mail, TRUE)){
1079 $message[]= msgPool::invalid(_("Mail address"),"","","%givenName.%sn@your-domain.com");
1080 }
1081 } else {
1082 if (!tests::is_email($mail)){
1083 $message[]= msgPool::invalid(_("Mail address"),"","","your-address@your-domain.com");
1084 }
1085 }
1087 /* Check if this mail address is already in use */
1088 $ldap->cd($this->config->current['BASE']);
1089 $filter = "(&(!(objectClass=gosaUserTemplate))(!(uid=".$this->uid."))".
1090 "(objectClass=gosaMailAccount)".
1091 "(|(mail=".$mail.")(alias=".$mail.")(gosaMailAlternateAddress=".$mail.")))";
1092 $ldap->search($filter,array("uid"));
1093 if ($ldap->count() != 0){
1094 $message[]= msgPool::duplicated(_("Mail address"));
1095 }
1096 }
1099 /* Check quota */
1100 if ($this->gosaMailQuota != '' && $this->acl_is_writeable("gosaMailQuota")){
1101 if (!is_numeric($this->gosaMailQuota)) {
1102 $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
1103 } else {
1104 $this->gosaMailQuota= (int) $this->gosaMailQuota;
1105 }
1106 }
1108 /* Check rejectsize for integer */
1109 if ($this->gosaMailMaxSize != '' && $this->acl_is_writeable("gosaMailMaxSize")){
1110 if (!is_numeric($this->gosaMailMaxSize)){
1111 $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
1112 } else {
1113 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
1114 }
1115 }
1117 /* Need gosaMailMaxSize if use_mailsize_limit is checked */
1118 if (is_integer(strpos($this->gosaMailDeliveryMode, "R")) && $this->gosaMailMaxSize == ""){
1119 $message[]= msgPool::required(_("Mail reject size"));
1120 }
1122 if((preg_match("/S/", $this->gosaMailDeliveryMode))&&(empty($this->gosaSpamMailbox))) {
1123 $message[]= msgPool::required(_("Spam folder"));
1124 }
1126 if ($this->mailMethod->vacationRangeEnabled()
1127 && preg_match('/V/', $this->gosaMailDeliveryMode)
1128 && $this->gosaVacationStart > $this->gosaVacationStop){
1129 $message[]= msgPool::invalid(_("Vacation interval"));
1130 }
1131 return($message);
1132 }
1135 /*! \brief Adapt from template, using 'dn'
1136 */
1137 function adapt_from_template($dn, $skip= array())
1138 {
1139 plugin::adapt_from_template($dn, $skip);
1141 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
1143 if (in_array($val, $skip)){
1144 continue;
1145 }
1147 $this->$val= array();
1148 if (isset($this->attrs["$val"]["count"])){
1149 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
1150 $value= $this->attrs["$val"][$i];
1151 foreach (array("sn", "givenName", "uid") as $repl){
1152 if (preg_match("/%$repl/i", $value)){
1153 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
1154 }
1155 }
1156 array_push($this->$val, strtolower(rewrite($value)));
1157 }
1158 }
1159 }
1160 $this->mail= strtolower(rewrite($this->mail));
1161 }
1164 /*! \brief Creates the mail part for the copy & paste dialog
1165 */
1166 function getCopyDialog()
1167 {
1168 if(!$this->is_account) return("");
1169 $smarty = get_smarty();
1170 $smarty->assign("mail",$this->mail);
1171 $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress);
1172 $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress);
1173 $str = $smarty->fetch(get_template_path("copypaste.tpl",TRUE, dirname(__FILE__)));
1175 $ret = array();
1176 $ret['status'] = "";
1177 $ret['string'] = $str;
1178 return($ret);
1179 }
1182 /*! \brief save_object for copy&paste vars
1183 */
1184 function saveCopyDialog()
1185 {
1186 if(!$this->is_account) return;
1188 /* Execute to save mailAlternateAddress && gosaMailForwardingAddress */
1189 $this->execute();
1190 if(isset($_POST['mail'])){
1191 $this->mail = $_POST['mail'];
1192 }
1193 }
1196 /*! \brief Prepare this account to be copied
1197 */
1198 function PrepareForCopyPaste($source)
1199 {
1200 plugin::PrepareForCopyPaste($source);
1202 /* Reset alternate mail addresses */
1203 $this->gosaMailAlternateAddress = array();
1204 }
1207 /*! \brief Prepare this class the be useable when editing multiple users at once
1208 */
1209 function get_multi_edit_values()
1210 {
1211 $ret = plugin::get_multi_edit_values();
1212 if(in_array("gosaMailQuota",$this->multi_boxes)){
1213 $ret['gosaMailQuota'] = $this->gosaMailQuota;
1214 }
1215 $flag_add = $flag_remove = array();
1216 $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1217 $opts = array(
1218 "R" => "use_mailsize_limit",
1219 "S" => "use_spam_filter",
1220 "L" => "only_local",
1221 "V" => "use_vacation",
1222 "C" => "own_script",
1223 "I" => "drop_own_mails");
1224 foreach($opts as $flag => $post){
1225 if(in_array($post, $this->multi_boxes)){
1226 if(preg_match("/".$flag."/",$tmp)){
1227 $flag_add[] = $flag;
1228 }else{
1229 $flag_remove[] = $flag;
1230 }
1231 }
1232 }
1233 $ret['flag_add'] = $flag_add;
1234 $ret['flag_remove'] = $flag_remove;
1236 echo "1";
1237 if($this->mailMethod->vacationRangeEnabled()){
1238 echo "2";
1239 if(in_array("V",$flag_add)){
1240 $ret['gosaVacationStart'] = $this->gosaVacationStart = $_POST['gosaVacationStart'];
1241 $ret['gosaVacationStop'] = $this->gosaVacationStop = $_POST['gosaVacationStop'];
1242 }
1243 }
1244 return($ret);
1245 }
1248 /*! \brief Check given input for multiple user edit
1249 */
1250 function multiple_check()
1251 {
1252 $message = plugin::multiple_check();
1254 if(empty($this->gosaMailServer) && in_array("gosaMailServer",$this->multi_boxes)){
1255 $message[]= msgPool::noserver(_("Mail"));
1256 }
1258 /* Check quota */
1259 if ($this->gosaMailQuota != '' && in_array("gosaMailQuota",$this->multi_boxes)){
1260 if (!is_numeric($this->gosaMailQuota)) {
1261 $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
1262 } else {
1263 $this->gosaMailQuota= (int) $this->gosaMailQuota;
1264 }
1265 }
1267 /* Check rejectsize for integer */
1268 if ($this->gosaMailMaxSize != '' && in_array("gosaMailMaxSize",$this->multi_boxes)){
1269 if (!is_numeric($this->gosaMailMaxSize)){
1270 $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
1271 } else {
1272 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
1273 }
1274 }
1276 if(empty($this->gosaSpamMailbox) && in_array("gosaSpamMailbox",$this->multi_boxes)){
1277 $message[]= msgPool::required(_("Spam folder"));
1278 }
1280 if ( in_array("use_vacation",$this->multi_boxes) &&
1281 preg_match('/V/', $this->gosaMailDeliveryMode) && $this->gosaVacationStart > $this->gosaVacationStop){
1282 $message[]= msgPool::invalid(_("Vacation interval"));
1283 }
1284 return($message);
1285 }
1288 /*! \brief ...
1289 */
1290 function set_multi_edit_values($values)
1291 {
1292 plugin::set_multi_edit_values($values);
1293 $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1294 if(isset($values['flag_add'])){
1295 foreach($values['flag_add'] as $flag){
1296 if(!preg_match("/".$flag."/",$tmp)){
1297 $tmp .= $flag;
1298 }
1299 }
1300 }
1301 if(isset($values['flag_remove'])){
1302 foreach($values['flag_remove'] as $flag){
1303 if(preg_match("/".$flag."/",$tmp)){
1304 $tmp = preg_replace("/".$flag."/","",$tmp);
1305 }
1306 }
1307 }
1308 $this->gosaMailDeliveryMode = "[".$tmp."]";
1310 /* Set vacation message and replace placeholder like %givenName
1311 */
1312 if(isset($values['gosaVacationMessage'])){
1313 $this->gosaVacationMessage = $this->prepare_vacation_template($values['gosaVacationMessage']);
1314 }
1315 }
1318 /*! \brief Initialize plugin to be used as multiple edit class.
1319 */
1320 function init_multiple_support($attrs,$all)
1321 {
1322 plugin::init_multiple_support($attrs,$all);
1323 if(isset($this->multi_attrs['gosaMailQuota'])){
1324 $this->gosaMailQuota = $this->multi_attrs['gosaMailQuota'];
1325 }
1326 }
1329 /*! \brief
1330 */
1331 function get_multi_init_values()
1332 {
1333 $attrs = plugin::get_multi_init_values();
1334 $attrs['gosaMailQuota'] = $this->gosaMailQuota;
1335 return($attrs);
1336 }
1339 /*! \brief Display multiple edit dialog
1340 */
1341 function multiple_execute()
1342 {
1343 return($this->execute());
1344 }
1347 /*! \brief Save posts from multiple edit dialog
1348 */
1349 function multiple_save_object()
1350 {
1351 plugin::multiple_save_object();
1353 $this->save_object();
1354 foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
1355 if(isset($_POST["use_".$attr])){
1356 $this->multi_boxes[] = $attr;
1357 }
1358 }
1359 }
1362 /*! \brief Creates the user names for the add_local_forward dialog
1363 */
1364 function make_name($attrs)
1365 {
1366 $name= "";
1367 if (isset($attrs['sn'][0])){
1368 $name= $attrs['sn'][0];
1369 }
1370 if (isset($attrs['givenName'][0])){
1371 if ($name != ""){
1372 $name.= ", ".$attrs['givenName'][0];
1373 } else {
1374 $name.= $attrs['givenName'][0];
1375 }
1376 }
1377 if ($name != ""){
1378 $name.= " ";
1379 }
1381 return ($name);
1382 }
1385 function allow_remove()
1386 {
1387 $resason = "";
1388 if(!$this->mailMethod->allow_remove($reason)){
1389 return($reason);
1390 }
1391 return("");
1392 }
1396 /*! \brief ACL settings
1397 */
1398 static function plInfo()
1399 {
1400 return (array(
1401 "plShortName" => _("Mail"),
1402 "plDescription" => _("Mail settings"),
1403 "plSelfModify" => TRUE,
1404 "plDepends" => array("user"), // This plugin depends on
1405 "plPriority" => 4, // Position in tabs
1406 "plSection" => array("personal" => _("My account")),
1407 "plCategory" => array("users"),
1408 "plOptions" => array(),
1410 "plProvidedAcls" => array(
1411 "mail" => _("Mail address"),
1412 "gosaMailServer" => _("Mail server"),
1413 "gosaMailQuota" => _("Quota size"),
1415 "gosaMailDeliveryModeV" => _("Add vacation information"), // This is flag of gosaMailDeliveryMode
1416 "gosaVacationMessage" => _("Vacation message"),
1418 "gosaMailDeliveryModeS" => _("Use spam filter"), // This is flag of gosaMailDeliveryMode
1419 "gosaSpamSortLevel" => _("Spam level"),
1420 "gosaSpamMailbox" => _("Spam mail box"),
1422 "sieveManagement" => _("Sieve management"),
1424 "gosaMailDeliveryModeR" => _("Reject due to mailsize"), // This is flag of gosaMailDeliveryMode
1425 "gosaMailMaxSize" => _("Mail max size"),
1427 "gosaMailForwardingAddress" => _("Forwarding address"),
1428 "gosaMailDeliveryModeL" => _("Local delivery"), // This is flag of gosaMailDeliveryMode
1429 "gosaMailDeliveryModeI" => _("No delivery to own mailbox "), // This is flag of gosaMailDeliveryMode
1430 "gosaMailAlternateAddress" => _("Mail alternative addresses"),
1432 "gosaMailForwardingAddress" => _("Forwarding address"),
1433 "gosaMailDeliveryModeC" => _("Use custom sieve script")) // This is flag of gosaMailDeliveryMode
1434 ));
1435 }
1438 }
1440 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1441 ?>