1 <?php
2 /*! \brief mail plugin
3 \author Cajus Pollmeier <pollmeier@gonicus.de>
4 \version 2.00
5 \date 24.07.2003
7 This class provides the functionality to read and write all attributes
8 relevant for gosaMailAccounts from/to the LDAP. It does syntax checking
9 and displays the formulars required.
10 */
12 /* Load sieve support */
13 require_once ("class_sieve.inc");
15 /* Load mail methods */
16 global $BASE_DIR;
17 get_dir_list("$BASE_DIR/include");
19 class mailAccount extends plugin
20 {
21 /* Definitions */
22 var $plHeadline = "Mail";
23 var $plDescription = "This does something";
24 var $method = "mailMethod";
26 /* CLI vars */
27 var $cli_summary = "Manage users mail account";
28 var $cli_description = "Some longer text\nfor help";
29 var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
31 /* plugin specific values */
32 var $mail = "";
33 var $uid = "";
34 var $gosaMailAlternateAddress = array();
35 var $gosaMailForwardingAddress = array();
36 var $gosaMailDeliveryMode = "[L ]";
37 var $gosaMailServer = "";
38 var $gosaMailQuota = "";
39 var $gosaMailMaxSize = "";
40 var $gosaVacationMessage = "";
41 var $gosaSpamSortLevel = "";
42 var $gosaSpamMailbox = "";
44 var $quotaUsage = 0;
45 var $forward_dialog = FALSE;
46 var $folder_prefix = "";
47 var $mailboxList = array();
48 var $default_permissions = "none";
49 var $member_permissions = "post";
50 var $members = array();
51 var $admins = array();
52 var $vacations = array();
53 var $perms = array( "lrs" => "read",
54 "lrsp" => "post",
55 "lrsip" => "append",
56 "lrswipcd" => "write",
57 "lrswipcda" => "all" );
59 /* attribute list for save action */
60 var $attributes= array("mail", "gosaMailServer", "gosaMailQuota", "gosaMailMaxSize","gosaMailForwardingAddress",
61 "gosaMailDeliveryMode", "gosaSpamSortLevel", "gosaSpamMailbox","gosaMailAlternateAddress",
62 "gosaVacationMessage", "gosaMailAlternateAddress", "gosaMailForwardingAddress");
63 var $objectclasses= array("gosaMailAccount");
66 /* constructor, if 'dn' is set, the node loads the given
67 'dn' from LDAP */
68 function mailAccount ($config, $dn= NULL)
69 {
70 /* Load bases attributes */
71 plugin::plugin($config, $dn);
73 if(isset($this->attrs['uid'])){
74 $this->uid = $this->attrs['uid'][0];
75 }
77 if(is_array($this->gosaMailServer) && isset($this->gosaMailServer[0])){
78 $this->gosaMailServer = $this->gosaMailServer[0];
79 }
81 /* Save initial account state */
82 $this->initially_was_account= $this->is_account;
84 /* Set mailMethod to the one defined in gosa.conf */
85 if (isset($this->config->current['MAILMETHOD'])){
86 $method= $this->config->current['MAILMETHOD'];
87 if (class_exists("mailMethod$method")){
88 $this->method= "mailMethod$method";
89 } else {
90 print_red(sprintf(_("There is no mail method '%s' specified in your gosa.conf available."), $method));
91 }
92 }
95 /* Create the account prefix user. user/
96 Preset folder prefix. Will change it later to respect
97 altnamespace. */
98 if (isset($this->config->current['CYRUSUNIXSTYLE']) && $this->config->current['CYRUSUNIXSTYLE'] == "true"){
99 $this->folder_prefix= "user/";
100 } else {
101 $this->folder_prefix= "user.";
102 }
105 /* This is not a new account, parse additional attributes */
106 if (($dn != NULL) && ($dn != "new") && $this->is_account){
108 /* Load attributes containing arrays */
109 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
110 $this->$val= array();
111 if (isset($this->attrs["$val"]["count"])){
112 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
113 array_push($this->$val, $this->attrs["$val"][$i]);
114 }
115 }
116 }
119 /* Only do IMAP actions if gosaMailServer attribute is set */
120 if (isset ($this->attrs["gosaMailServer"][0])){
122 $method = new $this->method($this->config);
123 $id = $method->uattrib;
125 /* Adapt attributes if needed */
126 $method->fixAttributesOnLoad($this);
128 /* FixAttributesOnLoad possibly creates an array out of gosaMailServer.
129 If the mail tab wasn't opened once before saving, the account can't be saved */
130 if(is_array($this->gosaMailServer)){
131 $this->gosaMailServer = $this->gosaMailServer[0];
132 }
134 if ($method->connect($this->attrs["gosaMailServer"][0])){
136 /* Update quota values */
137 $quota= $method->getQuota($this->folder_prefix.$this->$id);
139 if($quota){
140 if ($quota['gosaMailQuota'] == 2147483647){
141 $this->quotaUsage = "";
142 $this->gosaMailQuota = "";
143 } else {
144 $this->quotaUsage = $quota['quotaUsage'];
145 $this->gosaMailQuota = $quota['gosaMailQuota'];
146 }
147 }else{
148 $this->quotaUsage = "";
149 $this->gosaMailQuota = "";
150 print_red(sprintf(_("Can't get quota information for '%s'."),$this->folder_prefix.$this->$id));
151 }
153 /* Get mailboxes / folder like INBOX ..*/
154 $this->mailboxList= $method->getMailboxList($this->folder_prefix.$this->$id,$this->$id);
156 $method->disconnect();
157 }else{
158 /* Could not connect to ldap.
159 */
160 if (isset($this->attrs['gosaMailQuota'][0])){
161 $this->gosaMailQuota = $this->attrs['gosaMailQuota'][0];
162 }
163 }
164 }
165 }
167 /* Fill vacation array */
168 $this->vacation= array();
169 if (isset($this->config->current['VACATIONDIR'])){
170 $dir= $this->config->current['VACATIONDIR'];
171 if (is_dir($dir) && is_readable($dir)){
173 /* Look for files and build the vacation array */
174 $dh= opendir($dir);
175 while ($file = readdir($dh)){
176 $description= $this->parse_vacation("$dir/$file");
177 if ($description != ""){
178 $this->vacation["$dir/$file"]= $description;
179 }
180 }
181 closedir($dh);
182 }
183 }
186 /* Create filter */
188 /* Get global filter config */
189 if (!is_global("mailfilter")){
190 $ui= get_userinfo();
191 $base= get_base_from_people($ui->dn);
192 $mailfilter= array( "depselect" => $base,
193 "muser" => "",
194 "regex" => "*");
195 register_global("mailfilter", $mailfilter);
196 }
197 }
200 function parse_vacation($file)
201 {
202 $desc= "";
204 if (is_file($file)){
205 $fh = fopen($file, "r");
206 $line= fgets($fh, 256);
208 if (!preg_match('/^DESC:/', $line)){
209 print_red (_("No DESC tag in vacation file:")." $file");
210 return $desc;
211 }
212 fclose ($fh);
214 $desc= trim(preg_replace('/^DESC:\s*/', '', $line));
215 }
217 return $desc;
218 }
221 function execute()
222 {
223 /* Call parent execute */
224 plugin::execute();
226 /* Initialise vars */
228 /* Load templating engine */
229 $smarty= get_smarty();
230 $display= "";
232 /* Get available mailserver */
233 $mailserver= array();
234 foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
235 $mailserver[]= $key;
236 }
238 /* Handle account state */
240 /* Do we need to flip is_account state? */
241 if (isset($_POST['modify_state'])){
242 $this->is_account= !$this->is_account;
243 }
245 /* Do we represent a valid account? */
246 if (!$this->is_account && $this->parent == NULL){
247 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
248 _("This account has no mail extensions.")."</b>";
250 $display.= back_to_main();
251 return ($display);
252 }
254 /* Show tab dialog headers */
255 if ($this->parent != NULL){
256 if ($this->is_account){
257 $display= $this->show_header(_("Remove mail account"),
258 _("This account has mail features enabled. You can disable them by clicking below."));
259 } else {
260 $display= $this->show_header(_("Create mail account"), _("This account has mail features disabled. You can enable them by clicking below."));
261 return ($display);
262 }
263 }
266 /* Forwarder subdialog */
268 /* Trigger forward add dialog? */
269 if (isset($_POST['add_local_forwarder'])){
270 $this->forward_dialog= TRUE;
271 $this->dialog= TRUE;
272 }
274 /* Cancel forward add dialog? */
275 if (isset($_POST['add_locals_cancel'])){
276 $this->forward_dialog= FALSE;
277 $this->dialog= FALSE;
278 }
280 /* Finished adding of locals? */
281 if (isset($_POST['add_locals_finish'])){
282 if (count ($_POST['local_list']) &&
283 chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
285 /* Walk through list of forwarders, ignore own addresses */
286 foreach ($_POST['local_list'] as $val){
287 if (!in_array ($val, $this->gosaMailAlternateAddress) &&
288 $val != $this->mail){
290 $this->addForwarder($val);
291 $this->is_modified= TRUE;
292 }
293 }
294 }
295 $this->forward_dialog= FALSE;
296 $this->dialog= FALSE;
297 }
299 /* Add forward email addresses */
300 if (isset($_POST['add_forwarder'])){
301 if ($_POST['forward_address'] != ""){
303 /* Valid email address specified? */
304 $address= $_POST['forward_address'];
305 $valid= FALSE;
306 if (!is_email($address)){
307 if (!is_email($address, TRUE)){
308 if ($this->is_template){
309 $valid= TRUE;
310 } else {
311 print_red (_("You're trying to add an invalid email address to the list of forwarders."));
312 }
313 }
314 } elseif ($address == $this->mail
315 || in_array($address, $this->gosaMailAlternateAddress)) {
317 print_red (_("Adding your one of your own addresses to the forwarders makes no sense."));
319 } else {
320 $valid= TRUE;
321 }
323 if ($valid){
324 /* Add it */
325 if (chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
326 $this->addForwarder ($address);
327 $this->is_modified= TRUE;
328 }
330 }
331 }
332 }
334 /* Delete forward email addresses */
335 if (isset($_POST['delete_forwarder'])){
336 if (count($_POST['forwarder_list'])
337 && chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
339 $this->delForwarder ($_POST['forwarder_list']);
340 }
341 }
344 /* Alternate address handling */
346 /* Add alternate email addresses */
347 if (isset($_POST['add_alternate'])){
348 if ($_POST['alternate_address'] != "" &&
349 chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
351 $valid= FALSE;
352 if (!is_email($_POST['alternate_address'])){
353 if ($this->is_template){
354 if (!(is_email($_POST['alternate_address'], TRUE))){
355 print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
356 } else {
357 $valid= TRUE;
358 }
359 } else {
360 print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
361 }
363 } else {
364 $valid= TRUE;
365 }
367 if ($valid && ($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
368 $ui= get_userinfo();
369 if ($user != $ui->username){
370 print_red (_("The address you're trying to add is already used by user")." '$user'.");
371 }
372 }
373 }
374 }
376 /* Delete alternate email addresses */
377 if (isset($_POST['delete_alternate']) && isset ($_POST['alternates_list'])){
378 if (count($_POST['alternates_list']) &&
379 chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
381 $this->delAlternate ($_POST['alternates_list']);
382 }
383 }
386 /* Vacation message */
388 /* Import vacation message? */
389 if (isset($_POST["import_vacation"]) && isset($this->vacation[$_POST["vacation_template"]])){
390 $contents= "";
391 $lines= file($_POST["vacation_template"]);
392 foreach ($lines as $line){
393 if (!preg_match('/^DESC:/', $line)){
394 $contents.= $line;
395 }
396 }
398 /* Replace attributes */
399 $attrs= $this->parent->by_object['user']->attributes;
400 foreach ($attrs as $val){
401 $contents= preg_replace("/%$val/",
402 $this->parent->by_object['user']->$val, $contents);
403 }
405 /* Save message */
406 $this->gosaVacationMessage= htmlspecialchars($contents);
407 }
410 /* Display forward dialog if requested above */
412 /* Show forward add dialog */
413 if ($this->forward_dialog){
414 $ldap= $this->config->get_ldap_link();
416 /* Save data */
417 $mailfilter= get_global("mailfilter");
418 foreach( array("depselect", "muser", "regex") as $type){
419 if (isset($_POST[$type])){
420 $mailfilter[$type]= $_POST[$type];
421 }
422 }
423 if (isset($_GET['search'])){
424 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
425 if ($s == "**"){
426 $s= "*";
427 }
428 $mailfilter['regex']= $s;
429 }
430 register_global("mailfilter", $mailfilter);
432 /* Get actual list */
433 $mailusers= array ();
434 if ($mailfilter['regex'] != '*' && $mailfilter['regex'] != ""){
435 $regex= $mailfilter['regex'];
436 $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
437 } else {
438 $filter= "";
439 }
440 if ($mailfilter['muser'] != ""){
441 $user= $mailfilter['muser'];
442 $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
443 }
445 /* Add already present people to the filter */
446 $exclude= "";
447 foreach ($this->gosaMailForwardingAddress as $mail){
448 $exclude.= "(mail=$mail)";
449 }
450 if ($exclude != ""){
451 $filter.= "(!(|$exclude))";
452 }
454 $acl= array($this->config->current['BASE'] => ":all");
455 $res= get_list("(&(objectClass=gosaMailAccount)$filter)", $acl, $mailfilter['depselect'],
456 array("sn", "mail", "givenName"), GL_SIZELIMIT | GL_SUBSEARCH);
457 $ldap->cd($mailfilter['depselect']);
458 $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
459 error_reporting (0);
460 while ($attrs= $ldap->fetch()){
461 if(preg_match('/%/', $attrs['mail'][0])){
462 continue;
463 }
464 $name= $this->make_name($attrs);
465 $mailusers[$attrs['mail'][0]]= $name."<".
466 $attrs['mail'][0].">";
467 }
468 error_reporting (E_ALL);
469 natcasesort ($mailusers);
470 reset ($mailusers);
472 /* Show dialog */
473 $smarty->assign("search_image", get_template_path('images/search.png'));
474 $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
475 $smarty->assign("tree_image", get_template_path('images/tree.png'));
476 $smarty->assign("infoimage", get_template_path('images/info.png'));
477 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
478 $smarty->assign("mailusers", $mailusers);
479 if (isset($_POST['depselect'])){
480 $smarty->assign("depselect", $_POST['depselect']);
481 }
482 $smarty->assign("deplist", $this->config->idepartments);
483 $smarty->assign("apply", apply_filter());
484 $smarty->assign("alphabet", generate_alphabet());
485 $smarty->assign("hint", print_sizelimit_warning());
486 foreach( array("depselect", "muser", "regex") as $type){
487 $smarty->assign("$type", $mailfilter[$type]);
488 }
489 $smarty->assign("hint", print_sizelimit_warning());
491 $display.= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE, dirname(__FILE__)));
492 return ($display);
493 }
495 /* Display mail account tab */
497 $smarty->assign("mailServers", $mailserver);
498 foreach(array("gosaMailServer", "gosaMailQuota", "perms", "mail",
499 "gosaMailAlternateAddress", "gosaMailForwardingAddress",
500 "gosaVacationMessage", "gosaMailDeliveryMode",
501 "gosaMailMaxSize", "gosaSpamSortLevel", "gosaSpamMailbox") as $val){
503 $smarty->assign("$val", $this->$val);
504 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
505 }
507 if (is_numeric($this->gosaMailQuota) && $this->gosaMailQuota != 0){
508 $smarty->assign("quotausage", progressbar(round(($this->quotaUsage * 100)/ $this->gosaMailQuota),100,15,true));
509 $smarty->assign("quotadefined", "true");
510 } else {
511 $smarty->assign("quotadefined", "false");
512 }
514 /* Disable mail field if needed */
515 $method= new $this->method($this->config);
516 if ($method->uattrib == "mail" && $this->initially_was_account){
517 $smarty->assign("mailACL", "disabled");
518 }
521 if (!preg_match("/L/", $this->gosaMailDeliveryMode)) {
522 $smarty->assign("drop_own_mails", "checked");
523 } else {
524 $smarty->assign("drop_own_mails", "");
525 }
527 $types = array(
528 "V"=>"use_vacation",
529 "S"=>"use_spam_filter",
530 "R"=>"use_mailsize_limit",
531 "I"=>"only_local",
532 "C"=>"own_script");
534 /* Fill checkboxes */
535 foreach($types as $option => $varname){
536 if (preg_match("/".$option."/", $this->gosaMailDeliveryMode)) {
537 $smarty->assign($varname, "checked");
538 } else {
539 $smarty->assign($varname, "");
540 }
541 }
543 if (preg_match("/V/", $this->gosaMailDeliveryMode)) {
544 $smarty->assign("use_vacation", "checked");
545 } else {
546 $smarty->assign("use_vacation", "");
547 }
548 if (preg_match("/S/", $this->gosaMailDeliveryMode)) {
549 $smarty->assign("use_spam_filter", "checked");
550 } else {
551 $smarty->assign("use_spam_filter", "");
552 }
553 if (preg_match("/R/", $this->gosaMailDeliveryMode)) {
554 $smarty->assign("use_mailsize_limit", "checked");
555 } else {
556 $smarty->assign("use_mailsize_limit", "");
557 }
558 if (preg_match("/I/", $this->gosaMailDeliveryMode)) {
559 $smarty->assign("only_local", "checked");
560 } else {
561 $smarty->assign("only_local", "");
562 }
563 if (preg_match("/C/", $this->gosaMailDeliveryMode)) {
564 $smarty->assign("own_script", "checked");
565 } else {
566 $smarty->assign("own_script", "");
567 }
569 /* Have vacation templates? */
570 $smarty->assign("template", "");
571 if (count($this->vacation)){
572 $smarty->assign("show_templates", "true");
573 $smarty->assign("vacationtemplates", $this->vacation);
574 if (isset($_POST['vacation_template'])){
575 $smarty->assign("template", $_POST['vacation_template']);
576 }
577 } else {
578 $smarty->assign("show_templates", "false");
579 }
581 /* Fill spam selector */
582 $spamlevel= array();
583 for ($i= 0; $i<21; $i++){
584 $spamlevel[]= $i;
585 }
586 $smarty->assign("spamlevel", $spamlevel);
587 $smarty->assign("spambox", $this->mailboxList);
588 $smarty->assign("custom_sieveACL", chkacl($this->acl, "custom_sieve"));
589 $smarty->assign("only_localACL", chkacl($this->acl, "only_local"));
591 $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
592 return ($display);
593 }
596 /* remove object from parent */
597 function remove_from_parent()
598 {
599 /* Cancel if there's nothing to do here */
600 if (!$this->initially_was_account){
601 return;
602 }
604 /* include global link_info */
605 $ldap= $this->config->get_ldap_link();
607 /* Remove and write to LDAP */
608 plugin::remove_from_parent();
610 /* Zero arrays */
611 $this->attrs['gosaMailAlternateAddress']= array();
612 $this->attrs['gosaMailForwardingAddress']= array();
614 /* Adapt attributes if needed */
615 $method= new $this->method($this->config);
616 $method->fixAttributesOnRemove($this);
618 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
619 $ldap->cd($this->dn);
620 $this->cleanup();
621 $ldap->modify ($this->attrs);
623 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/mail account with dn '%s' failed."),$this->dn));
625 /* Connect to IMAP server for account deletion */
626 if ($this->gosaMailServer != ""){
627 $method= new $this->method($this->config);
628 $id= $method->uattrib;
629 if ($method->connect($this->gosaMailServer)){
631 /* Remove account from IMAP server */
632 $method->deleteMailbox($this->folder_prefix.$this->$id);
633 $method->disconnect();
634 }
635 }
637 /* Optionally execute a command after we're done */
638 $this->handle_post_events("remove");
639 }
642 /* Save data to object */
643 function save_object()
644 {
645 if (isset($_POST['mailTab'])){
646 /* Save ldap attributes */
647 plugin::save_object();
649 /* Assemble mail delivery mode
650 The mode field in ldap consists of values between braces, this must
651 be called when 'mail' is set, because checkboxes may not be set when
652 we're in some other dialog.
654 Example for gosaMailDeliveryMode [LR ]
655 L: Local delivery
656 R: Reject when exceeding mailsize limit
657 S: Use spam filter
658 V: Use vacation message
659 C: Use custm sieve script
660 I: Only insider delivery */
662 $tmp= "";
663 if (!isset($_POST["drop_own_mails"])){
664 $tmp.= "L";
665 }
666 if (isset($_POST["use_mailsize_limit"])){
667 $tmp.= "R";
668 }
669 if (isset($_POST["use_spam_filter"])){
670 $tmp.= "S";
671 }
672 if (isset($_POST["use_vacation"])){
673 $tmp.= "V";
674 }
675 if (isset($_POST["own_script"])){
676 $tmp.= "C";
677 }
678 if (isset($_POST["only_local"])){
679 $tmp.= "I";
680 }
681 $tmp= "[$tmp]";
683 if (chkacl ($this->acl, "gosaMailDeliveryMode") == ""){
684 if ($this->gosaMailDeliveryMode != $tmp){
685 $this->is_modified= TRUE;
686 }
687 $this->gosaMailDeliveryMode= $tmp;
688 }
689 }
690 }
693 /* Save data to LDAP, depending on is_account we save or delete */
694 function save()
695 {
696 $ldap= $this->config->get_ldap_link();
698 /* Call parents save to prepare $this->attrs */
699 plugin::save();
701 /* Save arrays */
702 $this->attrs['gosaMailAlternateAddress']= $this->gosaMailAlternateAddress;
703 $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
705 /* Adapt attributes if needed */
706 $method= new $this->method($this->config);
707 $id= $method->uattrib;
709 $method->fixAttributesOnStore($this);
711 /* Remove Mailquota if = "" or "0" */
712 if((isset($this->attrs['gosaMailQuota']))&&(!$this->attrs['gosaMailQuota'])) {
713 $this->attrs['gosaMailQuota']=0;
714 }
716 if(empty($this->attrs['gosaSpamMailbox'])){
717 unset($this->attrs['gosaSpamMailbox']);
718 }
720 $this->attrs['mail'] = strtolower($this->attrs['mail']);
722 /* Save data to LDAP */
723 $ldap->cd($this->dn);
724 $this->cleanup();
725 $ldap->modify ($this->attrs);
727 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/mail account with dn '%s' failed."),$this->dn));
729 /* Only do IMAP actions if we are not a template */
730 if (!$this->is_template){
732 if ($method->connect($this->gosaMailServer)){
733 $method->updateMailbox($this->folder_prefix.$this->$id);
735 $method->setQuota($this->folder_prefix.$this->$id, $this->gosaMailQuota);
736 $method->disconnect();
738 /* Write sieve information only if not in C mode */
739 if (!is_integer(strpos($this->gosaMailDeliveryMode, "C"))){
740 $method->configureFilter($this->$id,
741 $this->gosaMailDeliveryMode,
742 $this->mail,
743 $this->gosaMailAlternateAddress,
744 $this->gosaMailMaxSize,
745 $this->gosaSpamMailbox,
746 $this->gosaSpamSortLevel,
747 $this->gosaVacationMessage);
748 }
749 }
750 }
752 /* Optionally execute a command after we're done */
753 if ($this->initially_was_account == $this->is_account){
754 if ($this->is_modified){
755 $this->handle_post_events("modify");
756 }
757 } else {
758 $this->handle_post_events("add");
759 }
761 }
764 /* Check formular input */
765 function check()
766 {
767 if(!$this->is_account) return(array());
769 $ldap= $this->config->get_ldap_link();
771 /* Call common method to give check the hook */
772 $message= plugin::check();
774 if(empty($this->gosaMailServer)){
775 $message[]= _("There is no valid mailserver specified, please add one in the system setup.");
776 }
778 /* must: mail */
779 if ($this->mail == ""){
780 $message[]= _("The required field 'Primary address' is not set.");
781 }
782 if ($this->is_template){
783 if (!is_email($this->mail, TRUE)){
784 $message[]= _("Please enter a valid email address in 'Primary address' field.");
785 }
786 } else {
787 if (!is_email($this->mail)){
788 $message[]= _("Please enter a valid email address in 'Primary address' field.");
789 }
790 }
791 $ldap->cd($this->config->current['BASE']);
792 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=".$this->mail.")(gosaMailAlternateAddress=".$this->mail."))(!(uid=".$this->uid."))(!(cn=".$this->uid.")))", array("uid"));
793 if ($ldap->count() != 0){
794 $message[]= _("The primary address you've entered is already in use.");
795 }
797 /* Check quota */
798 if ($this->gosaMailQuota != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
799 if (!is_numeric($this->gosaMailQuota)) {
800 $message[]= _("Value in 'Quota size' is not valid.");
801 } else {
802 $this->gosaMailQuota= (int) $this->gosaMailQuota;
803 }
804 }
806 /* Check rejectsize for integer */
807 if ($this->gosaMailMaxSize != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
808 if (!is_numeric($this->gosaMailMaxSize)){
809 $message[]= _("Please specify a vaild mail size for mails to be rejected.");
810 } else {
811 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
812 }
813 }
815 /* Need gosaMailMaxSize if use_mailsize_limit is checked */
816 if (is_integer(strpos($this->gosaMailDeliveryMode, "R")) &&
817 $this->gosaMailMaxSize == ""){
819 $message[]= _("You need to set the maximum mail size in order to reject anything.");
820 }
822 if((preg_match("/S/", $this->gosaMailDeliveryMode))&&(empty($this->gosaSpamMailbox))) {
823 $message[]= _("You specified Spam settings, but there is no Folder specified.");
824 }
826 return ($message);
827 }
830 /* Adapt from template, using 'dn' */
831 function adapt_from_template($dn)
832 {
833 plugin::adapt_from_template($dn);
835 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
836 $this->$val= array();
837 if (isset($this->attrs["$val"]["count"])){
838 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
839 $value= $this->attrs["$val"][$i];
840 foreach (array("sn", "givenName", "uid") as $repl){
841 if (preg_match("/%$repl/i", $value)){
842 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
843 }
844 }
845 array_push($this->$val, strtolower(rewrite($value)));
846 }
847 }
848 }
849 $this->mail= strtolower(rewrite($this->mail));
850 }
853 /* Add entry to forwarder list */
854 function addForwarder($address)
855 {
856 $this->gosaMailForwardingAddress[]= $address;
857 $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
858 sort ($this->gosaMailForwardingAddress);
859 reset ($this->gosaMailForwardingAddress);
860 $this->is_modified= TRUE;
861 }
864 /* Remove list of addresses from forwarder list */
865 function delForwarder($addresses)
866 {
867 $this->gosaMailForwardingAddress= array_remove_entries ($addresses, $this->gosaMailForwardingAddress);
868 $this->is_modified= TRUE;
869 }
872 /* Add given mail address to the list of alternate adresses ,
873 check if this mal address is used, skip adding in this case */
874 function addAlternate($address)
875 {
876 $ldap= $this->config->get_ldap_link();
877 $address= strtolower($address);
879 /* Is this address already assigned in LDAP? */
880 $ldap->cd ($this->config->current['BASE']);
881 $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)"."(gosaMailAlternateAddress=$address)))", array("uid"));
883 if ($ldap->count() > 0){
884 $attrs= $ldap->fetch ();
885 return ($attrs["uid"][0]);
886 }
888 /* Add to list of alternates */
889 if (!in_array($address, $this->gosaMailAlternateAddress)){
890 $this->gosaMailAlternateAddress[]= $address;
891 $this->is_modified= TRUE;
892 }
894 sort ($this->gosaMailAlternateAddress);
895 reset ($this->gosaMailAlternateAddress);
896 return ("");
897 }
900 function delAlternate($addresses)
901 {
902 $this->gosaMailAlternateAddress= array_remove_entries ($addresses,
903 $this->gosaMailAlternateAddress);
904 $this->is_modified= TRUE;
905 }
907 function make_name($attrs)
908 {
909 $name= "";
910 if (isset($attrs['sn'][0])){
911 $name= $attrs['sn'][0];
912 }
913 if (isset($attrs['givenName'][0])){
914 if ($name != ""){
915 $name.= ", ".$attrs['givenName'][0];
916 } else {
917 $name.= $attrs['givenName'][0];
918 }
919 }
920 if ($name != ""){
921 $name.= " ";
922 }
924 return ($name);
925 }
928 /* Create the mail part for the copy & paste dialog */
929 function getCopyDialog()
930 {
931 if(!$this->is_account) return("");
932 $smarty = get_smarty();
933 $smarty->assign("mail",$this->mail);
934 $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress);
935 $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress);
936 $str = $smarty->fetch(get_template_path("copypaste.tpl",TRUE, dirname(__FILE__)));
938 $ret = array();
939 $ret['status'] = "";
940 $ret['string'] = $str;
941 return($ret);
942 }
944 function saveCopyDialog()
945 {
946 if(!$this->is_account) return;
948 /* Execute to save mailAlternateAddress && gosaMailForwardingAddress */
949 $this->execute();
951 if(isset($_POST['mail'])){
952 $this->mail = $_POST['mail'];
953 }
955 }
957 function allow_remove()
958 {
959 if (isset($this->config->current['MAILMETHOD'])){
960 $method= $this->config->current['MAILMETHOD'];
961 if(preg_match("/kolab/i",$method)){
962 $ldap = $this->config->get_ldap_link();
963 $ldap->cd($this->config->current['BASE']);
964 $ldap->cat($this->dn);
965 if($ldap->count()){
966 $attrs = $ldap->fetch();
967 if(isset($attrs['kolabDeleteFlag'])){
968 return(_("Waiting for kolab to remove mail properties."));
969 }elseif(in_array("gosaMailAccount",$attrs['objectClass'])){
970 return(_("Please remove the mail account first, to allow kolab to call its remove methods."));
971 }
972 }
973 }
974 }
975 }
976 }
978 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
979 ?>