1 <?php
2 /*!
3 \brief mail plugin
4 \author Fabian Hicker <Fabian.Hickert@GONICUS.de>
5 \version 2.6.2
6 \date 03.12.2007
8 This class provides the functionality to read and write all attributes
9 relevant for gosaMailAccounts from/to the LDAP.
10 It does syntax checking and displays the formulars required.
11 Special handling like sieve or imap actions will be implemented
12 by the mailMethods.
15 Functions :
17 - mailAccount (&$config, $dn= NULL)
18 - execute()
19 - save_object()
20 - get_vacation_templates()
21 - addForwarder($address)
22 - delForwarder($addresses)
23 - addAlternate($address)
24 - delAlternate($addresses)
25 - prepare_vacation_template($contents)
26 - display_forward_dialog()
27 - remove_from_parent()
28 - save()
29 - check()
30 - adapt_from_template($dn, $skip= array())
31 - getCopyDialog()
32 - saveCopyDialog()
33 - PrepareForCopyPaste($source)
34 - get_multi_edit_values()
35 - multiple_check()
36 - set_multi_edit_values($values)
37 - init_multiple_support($attrs,$all)
38 - get_multi_init_values()
39 - multiple_execute()
40 - multiple_save_object()
41 - make_name($attrs)
42 - plInfo()
45 */
47 class mailAccount extends plugin
48 {
49 /* Definitions */
50 var $plHeadline = "Mail";
51 var $plDescription = "This does something";
52 var $view_logged = FALSE;
53 var $is_account = FALSE;
54 var $initially_was_account = FALSE;
56 /* GOsa mail attributes */
57 var $mail = "";
58 var $gosaVacationStart = 0;
59 var $gosaVacationStop = 0;
60 var $gosaMailAlternateAddress = array();
61 var $gosaMailForwardingAddress = array();
62 var $gosaMailDeliveryMode = "[L ]";
63 var $gosaMailServer = "";
64 var $gosaMailQuota = "";
65 var $gosaMailMaxSize = "";
66 var $gosaVacationMessage = "";
67 var $gosaSpamSortLevel = "";
68 var $gosaSpamMailbox = "";
70 /* The methods defaults */
71 var $quotaUsage = -1; // Means unknown
73 var $mailMethod = NULL;
74 var $MailDomain = "";
75 var $sieveManagementUsed = FALSE;
76 var $vacationTemplates = array();
77 var $sieve_management = NULL;
78 var $forward_dialog = FALSE;
79 var $initial_uid = "";
80 var $mailDomainPart = "";
81 var $mailDomainParts = array();
82 var $MailBoxes = array("INBOX");
84 /* Used LDAP attributes && classes */
85 var $attributes= array(
86 "mail", "gosaMailServer","gosaMailQuota", "gosaMailMaxSize","gosaMailForwardingAddress",
87 "gosaMailDeliveryMode", "gosaSpamSortLevel", "gosaSpamMailbox","gosaMailAlternateAddress",
88 "gosaVacationStart","gosaVacationStop", "gosaVacationMessage", "gosaMailAlternateAddress",
89 "gosaMailForwardingAddress");
90 var $objectclasses= array("gosaMailAccount");
92 var $multiple_support = TRUE;
94 var $uid = "";
95 var $cn = "";
98 /*! \brief Initialize the mailAccount
99 */
100 function __construct (&$config, $dn= NULL)
101 {
102 plugin::plugin($config,$dn);
104 /* Get attributes from parent object
105 */
106 foreach(array("uid","cn") as $attr){
107 if(isset($this->parent->by_object['group']) && isset($this->parent->by_object['group']->$attr)){
108 $this->$attr = &$this->parent->by_object['group']->$attr;
109 }elseif(isset($this->attrs[$attr])){
110 $this->$attr = $this->attrs[$attr][0];
111 }
112 }
114 /* Intialize the used mailMethod
115 */
116 $tmp = new mailMethod($config,$this);
117 $this->mailMethod = $tmp->get_method();
118 $this->mailMethod->fixAttributesOnLoad();
119 $this->mailDomainParts = $this->mailMethod->getMailDomains();
120 $this->SpamLevels = $this->mailMethod->getSpamLevels();
122 /* Remember account status
123 */
124 $this->initially_was_account = $this->is_account;
126 /* Initialize vacation settings, if enabled.
127 */
128 if(empty($this->gosaVacationStart) && $this->mailMethod->vacationRangeEnabled()){
129 $this->gosaVacationStart = time();
130 $this->gosaVacationStop = time();
131 }
133 /* Read vacation templates
134 */
135 $this->vacationTemplates = $this->get_vacation_templates();
137 /* Initialize configured values
138 */
139 if($this->is_account){
141 if($this->mailMethod->connect() && $this->mailMethod->account_exists()){
143 /* Read quota */
144 $this->gosaMailQuota = $this->mailMethod->getQuota($this->gosaMailQuota);
145 $this->quotaUsage = $this->mailMethod->getQuotaUsage($this->quotaUsage);
146 if($this->mailMethod->is_error()){
147 msg_dialog::display(_("Mail error"), sprintf(_("Cannot read quota settings: %s"),
148 $this->mailMethod->get_error()), ERROR_DIALOG);
149 }
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 /* _Multiple users vars_ */
410 foreach($this->attributes as $attr){
411 $u_attr = "use_".$attr;
412 $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
413 }
414 foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
415 $u_attr = "use_".$attr;
416 $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
417 }
420 /****************
421 SMARTY- Assign flags
422 ****************/
424 $types = array(
425 "V"=>"use_vacation",
426 "S"=>"use_spam_filter",
427 "R"=>"use_mailsize_limit",
428 "I"=>"drop_own_mails",
429 "C"=>"own_script");
430 foreach($types as $option => $varname){
431 if (preg_match("/".$option."/", $this->gosaMailDeliveryMode)) {
432 $smarty->assign($varname, "checked");
433 } else {
434 $smarty->assign($varname, "");
435 }
436 }
437 if (!preg_match("/L/", $this->gosaMailDeliveryMode)) {
438 $smarty->assign("only_local", "checked");
439 } else {
440 $smarty->assign("only_local", "");
441 }
444 /****************
445 Smarty- Vacation settings
446 ****************/
447 $smarty->assign("rangeEnabled", FALSE);
448 $smarty->assign("template", "");
449 if (count($this->vacationTemplates)){
450 $smarty->assign("show_templates", "true");
451 $smarty->assign("vacationtemplates", $this->vacationTemplates);
452 if (isset($_POST['vacation_template'])){
453 $smarty->assign("template", $_POST['vacation_template']);
454 }
455 } else {
456 $smarty->assign("show_templates", "false");
457 }
459 /* Vacation range assigments
460 */
461 if($this->mailMethod->vacationRangeEnabled()){
462 $smarty->assign("rangeEnabled", TRUE);
463 if($this->gosaVacationStop ==0){
464 $date= getdate(time());
465 $date["mday"]++;
466 }else{
467 $date= getdate($this->gosaVacationStop);
468 }
469 $smarty->assign("end_day", $date["mday"]);
470 $smarty->assign("end_month", $date["mon"]-1);
471 $smarty->assign("end_year", $date["year"]);
473 if($this->gosaVacationStart == 0){
474 $date= getdate(time());
475 }else{
476 $date= getdate($this->gosaVacationStart);
477 }
478 $smarty->assign("start_day", $date["mday"]);
479 $smarty->assign("start_month", $date["mon"]-1);
480 $smarty->assign("start_year", $date["year"]);
481 $days= array();
482 for($d= 1; $d<32; $d++){
483 $days[$d]= $d;
484 }
485 $years= array();
486 for($y= $date['year']-10; $y<$date['year']+10; $y++){
487 $years[]= $y;
488 }
489 $months= msgPool::months();
490 $smarty->assign("months", $months);
491 $smarty->assign("years", $years);
492 $smarty->assign("days", $days);
493 }
495 /* fill filter settings
496 */
497 $smarty->assign("spamlevel", $this->SpamLevels);
498 $smarty->assign("spambox" , $this->MailBoxes);
500 $smarty->assign("multiple_support",$this->multiple_support_active);
501 return($display.$smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
502 }
506 /* Save data to object */
507 function save_object()
508 {
509 if (isset($_POST['mailTab'])){
511 /* Save ldap attributes */
512 $mail = $this->mail;
513 $server = $this->gosaMailServer;
514 plugin::save_object();
516 if(!$this->mailMethod->isModifyableServer() && $this->initially_was_account){
517 $this->gosaMailServer = $server;
518 }
520 if(!$this->mailMethod->isModifyableMail() && $this->initially_was_account){
521 $this->mail = $mail;
522 }else{
524 /* Get posted mail domain part, if necessary
525 */
526 if($this->mailMethod->domainSelectionEnabled() && isset($_POST['MailDomain'])){
527 if(in_array(get_post('MailDomain'), $this->mailDomainParts)){
528 $this->mailDomainPart = get_post('MailDomain');
529 }
530 }
531 }
533 /* Import vacation message?
534 */
535 if (isset($_POST["import_vacation"]) && isset($this->vacationTemplates[$_POST["vacation_template"]])){
536 if($this->multiple_support_active){
537 $contents = ltrim(preg_replace("/^DESC:.*$/m","",file_get_contents($_POST["vacation_template"])));
538 }else{
539 $contents = $this->prepare_vacation_template(file_get_contents($_POST["vacation_template"]));
540 }
541 $this->gosaVacationMessage= htmlspecialchars($contents);
542 }
544 /* Handle flags
545 */
546 if(isset($_POST['own_script'])){
547 if(!preg_match("/C/",$this->gosaMailDeliveryMode)){
548 $str= preg_replace("/[\[\]]/","",$this->gosaMailDeliveryMode);
549 $this->gosaMailDeliveryMode = "[".$str."C]";
550 }
551 }else{
553 /* Assemble mail delivery mode
554 The mode field in ldap consists of values between braces, this must
555 be called when 'mail' is set, because checkboxes may not be set when
556 we're in some other dialog.
558 Example for gosaMailDeliveryMode [LR ]
559 L - Local delivery
560 R - Reject when exceeding mailsize limit
561 S - Use spam filter
562 V - Use vacation message
563 C - Use custm sieve script
564 I - Only insider delivery */
566 $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
569 /* Handle delivery flags */
570 if($this->acl_is_writeable("gosaMailDeliveryModeL")){
571 if(!preg_match("/L/",$tmp) && !isset($_POST['only_local'])){
572 $tmp.="L";
573 }elseif(preg_match("/L/",$tmp) && isset($_POST['only_local'])){
574 $tmp = preg_replace("/L/","",$tmp);
575 }
576 }
577 $opts = array(
578 "R" => "use_mailsize_limit",
579 "S" => "use_spam_filter",
580 "V" => "use_vacation",
581 "C" => "own_script",
582 "I" => "drop_own_mails");
584 foreach($opts as $flag => $post){
585 if($this->acl_is_writeable("gosaMailDeliveryMode".$flag)){
586 if(!preg_match("/".$flag."/",$tmp) && isset($_POST[$post])){
587 $tmp.= $flag;
588 }elseif(preg_match("/".$flag."/",$tmp) && !isset($_POST[$post])){
589 $tmp = preg_replace("/".$flag."/","",$tmp);
590 }
591 }
592 }
594 $tmp= "[$tmp]";
595 if ($this->gosaMailDeliveryMode != $tmp){
596 $this->is_modified= TRUE;
597 }
598 $this->gosaMailDeliveryMode= $tmp;
600 /* Get start/stop values for vacation scope of application
601 */
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){
745 /* Replace vacation start and end time */
746 if($this->mailMethod->vacationRangeEnabled()){
747 if(preg_match("/%start/",$contents)){
748 $contents = preg_replace("/%start/",date("d.m.Y",$this->gosaVacationStart),$contents);
749 }
750 if(preg_match("/%end/",$contents)){
751 $contents = preg_replace("/%end/",date("d.m.Y",$this->gosaVacationStop),$contents);
752 }
753 }else{
754 if(preg_match("/%start/",$contents)){
755 $contents = preg_replace("/%start/", _("unknown"),$contents);
756 }
757 if(preg_match("/%end/",$contents)){
758 $contents = preg_replace("/%end/", _("unknown"), $contents);
759 }
760 }
762 foreach ($attrs as $val){
763 if(preg_match("/dateOfBirth/",$val)){
764 if($obj->use_dob){
765 $contents= preg_replace("/%$val/",date("Y-d-m",$obj->dateOfBirth),$contents);
766 }
767 }else {
768 $contents= preg_replace("/%$val/",
769 $obj->$val, $contents);
770 }
772 }
773 }
774 $contents = ltrim(preg_replace("/^DESC:.*$/m","",$contents),"\n ");
775 return($contents);
776 }
779 /*! \brief Displays a dialog that allows mail address selection.
780 */
781 function display_forward_dialog()
782 {
783 restore_error_handler();
785 $smarty = get_smarty();
786 $ldap= $this->config->get_ldap_link();
788 /* Save data */
789 $mailfilter= session::get("mailfilter");
790 foreach( array("depselect", "muser", "regex") as $type){
791 if (isset($_POST[$type])){
792 $mailfilter[$type]= $_POST[$type];
793 }
794 }
795 if (isset($_GET['search'])){
796 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
797 if ($s == "**"){
798 $s= "*";
799 }
800 $mailfilter['regex']= $s;
801 }
802 session::set("mailfilter", $mailfilter);
804 /* Get actual list */
805 $mailusers= array ();
806 if ($mailfilter['regex'] != '*' && $mailfilter['regex'] != ""){
807 $regex= $mailfilter['regex'];
808 $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
809 } else {
810 $filter= "";
811 }
812 if ($mailfilter['muser'] != ""){
813 $user= $mailfilter['muser'];
814 $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
815 }
817 /* Add already present people to the filter */
818 $exclude= "";
819 foreach ($this->gosaMailForwardingAddress as $mail){
820 $exclude.= "(mail=$mail)";
821 }
822 if ($exclude != ""){
823 $filter.= "(!(|$exclude))";
824 }
825 $res= get_list("(&(objectClass=gosaMailAccount)$filter)", "users", $mailfilter['depselect'],
826 array("sn", "mail", "givenName"), GL_SIZELIMIT | GL_SUBSEARCH);
827 $ldap->cd($mailfilter['depselect']);
828 $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
829 while ($attrs= $ldap->fetch()){
830 if(preg_match('/%/', $attrs['mail'][0])){
831 continue;
832 }
833 $name= $this->make_name($attrs);
834 $mailusers[$attrs['mail'][0]]= $name."<".
835 $attrs['mail'][0].">";
836 }
837 natcasesort ($mailusers);
838 reset ($mailusers);
840 /* Show dialog */
841 $smarty->assign("search_image", get_template_path('images/lists/search.png'));
842 $smarty->assign("usearch_image", get_template_path('images/lists/search-user.png'));
843 $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
844 $smarty->assign("infoimage", get_template_path('images/info.png'));
845 $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
846 $smarty->assign("mailusers", $mailusers);
847 if (isset($_POST['depselect'])){
848 $smarty->assign("depselect", $_POST['depselect']);
849 }
850 $smarty->assign("deplist", $this->config->idepartments);
851 $smarty->assign("apply", apply_filter());
852 $smarty->assign("alphabet", generate_alphabet());
853 $smarty->assign("hint", print_sizelimit_warning());
854 foreach( array("depselect", "muser", "regex") as $type){
855 $smarty->assign("$type", $mailfilter[$type]);
856 }
857 $smarty->assign("hint", print_sizelimit_warning());
858 $display= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE, dirname(__FILE__)));
859 return ($display);
860 }
863 /*! \brief Removes the mailAccount extension from ldap
864 */
865 function remove_from_parent()
866 {
867 /* Cancel if there's nothing to do here */
868 if (!$this->initially_was_account){
869 return;
870 }
872 /* If domain part was selectable, contruct mail address */
873 if($this->mailMethod->domainSelectionEnabled()){
874 $this->mail = $this->mail."@".$this->mailDomainPart;
875 }
877 /* Update sharedFolder dependencies.
878 Open each shared folder and remove this account.
879 Then Save the group to ensure that all necessary
880 actions will be taken (imap acls updated aso.).
881 */
882 $ldap = $this->config->get_ldap_link();
883 $ldap->cd($this->config->current['BASE']);
884 $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array("dn"));
885 while($attrs = $ldap->fetch()){
886 $grp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
887 if(isset($grp->by_object['mailgroup']) && isset($grp->by_object['group'])){
888 $grp->by_object['group']->removeUser($this->uid);
890 /* Do not save the complete group! This will quit the complete membership
891 */
892 $grp->by_object['mailgroup']->save();
893 }
894 }
896 /* Remove GOsa attributes */
897 plugin::remove_from_parent();
899 /* Zero arrays */
900 $this->attrs['gosaMailAlternateAddress'] = array();
901 $this->attrs['gosaMailForwardingAddress']= array();
904 $this->mailMethod->fixAttributesOnRemove();
905 $this->cleanup();
907 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
908 $ldap= $this->config->get_ldap_link();
909 $ldap->cd($this->dn);
910 $ldap->modify ($this->attrs);
912 /* Add "view" to logging class */
913 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
914 if (!$ldap->success()){
915 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
916 }
918 /* Let the mailMethod remove this mailbox, e.g. from imap and
919 update shared folder membership, ACL may need to be updated.
920 */
921 if (!$this->is_template){
923 if(!$this->mailMethod->connect()){
924 msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"),
925 $this->mailMethod->get_error()), ERROR_DIALOG);
926 }else{
927 if(!$this->mailMethod->deleteMailbox()){
928 msg_dialog::display(_("Mail error"), sprintf(_("Cannot remove mailbox: %s"),
929 $this->mailMethod->get_error()), ERROR_DIALOG);
930 }
931 }
932 }
933 $this->mailMethod->disconnect();
935 /* Optionally execute a command after we're done */
936 $this->handle_post_events("remove",array("uid" => $this->uid));
937 }
940 /*! \brief Save the mailAccount settings to the ldap database.
941 */
942 function save()
943 {
944 $ldap= $this->config->get_ldap_link();
946 /* If domain part was selectable, contruct mail address */
947 if(!(!$this->mailMethod->isModifyableMail() && $this->initially_was_account)){
949 if($this->mailMethod->domainSelectionEnabled()){
950 $this->mail = $this->mail."@".$this->mailDomainPart;
951 }
953 /* Enforce lowercase mail address and trim whitespaces
954 */
955 $this->mail = trim(strtolower($this->mail));
956 }
959 /* Call parents save to prepare $this->attrs */
960 plugin::save();
962 /* Save arrays */
963 $this->attrs['gosaMailAlternateAddress'] = $this->gosaMailAlternateAddress;
964 $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
966 if(!$this->mailMethod->vacationRangeEnabled()){
967 $this->attrs['gosaVacationStart'] = $this->attrs['gosaVacationStop'] = array();
968 }elseif (!preg_match('/V/', $this->gosaMailDeliveryMode)){
969 unset($this->attrs['gosaVacationStart']);
970 unset($this->attrs['gosaVacationStop']);
971 }
973 /* Map method attributes */
974 $this->mailMethod->fixAttributesOnStore();
976 /* Save data to LDAP */
977 $ldap->cd($this->dn);
978 $this->cleanup();
979 $ldap->modify ($this->attrs);
981 if (!$ldap->success()){
982 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
983 }
985 /* Log last action */
986 if($this->initially_was_account){
987 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
988 }else{
989 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
990 }
992 /* Only do IMAP actions if we are not a template */
993 if (!$this->is_template){
994 $this->mailMethod->connect();
995 if(!$this->mailMethod->is_connected()){
996 msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"),
997 $this->mailMethod->get_error()), ERROR_DIALOG);
998 }else{
999 if(!$this->mailMethod->updateMailbox()){
1000 msg_dialog::display(_("Mail error"), sprintf(_("Cannot update mailbox: %s"),
1001 $this->mailMethod->get_error()), ERROR_DIALOG);
1002 }
1003 if(!$this->mailMethod->setQuota($this->gosaMailQuota)){
1004 msg_dialog::display(_("Mail error"), sprintf(_("Cannot write quota settings: %s"),
1005 $this->mailMethod->get_error()), ERROR_DIALOG);
1006 }
1008 if (!is_integer(strpos($this->gosaMailDeliveryMode, "C"))){
1010 /* Do not write sieve settings if this account is new and
1011 doesn't seem to exist.
1012 */
1013 if(!$this->initially_was_account && !$this->mailMethod->account_exists()){
1014 @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,
1015 "Skipping sieve settings, the account doesn't seem to be created already.</b>","");
1016 }else{
1017 if(!$this->mailMethod->saveSieveSettings()){
1018 msg_dialog::display(_("Mail error"), $this->mailMethod->get_error(), ERROR_DIALOG);
1019 }
1020 }
1021 }else{
1022 @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,
1023 "User uses an own sieve script, skipping sieve update.".$str."</b>","");
1024 $this->sieve_management->save();
1025 }
1026 }
1027 }
1028 $this->mailMethod->disconnect();
1030 /* Update sharedFolder dependencies.
1031 Open each shared folder and remove this account.
1032 Then Save the group to ensure that all necessary
1033 actions will be taken (imap acls updated aso.).
1034 */
1035 if(!$this->initially_was_account){
1036 $ldap = $this->config->get_ldap_link();
1037 $ldap->cd($this->config->current['BASE']);
1038 $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array("dn"));
1039 while($attrs = $ldap->fetch()){
1040 $grp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
1041 if(isset($grp->by_object['mailgroup'])){
1042 /* Do not save the complete group! This will quit the complete membership
1043 */
1044 $grp->by_object['mailgroup']->save();
1045 }
1046 }
1047 }
1049 /* Optionally execute a command after we're done */
1050 if ($this->initially_was_account == $this->is_account){
1051 if ($this->is_modified){
1052 $this->handle_post_events("modify", array("uid" => $this->uid));
1053 }
1054 } else {
1055 $this->handle_post_events("add", array("uid" => $this->uid));
1056 }
1057 }
1060 /*! \brief Check given values
1061 */
1062 function check()
1063 {
1064 if(!$this->is_account){
1065 return(array());
1066 }
1068 $ldap= $this->config->get_ldap_link();
1070 /* Call common method to give check the hook */
1071 $message= plugin::check();
1073 if(empty($this->gosaMailServer)){
1074 $message[]= msgPool::noserver(_("Mail"));
1075 }
1077 /* Mail address checks */
1078 $mail = $this->mail;
1079 if(!(!$this->mailMethod->isModifyableMail() && $this->initially_was_account)){
1081 if($this->mailMethod->domainSelectionEnabled()){
1082 $mail.= "@".$this->mailDomainPart;
1083 }
1085 if (empty($mail)){
1086 $message[]= msgPool::required(_("Primary address"));
1087 }
1088 if ($this->is_template){
1089 if (!tests::is_email($mail, TRUE)){
1090 $message[]= msgPool::invalid(_("Mail address"),"","","%givenName.%sn@your-domain.com");
1091 }
1092 } else {
1093 if (!tests::is_email($mail)){
1094 $message[]= msgPool::invalid(_("Mail address"),"","","your-address@your-domain.com");
1095 }
1096 }
1098 /* Check if this mail address is already in use */
1099 $ldap->cd($this->config->current['BASE']);
1100 $filter = "(&(!(objectClass=gosaUserTemplate))(!(uid=".$this->uid."))".
1101 "(objectClass=gosaMailAccount)".
1102 "(|(mail=".$mail.")(alias=".$mail.")(gosaMailAlternateAddress=".$mail.")))";
1103 $ldap->search($filter,array("uid"));
1104 if ($ldap->count() != 0){
1105 $message[]= msgPool::duplicated(_("Mail address"));
1106 }
1107 }
1110 /* Check quota */
1111 if ($this->gosaMailQuota != '' && $this->acl_is_writeable("gosaMailQuota")){
1112 if (!is_numeric($this->gosaMailQuota)) {
1113 $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
1114 } else {
1115 $this->gosaMailQuota= (int) $this->gosaMailQuota;
1116 }
1117 }
1119 /* Check rejectsize for integer */
1120 if ($this->gosaMailMaxSize != '' && $this->acl_is_writeable("gosaMailMaxSize")){
1121 if (!is_numeric($this->gosaMailMaxSize)){
1122 $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
1123 } else {
1124 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
1125 }
1126 }
1128 /* Need gosaMailMaxSize if use_mailsize_limit is checked */
1129 if (is_integer(strpos($this->gosaMailDeliveryMode, "R")) && $this->gosaMailMaxSize == ""){
1130 $message[]= msgPool::required(_("Mail reject size"));
1131 }
1133 if((preg_match("/S/", $this->gosaMailDeliveryMode))&&(empty($this->gosaSpamMailbox))) {
1134 $message[]= msgPool::required(_("Spam folder"));
1135 }
1137 if ($this->mailMethod->vacationRangeEnabled()
1138 && preg_match('/V/', $this->gosaMailDeliveryMode)
1139 && $this->gosaVacationStart > $this->gosaVacationStop){
1140 $message[]= msgPool::invalid(_("Vacation interval"));
1141 }
1142 return($message);
1143 }
1146 /*! \brief Adapt from template, using 'dn'
1147 */
1148 function adapt_from_template($dn, $skip= array())
1149 {
1150 plugin::adapt_from_template($dn, $skip);
1152 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
1154 if (in_array($val, $skip)){
1155 continue;
1156 }
1158 $this->$val= array();
1159 if (isset($this->attrs["$val"]["count"])){
1160 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
1161 $value= $this->attrs["$val"][$i];
1162 foreach (array("sn", "givenName", "uid") as $repl){
1163 if (preg_match("/%$repl/i", $value)){
1164 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
1165 }
1166 }
1167 array_push($this->$val, strtolower(rewrite($value)));
1168 }
1169 }
1170 }
1171 $this->mail= strtolower(rewrite($this->mail));
1172 }
1175 /*! \brief Creates the mail part for the copy & paste dialog
1176 */
1177 function getCopyDialog()
1178 {
1179 if(!$this->is_account) return("");
1180 $smarty = get_smarty();
1181 $smarty->assign("mail",$this->mail);
1182 $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress);
1183 $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress);
1184 $str = $smarty->fetch(get_template_path("copypaste.tpl",TRUE, dirname(__FILE__)));
1186 $ret = array();
1187 $ret['status'] = "";
1188 $ret['string'] = $str;
1189 return($ret);
1190 }
1193 /*! \brief save_object for copy&paste vars
1194 */
1195 function saveCopyDialog()
1196 {
1197 if(!$this->is_account) return;
1199 /* Execute to save mailAlternateAddress && gosaMailForwardingAddress */
1200 $this->execute();
1201 if(isset($_POST['mail'])){
1202 $this->mail = $_POST['mail'];
1203 }
1204 }
1207 /*! \brief Prepare this account to be copied
1208 */
1209 function PrepareForCopyPaste($source)
1210 {
1211 plugin::PrepareForCopyPaste($source);
1213 /* Reset alternate mail addresses */
1214 $this->gosaMailAlternateAddress = array();
1215 }
1218 /*! \brief Prepare this class the be useable when editing multiple users at once
1219 */
1220 function get_multi_edit_values()
1221 {
1222 $ret = plugin::get_multi_edit_values();
1223 if(in_array("gosaMailQuota",$this->multi_boxes)){
1224 $ret['gosaMailQuota'] = $this->gosaMailQuota;
1225 }
1226 $flag_add = $flag_remove = array();
1227 $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1228 $opts = array(
1229 "R" => "use_mailsize_limit",
1230 "S" => "use_spam_filter",
1231 "L" => "only_local",
1232 "V" => "use_vacation",
1233 "C" => "own_script",
1234 "I" => "drop_own_mails");
1235 foreach($opts as $flag => $post){
1236 if(in_array($post, $this->multi_boxes)){
1237 if(preg_match("/".$flag."/",$tmp)){
1238 $flag_add[] = $flag;
1239 }else{
1240 $flag_remove[] = $flag;
1241 }
1242 }
1243 }
1244 $ret['flag_add'] = $flag_add;
1245 $ret['flag_remove'] = $flag_remove;
1247 if($this->mailMethod->vacationRangeEnabled()){
1248 if(in_array("V",$flag_add)){
1249 $ret['gosaVacationStart'] = $this->gosaVacationStart = $_POST['gosaVacationStart'];
1250 $ret['gosaVacationStop'] = $this->gosaVacationStop = $_POST['gosaVacationStop'];
1251 }
1252 }
1253 return($ret);
1254 }
1257 /*! \brief Check given input for multiple user edit
1258 */
1259 function multiple_check()
1260 {
1261 $message = plugin::multiple_check();
1263 if(empty($this->gosaMailServer) && in_array("gosaMailServer",$this->multi_boxes)){
1264 $message[]= msgPool::noserver(_("Mail"));
1265 }
1267 /* Check quota */
1268 if ($this->gosaMailQuota != '' && in_array("gosaMailQuota",$this->multi_boxes)){
1269 if (!is_numeric($this->gosaMailQuota)) {
1270 $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
1271 } else {
1272 $this->gosaMailQuota= (int) $this->gosaMailQuota;
1273 }
1274 }
1276 /* Check rejectsize for integer */
1277 if ($this->gosaMailMaxSize != '' && in_array("gosaMailMaxSize",$this->multi_boxes)){
1278 if (!is_numeric($this->gosaMailMaxSize)){
1279 $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
1280 } else {
1281 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
1282 }
1283 }
1285 if(empty($this->gosaSpamMailbox) && in_array("gosaSpamMailbox",$this->multi_boxes)){
1286 $message[]= msgPool::required(_("Spam folder"));
1287 }
1289 if ($this->mailMethod->vacationRangeEnabled() && in_array("use_vacation",$this->multi_boxes) &&
1290 preg_match('/V/', $this->gosaMailDeliveryMode) && $this->gosaVacationStart > $this->gosaVacationStop){
1291 $message[]= msgPool::invalid(_("Vacation interval"));
1292 }
1293 return($message);
1294 }
1297 /*! \brief ...
1298 */
1299 function set_multi_edit_values($values)
1300 {
1301 plugin::set_multi_edit_values($values);
1302 $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1303 if(isset($values['flag_add'])){
1304 foreach($values['flag_add'] as $flag){
1305 if(!preg_match("/".$flag."/",$tmp)){
1306 $tmp .= $flag;
1307 }
1308 }
1309 }
1310 if(isset($values['flag_remove'])){
1311 foreach($values['flag_remove'] as $flag){
1312 if(preg_match("/".$flag."/",$tmp)){
1313 $tmp = preg_replace("/".$flag."/","",$tmp);
1314 }
1315 }
1316 }
1317 $this->gosaMailDeliveryMode = "[".$tmp."]";
1319 /* Set vacation message and replace placeholder like %givenName
1320 */
1321 if(isset($values['gosaVacationMessage'])){
1322 $this->gosaVacationMessage = $this->prepare_vacation_template($values['gosaVacationMessage']);
1323 }
1324 }
1327 /*! \brief Initialize plugin to be used as multiple edit class.
1328 */
1329 function init_multiple_support($attrs,$all)
1330 {
1331 plugin::init_multiple_support($attrs,$all);
1332 if(isset($this->multi_attrs['gosaMailQuota'])){
1333 $this->gosaMailQuota = $this->multi_attrs['gosaMailQuota'];
1334 }
1335 }
1338 /*! \brief
1339 */
1340 function get_multi_init_values()
1341 {
1342 $attrs = plugin::get_multi_init_values();
1343 $attrs['gosaMailQuota'] = $this->gosaMailQuota;
1344 return($attrs);
1345 }
1348 /*! \brief Display multiple edit dialog
1349 */
1350 function multiple_execute()
1351 {
1352 return($this->execute());
1353 }
1356 /*! \brief Save posts from multiple edit dialog
1357 */
1358 function multiple_save_object()
1359 {
1360 plugin::multiple_save_object();
1362 $this->save_object();
1363 foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
1364 if(isset($_POST["use_".$attr])){
1365 $this->multi_boxes[] = $attr;
1366 }
1367 }
1368 }
1371 /*! \brief Creates the user names for the add_local_forward dialog
1372 */
1373 function make_name($attrs)
1374 {
1375 $name= "";
1376 if (isset($attrs['sn'][0])){
1377 $name= $attrs['sn'][0];
1378 }
1379 if (isset($attrs['givenName'][0])){
1380 if ($name != ""){
1381 $name.= ", ".$attrs['givenName'][0];
1382 } else {
1383 $name.= $attrs['givenName'][0];
1384 }
1385 }
1386 if ($name != ""){
1387 $name.= " ";
1388 }
1390 return ($name);
1391 }
1394 function allow_remove()
1395 {
1396 $resason = "";
1397 if(!$this->mailMethod->allow_remove($reason)){
1398 return($reason);
1399 }
1400 return("");
1401 }
1405 /*! \brief ACL settings
1406 */
1407 static function plInfo()
1408 {
1409 return (array(
1410 "plShortName" => _("Mail"),
1411 "plDescription" => _("Mail settings"),
1412 "plSelfModify" => TRUE,
1413 "plDepends" => array("user"), // This plugin depends on
1414 "plPriority" => 4, // Position in tabs
1415 "plSection" => array("personal" => _("My account")),
1416 "plCategory" => array("users"),
1417 "plOptions" => array(),
1419 "plProvidedAcls" => array(
1420 "mail" => _("Mail address"),
1421 "gosaMailServer" => _("Mail server"),
1422 "gosaMailQuota" => _("Quota size"),
1424 "gosaMailDeliveryModeV" => _("Add vacation information"), // This is flag of gosaMailDeliveryMode
1425 "gosaVacationMessage" => _("Vacation message"),
1427 "gosaMailDeliveryModeS" => _("Use spam filter"), // This is flag of gosaMailDeliveryMode
1428 "gosaSpamSortLevel" => _("Spam level"),
1429 "gosaSpamMailbox" => _("Spam mail box"),
1431 "sieveManagement" => _("Sieve management"),
1433 "gosaMailDeliveryModeR" => _("Reject due to mailsize"), // This is flag of gosaMailDeliveryMode
1434 "gosaMailMaxSize" => _("Mail max size"),
1436 "gosaMailForwardingAddress" => _("Forwarding address"),
1437 "gosaMailDeliveryModeL" => _("Local delivery"), // This is flag of gosaMailDeliveryMode
1438 "gosaMailDeliveryModeI" => _("No delivery to own mailbox "), // This is flag of gosaMailDeliveryMode
1439 "gosaMailAlternateAddress" => _("Mail alternative addresses"),
1441 "gosaMailForwardingAddress" => _("Forwarding address"),
1442 "gosaMailDeliveryModeC" => _("Use custom sieve script")) // This is flag of gosaMailDeliveryMode
1443 ));
1444 }
1447 }
1449 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1450 ?>