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 = "";
59 var $gosaVacationStop = "";
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();
210 /* Convert start/stop dates */
211 #TODO: use date format
212 $this->gosaVacationStart= date('d.m.Y', $this->gosaVacationStart);
213 $this->gosaVacationStop= date('d.m.Y', $this->gosaVacationStop);
214 }
217 function execute()
218 {
220 /* Call parent execute */
221 $display = plugin::execute();
223 /* Log view */
224 if($this->is_account && !$this->view_logged){
225 $this->view_logged = TRUE;
226 new log("view","users/".get_class($this),$this->dn);
227 }
230 /****************
231 Account status
232 ****************/
234 if(isset($_POST['modify_state'])){
235 if($this->is_account && $this->acl_is_removeable() && $this->mailMethod->accountRemoveAble()){
236 $this->is_account= FALSE;
237 }elseif(!$this->is_account && $this->acl_is_createable() && $this->mailMethod->accountCreateable()){
238 $this->is_account= TRUE;
239 }
240 }
241 if(!$this->multiple_support_active){
242 if (!$this->is_account && $this->parent === NULL){
243 $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\"> <b>".
244 msgPool::noValidExtension(_("Mail"))."</b>";
245 $display.= back_to_main();
246 return ($display);
247 }
248 if ($this->parent !== NULL){
249 if ($this->is_account){
250 $reason = "";
251 if(!$this->mailMethod->accountRemoveable($reason)){
252 $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Mail")),$reason ,TRUE,TRUE);
253 }else{
254 $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Mail")),msgPool::featuresEnabled(_("Mail")));
255 }
256 } else {
257 $reason = "";
258 if(!$this->mailMethod->accountCreateable($reason)){
259 $display= $this->show_disable_header(msgPool::addFeaturesButton(_("Mail")),$reason ,TRUE,TRUE);
260 }else{
261 $display= $this->show_disable_header(msgPool::addFeaturesButton(_("Mail")),msgPool::featuresDisabled(_("Mail")));
262 }
263 return ($display);
264 }
265 }
266 }
268 /****************
269 Sieve Management Dialog
270 ****************/
271 if($this->mailMethod->allowSieveManagement()){
272 if(isset($_POST['sieveManagement'])
273 && preg_match("/C/",$this->gosaMailDeliveryMode)
274 && $this->acl_is_writeable("sieveManagement")
275 && $this->mailMethod->allowSieveManagement()) {
276 $this->dialog = $this->sieve_management;
277 }
278 if(isset($_POST['sieve_cancel'])){
279 $this->dialog = FALSE;
280 }
281 if(isset($_POST['sieve_finish'])){
282 $this->sieve_management = $this->dialog;
283 $this->dialog = FALSE;
284 }
285 if(is_object($this->dialog)){
286 $this->dialog->save_object();
287 return($this->dialog->execute());
288 }
289 }
291 /****************
292 Forward addresses
293 ****************/
294 if (isset($_POST['add_local_forwarder'])){
295 $this->forward_dialog= TRUE;
296 $this->dialog= TRUE;
297 }
298 if (isset($_POST['add_locals_cancel'])){
299 $this->forward_dialog= FALSE;
300 $this->dialog= FALSE;
301 }
302 if (isset($_POST['add_locals_finish'])){
303 if (isset($_POST['local_list'])){
304 if($this->acl_is_writeable("gosaMailForwardingAddress")){
305 foreach ($_POST['local_list'] as $val){
306 if (!in_array ($val, $this->gosaMailAlternateAddress) &&
307 $val != $this->mail){
308 $this->addForwarder($val);
309 $this->is_modified= TRUE;
310 }
311 }
312 }
313 $this->forward_dialog= FALSE;
314 $this->dialog= FALSE;
315 } else {
316 msg_dialog::display(_("Error"), _("Please select an entry!"), ERROR_DIALOG);
317 }
318 }
319 if (isset($_POST['add_forwarder'])){
320 if ($_POST['forward_address'] != ""){
321 $address= $_POST['forward_address'];
322 $valid= FALSE;
323 if (!tests::is_email($address)){
324 if (!tests::is_email($address, TRUE)){
325 if ($this->is_template){
326 $valid= TRUE;
327 } else {
328 msg_dialog::display(_("Error"), msgPool::invalid(_("Mail address"),
329 "","","your-address@your-domain.com"),ERROR_DIALOG);
330 }
331 }
332 } elseif ($address == $this->mail
333 || in_array($address, $this->gosaMailAlternateAddress)) {
334 msg_dialog::display(_("Error"),_("Cannot add primary address to the list of forwarders!") , ERROR_DIALOG);
335 } else {
336 $valid= TRUE;
337 }
338 if ($valid){
339 if($this->acl_is_writeable("gosaMailForwardingAddress")){
340 $this->addForwarder ($address);
341 $this->is_modified= TRUE;
342 }
343 }
344 }
345 }
346 if (isset($_POST['delete_forwarder'])){
347 $this->delForwarder ($_POST['forwarder_list']);
348 }
349 if ($this->forward_dialog){
350 return($this->display_forward_dialog());
351 }
354 /****************
355 Alternate addresses
356 ****************/
358 if (isset($_POST['add_alternate'])){
359 $valid= FALSE;
360 if (!tests::is_email($_POST['alternate_address'])){
361 if ($this->is_template){
362 if (!(tests::is_email($_POST['alternate_address'], TRUE))){
363 msg_dialog::display(_("Error"),msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com"),ERROR_DIALOG);
364 } else {
365 $valid= TRUE;
366 }
367 } else {
368 msg_dialog::display(_("Error"),msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com"),ERROR_DIALOG);
369 }
370 } else {
371 $valid= TRUE;
372 }
373 if ($valid && ($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
374 $ui= get_userinfo();
375 msg_dialog::display(_("Error"), msgPool::duplicated(_("Mail address"))." ".
376 sprintf(_("Address is already in use by user '%s'."), $user), ERROR_DIALOG);
377 }
378 }
379 if (isset($_POST['delete_alternate']) && isset($_POST['alternates_list'])){
380 $this->delAlternate ($_POST['alternates_list']);
381 }
383 /****************
384 SMARTY- Assign smarty variables
385 ****************/
386 $smarty = get_smarty();
387 $smarty->assign("usePrototype", "true");
388 $smarty->assign("initially_was_account", $this->initially_was_account);
389 $smarty->assign("isModifyableMail" , $this->mailMethod->isModifyableMail());
390 $smarty->assign("isModifyableServer", $this->mailMethod->isModifyableServer());
391 $smarty->assign("mailEqualsCN", $this->mailMethod->mailEqualsCN());
393 $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
394 $tmp = $this->plInfo();
395 foreach($tmp['plProvidedAcls'] as $name => $transl){
396 $smarty->assign("$name"."ACL", $this->getacl($name,$SkipWrite));
397 }
398 foreach($this->attributes as $attr){
399 $smarty->assign($attr,$this->$attr);
400 }
401 $smarty->assign("quotaEnabled", $this->mailMethod->quotaEnabled());
402 if($this->mailMethod->quotaEnabled()){
403 $smarty->assign("quotaUsage", mailMethod::quota_to_image($this->quotaUsage,$this->gosaMailQuota));
404 $smarty->assign("gosaMailQuota",$this->gosaMailQuota);
405 }
406 $smarty->assign("domainSelectionEnabled", $this->mailMethod->domainSelectionEnabled());
407 $smarty->assign("MailDomains", $this->mailDomainParts);
408 $smarty->assign("MailDomain" , $this->mailDomainPart);
409 $smarty->assign("MailServers", $this->mailMethod->getMailServers());
410 $smarty->assign("allowSieveManagement", $this->mailMethod->allowSieveManagement());
411 $smarty->assign("own_script", $this->sieveManagementUsed);
413 /* _Multiple users vars_ */
414 foreach($this->attributes as $attr){
415 $u_attr = "use_".$attr;
416 $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
417 }
418 foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
419 $u_attr = "use_".$attr;
420 $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
421 }
424 /****************
425 SMARTY- Assign flags
426 ****************/
428 $types = array(
429 "V"=>"use_vacation",
430 "S"=>"use_spam_filter",
431 "R"=>"use_mailsize_limit",
432 "I"=>"drop_own_mails",
433 "C"=>"own_script");
434 foreach($types as $option => $varname){
435 if (preg_match("/".$option."/", $this->gosaMailDeliveryMode)) {
436 $smarty->assign($varname, "checked");
437 } else {
438 $smarty->assign($varname, "");
439 }
440 }
441 if (!preg_match("/L/", $this->gosaMailDeliveryMode)) {
442 $smarty->assign("only_local", "checked");
443 } else {
444 $smarty->assign("only_local", "");
445 }
448 /****************
449 Smarty- Vacation settings
450 ****************/
451 $smarty->assign("rangeEnabled", FALSE);
452 $smarty->assign("template", "");
453 if (count($this->vacationTemplates)){
454 $smarty->assign("show_templates", "true");
455 $smarty->assign("vacationtemplates", $this->vacationTemplates);
456 if (isset($_POST['vacation_template'])){
457 $smarty->assign("template", $_POST['vacation_template']);
458 }
459 } else {
460 $smarty->assign("show_templates", "false");
461 }
463 /* Vacation range assigments
464 */
465 if($this->mailMethod->vacationRangeEnabled()){
466 $smarty->assign("rangeEnabled", TRUE);
467 }
469 /* fill filter settings
470 */
471 $smarty->assign("spamlevel", $this->SpamLevels);
472 $smarty->assign("spambox" , $this->MailBoxes);
474 $smarty->assign("multiple_support",$this->multiple_support_active);
475 return($display.$smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
476 }
480 /* Save data to object */
481 function save_object()
482 {
483 if (isset($_POST['mailTab'])){
485 /* Save ldap attributes */
486 $mail = $this->mail;
487 $server = $this->gosaMailServer;
488 plugin::save_object();
490 if(!$this->mailMethod->isModifyableServer() && $this->initially_was_account){
491 $this->gosaMailServer = $server;
492 }
494 if(!$this->mailMethod->isModifyableMail() && $this->initially_was_account){
495 $this->mail = $mail;
496 }else{
498 /* Get posted mail domain part, if necessary
499 */
500 if($this->mailMethod->domainSelectionEnabled() && isset($_POST['MailDomain'])){
501 if(in_array(get_post('MailDomain'), $this->mailDomainParts)){
502 $this->mailDomainPart = get_post('MailDomain');
503 }
504 }
505 }
507 /* Import vacation message?
508 */
509 if (isset($_POST["import_vacation"]) && isset($this->vacationTemplates[$_POST["vacation_template"]])){
510 if($this->multiple_support_active){
511 $contents = ltrim(preg_replace("/^DESC:.*$/m","",file_get_contents($_POST["vacation_template"])));
512 }else{
513 $contents = $this->prepare_vacation_template(file_get_contents($_POST["vacation_template"]));
514 }
515 $this->gosaVacationMessage= htmlspecialchars($contents);
516 }
518 /* Handle flags
519 */
520 if(isset($_POST['own_script'])){
521 if(!preg_match("/C/",$this->gosaMailDeliveryMode)){
522 $str= preg_replace("/[\[\]]/","",$this->gosaMailDeliveryMode);
523 $this->gosaMailDeliveryMode = "[".$str."C]";
524 }
525 }else{
527 /* Assemble mail delivery mode
528 The mode field in ldap consists of values between braces, this must
529 be called when 'mail' is set, because checkboxes may not be set when
530 we're in some other dialog.
532 Example for gosaMailDeliveryMode [LR ]
533 L - Local delivery
534 R - Reject when exceeding mailsize limit
535 S - Use spam filter
536 V - Use vacation message
537 C - Use custm sieve script
538 I - Only insider delivery */
540 $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
543 /* Handle delivery flags */
544 if($this->acl_is_writeable("gosaMailDeliveryModeL")){
545 if(!preg_match("/L/",$tmp) && !isset($_POST['only_local'])){
546 $tmp.="L";
547 }elseif(preg_match("/L/",$tmp) && isset($_POST['only_local'])){
548 $tmp = preg_replace("/L/","",$tmp);
549 }
550 }
551 $opts = array(
552 "R" => "use_mailsize_limit",
553 "S" => "use_spam_filter",
554 "V" => "use_vacation",
555 "C" => "own_script",
556 "I" => "drop_own_mails");
558 foreach($opts as $flag => $post){
559 if($this->acl_is_writeable("gosaMailDeliveryMode".$flag)){
560 if(!preg_match("/".$flag."/",$tmp) && isset($_POST[$post])){
561 $tmp.= $flag;
562 }elseif(preg_match("/".$flag."/",$tmp) && !isset($_POST[$post])){
563 $tmp = preg_replace("/".$flag."/","",$tmp);
564 }
565 }
566 }
568 $tmp= "[$tmp]";
569 if ($this->gosaMailDeliveryMode != $tmp){
570 $this->is_modified= TRUE;
571 }
572 $this->gosaMailDeliveryMode= $tmp;
574 /* Get start/stop values for vacation scope of application
575 */
576 if($this->mailMethod->vacationRangeEnabled()){
577 if($this->acl_is_writeable("gosaVacationMessage") && preg_match("/V/",$this->gosaMailDeliveryMode)){
578 if(isset($_POST['gosaVacationStart'])){
579 $this->gosaVacationStart = $_POST['gosaVacationStart'];
580 }
581 if(isset($_POST['gosaVacationStop'])){
582 $this->gosaVacationStop = $_POST['gosaVacationStop'];
583 }
584 }
585 }
586 }
587 }
588 }
591 /*! \brief Parse vacation templates and build up an array
592 containing 'filename' => 'description'.
593 Used to fill vacation dropdown box.
594 @return Array All useable vacation templates.
595 */
596 function get_vacation_templates()
597 {
598 $vct = array();
599 if ($this->config->get_cfg_value("vacationTemplateDirectory") != ""){
600 $dir= $this->config->get_cfg_value("vacationTemplateDirectory");
601 if (is_dir($dir) && is_readable($dir)){
602 $dh = opendir($dir);
603 while($file = readdir($dh)){
604 $description= "";
605 if (is_file($dir."/".$file)){
606 $fh = fopen($dir."/".$file, "r");
607 $line= fgets($fh, 256);
608 if (!preg_match('/^DESC:/', $line)){
609 msg_dialog::display(_("Configuration error"), sprintf(_("No DESC tag in vacation template '%s'!"), $file), ERROR_DIALOG);
610 }else{
611 $description= trim(preg_replace('/^DESC:\s*/', '', $line));
612 }
613 fclose ($fh);
614 }
615 if ($description != ""){
616 $vct["$dir/$file"]= $description;
617 }
618 }
619 closedir($dh);
620 }
621 }
622 return($vct);
623 }
626 /*! \brief Adds the given mail address to the list of mail forwarders
627 */
628 function addForwarder($address)
629 {
630 if(empty($address)) return;
631 if($this->acl_is_writeable("gosaMailForwardingAddress")){
632 $this->gosaMailForwardingAddress[]= $address;
633 $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
634 sort ($this->gosaMailForwardingAddress);
635 reset ($this->gosaMailForwardingAddress);
636 $this->is_modified= TRUE;
637 }else{
638 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
639 }
640 }
643 /*! \brief Removes the given mail address from the list of mail forwarders
644 */
645 function delForwarder($addresses)
646 {
647 if($this->acl_is_writeable("gosaMailForwardingAddress")){
648 $this->gosaMailForwardingAddress= array_remove_entries ($addresses, $this->gosaMailForwardingAddress);
649 $this->is_modified= TRUE;
650 }else{
651 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
652 }
653 }
656 /*! \brief Add given mail address to the list of alternate adresses ,
657 . check if this mal address is used, skip adding in this case
658 */
659 function addAlternate($address)
660 {
661 if(empty($address)) return;
662 if($this->acl_is_writeable("gosaMailAlternateAddress")){
663 $ldap= $this->config->get_ldap_link();
664 $address= strtolower($address);
666 /* Is this address already assigned in LDAP? */
667 $ldap->cd ($this->config->current['BASE']);
668 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=$address)".
669 "(alias=$address)(gosaMailAlternateAddress=$address)))", array("uid"));
670 if ($ldap->count() > 0){
671 $attrs= $ldap->fetch ();
672 return ($attrs["uid"][0]);
673 }
674 if (!in_array($address, $this->gosaMailAlternateAddress)){
675 $this->gosaMailAlternateAddress[]= $address;
676 $this->is_modified= TRUE;
677 }
678 sort ($this->gosaMailAlternateAddress);
679 reset ($this->gosaMailAlternateAddress);
680 return ("");
681 }else{
682 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
683 }
684 }
687 /*! \brief Removes the given mail address from the alternate addresses list
688 */
689 function delAlternate($addresses)
690 {
691 if($this->acl_is_writeable("gosaMailAlternateAddress")){
692 $this->gosaMailAlternateAddress= array_remove_entries ($addresses,$this->gosaMailAlternateAddress);
693 $this->is_modified= TRUE;
694 }else{
695 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
696 }
697 }
700 /*! \brief Prepare importet vacation string. \
701 . Replace placeholder like %givenName a.s.o.
702 @param string Vacation string
703 @return string Completed vacation string
704 */
705 private function prepare_vacation_template($contents)
706 {
707 /* Replace attributes */
708 $attrs = array();
709 $obj = NULL;
710 if(isset($this->parent->by_object['user'])){
711 $attrs = $this->parent->by_object['user']->attributes;
712 $obj = $this->parent->by_object['user'];
713 }else{
714 $obj = new user($this->config,$this->dn);
715 $attrs = $obj->attributes;
716 }
717 if($obj){
719 /* Replace vacation start and end time */
720 if($this->mailMethod->vacationRangeEnabled()){
721 if(preg_match("/%start/",$contents)){
722 $contents = preg_replace("/%start/",$this->gosaVacationStart,$contents);
723 }
724 if(preg_match("/%end/",$contents)){
725 $contents = preg_replace("/%end/",$this->gosaVacationStop,$contents);
726 }
727 }else{
728 if(preg_match("/%start/",$contents)){
729 $contents = preg_replace("/%start/", _("unknown"),$contents);
730 }
731 if(preg_match("/%end/",$contents)){
732 $contents = preg_replace("/%end/", _("unknown"), $contents);
733 }
734 }
736 foreach ($attrs as $val){
737 if(preg_match("/dateOfBirth/",$val)){
738 if($obj->use_dob){
739 $contents= preg_replace("/%$val/",date("Y-d-m",$obj->dateOfBirth),$contents);
740 }
741 }else {
742 $contents= preg_replace("/%$val/",
743 $obj->$val, $contents);
744 }
746 }
747 }
748 $contents = ltrim(preg_replace("/^DESC:.*$/m","",$contents),"\n ");
749 return($contents);
750 }
753 /*! \brief Displays a dialog that allows mail address selection.
754 */
755 function display_forward_dialog()
756 {
757 restore_error_handler();
759 $smarty = get_smarty();
760 $ldap= $this->config->get_ldap_link();
762 /* Save data */
763 $mailfilter= session::get("mailfilter");
764 foreach( array("depselect", "muser", "regex") as $type){
765 if (isset($_POST[$type])){
766 $mailfilter[$type]= $_POST[$type];
767 }
768 }
769 if (isset($_GET['search'])){
770 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
771 if ($s == "**"){
772 $s= "*";
773 }
774 $mailfilter['regex']= $s;
775 }
776 session::set("mailfilter", $mailfilter);
778 /* Get actual list */
779 $mailusers= array ();
780 if ($mailfilter['regex'] != '*' && $mailfilter['regex'] != ""){
781 $regex= $mailfilter['regex'];
782 $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
783 } else {
784 $filter= "";
785 }
786 if ($mailfilter['muser'] != ""){
787 $user= $mailfilter['muser'];
788 $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
789 }
791 /* Add already present people to the filter */
792 $exclude= "";
793 foreach ($this->gosaMailForwardingAddress as $mail){
794 $exclude.= "(mail=$mail)";
795 }
796 if ($exclude != ""){
797 $filter.= "(!(|$exclude))";
798 }
799 $res= get_list("(&(objectClass=gosaMailAccount)$filter)", "users", $mailfilter['depselect'],
800 array("sn", "mail", "givenName"), GL_SIZELIMIT | GL_SUBSEARCH);
801 $ldap->cd($mailfilter['depselect']);
802 $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
803 while ($attrs= $ldap->fetch()){
804 if(preg_match('/%/', $attrs['mail'][0])){
805 continue;
806 }
807 $name= $this->make_name($attrs);
808 $mailusers[$attrs['mail'][0]]= $name."<".
809 $attrs['mail'][0].">";
810 }
811 natcasesort ($mailusers);
812 reset ($mailusers);
814 /* Show dialog */
815 $smarty->assign("search_image", get_template_path('images/lists/search.png'));
816 $smarty->assign("usearch_image", get_template_path('images/lists/search-user.png'));
817 $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
818 $smarty->assign("infoimage", get_template_path('images/info.png'));
819 $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
820 $smarty->assign("mailusers", $mailusers);
821 if (isset($_POST['depselect'])){
822 $smarty->assign("depselect", $_POST['depselect']);
823 }
824 $smarty->assign("deplist", $this->config->idepartments);
825 $smarty->assign("apply", apply_filter());
826 $smarty->assign("alphabet", generate_alphabet());
827 $smarty->assign("hint", print_sizelimit_warning());
828 foreach( array("depselect", "muser", "regex") as $type){
829 $smarty->assign("$type", $mailfilter[$type]);
830 }
831 $smarty->assign("hint", print_sizelimit_warning());
832 $display= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE, dirname(__FILE__)));
833 return ($display);
834 }
837 /*! \brief Removes the mailAccount extension from ldap
838 */
839 function remove_from_parent()
840 {
841 /* Cancel if there's nothing to do here */
842 if (!$this->initially_was_account){
843 return;
844 }
846 /* If domain part was selectable, contruct mail address */
847 if($this->mailMethod->domainSelectionEnabled()){
848 $this->mail = $this->mail."@".$this->mailDomainPart;
849 }
851 /* Update sharedFolder dependencies.
852 Open each shared folder and remove this account.
853 Then Save the group to ensure that all necessary
854 actions will be taken (imap acls updated aso.).
855 */
856 $ldap = $this->config->get_ldap_link();
857 $ldap->cd($this->config->current['BASE']);
858 $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array("dn"));
859 while($attrs = $ldap->fetch()){
860 $grp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
861 if(isset($grp->by_object['mailgroup']) && isset($grp->by_object['group'])){
862 $grp->by_object['group']->removeUser($this->uid);
864 /* Do not save the complete group! This will quit the complete membership
865 */
866 $grp->by_object['mailgroup']->save();
867 }
868 }
870 /* Remove GOsa attributes */
871 plugin::remove_from_parent();
873 /* Zero arrays */
874 $this->attrs['gosaMailAlternateAddress'] = array();
875 $this->attrs['gosaMailForwardingAddress']= array();
878 $this->mailMethod->fixAttributesOnRemove();
879 $this->cleanup();
881 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
882 $ldap= $this->config->get_ldap_link();
883 $ldap->cd($this->dn);
884 $ldap->modify ($this->attrs);
886 /* Add "view" to logging class */
887 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
888 if (!$ldap->success()){
889 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
890 }
892 /* Let the mailMethod remove this mailbox, e.g. from imap and
893 update shared folder membership, ACL may need to be updated.
894 */
895 if (!$this->is_template){
897 if(!$this->mailMethod->connect()){
898 msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"),
899 $this->mailMethod->get_error()), ERROR_DIALOG);
900 }else{
901 if(!$this->mailMethod->deleteMailbox()){
902 msg_dialog::display(_("Mail error"), sprintf(_("Cannot remove mailbox: %s"),
903 $this->mailMethod->get_error()), ERROR_DIALOG);
904 }
905 }
906 }
907 $this->mailMethod->disconnect();
909 /* Optionally execute a command after we're done */
910 $this->handle_post_events("remove",array("uid" => $this->uid));
911 }
914 /*! \brief Save the mailAccount settings to the ldap database.
915 */
916 function save()
917 {
918 $ldap= $this->config->get_ldap_link();
920 /* If domain part was selectable, contruct mail address */
921 if(!(!$this->mailMethod->isModifyableMail() && $this->initially_was_account)){
923 if($this->mailMethod->domainSelectionEnabled()){
924 $this->mail = $this->mail."@".$this->mailDomainPart;
925 }
927 /* Enforce lowercase mail address and trim whitespaces
928 */
929 $this->mail = trim(strtolower($this->mail));
930 }
933 /* Call parents save to prepare $this->attrs */
934 plugin::save();
936 /* Save arrays */
937 $this->attrs['gosaMailAlternateAddress'] = $this->gosaMailAlternateAddress;
938 $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
940 if(!$this->mailMethod->vacationRangeEnabled()){
941 $this->attrs['gosaVacationStart'] = $this->attrs['gosaVacationStop'] = array();
942 }elseif (!preg_match('/V/', $this->gosaMailDeliveryMode)){
943 unset($this->attrs['gosaVacationStart']);
944 unset($this->attrs['gosaVacationStop']);
945 } else {
946 /* Adapt values to be timestamps */
947 list($day, $month, $year)= split('\.', $this->gosaVacationStart);
948 $this->attrs['gosaVacationStart']= mktime(0,0,0,$month, $day, $year);
949 list($day, $month, $year)= split('\.', $this->gosaVacationStop);
950 $this->attrs['gosaVacationStop']= mktime(0,0,0,$month, $day, $year);
951 }
953 /* Map method attributes */
954 $this->mailMethod->fixAttributesOnStore();
956 /* Save data to LDAP */
957 $ldap->cd($this->dn);
958 $this->cleanup();
959 $ldap->modify ($this->attrs);
961 if (!$ldap->success()){
962 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
963 }
965 /* Log last action */
966 if($this->initially_was_account){
967 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
968 }else{
969 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
970 }
972 /* Only do IMAP actions if we are not a template */
973 if (!$this->is_template){
974 $this->mailMethod->connect();
975 if(!$this->mailMethod->is_connected()){
976 msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"),
977 $this->mailMethod->get_error()), ERROR_DIALOG);
978 }else{
979 if(!$this->mailMethod->updateMailbox()){
980 msg_dialog::display(_("Mail error"), sprintf(_("Cannot update mailbox: %s"),
981 $this->mailMethod->get_error()), ERROR_DIALOG);
982 }
983 if(!$this->mailMethod->setQuota($this->gosaMailQuota)){
984 msg_dialog::display(_("Mail error"), sprintf(_("Cannot write quota settings: %s"),
985 $this->mailMethod->get_error()), ERROR_DIALOG);
986 }
988 if (!is_integer(strpos($this->gosaMailDeliveryMode, "C"))){
990 /* Do not write sieve settings if this account is new and
991 doesn't seem to exist.
992 */
993 if(!$this->initially_was_account && !$this->mailMethod->account_exists()){
994 @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,
995 "Skipping sieve settings, the account doesn't seem to be created already.</b>","");
996 }else{
997 if(!$this->mailMethod->saveSieveSettings()){
998 msg_dialog::display(_("Mail error saving sieve settings"), $this->mailMethod->get_error(), ERROR_DIALOG);
999 }
1000 }
1001 }else{
1002 @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,
1003 "User uses an own sieve script, skipping sieve update.".$str."</b>","");
1004 $this->sieve_management->save();
1005 }
1006 }
1007 }
1008 $this->mailMethod->disconnect();
1010 /* Update sharedFolder dependencies.
1011 Open each shared folder and remove this account.
1012 Then Save the group to ensure that all necessary
1013 actions will be taken (imap acls updated aso.).
1014 */
1015 if(!$this->initially_was_account){
1016 $ldap = $this->config->get_ldap_link();
1017 $ldap->cd($this->config->current['BASE']);
1018 $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array("dn"));
1019 while($attrs = $ldap->fetch()){
1020 $grp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
1021 if(isset($grp->by_object['mailgroup'])){
1022 /* Do not save the complete group! This will quit the complete membership
1023 */
1024 $grp->by_object['mailgroup']->save();
1025 }
1026 }
1027 }
1029 /* Optionally execute a command after we're done */
1030 if ($this->initially_was_account == $this->is_account){
1031 if ($this->is_modified){
1032 $this->handle_post_events("modify", array("uid" => $this->uid));
1033 }
1034 } else {
1035 $this->handle_post_events("add", array("uid" => $this->uid));
1036 }
1037 }
1040 /*! \brief Check given values
1041 */
1042 function check()
1043 {
1044 if(!$this->is_account){
1045 return(array());
1046 }
1048 $ldap= $this->config->get_ldap_link();
1050 /* Call common method to give check the hook */
1051 $message= plugin::check();
1053 if(empty($this->gosaMailServer)){
1054 $message[]= msgPool::noserver(_("Mail"));
1055 }
1057 /* Mail address checks */
1058 $mail = $this->mail;
1059 if(!(!$this->mailMethod->isModifyableMail() && $this->initially_was_account)){
1061 if($this->mailMethod->domainSelectionEnabled()){
1062 $mail.= "@".$this->mailDomainPart;
1063 }
1065 if (empty($mail)){
1066 $message[]= msgPool::required(_("Primary address"));
1067 }
1068 if ($this->is_template){
1069 if (!tests::is_email($mail, TRUE)){
1070 $message[]= msgPool::invalid(_("Mail address"),"","","%givenName.%sn@your-domain.com");
1071 }
1072 } else {
1073 if (!tests::is_email($mail)){
1074 $message[]= msgPool::invalid(_("Mail address"),"","","your-address@your-domain.com");
1075 }
1076 }
1078 /* Check if this mail address is already in use */
1079 $ldap->cd($this->config->current['BASE']);
1080 $filter = "(&(!(objectClass=gosaUserTemplate))(!(uid=".$this->uid."))".
1081 "(objectClass=gosaMailAccount)".
1082 "(|(mail=".$mail.")(alias=".$mail.")(gosaMailAlternateAddress=".$mail.")))";
1083 $ldap->search($filter,array("uid"));
1084 if ($ldap->count() != 0){
1085 $message[]= msgPool::duplicated(_("Mail address"));
1086 }
1087 }
1090 /* Check quota */
1091 if ($this->gosaMailQuota != '' && $this->acl_is_writeable("gosaMailQuota")){
1092 if (!is_numeric($this->gosaMailQuota)) {
1093 $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
1094 } else {
1095 $this->gosaMailQuota= (int) $this->gosaMailQuota;
1096 }
1097 }
1099 /* Check rejectsize for integer */
1100 if ($this->gosaMailMaxSize != '' && $this->acl_is_writeable("gosaMailMaxSize")){
1101 if (!is_numeric($this->gosaMailMaxSize)){
1102 $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
1103 } else {
1104 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
1105 }
1106 }
1108 /* Need gosaMailMaxSize if use_mailsize_limit is checked */
1109 if (is_integer(strpos($this->gosaMailDeliveryMode, "R")) && $this->gosaMailMaxSize == ""){
1110 $message[]= msgPool::required(_("Mail reject size"));
1111 }
1113 if((preg_match("/S/", $this->gosaMailDeliveryMode))&&(empty($this->gosaSpamMailbox))) {
1114 $message[]= msgPool::required(_("Spam folder"));
1115 }
1117 if ($this->mailMethod->vacationRangeEnabled() && preg_match('/V/', $this->gosaMailDeliveryMode)){
1119 /* Check date strings */
1120 $state= true;
1121 if ($this->gosaVacationStart == "" || !tests::is_date($this->gosaVacationStart)) {
1122 $message[]= msgPool::invalid(_("from"),$this->gosaVacationStart);
1123 $state= false;
1124 }
1125 if ($this->gosaVacationStart == "" || !tests::is_date($this->gosaVacationStop)) {
1126 $message[]= msgPool::invalid(_("to"),$this->gosaVacationStop);
1127 $state= false;
1128 }
1130 #TODO: take care of date format
1131 if ($state) {
1132 list($day, $month, $year)= split('\.', $this->gosaVacationStart);
1133 $start= mktime(0,0,0,$month, $day, $year);
1134 list($day, $month, $year)= split('\.', $this->gosaVacationStop);
1135 $stop= mktime(0,0,0,$month, $day, $year);
1136 if($start > $stop){
1137 $message[]= msgPool::invalid(_("Vacation interval"));
1138 }
1139 }
1140 }
1141 return($message);
1142 }
1145 /*! \brief Adapt from template, using 'dn'
1146 */
1147 function adapt_from_template($dn, $skip= array())
1148 {
1149 plugin::adapt_from_template($dn, $skip);
1151 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
1153 if (in_array($val, $skip)){
1154 continue;
1155 }
1157 $this->$val= array();
1158 if (isset($this->attrs["$val"]["count"])){
1159 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
1160 $value= $this->attrs["$val"][$i];
1161 foreach (array("sn", "givenName", "uid") as $repl){
1162 if (preg_match("/%$repl/i", $value)){
1163 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
1164 }
1165 }
1166 array_push($this->$val, strtolower(rewrite($value)));
1167 }
1168 }
1169 }
1170 $this->mail= strtolower(rewrite($this->mail));
1171 }
1174 /*! \brief Creates the mail part for the copy & paste dialog
1175 */
1176 function getCopyDialog()
1177 {
1178 if(!$this->is_account) return("");
1179 $smarty = get_smarty();
1180 $smarty->assign("mail",$this->mail);
1181 $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress);
1182 $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress);
1183 $str = $smarty->fetch(get_template_path("copypaste.tpl",TRUE, dirname(__FILE__)));
1185 $ret = array();
1186 $ret['status'] = "";
1187 $ret['string'] = $str;
1188 return($ret);
1189 }
1192 /*! \brief save_object for copy&paste vars
1193 */
1194 function saveCopyDialog()
1195 {
1196 if(!$this->is_account) return;
1198 /* Execute to save mailAlternateAddress && gosaMailForwardingAddress */
1199 $this->execute();
1200 if(isset($_POST['mail'])){
1201 $this->mail = $_POST['mail'];
1202 }
1203 }
1206 /*! \brief Prepare this account to be copied
1207 */
1208 function PrepareForCopyPaste($source)
1209 {
1210 plugin::PrepareForCopyPaste($source);
1212 /* Reset alternate mail addresses */
1213 $this->gosaMailAlternateAddress = array();
1214 }
1217 /*! \brief Prepare this class the be useable when editing multiple users at once
1218 */
1219 function get_multi_edit_values()
1220 {
1221 $ret = plugin::get_multi_edit_values();
1222 if(in_array("gosaMailQuota",$this->multi_boxes)){
1223 $ret['gosaMailQuota'] = $this->gosaMailQuota;
1224 }
1225 $flag_add = $flag_remove = array();
1226 $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1227 $opts = array(
1228 "R" => "use_mailsize_limit",
1229 "S" => "use_spam_filter",
1230 "L" => "only_local",
1231 "V" => "use_vacation",
1232 "C" => "own_script",
1233 "I" => "drop_own_mails");
1234 foreach($opts as $flag => $post){
1235 if(in_array($post, $this->multi_boxes)){
1236 if(preg_match("/".$flag."/",$tmp)){
1237 $flag_add[] = $flag;
1238 }else{
1239 $flag_remove[] = $flag;
1240 }
1241 }
1242 }
1243 $ret['flag_add'] = $flag_add;
1244 $ret['flag_remove'] = $flag_remove;
1246 if($this->mailMethod->vacationRangeEnabled()){
1247 if(in_array("V",$flag_add)){
1248 $ret['gosaVacationStart'] = $this->gosaVacationStart = $_POST['gosaVacationStart'];
1249 $ret['gosaVacationStop'] = $this->gosaVacationStop = $_POST['gosaVacationStop'];
1250 }
1251 }
1252 return($ret);
1253 }
1256 /*! \brief Check given input for multiple user edit
1257 */
1258 function multiple_check()
1259 {
1260 $message = plugin::multiple_check();
1262 if(empty($this->gosaMailServer) && in_array("gosaMailServer",$this->multi_boxes)){
1263 $message[]= msgPool::noserver(_("Mail"));
1264 }
1266 /* Check quota */
1267 if ($this->gosaMailQuota != '' && in_array("gosaMailQuota",$this->multi_boxes)){
1268 if (!is_numeric($this->gosaMailQuota)) {
1269 $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
1270 } else {
1271 $this->gosaMailQuota= (int) $this->gosaMailQuota;
1272 }
1273 }
1275 /* Check rejectsize for integer */
1276 if ($this->gosaMailMaxSize != '' && in_array("gosaMailMaxSize",$this->multi_boxes)){
1277 if (!is_numeric($this->gosaMailMaxSize)){
1278 $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
1279 } else {
1280 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
1281 }
1282 }
1284 if(empty($this->gosaSpamMailbox) && in_array("gosaSpamMailbox",$this->multi_boxes)){
1285 $message[]= msgPool::required(_("Spam folder"));
1286 }
1288 if ($this->mailMethod->vacationRangeEnabled() && preg_match('/V/', $this->gosaMailDeliveryMode)){
1290 /* Check date strings */
1291 $state= true;
1292 if ($this->gosaVacationStart == "" || !tests::is_date($this->gosaVacationStart)) {
1293 $message[]= msgPool::invalid(_("from"),$this->gosaVacationStart);
1294 $state= false;
1295 }
1296 if ($this->gosaVacationStart == "" || !tests::is_date($this->gosaVacationStop)) {
1297 $message[]= msgPool::invalid(_("to"),$this->gosaVacationStop);
1298 $state= false;
1299 }
1301 #TODO: take care of date format
1302 if ($state) {
1303 list($day, $month, $year)= split('\.', $this->gosaVacationStart);
1304 $start= mktime(0,0,0,$month, $day, $year);
1305 list($day, $month, $year)= split('\.', $this->gosaVacationStop);
1306 $stop= mktime(0,0,0,$month, $day, $year);
1307 if($start > $stop){
1308 $message[]= msgPool::invalid(_("Vacation interval"));
1309 }
1310 }
1311 }
1312 return($message);
1313 }
1316 /*! \brief ...
1317 */
1318 function set_multi_edit_values($values)
1319 {
1320 plugin::set_multi_edit_values($values);
1321 $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1322 if(isset($values['flag_add'])){
1323 foreach($values['flag_add'] as $flag){
1324 if(!preg_match("/".$flag."/",$tmp)){
1325 $tmp .= $flag;
1326 }
1327 }
1328 }
1329 if(isset($values['flag_remove'])){
1330 foreach($values['flag_remove'] as $flag){
1331 if(preg_match("/".$flag."/",$tmp)){
1332 $tmp = preg_replace("/".$flag."/","",$tmp);
1333 }
1334 }
1335 }
1336 $this->gosaMailDeliveryMode = "[".$tmp."]";
1338 /* Set vacation message and replace placeholder like %givenName
1339 */
1340 if(isset($values['gosaVacationMessage'])){
1341 $this->gosaVacationMessage = $this->prepare_vacation_template($values['gosaVacationMessage']);
1342 }
1343 }
1346 /*! \brief Initialize plugin to be used as multiple edit class.
1347 */
1348 function init_multiple_support($attrs,$all)
1349 {
1350 plugin::init_multiple_support($attrs,$all);
1351 if(isset($this->multi_attrs['gosaMailQuota'])){
1352 $this->gosaMailQuota = $this->multi_attrs['gosaMailQuota'];
1353 }
1354 }
1357 /*! \brief
1358 */
1359 function get_multi_init_values()
1360 {
1361 $attrs = plugin::get_multi_init_values();
1362 $attrs['gosaMailQuota'] = $this->gosaMailQuota;
1363 return($attrs);
1364 }
1367 /*! \brief Display multiple edit dialog
1368 */
1369 function multiple_execute()
1370 {
1371 return($this->execute());
1372 }
1375 /*! \brief Save posts from multiple edit dialog
1376 */
1377 function multiple_save_object()
1378 {
1379 plugin::multiple_save_object();
1381 $this->save_object();
1382 foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
1383 if(isset($_POST["use_".$attr])){
1384 $this->multi_boxes[] = $attr;
1385 }
1386 }
1387 }
1390 /*! \brief Creates the user names for the add_local_forward dialog
1391 */
1392 function make_name($attrs)
1393 {
1394 $name= "";
1395 if (isset($attrs['sn'][0])){
1396 $name= $attrs['sn'][0];
1397 }
1398 if (isset($attrs['givenName'][0])){
1399 if ($name != ""){
1400 $name.= ", ".$attrs['givenName'][0];
1401 } else {
1402 $name.= $attrs['givenName'][0];
1403 }
1404 }
1405 if ($name != ""){
1406 $name.= " ";
1407 }
1409 return ($name);
1410 }
1413 function allow_remove()
1414 {
1415 $resason = "";
1416 if(!$this->mailMethod->allow_remove($reason)){
1417 return($reason);
1418 }
1419 return("");
1420 }
1424 /*! \brief ACL settings
1425 */
1426 static function plInfo()
1427 {
1428 return (array(
1429 "plShortName" => _("Mail"),
1430 "plDescription" => _("Mail settings"),
1431 "plSelfModify" => TRUE,
1432 "plDepends" => array("user"), // This plugin depends on
1433 "plPriority" => 4, // Position in tabs
1434 "plSection" => array("personal" => _("My account")),
1435 "plCategory" => array("users"),
1436 "plOptions" => array(),
1438 "plProvidedAcls" => array(
1439 "mail" => _("Mail address"),
1440 "gosaMailServer" => _("Mail server"),
1441 "gosaMailQuota" => _("Quota size"),
1443 "gosaMailDeliveryModeV" => _("Add vacation information"), // This is flag of gosaMailDeliveryMode
1444 "gosaVacationMessage" => _("Vacation message"),
1446 "gosaMailDeliveryModeS" => _("Use spam filter"), // This is flag of gosaMailDeliveryMode
1447 "gosaSpamSortLevel" => _("Spam level"),
1448 "gosaSpamMailbox" => _("Spam mail box"),
1450 "sieveManagement" => _("Sieve management"),
1452 "gosaMailDeliveryModeR" => _("Reject due to mailsize"), // This is flag of gosaMailDeliveryMode
1453 "gosaMailMaxSize" => _("Mail max size"),
1455 "gosaMailForwardingAddress" => _("Forwarding address"),
1456 "gosaMailDeliveryModeL" => _("Local delivery"), // This is flag of gosaMailDeliveryMode
1457 "gosaMailDeliveryModeI" => _("No delivery to own mailbox "), // This is flag of gosaMailDeliveryMode
1458 "gosaMailAlternateAddress" => _("Mail alternative addresses"),
1460 "gosaMailForwardingAddress" => _("Forwarding address"),
1461 "gosaMailDeliveryModeC" => _("Use custom sieve script")) // This is flag of gosaMailDeliveryMode
1462 ));
1463 }
1466 }
1468 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1469 ?>