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", "lrsp" => "post", "lrsip" => "append",
54 "lrswipcd" => "write", "lrswipcda" => "all" );
56 /* attribute list for save action */
57 var $attributes= array("mail", "gosaMailServer", "gosaMailQuota", "gosaMailMaxSize",
58 "gosaMailDeliveryMode", "gosaSpamSortLevel", "gosaSpamMailbox",
59 "gosaVacationMessage", "uid");
60 var $objectclasses= array("gosaMailAccount");
63 /* constructor, if 'dn' is set, the node loads the given
64 'dn' from LDAP */
65 function mailAccount ($config, $dn= NULL)
66 {
67 /* Configuration is fine, allways */
68 $this->config= $config;
70 /* Load bases attributes */
71 plugin::plugin($config, $dn);
73 /* Set mailMethod to the one defined in gosa.conf */
74 if (isset($this->config->current['MAILMETHOD'])){
75 $method= $this->config->current['MAILMETHOD'];
76 if (class_exists("mailMethod$method")){
77 $this->method= "mailMethod$method";
78 } else {
79 print_red(sprintf(_("There is no mail method '%s' specified in your gosa.conf available."), $method));
80 }
81 }
83 /* Preset folder prefix. Will change it later to respect
84 altnamespace. */
85 if (isset($this->config->current['CYRUSUNIXSTYLE']) && $this->config->current['CYRUSUNIXSTYLE'] == "true"){
86 $this->folder_prefix= "user/";
87 } else {
88 $this->folder_prefix= "user.";
89 }
91 if ($dn != NULL){
93 /* Load attributes containing arrays */
94 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
95 if (isset($this->attrs["$val"]["count"])){
96 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
97 array_push($this->$val, $this->attrs["$val"][$i]);
98 }
99 }
100 }
102 /* Only do IMAP actions if gosaMailServer attribute is set */
103 if (isset ($this->attrs["gosaMailServer"][0])){
104 $method= new $this->method($this->config);
105 $id= $method->uattrib;
106 if ($method->connect($this->attrs["gosaMailServer"][0])){
107 $quota= $method->getQuota($this->folder_prefix.$this->$id);
109 /* Update quota values */
110 if ($quota['gosaMailQuota'] == 2147483647){
111 $this->quotaUsage= "";
112 $this->gosaMailQuota= "";
113 } else {
114 $this->quotaUsage= $quota['quotaUsage'];
115 $this->gosaMailQuota= $quota['gosaMailQuota'];
116 }
117 $this->mailboxList= $method->getMailboxList(
118 $this->folder_prefix.$this->$id,
119 $this->$id);
120 $method->disconnect();
121 }
123 /* Adapt attributes if needed */
124 $method->fixAttributesOnLoad($this);
125 }
126 }
128 /* Fill vacation array */
129 $this->vacation= array();
130 if (isset($this->config->current['VACATIONDIR'])){
131 $dir= $this->config->current['VACATIONDIR'];
132 if (is_dir($dir) && is_readable($dir)){
134 /* Look for files and build the vacation array */
135 $dh= opendir($dir);
136 while ($file = readdir($dh)){
137 $description= $this->parse_vacation("$dir/$file");
138 if ($description != ""){
139 $this->vacation["$dir/$file"]= $description;
140 }
141 }
142 closedir($dh);
143 }
144 }
146 /* Get global filter config */
147 if (!is_global("mailfilter")){
148 $ui= get_userinfo();
149 $base= get_base_from_people($ui->dn);
150 $mailfilter= array( "depselect" => $base,
151 "muser" => "",
152 "regex" => "*");
153 register_global("mailfilter", $mailfilter);
154 }
156 /* Save initial account state */
157 $this->initially_was_account= $this->is_account;
158 }
161 function parse_vacation($file)
162 {
163 $desc= "";
165 if (is_file($file)){
166 $fh = fopen($file, "r");
167 $line= fgets($fh, 256);
169 if (!preg_match('/^DESC:/', $line)){
170 print_red (_("No DESC tag in vacation file:")." $file");
171 return $desc;
172 }
173 fclose ($fh);
175 $desc= trim(preg_replace('/^DESC:\s*/', '', $line));
176 }
178 return $desc;
179 }
182 function execute()
183 {
184 /* Call parent execute */
185 plugin::execute();
187 /* Load templating engine */
188 $smarty= get_smarty();
189 $display= "";
191 $mailserver= array();
192 foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
193 $mailserver[]= $key;
194 }
196 /* Do we need to flip is_account state? */
197 if (isset($_POST['modify_state'])){
198 $this->is_account= !$this->is_account;
199 }
201 /* Show main page */
202 $mailserver= array();
203 foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
204 $mailserver[]= $key;
205 }
207 /* Do we represent a valid account? */
208 if (!$this->is_account && $this->parent == NULL){
209 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
210 _("This account has no mail extensions.")."</b>";
212 $display.= back_to_main();
213 return ($display);
214 }
216 /* Show tab dialog headers */
217 if ($this->parent != NULL){
218 if ($this->is_account){
219 $display= $this->show_header(_("Remove mail account"),
220 _("This account has mail features enabled. You can disable them by clicking below."));
221 } else {
222 $display= $this->show_header(_("Create mail account"), _("This account has mail features disabled. You can enable them by clicking below."));
223 return ($display);
224 }
225 }
227 /* Trigger forward add dialog? */
228 if (isset($_POST['add_local_forwarder'])){
229 $this->forward_dialog= TRUE;
230 $this->dialog= TRUE;
231 }
233 /* Cancel forward add dialog? */
234 if (isset($_POST['add_locals_cancel'])){
235 $this->forward_dialog= FALSE;
236 $this->dialog= FALSE;
237 }
239 /* Finished adding of locals? */
240 if (isset($_POST['add_locals_finish'])){
241 if (count ($_POST['local_list']) &&
242 chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
244 /* Walk through list of forwarders, ignore own addresses */
245 foreach ($_POST['local_list'] as $val){
246 if (!in_array ($val, $this->gosaMailAlternateAddress) &&
247 $val != $this->mail){
249 $this->addForwarder($val);
250 $this->is_modified= TRUE;
251 }
252 }
253 }
254 $this->forward_dialog= FALSE;
255 $this->dialog= FALSE;
256 }
258 /* Add forward email addresses */
259 if (isset($_POST['add_forwarder'])){
260 if ($_POST['forward_address'] != ""){
262 /* Valid email address specified? */
263 $address= $_POST['forward_address'];
264 $valid= FALSE;
265 if (!is_email($address)){
266 if (!is_email($address, TRUE)){
267 if ($this->is_template){
268 $valid= TRUE;
269 } else {
270 print_red (_("You're trying to add an invalid email address to the list of forwarders."));
271 }
272 }
273 } elseif ($address == $this->mail
274 || in_array($address, $this->gosaMailAlternateAddress)) {
276 print_red (_("Adding your one of your own addresses to the forwarders makes no sense."));
278 } else {
279 $valid= TRUE;
280 }
282 if ($valid){
283 /* Add it */
284 if (chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
285 $this->addForwarder ($address);
286 $this->is_modified= TRUE;
287 }
289 }
290 }
291 }
293 /* Delete forward email addresses */
294 if (isset($_POST['delete_forwarder'])){
295 if (count($_POST['forwarder_list'])
296 && chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
298 $this->delForwarder ($_POST['forwarder_list']);
299 }
300 }
302 /* Add alternate email addresses */
303 if (isset($_POST['add_alternate'])){
304 if ($_POST['alternate_address'] != "" &&
305 chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
307 $valid= FALSE;
308 if (!is_email($_POST['alternate_address'])){
309 if ($this->is_template){
310 if (!(is_email($_POST['alternate_address'], TRUE))){
311 print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
312 } else {
313 $valid= TRUE;
314 }
315 } else {
316 print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
317 }
319 } else {
320 $valid= TRUE;
321 }
323 if ($valid && ($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
324 $ui= get_userinfo();
325 if ($user != $ui->username){
326 print_red (_("The address you're trying to add is already used by user")." '$user'.");
327 }
328 }
329 }
330 }
332 /* Delete alternate email addresses */
333 if (isset($_POST['delete_alternate']) && isset ($_POST['alternates_list'])){
334 if (count($_POST['alternates_list']) &&
335 chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
337 $this->delAlternate ($_POST['alternates_list']);
338 }
339 }
341 /* Import vacation message? */
342 if (isset($_POST["import_vacation"]) && isset($this->vacation[$_POST["vacation_template"]])){
343 $contents= "";
344 $lines= file($_POST["vacation_template"]);
345 foreach ($lines as $line){
346 if (!preg_match('/^DESC:/', $line)){
347 $contents.= $line;
348 }
349 }
351 /* Replace attributes */
352 $attrs= $this->parent->by_object['user']->attributes;
353 foreach ($attrs as $val){
354 $contents= preg_replace("/%$val/",
355 $this->parent->by_object['user']->$val, $contents);
356 }
358 /* Save message */
359 $this->gosaVacationMessage= htmlspecialchars($contents);
360 }
362 /* Show forward add dialog */
363 if ($this->forward_dialog){
364 $ldap= $this->config->get_ldap_link();
366 /* Save data */
367 $mailfilter= get_global("mailfilter");
368 foreach( array("depselect", "muser", "regex") as $type){
369 if (isset($_POST[$type])){
370 $mailfilter[$type]= $_POST[$type];
371 }
372 }
373 if (isset($_GET['search'])){
374 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
375 if ($s == "**"){
376 $s= "*";
377 }
378 $mailfilter['regex']= $s;
379 }
380 register_global("mailfilter", $mailfilter);
382 /* Get actual list */
383 $mailusers= array ();
384 if ($mailfilter['regex'] != '*' && $mailfilter['regex'] != ""){
385 $regex= $mailfilter['regex'];
386 $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
387 } else {
388 $filter= "";
389 }
390 if ($mailfilter['muser'] != ""){
391 $user= $mailfilter['muser'];
392 $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
393 }
395 /* Add already present people to the filter */
396 $exclude= "";
397 foreach ($this->gosaMailForwardingAddress as $mail){
398 $exclude.= "(mail=$mail)";
399 }
400 if ($exclude != ""){
401 $filter.= "(!(|$exclude))";
402 }
404 $acl= array($this->config->current['BASE'] => ":all");
405 $res= get_list($acl, "(&(objectClass=gosaMailAccount)$filter)", TRUE, $mailfilter['depselect'], array("sn", "mail", "givenName"), TRUE);
406 $ldap->cd($mailfilter['depselect']);
407 $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
408 error_reporting (0);
409 while ($attrs= $ldap->fetch()){
410 if(preg_match('/%/', $attrs['mail'][0])){
411 continue;
412 }
413 $name= $this->make_name($attrs);
414 $mailusers[$attrs['mail'][0]]= $name."<".
415 $attrs['mail'][0].">";
416 }
417 error_reporting (E_ALL);
418 natcasesort ($mailusers);
419 reset ($mailusers);
421 /* Show dialog */
422 $smarty->assign("search_image", get_template_path('images/search.png'));
423 $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
424 $smarty->assign("tree_image", get_template_path('images/tree.png'));
425 $smarty->assign("infoimage", get_template_path('images/info.png'));
426 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
427 $smarty->assign("mailusers", $mailusers);
428 if (isset($_POST['depselect'])){
429 $smarty->assign("depselect", $_POST['depselect']);
430 }
431 $smarty->assign("deplist", $this->config->idepartments);
432 $smarty->assign("apply", apply_filter());
433 $smarty->assign("alphabet", generate_alphabet());
434 $smarty->assign("hint", print_sizelimit_warning());
435 foreach( array("depselect", "muser", "regex") as $type){
436 $smarty->assign("$type", $mailfilter[$type]);
437 }
438 $smarty->assign("hint", print_sizelimit_warning());
440 $display.= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE, dirname(__FILE__)));
441 return ($display);
442 }
444 $smarty->assign("mailServers", $mailserver);
445 foreach(array("gosaMailServer", "gosaMailQuota", "perms", "mail",
446 "gosaMailAlternateAddress", "gosaMailForwardingAddress",
447 "gosaVacationMessage", "gosaMailDeliveryMode",
448 "gosaMailMaxSize", "gosaSpamSortLevel", "gosaSpamMailbox") as $val){
450 $smarty->assign("$val", $this->$val);
451 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
452 }
454 if (is_numeric($this->gosaMailQuota) && $this->gosaMailQuota != 0){
455 $smarty->assign("quotausage", progressbar(round(($this->quotaUsage * 100)/ $this->gosaMailQuota),100,15,true));
456 $smarty->assign("quotadefined", "true");
457 } else {
458 $smarty->assign("quotadefined", "false");
459 }
461 /* Disable mail field if needed */
462 $method= new $this->method($this->config);
463 if ($method->uattrib == "mail" && $this->initially_was_account){
464 $smarty->assign("mailACL", "disabled");
465 }
467 /* Fill checkboxes */
468 if (!preg_match("/L/", $this->gosaMailDeliveryMode)) {
469 $smarty->assign("drop_own_mails", "checked");
470 } else {
471 $smarty->assign("drop_own_mails", "");
472 }
473 if (preg_match("/V/", $this->gosaMailDeliveryMode)) {
474 $smarty->assign("use_vacation", "checked");
475 } else {
476 $smarty->assign("use_vacation", "");
477 }
478 if (preg_match("/S/", $this->gosaMailDeliveryMode)) {
479 $smarty->assign("use_spam_filter", "checked");
480 } else {
481 $smarty->assign("use_spam_filter", "");
482 }
483 if (preg_match("/R/", $this->gosaMailDeliveryMode)) {
484 $smarty->assign("use_mailsize_limit", "checked");
485 } else {
486 $smarty->assign("use_mailsize_limit", "");
487 }
488 if (preg_match("/I/", $this->gosaMailDeliveryMode)) {
489 $smarty->assign("only_local", "checked");
490 } else {
491 $smarty->assign("only_local", "");
492 }
493 if (preg_match("/C/", $this->gosaMailDeliveryMode)) {
494 $smarty->assign("own_script", "checked");
495 } else {
496 $smarty->assign("own_script", "");
497 }
499 /* Have vacation templates? */
500 $smarty->assign("template", "");
501 if (count($this->vacation)){
502 $smarty->assign("show_templates", "true");
503 $smarty->assign("vacationtemplates", $this->vacation);
504 if (isset($_POST['vacation_template'])){
505 $smarty->assign("template", $_POST['vacation_template']);
506 }
507 } else {
508 $smarty->assign("show_templates", "false");
509 }
511 /* Fill spam selector */
512 $spamlevel= array();
513 for ($i= 0; $i<21; $i++){
514 $spamlevel[]= $i;
515 }
516 $smarty->assign("spamlevel", $spamlevel);
517 $smarty->assign("spambox", $this->mailboxList);
518 $smarty->assign("custom_sieveACL", chkacl($this->acl, "custom_sieve"));
519 $smarty->assign("only_localACL", chkacl($this->acl, "only_local"));
521 $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
522 return ($display);
523 }
526 /* remove object from parent */
527 function remove_from_parent()
528 {
529 /* Cancel if there's nothing to do here */
530 if (!$this->initially_was_account){
531 return;
532 }
534 /* include global link_info */
535 $ldap= $this->config->get_ldap_link();
537 /* Remove and write to LDAP */
538 plugin::remove_from_parent();
540 /* Zero arrays */
541 $this->attrs['gosaMailAlternateAddress']= array();
542 $this->attrs['gosaMailForwardingAddress']= array();
544 /* Adapt attributes if needed */
545 $method= new $this->method($this->config);
546 $method->fixAttributesOnRemove($this);
548 /* Mailmethod wants us to remove the entry from LDAP. Keep uid! */
549 #fixme: || kolab || is differs here, you can't delete all attrs specified in this plugin ....
550 #fixme: there are some attributes we have to keep, i think.
551 unset ($this->attrs['uid']);
555 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
556 $this->attributes, "Save");
557 $ldap->cd($this->dn);
558 $ldap->modify($this->attrs);
559 show_ldap_error($ldap->get_error());
561 /* Connect to IMAP server for account deletion */
562 if ($this->gosaMailServer != ""){
563 $method= new $this->method($this->config);
564 $id= $method->uattrib;
565 if ($method->connect($this->gosaMailServer)){
567 /* Remove account from IMAP server */
568 $method->deleteMailbox($this->folder_prefix.$this->$id);
569 $method->disconnect();
570 }
571 }
573 /* Optionally execute a command after we're done */
574 $this->handle_post_events("remove");
575 }
578 /* Save data to object */
579 function save_object()
580 {
581 if (isset($_POST['mailTab'])){
582 /* Save ldap attributes */
583 plugin::save_object();
585 /* Assemble mail delivery mode
586 The mode field in ldap consists of values between braces, this must
587 be called when 'mail' is set, because checkboxes may not be set when
588 we're in some other dialog.
590 Example for gosaMailDeliveryMode [LR ]
591 L: Local delivery
592 R: Reject when exceeding mailsize limit
593 S: Use spam filter
594 V: Use vacation message
595 C: Use custm sieve script
596 I: Only insider delivery */
598 $tmp= "";
599 if (!isset($_POST["drop_own_mails"])){
600 $tmp.= "L";
601 }
602 if (isset($_POST["use_mailsize_limit"])){
603 $tmp.= "R";
604 }
605 if (isset($_POST["use_spam_filter"])){
606 $tmp.= "S";
607 }
608 if (isset($_POST["use_vacation"])){
609 $tmp.= "V";
610 }
611 if (isset($_POST["own_script"])){
612 $tmp.= "C";
613 }
614 if (isset($_POST["only_local"])){
615 $tmp.= "I";
616 }
617 $tmp= "[$tmp]";
619 if (chkacl ($this->acl, "gosaMailDeliveryMode") == ""){
620 if ($this->gosaMailDeliveryMode != $tmp){
621 $this->is_modified= TRUE;
622 }
623 $this->gosaMailDeliveryMode= $tmp;
624 }
625 }
626 }
629 /* Save data to LDAP, depending on is_account we save or delete */
630 function save()
631 {
632 $ldap= $this->config->get_ldap_link();
634 /* Call parents save to prepare $this->attrs */
635 plugin::save();
637 /* Save arrays */
638 $this->attrs['gosaMailAlternateAddress']= $this->gosaMailAlternateAddress;
639 $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
641 /* Adapt attributes if needed */
642 $method= new $this->method($this->config);
643 $id= $method->uattrib;
644 $method->fixAttributesOnStore($this);
646 /* Remove Mailquota if = "" */
647 if((isset($this->attrs['gosaMailQuota']))&&($this->attrs['gosaMailQuota']=="")) {
648 $this->attrs['gosaMailQuota']=array();
649 }
651 if(empty($this->attrs['gosaSpamMailbox'])){
652 unset($this->attrs['gosaSpamMailbox']);
653 }
655 /* Save data to LDAP */
656 $ldap->cd($this->dn);
657 $ldap->modify($this->attrs);
658 show_ldap_error($ldap->get_error());
660 /* Only do IMAP actions if we are not a template */
661 if (!$this->is_template){
662 if ($method->connect($this->gosaMailServer)){
663 $method->updateMailbox($this->folder_prefix.$this->$id);
664 $method->setQuota($this->folder_prefix.$this->$id, $this->gosaMailQuota);
665 $method->disconnect();
667 /* Write sieve information only if not in C mode */
668 if (!is_integer(strpos($this->gosaMailDeliveryMode, "C"))){
669 $method->configureFilter($this->$id,
670 $this->gosaMailDeliveryMode,
671 $this->mail,
672 $this->gosaMailAlternateAddress,
673 $this->gosaMailMaxSize,
674 $this->gosaSpamMailbox,
675 $this->gosaSpamSortLevel,
676 $this->gosaVacationMessage);
677 }
678 }
679 }
681 /* Optionally execute a command after we're done */
682 if ($this->initially_was_account == $this->is_account){
683 if ($this->is_modified){
684 $this->handle_post_events("modify");
685 }
686 } else {
687 $this->handle_post_events("add");
688 }
690 }
692 /* Check formular input */
693 function check()
694 {
695 $ldap= $this->config->get_ldap_link();
697 $message= array();
699 if(empty($this->gosaMailServer)){
700 $message[]= _("There is no valid mailserver specified, please add one in the system setup.");
701 }
703 /* must: mail */
704 if ($this->mail == ""){
705 $message[]= _("The required field 'Primary address' is not set.");
706 }
707 if ($this->is_template){
708 if (!is_email($this->mail, TRUE)){
709 $message[]= _("Please enter a valid email address in 'Primary address' field.");
710 }
711 } else {
712 if (!is_email($this->mail)){
713 $message[]= _("Please enter a valid email address in 'Primary address' field.");
714 }
715 }
716 $ldap->cd($this->config->current['BASE']);
717 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=".$this->mail.")(gosaMailAlternateAddress=".
718 $this->mail."))(!(uid=".$this->uid."))(!(cn=".$this->uid.")))", array("uid"));
719 if ($ldap->count() != 0){
720 $message[]= _("The primary address you've entered is already in use.");
721 }
723 /* Check quota */
724 if ($this->gosaMailQuota != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
725 if (!is_numeric($this->gosaMailQuota)) {
726 $message[]= _("Value in 'Quota size' is not valid.");
727 } else {
728 $this->gosaMailQuota= (int) $this->gosaMailQuota;
729 }
730 }
732 /* Check rejectsize for integer */
733 if ($this->gosaMailMaxSize != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
734 if (!is_numeric($this->gosaMailMaxSize)){
735 $message[]= _("Please specify a vaild mail size for mails to be rejected.");
736 } else {
737 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
738 }
739 }
741 /* Need gosaMailMaxSize if use_mailsize_limit is checked */
742 if (is_integer(strpos($this->gosaMailDeliveryMode, "R")) &&
743 $this->gosaMailMaxSize == ""){
745 $message[]= _("You need to set the maximum mail size in order to reject anything.");
746 }
748 if((preg_match("/S/", $this->gosaMailDeliveryMode))&&(empty($this->gosaSpamMailbox))) {
749 $message[]= _("You specified Spam settings, but there is no Folder specified.");
750 }
752 return ($message);
753 }
755 /* Adapt from template, using 'dn' */
756 function adapt_from_template($dn)
757 {
758 plugin::adapt_from_template($dn);
760 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
761 $this->$val= array();
762 if (isset($this->attrs["$val"]["count"])){
763 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
764 $value= $this->attrs["$val"][$i];
765 foreach (array("sn", "givenName", "uid") as $repl){
766 if (preg_match("/%$repl/i", $value)){
767 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
768 }
769 }
770 array_push($this->$val, strtolower(rewrite($value)));
771 }
772 }
773 }
774 $this->mail= strtolower(rewrite($this->mail));
775 }
777 /* Add entry to forwarder list */
778 function addForwarder($address)
779 {
780 $this->gosaMailForwardingAddress[]= $address;
781 $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
783 sort ($this->gosaMailForwardingAddress);
784 reset ($this->gosaMailForwardingAddress);
785 $this->is_modified= TRUE;
786 }
788 /* Remove list of addresses from forwarder list */
789 function delForwarder($addresses)
790 {
791 $this->gosaMailForwardingAddress= array_remove_entries ($addresses, $this->gosaMailForwardingAddress);
792 $this->is_modified= TRUE;
793 }
797 function addAlternate($address)
798 {
799 $ldap= $this->config->get_ldap_link();
801 $address= strtolower($address);
803 /* Is this address already assigned in LDAP? */
804 $ldap->cd ($this->config->current['BASE']);
805 $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)".
806 "(gosaMailAlternateAddress=$address)))", array("uid"));
808 if ($ldap->count() > 0){
809 $attrs= $ldap->fetch ();
810 return ($attrs["uid"][0]);
811 }
813 /* Add to list of alternates */
814 if (!in_array($address, $this->gosaMailAlternateAddress)){
815 $this->gosaMailAlternateAddress[]= $address;
816 $this->is_modified= TRUE;
817 }
819 sort ($this->gosaMailAlternateAddress);
820 reset ($this->gosaMailAlternateAddress);
822 return ("");
823 }
826 function delAlternate($addresses)
827 {
828 $this->gosaMailAlternateAddress= array_remove_entries ($addresses,
829 $this->gosaMailAlternateAddress);
830 $this->is_modified= TRUE;
831 }
833 function make_name($attrs)
834 {
835 $name= "";
836 if (isset($attrs['sn'][0])){
837 $name= $attrs['sn'][0];
838 }
839 if (isset($attrs['givenName'][0])){
840 if ($name != ""){
841 $name.= ", ".$attrs['givenName'][0];
842 } else {
843 $name.= $attrs['givenName'][0];
844 }
845 }
846 if ($name != ""){
847 $name.= " ";
848 }
850 return ($name);
851 }
853 }
855 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
856 ?>