1 <?php
2 /*!
3 \brief mail plugin
4 \author Fabian Hicker <Fabian.Hickert@GONICUS.de>
5 \version 2.6.2
6 \date 03.12.2007
8 This class provides the functionality to read and write all attributes
9 relevant for gosaMailAccounts from/to the LDAP.
10 It does syntax checking and displays the formulars required.
11 Special handling like sieve or imap actions will be implemented
12 by the mailMethods.
15 Functions :
17 - mailAccount (&$config, $dn= NULL)
18 - execute()
19 - save_object()
20 - get_vacation_templates()
21 - addForwarder($address)
22 - delForwarder($addresses)
23 - addAlternate($address)
24 - delAlternate($addresses)
25 - prepare_vacation_template($contents)
26 - remove_from_parent()
27 - save()
28 - check()
29 - adapt_from_template($dn, $skip= array())
30 - getCopyDialog()
31 - saveCopyDialog()
32 - PrepareForCopyPaste($source)
33 - get_multi_edit_values()
34 - multiple_check()
35 - set_multi_edit_values($values)
36 - init_multiple_support($attrs,$all)
37 - get_multi_init_values()
38 - multiple_execute()
39 - multiple_save_object()
40 - make_name($attrs)
41 - plInfo()
44 */
46 class mailAccount extends plugin
47 {
48 /* Definitions */
49 var $plHeadline = "Mail";
50 var $plDescription = "This does something";
51 var $view_logged = FALSE;
52 var $is_account = FALSE;
53 var $initially_was_account = FALSE;
55 /* GOsa mail attributes */
56 var $mail = "";
57 var $gosaVacationStart = "";
58 var $gosaVacationStop = "";
59 var $gosaMailAlternateAddress = array();
60 var $gosaMailForwardingAddress = array();
61 var $gosaMailDeliveryMode = "[L ]";
62 var $gosaMailServer = "";
63 var $gosaMailQuota = "";
64 var $gosaMailMaxSize = "";
65 var $gosaVacationMessage = "";
66 var $gosaSpamSortLevel = "";
67 var $gosaSpamMailbox = "";
69 /* The methods defaults */
70 var $quotaUsage = -1; // Means unknown
72 var $mailMethod = NULL;
73 var $MailDomain = "";
74 var $sieveManagementUsed = FALSE;
75 var $vacationTemplates = array();
76 var $sieve_management = NULL;
77 var $mailAddressSelect = FALSE;
78 var $initial_uid = "";
79 var $mailDomainPart = "";
80 var $mailDomainParts = array();
81 var $MailBoxes = array("INBOX");
83 /* Used LDAP attributes && classes */
84 var $attributes= array(
85 "mail", "gosaMailServer","gosaMailQuota", "gosaMailMaxSize","gosaMailForwardingAddress",
86 "gosaMailDeliveryMode", "gosaSpamSortLevel", "gosaSpamMailbox","gosaMailAlternateAddress",
87 "gosaVacationStart","gosaVacationStop", "gosaVacationMessage", "gosaMailAlternateAddress",
88 "gosaMailForwardingAddress");
89 var $objectclasses= array("gosaMailAccount");
91 var $multiple_support = TRUE;
93 var $uid = "";
94 var $cn = "";
97 /*! \brief Initialize the mailAccount
98 */
99 function __construct (&$config, $dn= NULL)
100 {
101 plugin::plugin($config,$dn);
103 /* Get attributes from parent object
104 */
105 foreach(array("uid","cn") as $attr){
106 if(isset($this->parent->by_object['group']) && isset($this->parent->by_object['group']->$attr)){
107 $this->$attr = &$this->parent->by_object['group']->$attr;
108 }elseif(isset($this->attrs[$attr])){
109 $this->$attr = $this->attrs[$attr][0];
110 }
111 }
113 /* Intialize the used mailMethod
114 */
115 $tmp = new mailMethod($config,$this);
116 $this->mailMethod = $tmp->get_method();
117 $this->mailMethod->fixAttributesOnLoad();
118 $this->mailDomainParts = $this->mailMethod->getMailDomains();
119 $this->SpamLevels = $this->mailMethod->getSpamLevels();
121 /* Remember account status
122 */
123 $this->initially_was_account = $this->is_account;
125 /* Initialize vacation settings, if enabled.
126 */
127 if(empty($this->gosaVacationStart) && $this->mailMethod->vacationRangeEnabled()){
128 $this->gosaVacationStart = time();
129 $this->gosaVacationStop = time();
130 }
132 /* Read vacation templates
133 */
134 $this->vacationTemplates = $this->get_vacation_templates();
136 /* Initialize configured values
137 */
138 if($this->is_account){
140 if($this->mailMethod->connect() && $this->mailMethod->account_exists()){
142 /* Read quota */
143 $this->gosaMailQuota = $this->mailMethod->getQuota($this->gosaMailQuota);
144 $this->quotaUsage = $this->mailMethod->getQuotaUsage($this->quotaUsage);
145 if($this->mailMethod->is_error()){
146 msg_dialog::display(_("Mail error"), sprintf(_("Cannot read quota settings: %s"),
147 $this->mailMethod->get_error()), ERROR_DIALOG);
148 }
150 /* Read mailboxes */
151 $this->MailBoxes = $this->mailMethod->getMailboxList($this->MailBoxes);
152 if($this->mailMethod->is_error()){
153 msg_dialog::display(_("Mail error"), sprintf(_("Cannot get list of mailboxes: %s"),
154 $this->mailMethod->get_error()), ERROR_DIALOG);
155 }
157 }elseif(!$this->mailMethod->is_connected()){
158 msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"),
159 $this->mailMethod->get_error()), ERROR_DIALOG);
160 }elseif(!$this->mailMethod->account_exists()){
161 msg_dialog::display(_("Mail error"), sprintf(_("Mailbox '%s' doesn't exists on mail server: %s"),
162 $this->mailMethod->get_account_id(),$this->gosaMailServer), ERROR_DIALOG);
163 }
165 /* If the doamin part is selectable, we have to split the mail address
166 */
167 if(!(!$this->mailMethod->isModifyableMail() && $this->is_account)){
168 if($this->mailMethod->domainSelectionEnabled()){
169 $this->mailDomainPart = preg_replace("/^[^@]*+@/","",$this->mail);
170 $this->mail = preg_replace("/@.*$/","\\1",$this->mail);
171 if(!in_array($this->mailDomainPart,$this->mailDomainParts)){
172 $this->mailDomainParts[] = $this->mailDomainPart;
173 }
174 }
175 }
177 /* Load attributes containing arrays */
178 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
179 $this->$val= array();
180 if (isset($this->attrs["$val"]["count"])){
181 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
182 array_push($this->$val, $this->attrs["$val"][$i]);
183 }
184 }
185 }
186 }
188 /* Intialize sieveManagement if necessary */
189 if($this->mailMethod->allowSieveManagement()){
190 $this->mailboxList = &$this->MailBoxes;
191 $this->sieve_management = new sieveManagement($this->config,$this->dn,$this,$this->mailMethod->getUAttrib());
192 }
194 /* Disconnect mailMethod. Connect on demand later.
195 */
196 $this->mailMethod->disconnect();
198 /* Convert start/stop dates */
199 #TODO: use date format
200 $this->gosaVacationStart= date('d.m.Y', $this->gosaVacationStart);
201 $this->gosaVacationStop= date('d.m.Y', $this->gosaVacationStop);
202 }
205 function execute()
206 {
208 /* Call parent execute */
209 $display = plugin::execute();
211 /* Log view */
212 if($this->is_account && !$this->view_logged){
213 $this->view_logged = TRUE;
214 new log("view","users/".get_class($this),$this->dn);
215 }
218 /****************
219 Account status
220 ****************/
222 if(isset($_POST['modify_state'])){
223 if($this->is_account && $this->acl_is_removeable() && $this->mailMethod->accountRemoveAble()){
224 $this->is_account= FALSE;
225 }elseif(!$this->is_account && $this->acl_is_createable() && $this->mailMethod->accountCreateable()){
226 $this->is_account= TRUE;
227 }
228 }
229 if(!$this->multiple_support_active){
230 if (!$this->is_account && $this->parent === NULL){
231 $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\"> <b>".
232 msgPool::noValidExtension(_("Mail"))."</b>";
233 $display.= back_to_main();
234 return ($display);
235 }
236 if ($this->parent !== NULL){
237 if ($this->is_account){
238 $reason = "";
239 if(!$this->mailMethod->accountRemoveable($reason)){
240 $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Mail")),$reason ,TRUE,TRUE);
241 }else{
242 $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Mail")),msgPool::featuresEnabled(_("Mail")));
243 }
244 } else {
245 $reason = "";
246 if(!$this->mailMethod->accountCreateable($reason)){
247 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Mail")),$reason ,TRUE,TRUE);
248 }else{
249 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Mail")),msgPool::featuresDisabled(_("Mail")));
250 }
251 return ($display);
252 }
253 }
254 }
256 /****************
257 Sieve Management Dialog
258 ****************/
259 if($this->mailMethod->allowSieveManagement()){
260 if(isset($_POST['sieveManagement'])
261 && preg_match("/C/",$this->gosaMailDeliveryMode)
262 && $this->acl_is_writeable("sieveManagement")
263 && $this->mailMethod->allowSieveManagement()) {
264 $this->dialog = $this->sieve_management;
265 }
266 if(isset($_POST['sieve_cancel'])){
267 $this->dialog = FALSE;
268 }
269 if(isset($_POST['sieve_finish'])){
270 $this->sieve_management = $this->dialog;
271 $this->dialog = FALSE;
272 }
273 if(is_object($this->dialog)){
274 $this->dialog->save_object();
275 return($this->dialog->execute());
276 }
277 }
279 /****************
280 Forward addresses
281 ****************/
283 if (isset($_POST['add_local_forwarder'])){
284 $this->mailAddressSelect= new mailAddressSelect($this->config, get_userinfo());
285 $this->dialog= TRUE;
286 }
287 if (isset($_POST['mailAddressSelect_cancel'])){
288 $this->mailAddressSelect= FALSE;
289 $this->dialog= FALSE;
290 }
292 if (isset($_POST['mailAddressSelect_save']) && $this->mailAddressSelect instanceOf mailAddressSelect){
294 if($this->acl_is_writeable("gosaMailForwardingAddress")){
295 $list = $this->mailAddressSelect->save();
296 foreach ($list as $entry){
297 $val = $entry['mail'][0];
298 if (!in_array ($val, $this->gosaMailAlternateAddress) && $val != $this->mail){
299 $this->addForwarder($val);
300 $this->is_modified= TRUE;
301 }
302 }
303 $this->mailAddressSelect= FALSE;
304 $this->dialog= FALSE;
305 } else {
306 msg_dialog::display(_("Error"), _("Please select an entry!"), ERROR_DIALOG);
307 }
308 }
310 if($this->mailAddressSelect instanceOf mailAddressSelect){
311 $used = array();
312 $used['mail'] = array_values($this->gosaMailAlternateAddress);
313 $used['mail'] = array_merge($used['mail'], array_values($this->gosaMailForwardingAddress));
314 $used['mail'][] = $this->mail;
316 // Build up blocklist
317 session::set('filterBlacklist', $used);
318 return($this->mailAddressSelect->execute());
319 }
321 if (isset($_POST['add_forwarder'])){
322 if ($_POST['forward_address'] != ""){
323 $address= get_post('forward_address');
324 $valid= FALSE;
325 if (!tests::is_email($address)){
326 if (!tests::is_email($address, TRUE)){
327 if ($this->is_template){
328 $valid= TRUE;
329 } else {
330 msg_dialog::display(_("Error"), msgPool::invalid(_("Mail address"),
331 "","","your-address@your-domain.com"),ERROR_DIALOG);
332 }
333 }
334 } elseif ($address == $this->mail
335 || in_array($address, $this->gosaMailAlternateAddress)) {
336 msg_dialog::display(_("Error"),_("Cannot add primary address to the list of forwarders!") , ERROR_DIALOG);
337 } else {
338 $valid= TRUE;
339 }
340 if ($valid){
341 if($this->acl_is_writeable("gosaMailForwardingAddress")){
342 $this->addForwarder ($address);
343 $this->is_modified= TRUE;
344 }
345 }
346 }
347 }
348 if (isset($_POST['delete_forwarder'])){
349 $this->delForwarder ($_POST['forwarder_list']);
350 }
351 if ($this->mailAddressSelect instanceOf mailAddressSelect){
353 return($this->mailAddressSelect->execute());
354 }
357 /****************
358 Alternate addresses
359 ****************/
361 if (isset($_POST['add_alternate'])){
362 $valid= FALSE;
363 if (!tests::is_email($_POST['alternate_address'])){
364 if ($this->is_template){
365 if (!(tests::is_email($_POST['alternate_address'], TRUE))){
366 msg_dialog::display(_("Error"),msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com"),ERROR_DIALOG);
367 } else {
368 $valid= TRUE;
369 }
370 } else {
371 msg_dialog::display(_("Error"),msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com"),ERROR_DIALOG);
372 }
373 } else {
374 $valid= TRUE;
375 }
376 if ($valid && ($user= $this->addAlternate (get_post('alternate_address'))) != ""){
377 $ui= get_userinfo();
378 $addon= "";
379 if ($user[0] == "!") {
380 $addon= sprintf(_("Address is already in use by group '%s'."), mb_substr($user, 1));
381 } else {
382 $addon= sprintf(_("Address is already in use by user '%s'."), $user);
383 }
384 msg_dialog::display(_("Error"), msgPool::duplicated(_("Mail address"))."<br><br><i>".
385 "$addon</i>", ERROR_DIALOG);
386 }
387 }
388 if (isset($_POST['delete_alternate']) && isset($_POST['alternates_list'])){
389 $this->delAlternate ($_POST['alternates_list']);
390 }
392 /****************
393 SMARTY- Assign smarty variables
394 ****************/
395 $smarty = get_smarty();
397 $smarty->assign("initially_was_account", $this->initially_was_account);
398 $smarty->assign("isModifyableMail" , $this->mailMethod->isModifyableMail());
399 $smarty->assign("isModifyableServer", $this->mailMethod->isModifyableServer());
400 $smarty->assign("mailEqualsCN", $this->mailMethod->mailEqualsCN());
402 $tmp = $this->plInfo();
403 foreach($tmp['plProvidedAcls'] as $name => $transl){
404 $smarty->assign("$name"."ACL", $this->getacl($name));
405 }
406 foreach($this->attributes as $attr){
407 $smarty->assign($attr,set_post($this->$attr));
408 }
409 $smarty->assign("quotaEnabled", $this->mailMethod->quotaEnabled());
410 if($this->mailMethod->quotaEnabled()){
411 $smarty->assign("quotaUsage", mailMethod::quota_to_image($this->quotaUsage,$this->gosaMailQuota));
412 $smarty->assign("gosaMailQuota",set_post($this->gosaMailQuota));
413 }
414 $smarty->assign("domainSelectionEnabled", $this->mailMethod->domainSelectionEnabled());
415 $smarty->assign("MailDomains", set_post($this->mailDomainParts));
416 $smarty->assign("MailDomain" , set_post($this->mailDomainPart));
417 $smarty->assign("MailServers", set_post($this->mailMethod->getMailServers()));
418 $smarty->assign("allowSieveManagement", $this->mailMethod->allowSieveManagement());
419 $smarty->assign("own_script", $this->sieveManagementUsed);
421 /* _Multiple users vars_ */
422 foreach($this->attributes as $attr){
423 $u_attr = "use_".$attr;
424 $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
425 }
426 foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
427 $u_attr = "use_".$attr;
428 $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
429 }
432 /****************
433 SMARTY- Assign flags
434 ****************/
436 $types = array(
437 "V"=>"use_vacation",
438 "S"=>"use_spam_filter",
439 "R"=>"use_mailsize_limit",
440 "I"=>"drop_own_mails",
441 "C"=>"own_script");
442 foreach($types as $option => $varname){
443 if (preg_match("/".$option."/", $this->gosaMailDeliveryMode)) {
444 $smarty->assign($varname, "checked");
445 } else {
446 $smarty->assign($varname, "");
447 }
448 }
449 if (!preg_match("/L/", $this->gosaMailDeliveryMode)) {
450 $smarty->assign("only_local", "checked");
451 } else {
452 $smarty->assign("only_local", "");
453 }
456 /****************
457 Smarty- Vacation settings
458 ****************/
459 $smarty->assign("rangeEnabled", FALSE);
460 $smarty->assign("template", "");
461 if (count($this->vacationTemplates)){
462 $smarty->assign("show_templates", "true");
463 $smarty->assign("vacationtemplates", set_post($this->vacationTemplates));
464 if (isset($_POST['vacation_template'])){
465 $smarty->assign("template", set_post(get_post('vacation_template')));
466 }
467 } else {
468 $smarty->assign("show_templates", "false");
469 }
471 /* Vacation range assigments
472 */
473 if($this->mailMethod->vacationRangeEnabled()){
474 $smarty->assign("rangeEnabled", TRUE);
475 }
477 /* fill filter settings
478 */
479 $smarty->assign("spamlevel", $this->SpamLevels);
480 $smarty->assign("spambox" , $this->MailBoxes);
482 $smarty->assign("multiple_support",$this->multiple_support_active);
483 return($display.$smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
484 }
488 /* Save data to object */
489 function save_object()
490 {
491 if (isset($_POST['mailTab'])){
493 /* Save ldap attributes */
494 $mail = $this->mail;
495 $server = $this->gosaMailServer;
496 plugin::save_object();
498 if(!$this->mailMethod->isModifyableServer() && $this->initially_was_account){
499 $this->gosaMailServer = $server;
500 }
502 if(!$this->mailMethod->isModifyableMail() && $this->initially_was_account){
503 $this->mail = $mail;
504 }else{
506 /* Get posted mail domain part, if necessary
507 */
508 if($this->mailMethod->domainSelectionEnabled() && isset($_POST['MailDomain'])){
509 if(in_array(get_post('MailDomain'), $this->mailDomainParts)){
510 $this->mailDomainPart = get_post('MailDomain');
511 }
512 }
513 }
515 /* Import vacation message?
516 */
517 if (isset($_POST["import_vacation"]) && isset($this->vacationTemplates[$_POST["vacation_template"]])){
518 if($this->multiple_support_active){
519 $contents = ltrim(preg_replace("/^DESC:.*$/m","",file_get_contents(get_post("vacation_template"))));
520 }else{
521 $contents = $this->prepare_vacation_template(file_get_contents(get_post("vacation_template")));
522 }
523 $this->gosaVacationMessage= htmlspecialchars($contents);
524 }
526 /* Handle flags
527 */
528 if(isset($_POST['own_script'])){
529 if(!preg_match("/C/",$this->gosaMailDeliveryMode)){
530 $str= preg_replace("/[\[\]]/","",$this->gosaMailDeliveryMode);
531 $this->gosaMailDeliveryMode = "[".$str."C]";
532 }
533 }else{
535 /* Assemble mail delivery mode
536 The mode field in ldap consists of values between braces, this must
537 be called when 'mail' is set, because checkboxes may not be set when
538 we're in some other dialog.
540 Example for gosaMailDeliveryMode [LR ]
541 L - Local delivery
542 R - Reject when exceeding mailsize limit
543 S - Use spam filter
544 V - Use vacation message
545 C - Use custm sieve script
546 I - Only insider delivery */
548 $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
551 /* Handle delivery flags */
552 if($this->acl_is_writeable("gosaMailDeliveryModeL")){
553 if(!preg_match("/L/",$tmp) && !isset($_POST['only_local'])){
554 $tmp.="L";
555 }elseif(preg_match("/L/",$tmp) && isset($_POST['only_local'])){
556 $tmp = preg_replace("/L/","",$tmp);
557 }
558 }
559 $opts = array(
560 "R" => "use_mailsize_limit",
561 "S" => "use_spam_filter",
562 "V" => "use_vacation",
563 "C" => "own_script",
564 "I" => "drop_own_mails");
566 foreach($opts as $flag => $post){
567 if($this->acl_is_writeable("gosaMailDeliveryMode".$flag)){
568 if(!preg_match("/".$flag."/",$tmp) && isset($_POST[$post])){
569 $tmp.= $flag;
570 }elseif(preg_match("/".$flag."/",$tmp) && !isset($_POST[$post])){
571 $tmp = preg_replace("/".$flag."/","",$tmp);
572 }
573 }
574 }
576 $tmp= "[$tmp]";
577 if ($this->gosaMailDeliveryMode != $tmp){
578 $this->is_modified= TRUE;
579 }
580 $this->gosaMailDeliveryMode= $tmp;
582 /* Get start/stop values for vacation scope of application
583 */
584 if($this->mailMethod->vacationRangeEnabled()){
585 if($this->acl_is_writeable("gosaVacationMessage") && preg_match("/V/",$this->gosaMailDeliveryMode)){
586 if(isset($_POST['gosaVacationStart'])){
587 $this->gosaVacationStart = get_post('gosaVacationStart');
588 }
589 if(isset($_POST['gosaVacationStop'])){
590 $this->gosaVacationStop = get_post('gosaVacationStop');
591 }
592 }
593 }
594 }
595 }
596 }
599 /*! \brief Parse vacation templates and build up an array
600 containing 'filename' => 'description'.
601 Used to fill vacation dropdown box.
602 @return Array All useable vacation templates.
603 */
604 function get_vacation_templates()
605 {
606 $vct = array();
607 if ($this->config->get_cfg_value("core","vacationTemplateDirectory") != ""){
608 $dir= $this->config->get_cfg_value("core","vacationTemplateDirectory");
609 if (is_dir($dir) && is_readable($dir)){
610 $dh = opendir($dir);
611 while($file = readdir($dh)){
612 $description= "";
613 if (is_file($dir."/".$file)){
614 $fh = fopen($dir."/".$file, "r");
615 $line= fgets($fh, 256);
616 if (!preg_match('/^DESC:/', $line)){
617 msg_dialog::display(_("Configuration error"), sprintf(_("No DESC tag in vacation template '%s'!"), $file), ERROR_DIALOG);
618 }else{
619 $description= trim(preg_replace('/^DESC:\s*/', '', $line));
620 }
621 fclose ($fh);
622 }
623 if ($description != ""){
624 $vct["$dir/$file"]= $description;
625 }
626 }
627 closedir($dh);
628 }
629 }
630 return($vct);
631 }
634 /*! \brief Adds the given mail address to the list of mail forwarders
635 */
636 function addForwarder($address)
637 {
638 if(empty($address)) return;
639 if($this->acl_is_writeable("gosaMailForwardingAddress")){
640 $this->gosaMailForwardingAddress[]= $address;
641 $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
642 sort ($this->gosaMailForwardingAddress);
643 reset ($this->gosaMailForwardingAddress);
644 $this->is_modified= TRUE;
645 }else{
646 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
647 }
648 }
651 /*! \brief Removes the given mail address from the list of mail forwarders
652 */
653 function delForwarder($addresses)
654 {
655 if($this->acl_is_writeable("gosaMailForwardingAddress")){
656 $this->gosaMailForwardingAddress= array_remove_entries ($addresses, $this->gosaMailForwardingAddress);
657 $this->is_modified= TRUE;
658 }else{
659 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
660 }
661 }
664 /*! \brief Add given mail address to the list of alternate adresses ,
665 . check if this mal address is used, skip adding in this case
666 */
667 function addAlternate($address)
668 {
669 if(empty($address)) return;
670 if($this->acl_is_writeable("gosaMailAlternateAddress")){
671 $ldap= $this->config->get_ldap_link();
672 $address= strtolower($address);
674 /* Is this address already assigned in LDAP? */
675 $ldap->cd ($this->config->current['BASE']);
676 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=$address)".
677 "(alias=$address)(gosaMailAlternateAddress=$address)))", array("uid", "cn"));
678 if ($ldap->count() > 0){
679 $attrs= $ldap->fetch ();
680 if (!isset($attrs["uid"])) {
681 return ("!".$attrs["cn"][0]);
682 }
683 return ($attrs["uid"][0]);
684 }
685 if (!in_array($address, $this->gosaMailAlternateAddress)){
686 $this->gosaMailAlternateAddress[]= $address;
687 $this->is_modified= TRUE;
688 }
689 sort ($this->gosaMailAlternateAddress);
690 reset ($this->gosaMailAlternateAddress);
691 return ("");
692 }else{
693 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
694 }
695 }
698 /*! \brief Removes the given mail address from the alternate addresses list
699 */
700 function delAlternate($addresses)
701 {
702 if($this->acl_is_writeable("gosaMailAlternateAddress")){
703 $this->gosaMailAlternateAddress= array_remove_entries ($addresses,$this->gosaMailAlternateAddress);
704 $this->is_modified= TRUE;
705 }else{
706 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
707 }
708 }
711 /*! \brief Prepare importet vacation string. \
712 . Replace placeholder like %givenName a.s.o.
713 @param string Vacation string
714 @return string Completed vacation string
715 */
716 private function prepare_vacation_template($contents)
717 {
718 /* Replace attributes */
719 $attrs = array();
720 $obj = NULL;
721 if(isset($this->parent->by_object['user'])){
722 $attrs = $this->parent->by_object['user']->attributes;
723 $obj = $this->parent->by_object['user'];
724 }else{
725 $obj = new user($this->config,$this->dn);
726 $attrs = $obj->attributes;
727 }
728 if($obj){
730 /* Replace vacation start and end time */
731 if($this->mailMethod->vacationRangeEnabled()){
732 if(preg_match("/%start/",$contents)){
733 $contents = preg_replace("/%start/",$this->gosaVacationStart,$contents);
734 }
735 if(preg_match("/%end/",$contents)){
736 $contents = preg_replace("/%end/",$this->gosaVacationStop,$contents);
737 }
738 }else{
739 if(preg_match("/%start/",$contents)){
740 $contents = preg_replace("/%start/", _("unknown"),$contents);
741 }
742 if(preg_match("/%end/",$contents)){
743 $contents = preg_replace("/%end/", _("unknown"), $contents);
744 }
745 }
747 foreach ($attrs as $val){
749 // We can only replace strings here
750 if(!is_string($obj->$val)) continue;
752 if(preg_match("/dateOfBirth/",$val)){
753 if($obj->use_dob){
754 $contents= preg_replace("/%$val/",date("Y-d-m",$obj->dateOfBirth),$contents);
755 }
756 }else {
757 $contents= preg_replace("/%$val/",
758 $obj->$val, $contents);
759 }
761 }
762 }
763 $contents = ltrim(preg_replace("/^DESC:.*$/m","",$contents),"\n ");
764 return($contents);
765 }
768 /*! \brief Removes the mailAccount extension from ldap
769 */
770 function remove_from_parent()
771 {
772 /* Cancel if there's nothing to do here */
773 if (!$this->initially_was_account){
774 return;
775 }
777 /* If domain part was selectable, contruct mail address */
778 if($this->mailMethod->domainSelectionEnabled()){
779 $this->mail = $this->mail."@".$this->mailDomainPart;
780 }
782 /* Update sharedFolder dependencies.
783 Open each shared folder and remove this account.
784 Then Save the group to ensure that all necessary
785 actions will be taken (imap acls updated aso.).
786 */
787 $ldap = $this->config->get_ldap_link();
788 $ldap->cd($this->config->current['BASE']);
789 $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array("dn"));
790 while($attrs = $ldap->fetch()){
791 $grp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
792 if(isset($grp->by_object['mailgroup']) && isset($grp->by_object['group'])){
793 $grp->by_object['group']->removeUser($this->uid);
795 /* Do not save the complete group! This will quit the complete membership
796 */
797 $grp->by_object['mailgroup']->save();
798 }
799 }
801 // Do NOT remove the mail attribute while it is used in the Fax Account.
802 if(isset($this->parent->by_object['gofaxAccount'])){
803 $fax = $this->parent->by_object['gofaxAccount'];
805 // Fax delivery to the mail account is activated, keep the mail attribute.
806 if($fax->goFaxDeliveryMode & 32){
807 $this->attributes = array_remove_entries(array('mail'), $this->attributes) ;
808 }
809 }
811 /* Remove GOsa attributes */
812 plugin::remove_from_parent();
814 /* Zero arrays */
815 $this->attrs['gosaMailAlternateAddress'] = array();
816 $this->attrs['gosaMailForwardingAddress']= array();
819 $this->mailMethod->fixAttributesOnRemove();
820 $this->cleanup();
822 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
823 $ldap= $this->config->get_ldap_link();
824 $ldap->cd($this->dn);
825 $ldap->modify ($this->attrs);
827 /* Add "view" to logging class */
828 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
829 if (!$ldap->success()){
830 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
831 }
833 /* Let the mailMethod remove this mailbox, e.g. from imap and
834 update shared folder membership, ACL may need to be updated.
835 */
836 if (!$this->is_template){
838 if(!$this->mailMethod->connect()){
839 msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"),
840 $this->mailMethod->get_error()), ERROR_DIALOG);
841 }else{
842 if(!$this->mailMethod->deleteMailbox()){
843 msg_dialog::display(_("Mail error"), sprintf(_("Cannot remove mailbox: %s"),
844 $this->mailMethod->get_error()), ERROR_DIALOG);
845 }
846 }
847 }
848 $this->mailMethod->disconnect();
850 /* Optionally execute a command after we're done */
851 $this->handle_post_events("remove",array("uid" => $this->uid));
852 }
855 /*! \brief Save the mailAccount settings to the ldap database.
856 */
857 function save()
858 {
859 $ldap= $this->config->get_ldap_link();
861 /* If domain part was selectable, contruct mail address */
862 if(!(!$this->mailMethod->isModifyableMail() && $this->initially_was_account)){
864 if($this->mailMethod->domainSelectionEnabled()){
865 $this->mail = $this->mail."@".$this->mailDomainPart;
866 }
868 /* Enforce lowercase mail address and trim whitespaces
869 */
870 $this->mail = trim(strtolower($this->mail));
871 }
874 /* Call parents save to prepare $this->attrs */
875 plugin::save();
877 /* Save arrays */
878 $this->attrs['gosaMailAlternateAddress'] = $this->gosaMailAlternateAddress;
879 $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
881 if(!$this->mailMethod->vacationRangeEnabled()){
882 $this->attrs['gosaVacationStart'] = $this->attrs['gosaVacationStop'] = array();
883 }elseif (!preg_match('/V/', $this->gosaMailDeliveryMode)){
884 unset($this->attrs['gosaVacationStart']);
885 unset($this->attrs['gosaVacationStop']);
886 } else {
887 /* Adapt values to be timestamps */
888 list($day, $month, $year)= explode('.', $this->gosaVacationStart);
889 $this->attrs['gosaVacationStart']= mktime(0,0,0,$month, $day, $year);
890 list($day, $month, $year)= explode('.', $this->gosaVacationStop);
891 $this->attrs['gosaVacationStop']= mktime(0,0,0,$month, $day, $year);
892 }
894 /* Map method attributes */
895 $this->mailMethod->fixAttributesOnStore();
897 /* Save data to LDAP */
898 $ldap->cd($this->dn);
899 $this->cleanup();
900 $ldap->modify ($this->attrs);
902 if (!$ldap->success()){
903 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
904 }
906 /* Log last action */
907 if($this->initially_was_account){
908 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
909 }else{
910 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
911 }
913 /* Only do IMAP actions if we are not a template */
914 if (!$this->is_template){
915 $this->mailMethod->connect();
916 if(!$this->mailMethod->is_connected()){
917 msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"),
918 $this->mailMethod->get_error()), ERROR_DIALOG);
919 }else{
920 if(!$this->mailMethod->updateMailbox()){
921 msg_dialog::display(_("Mail error"), sprintf(_("Cannot update mailbox: %s"),
922 $this->mailMethod->get_error()), ERROR_DIALOG);
923 }
924 if(!$this->mailMethod->setQuota($this->gosaMailQuota)){
925 msg_dialog::display(_("Mail error"), sprintf(_("Cannot write quota settings: %s"),
926 $this->mailMethod->get_error()), ERROR_DIALOG);
927 }
929 if (!is_integer(strpos($this->gosaMailDeliveryMode, "C"))){
931 /* Do not write sieve settings if this account is new and
932 doesn't seem to exist.
933 */
934 if(!$this->initially_was_account && !$this->mailMethod->account_exists()){
935 @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,
936 "Skipping sieve settings, the account doesn't seem to be created already.</b>","");
937 }else{
938 if(!$this->mailMethod->saveSieveSettings()){
939 msg_dialog::display(_("Mail error saving sieve settings"), $this->mailMethod->get_error(), ERROR_DIALOG);
940 }
941 }
942 }else{
943 if ($this->sieve_management) {
944 @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,
945 "User uses an own sieve script, skipping sieve update.".$str."</b>","");
946 $this->sieve_management->save();
947 }
948 }
949 }
950 }
951 $this->mailMethod->disconnect();
953 /* Update sharedFolder dependencies.
954 Open each shared folder and remove this account.
955 Then Save the group to ensure that all necessary
956 actions will be taken (imap acls updated aso.).
957 */
958 if(!$this->initially_was_account){
959 $ldap = $this->config->get_ldap_link();
960 $ldap->cd($this->config->current['BASE']);
961 $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array("dn"));
962 while($attrs = $ldap->fetch()){
963 $grp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
964 if(isset($grp->by_object['mailgroup'])){
965 /* Do not save the complete group! This will quit the complete membership
966 */
967 $grp->by_object['mailgroup']->save();
968 }
969 }
970 }
972 /* Optionally execute a command after we're done */
973 if ($this->initially_was_account == $this->is_account){
974 if ($this->is_modified){
975 $this->handle_post_events("modify", array("uid" => $this->uid));
976 }
977 } else {
978 $this->handle_post_events("add", array("uid" => $this->uid));
979 }
980 }
983 /*! \brief Check given values
984 */
985 function check()
986 {
987 if(!$this->is_account){
988 return(array());
989 }
991 $ldap= $this->config->get_ldap_link();
993 /* Call common method to give check the hook */
994 $message= plugin::check();
996 if(empty($this->gosaMailServer)){
997 $message[]= msgPool::noserver(_("Mail"));
998 }
1000 /* Mail address checks */
1001 $mail = $this->mail;
1002 if(!(!$this->mailMethod->isModifyableMail() && $this->initially_was_account)){
1004 if($this->mailMethod->domainSelectionEnabled()){
1005 $mail.= "@".$this->mailDomainPart;
1006 }
1008 if (empty($mail)){
1009 $message[]= msgPool::required(_("Primary address"));
1010 }
1011 if ($this->is_template){
1012 if (!tests::is_email($mail, TRUE)){
1013 $message[]= msgPool::invalid(_("Mail address"),"","","%givenName.%sn@your-domain.com");
1014 }
1015 } else {
1016 if (!tests::is_email($mail)){
1017 $message[]= msgPool::invalid(_("Mail address"),"","","your-address@your-domain.com");
1018 }
1019 }
1021 /* Check if this mail address is already in use */
1022 $ldap->cd($this->config->current['BASE']);
1023 $filter = "(&(!(objectClass=gosaUserTemplate))(!(uid=".$this->uid."))".
1024 "(objectClass=gosaMailAccount)".
1025 "(|(mail=".$mail.")(alias=".$mail.")(gosaMailAlternateAddress=".$mail.")))";
1026 $ldap->search($filter,array("uid", "cn"));
1027 if ($ldap->count() != 0){
1028 $entry= $ldap->fetch();
1029 $addon= "";
1030 if (!isset($entry['uid'])) {
1031 $addon= sprintf(_("Address is already in use by group '%s'."), $entry['cn'][0]);
1032 } else {
1033 $addon= sprintf(_("Address is already in use by user '%s'."), $entry['uid'][0]);
1034 }
1035 $message[]= msgPool::duplicated(_("Mail address"))."<br><br><i>$addon</i>";
1036 }
1037 }
1040 /* Check quota */
1041 if ($this->gosaMailQuota != '' && $this->acl_is_writeable("gosaMailQuota")){
1042 if (!is_numeric($this->gosaMailQuota)) {
1043 $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
1044 } else {
1045 $this->gosaMailQuota= (int) $this->gosaMailQuota;
1046 }
1047 }
1049 /* Check rejectsize for integer */
1050 if ($this->gosaMailMaxSize != '' && $this->acl_is_writeable("gosaMailMaxSize")){
1051 if (!is_numeric($this->gosaMailMaxSize)){
1052 $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
1053 } else {
1054 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
1055 }
1056 }
1058 /* Need gosaMailMaxSize if use_mailsize_limit is checked */
1059 if (is_integer(strpos($this->gosaMailDeliveryMode, "R")) && $this->gosaMailMaxSize == ""){
1060 $message[]= msgPool::required(_("Mail reject size"));
1061 }
1063 if((preg_match("/S/", $this->gosaMailDeliveryMode))&&(empty($this->gosaSpamMailbox))) {
1064 $message[]= msgPool::required(_("Spam folder"));
1065 }
1067 if ($this->mailMethod->vacationRangeEnabled() && preg_match('/V/', $this->gosaMailDeliveryMode)){
1069 /* Check date strings */
1070 $state= true;
1071 if ($this->gosaVacationStart == "" || !tests::is_date($this->gosaVacationStart)) {
1072 $message[]= msgPool::invalid(_("from"),$this->gosaVacationStart);
1073 $state= false;
1074 }
1075 if ($this->gosaVacationStart == "" || !tests::is_date($this->gosaVacationStop)) {
1076 $message[]= msgPool::invalid(_("to"),$this->gosaVacationStop);
1077 $state= false;
1078 }
1080 #TODO: take care of date format
1081 if ($state) {
1082 list($day, $month, $year)= explode('.', $this->gosaVacationStart);
1083 $start= mktime(0,0,0,$month, $day, $year);
1084 list($day, $month, $year)= explode('.', $this->gosaVacationStop);
1085 $stop= mktime(0,0,0,$month, $day, $year);
1086 if($start > $stop){
1087 $message[]= msgPool::invalid(_("Vacation interval"));
1088 }
1089 }
1090 }
1091 return($message);
1092 }
1095 /*! \brief Adapt from template, using 'dn'
1096 */
1097 function adapt_from_template($dn, $skip= array())
1098 {
1099 plugin::adapt_from_template($dn, $skip);
1101 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
1103 if (in_array($val, $skip)){
1104 continue;
1105 }
1107 $this->$val= array();
1108 if (isset($this->attrs["$val"]["count"])){
1109 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
1110 $value= $this->attrs["$val"][$i];
1111 foreach (array("sn", "givenName", "uid") as $repl){
1112 if (preg_match("/%$repl/i", $value)){
1113 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
1114 }
1115 }
1116 array_push($this->$val, strtolower(rewrite($value)));
1117 }
1118 }
1119 }
1120 $this->mail= strtolower(rewrite($this->mail));
1122 // Fix mail address when using templates
1123 if($this->is_account && $this->mailMethod->domainSelectionEnabled()){
1124 $this->mailDomainPart = preg_replace("/^[^@]*+@/","",$this->mail);
1125 $this->mail = preg_replace("/@.*$/","\\1",$this->mail);
1126 if(!in_array($this->mailDomainPart,$this->mailDomainParts)){
1127 $this->mailDomainParts[] = $this->mailDomainPart;
1128 }
1129 }
1130 }
1133 /*! \brief Creates the mail part for the copy & paste dialog
1134 */
1135 function getCopyDialog()
1136 {
1137 if(!$this->is_account) return("");
1138 $smarty = get_smarty();
1139 $smarty->assign("mail",$this->mail);
1140 $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress);
1141 $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress);
1143 $smarty->assign("domainSelectionEnabled", $this->mailMethod->domainSelectionEnabled());
1144 $smarty->assign("MailDomains", $this->mailDomainParts);
1145 $smarty->assign("MailDomain" , $this->mailDomainPart);
1146 $smarty->assign("MailServers", $this->mailMethod->getMailServers());
1147 $smarty->assign("isModifyableMail" , $this->mailMethod->isModifyableMail());
1148 $smarty->assign("initially_was_account", $this->initially_was_account);
1150 $str = $smarty->fetch(get_template_path("copypaste.tpl",TRUE, dirname(__FILE__)));
1152 $ret = array();
1153 $ret['status'] = "";
1154 $ret['string'] = $str;
1155 return($ret);
1156 }
1159 /*! \brief save_object for copy&paste vars
1160 */
1161 function saveCopyDialog()
1162 {
1163 if(!$this->is_account) return;
1165 /* Execute to save mailAlternateAddress && gosaMailForwardingAddress */
1166 $this->execute();
1167 if(isset($_POST['mail'])){
1168 $this->mail = get_post('mail');
1169 }
1170 }
1173 /*! \brief Prepare this account to be copied
1174 */
1175 function PrepareForCopyPaste($source)
1176 {
1177 plugin::PrepareForCopyPaste($source);
1179 /* Reset alternate mail addresses */
1180 $this->gosaMailAlternateAddress = array();
1183 /* If the doamin part is selectable, we have to split the mail address
1184 */
1185 if($this->mailMethod->domainSelectionEnabled()){
1186 $this->mailDomainPart = preg_replace("/^[^@]*+@/","",$this->mail);
1187 $this->mail = preg_replace("/@.*$/","\\1",$this->mail);
1188 if(!in_array($this->mailDomainPart,$this->mailDomainParts)){
1189 $this->mailDomainParts[] = $this->mailDomainPart;
1190 }
1191 }
1193 // Initialize Vacation start/stop times
1194 // This value is set to 'dd.mm.YYYY' if no times are set in the source object.
1195 // But if they are set, then this values contain timestamps.
1196 if(isset($source['gosaVacationStart'][0])){
1197 $this->gosaVacationStart= date('d.m.Y', $source['gosaVacationStart'][0]);
1198 $this->gosaVacationStop= date('d.m.Y', $source['gosaVacationStop'][0]);
1199 }
1200 }
1203 /*! \brief Prepare this class the be useable when editing multiple users at once
1204 */
1205 function get_multi_edit_values()
1206 {
1207 $ret = plugin::get_multi_edit_values();
1208 if(in_array("gosaMailQuota",$this->multi_boxes)){
1209 $ret['gosaMailQuota'] = $this->gosaMailQuota;
1210 }
1211 $flag_add = $flag_remove = array();
1212 $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1213 $opts = array(
1214 "R" => "use_mailsize_limit",
1215 "S" => "use_spam_filter",
1216 "L" => "only_local",
1217 "V" => "use_vacation",
1218 "C" => "own_script",
1219 "I" => "drop_own_mails");
1220 foreach($opts as $flag => $post){
1221 if(in_array($post, $this->multi_boxes)){
1222 if(preg_match("/".$flag."/",$tmp)){
1223 $flag_add[] = $flag;
1224 }else{
1225 $flag_remove[] = $flag;
1226 }
1227 }
1228 }
1229 $ret['flag_add'] = $flag_add;
1230 $ret['flag_remove'] = $flag_remove;
1232 if($this->mailMethod->vacationRangeEnabled()){
1233 if(in_array("V",$flag_add)){
1234 $ret['gosaVacationStart'] = $this->gosaVacationStart = get_post('gosaVacationStart');
1235 $ret['gosaVacationStop'] = $this->gosaVacationStop = get_post('gosaVacationStop');
1236 }
1237 }
1238 return($ret);
1239 }
1242 /*! \brief Check given input for multiple user edit
1243 */
1244 function multiple_check()
1245 {
1246 $message = plugin::multiple_check();
1248 if(empty($this->gosaMailServer) && in_array("gosaMailServer",$this->multi_boxes)){
1249 $message[]= msgPool::noserver(_("Mail"));
1250 }
1252 /* Check quota */
1253 if ($this->gosaMailQuota != '' && in_array("gosaMailQuota",$this->multi_boxes)){
1254 if (!is_numeric($this->gosaMailQuota)) {
1255 $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
1256 } else {
1257 $this->gosaMailQuota= (int) $this->gosaMailQuota;
1258 }
1259 }
1261 /* Check rejectsize for integer */
1262 if ($this->gosaMailMaxSize != '' && in_array("gosaMailMaxSize",$this->multi_boxes)){
1263 if (!is_numeric($this->gosaMailMaxSize)){
1264 $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
1265 } else {
1266 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
1267 }
1268 }
1270 if(empty($this->gosaSpamMailbox) && in_array("gosaSpamMailbox",$this->multi_boxes)){
1271 $message[]= msgPool::required(_("Spam folder"));
1272 }
1274 if ($this->mailMethod->vacationRangeEnabled() && preg_match('/V/', $this->gosaMailDeliveryMode)){
1276 /* Check date strings */
1277 $state= true;
1278 if ($this->gosaVacationStart == "" || !tests::is_date($this->gosaVacationStart)) {
1279 $message[]= msgPool::invalid(_("from"),$this->gosaVacationStart);
1280 $state= false;
1281 }
1282 if ($this->gosaVacationStart == "" || !tests::is_date($this->gosaVacationStop)) {
1283 $message[]= msgPool::invalid(_("to"),$this->gosaVacationStop);
1284 $state= false;
1285 }
1287 #TODO: take care of date format
1288 if ($state) {
1289 list($day, $month, $year)= explode('.', $this->gosaVacationStart);
1290 $start= mktime(0,0,0,$month, $day, $year);
1291 list($day, $month, $year)= explode('.', $this->gosaVacationStop);
1292 $stop= mktime(0,0,0,$month, $day, $year);
1293 if($start > $stop){
1294 $message[]= msgPool::invalid(_("Vacation interval"));
1295 }
1296 }
1297 }
1298 return($message);
1299 }
1302 /*! \brief ...
1303 */
1304 function set_multi_edit_values($values)
1305 {
1306 plugin::set_multi_edit_values($values);
1307 $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1308 if(isset($values['flag_add'])){
1309 foreach($values['flag_add'] as $flag){
1310 if(!preg_match("/".$flag."/",$tmp)){
1311 $tmp .= $flag;
1312 }
1313 }
1314 }
1315 if(isset($values['flag_remove'])){
1316 foreach($values['flag_remove'] as $flag){
1317 if(preg_match("/".$flag."/",$tmp)){
1318 $tmp = preg_replace("/".$flag."/","",$tmp);
1319 }
1320 }
1321 }
1322 $this->gosaMailDeliveryMode = "[".$tmp."]";
1324 /* Set vacation message and replace placeholder like %givenName
1325 */
1326 if(isset($values['gosaVacationMessage'])){
1327 $this->gosaVacationMessage = $this->prepare_vacation_template($values['gosaVacationMessage']);
1328 }
1329 }
1332 /*! \brief Initialize plugin to be used as multiple edit class.
1333 */
1334 function init_multiple_support($attrs,$all)
1335 {
1336 plugin::init_multiple_support($attrs,$all);
1337 if(isset($this->multi_attrs['gosaMailQuota'])){
1338 $this->gosaMailQuota = $this->multi_attrs['gosaMailQuota'];
1339 }
1340 }
1343 /*! \brief
1344 */
1345 function get_multi_init_values()
1346 {
1347 $attrs = plugin::get_multi_init_values();
1348 $attrs['gosaMailQuota'] = $this->gosaMailQuota;
1349 return($attrs);
1350 }
1353 /*! \brief Display multiple edit dialog
1354 */
1355 function multiple_execute()
1356 {
1357 return($this->execute());
1358 }
1361 /*! \brief Save posts from multiple edit dialog
1362 */
1363 function multiple_save_object()
1364 {
1365 plugin::multiple_save_object();
1367 $this->save_object();
1368 foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
1369 if(isset($_POST["use_".$attr])){
1370 $this->multi_boxes[] = $attr;
1371 }
1372 }
1373 }
1376 /*! \brief Creates the user names for the add_local_forward dialog
1377 */
1378 function make_name($attrs)
1379 {
1380 $name= "";
1381 if (isset($attrs['sn'][0])){
1382 $name= $attrs['sn'][0];
1383 }
1384 if (isset($attrs['givenName'][0])){
1385 if ($name != ""){
1386 $name.= ", ".$attrs['givenName'][0];
1387 } else {
1388 $name.= $attrs['givenName'][0];
1389 }
1390 }
1391 if ($name != ""){
1392 $name.= " ";
1393 }
1395 return ($name);
1396 }
1399 function allow_remove()
1400 {
1401 $resason = "";
1402 if(!$this->mailMethod->allow_remove($reason)){
1403 return($reason);
1404 }
1405 return("");
1406 }
1410 /*! \brief ACL settings
1411 */
1412 static function plInfo()
1413 {
1414 return (array(
1415 "plShortName" => _("Mail"),
1416 "plDescription" => _("Mail settings"),
1417 "plSelfModify" => TRUE,
1418 "plDepends" => array("user"), // This plugin depends on
1419 "plPriority" => 4, // Position in tabs
1420 "plSection" => array("personal" => _("My account")),
1421 "plCategory" => array("users"),
1422 "plOptions" => array(),
1424 "plRequirements"=> array(
1425 'ldapSchema' => array('gosaMailAccount' => '>=2.7'),
1426 'onFailureDisablePlugin' => array(get_class())
1427 ),
1429 "plProperties" =>
1430 array(
1431 array(
1432 "name" => "cyrusDeleteMailbox",
1433 "type" => "bool",
1434 "default" => 'true',
1435 "description" => _("The 'cyrusDeleteMailbox' statement determines if GOsa should remove the mailbox from your IMAP server or keep it after the account is deleted in LDAP."),
1436 "check" => "gosaProperty::isBool",
1437 "migrate" => "",
1438 "group" => "mail",
1439 "mandatory" => FALSE
1440 ),
1441 array(
1442 "name" => "cyrusAutocreateFolders",
1443 "type" => "string",
1444 "default" => "",
1445 "description" => _("The 'cyrusAutocreateFolders' statement contains a comma seperated list of personal IMAP folders that should be created along initial account creation."),
1446 "check" => "gosaProperty::isString",
1447 "migrate" => "",
1448 "group" => "mail",
1449 "mandatory" => FALSE
1450 )
1451 ),
1454 "plProvidedAcls" => array(
1455 "mail" => _("Mail address"),
1456 "gosaMailServer" => _("Mail server"),
1457 "gosaMailQuota" => _("Quota size"),
1459 "gosaMailDeliveryModeV" => _("Add vacation information"), // This is flag of gosaMailDeliveryMode
1460 "gosaVacationMessage" => _("Vacation message"),
1462 "gosaMailDeliveryModeS" => _("Use spam filter"), // This is flag of gosaMailDeliveryMode
1463 "gosaSpamSortLevel" => _("Spam level"),
1464 "gosaSpamMailbox" => _("Spam mail box"),
1466 "sieveManagement" => _("Sieve management"),
1468 "gosaMailDeliveryModeR" => _("Reject due to mailsize"), // This is flag of gosaMailDeliveryMode
1469 "gosaMailMaxSize" => _("Mail max size"),
1471 "gosaMailForwardingAddress" => _("Forwarding address"),
1472 "gosaMailDeliveryModeL" => _("Local delivery"), // This is flag of gosaMailDeliveryMode
1473 "gosaMailDeliveryModeI" => _("No delivery to own mailbox "), // This is flag of gosaMailDeliveryMode
1474 "gosaMailAlternateAddress" => _("Mail alternative addresses"),
1476 "gosaMailForwardingAddress" => _("Forwarding address"),
1477 "gosaMailDeliveryModeC" => _("Use custom sieve script")) // This is flag of gosaMailDeliveryMode
1478 ));
1479 }
1482 }
1484 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1485 ?>