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 $this->cleanup();
559 $ldap->modify ($this->attrs);
561 show_ldap_error($ldap->get_error());
563 /* Connect to IMAP server for account deletion */
564 if ($this->gosaMailServer != ""){
565 $method= new $this->method($this->config);
566 $id= $method->uattrib;
567 if ($method->connect($this->gosaMailServer)){
569 /* Remove account from IMAP server */
570 $method->deleteMailbox($this->folder_prefix.$this->$id);
571 $method->disconnect();
572 }
573 }
575 /* Optionally execute a command after we're done */
576 $this->handle_post_events("remove");
577 }
580 /* Save data to object */
581 function save_object()
582 {
583 if (isset($_POST['mailTab'])){
584 /* Save ldap attributes */
585 plugin::save_object();
587 /* Assemble mail delivery mode
588 The mode field in ldap consists of values between braces, this must
589 be called when 'mail' is set, because checkboxes may not be set when
590 we're in some other dialog.
592 Example for gosaMailDeliveryMode [LR ]
593 L: Local delivery
594 R: Reject when exceeding mailsize limit
595 S: Use spam filter
596 V: Use vacation message
597 C: Use custm sieve script
598 I: Only insider delivery */
600 $tmp= "";
601 if (!isset($_POST["drop_own_mails"])){
602 $tmp.= "L";
603 }
604 if (isset($_POST["use_mailsize_limit"])){
605 $tmp.= "R";
606 }
607 if (isset($_POST["use_spam_filter"])){
608 $tmp.= "S";
609 }
610 if (isset($_POST["use_vacation"])){
611 $tmp.= "V";
612 }
613 if (isset($_POST["own_script"])){
614 $tmp.= "C";
615 }
616 if (isset($_POST["only_local"])){
617 $tmp.= "I";
618 }
619 $tmp= "[$tmp]";
621 if (chkacl ($this->acl, "gosaMailDeliveryMode") == ""){
622 if ($this->gosaMailDeliveryMode != $tmp){
623 $this->is_modified= TRUE;
624 }
625 $this->gosaMailDeliveryMode= $tmp;
626 }
627 }
628 }
631 /* Save data to LDAP, depending on is_account we save or delete */
632 function save()
633 {
634 $ldap= $this->config->get_ldap_link();
636 /* Call parents save to prepare $this->attrs */
637 plugin::save();
639 /* Save arrays */
640 $this->attrs['gosaMailAlternateAddress']= $this->gosaMailAlternateAddress;
641 $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
643 /* Adapt attributes if needed */
644 $method= new $this->method($this->config);
645 $id= $method->uattrib;
646 $method->fixAttributesOnStore($this);
648 /* Remove Mailquota if = "" */
649 if((isset($this->attrs['gosaMailQuota']))&&($this->attrs['gosaMailQuota']=="")) {
650 $this->attrs['gosaMailQuota']=array();
651 }
653 if(empty($this->attrs['gosaSpamMailbox'])){
654 unset($this->attrs['gosaSpamMailbox']);
655 }
657 /* Save data to LDAP */
658 $ldap->cd($this->dn);
659 $this->cleanup();
660 $ldap->modify ($this->attrs);
662 show_ldap_error($ldap->get_error());
664 /* Only do IMAP actions if we are not a template */
665 if (!$this->is_template){
666 if ($method->connect($this->gosaMailServer)){
667 $method->updateMailbox($this->folder_prefix.$this->$id);
668 $method->setQuota($this->folder_prefix.$this->$id, $this->gosaMailQuota);
669 $method->disconnect();
671 /* Write sieve information only if not in C mode */
672 if (!is_integer(strpos($this->gosaMailDeliveryMode, "C"))){
673 $method->configureFilter($this->$id,
674 $this->gosaMailDeliveryMode,
675 $this->mail,
676 $this->gosaMailAlternateAddress,
677 $this->gosaMailMaxSize,
678 $this->gosaSpamMailbox,
679 $this->gosaSpamSortLevel,
680 $this->gosaVacationMessage);
681 }
682 }
683 }
685 /* Optionally execute a command after we're done */
686 if ($this->initially_was_account == $this->is_account){
687 if ($this->is_modified){
688 $this->handle_post_events("modify");
689 }
690 } else {
691 $this->handle_post_events("add");
692 }
694 }
696 /* Check formular input */
697 function check()
698 {
699 $ldap= $this->config->get_ldap_link();
701 $message= array();
703 if(empty($this->gosaMailServer)){
704 $message[]= _("There is no valid mailserver specified, please add one in the system setup.");
705 }
707 /* must: mail */
708 if ($this->mail == ""){
709 $message[]= _("The required field 'Primary address' is not set.");
710 }
711 if ($this->is_template){
712 if (!is_email($this->mail, TRUE)){
713 $message[]= _("Please enter a valid email address in 'Primary address' field.");
714 }
715 } else {
716 if (!is_email($this->mail)){
717 $message[]= _("Please enter a valid email address in 'Primary address' field.");
718 }
719 }
720 $ldap->cd($this->config->current['BASE']);
721 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=".$this->mail.")(gosaMailAlternateAddress=".$this->mail."))(!(uid=".$this->uid."))(!(cn=".$this->uid.")))", array("uid"));
722 if ($ldap->count() != 0){
723 $message[]= _("The primary address you've entered is already in use.");
724 }
726 /* Check quota */
727 if ($this->gosaMailQuota != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
728 if (!is_numeric($this->gosaMailQuota)) {
729 $message[]= _("Value in 'Quota size' is not valid.");
730 } else {
731 $this->gosaMailQuota= (int) $this->gosaMailQuota;
732 }
733 }
735 /* Check rejectsize for integer */
736 if ($this->gosaMailMaxSize != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
737 if (!is_numeric($this->gosaMailMaxSize)){
738 $message[]= _("Please specify a vaild mail size for mails to be rejected.");
739 } else {
740 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
741 }
742 }
744 /* Need gosaMailMaxSize if use_mailsize_limit is checked */
745 if (is_integer(strpos($this->gosaMailDeliveryMode, "R")) &&
746 $this->gosaMailMaxSize == ""){
748 $message[]= _("You need to set the maximum mail size in order to reject anything.");
749 }
751 if((preg_match("/S/", $this->gosaMailDeliveryMode))&&(empty($this->gosaSpamMailbox))) {
752 $message[]= _("You specified Spam settings, but there is no Folder specified.");
753 }
755 return ($message);
756 }
758 /* Adapt from template, using 'dn' */
759 function adapt_from_template($dn)
760 {
761 plugin::adapt_from_template($dn);
763 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
764 $this->$val= array();
765 if (isset($this->attrs["$val"]["count"])){
766 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
767 $value= $this->attrs["$val"][$i];
768 foreach (array("sn", "givenName", "uid") as $repl){
769 if (preg_match("/%$repl/i", $value)){
770 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
771 }
772 }
773 array_push($this->$val, strtolower(rewrite($value)));
774 }
775 }
776 }
777 $this->mail= strtolower(rewrite($this->mail));
778 }
780 /* Add entry to forwarder list */
781 function addForwarder($address)
782 {
783 $this->gosaMailForwardingAddress[]= $address;
784 $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
786 sort ($this->gosaMailForwardingAddress);
787 reset ($this->gosaMailForwardingAddress);
788 $this->is_modified= TRUE;
789 }
791 /* Remove list of addresses from forwarder list */
792 function delForwarder($addresses)
793 {
794 $this->gosaMailForwardingAddress= array_remove_entries ($addresses, $this->gosaMailForwardingAddress);
795 $this->is_modified= TRUE;
796 }
800 function addAlternate($address)
801 {
802 $ldap= $this->config->get_ldap_link();
804 $address= strtolower($address);
806 /* Is this address already assigned in LDAP? */
807 $ldap->cd ($this->config->current['BASE']);
808 $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)"."(gosaMailAlternateAddress=$address)))", array("uid"));
810 if ($ldap->count() > 0){
811 $attrs= $ldap->fetch ();
812 return ($attrs["uid"][0]);
813 }
815 /* Add to list of alternates */
816 if (!in_array($address, $this->gosaMailAlternateAddress)){
817 $this->gosaMailAlternateAddress[]= $address;
818 $this->is_modified= TRUE;
819 }
821 sort ($this->gosaMailAlternateAddress);
822 reset ($this->gosaMailAlternateAddress);
824 return ("");
825 }
828 function delAlternate($addresses)
829 {
830 $this->gosaMailAlternateAddress= array_remove_entries ($addresses,
831 $this->gosaMailAlternateAddress);
832 $this->is_modified= TRUE;
833 }
835 function make_name($attrs)
836 {
837 $name= "";
838 if (isset($attrs['sn'][0])){
839 $name= $attrs['sn'][0];
840 }
841 if (isset($attrs['givenName'][0])){
842 if ($name != ""){
843 $name.= ", ".$attrs['givenName'][0];
844 } else {
845 $name.= $attrs['givenName'][0];
846 }
847 }
848 if ($name != ""){
849 $name.= " ";
850 }
852 return ($name);
853 }
855 }
857 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
858 ?>