fc1cf61e3210a4c184f71d40a73837272c08f22e
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);
108 $this->quotaUsage= $quota['quotaUsage'];
109 $this->gosaMailQuota= $quota['gosaMailQuota'];
110 $this->mailboxList= $method->getMailboxList(
111 $this->folder_prefix.$this->$id,
112 $this->$id);
113 $method->disconnect();
114 }
116 /* Adapt attributes if needed */
117 $method->fixAttributesOnLoad($this);
118 }
119 }
121 /* Fill vacation array */
122 $this->vacation= array();
123 if (isset($this->config->current['VACATIONDIR'])){
124 $dir= $this->config->current['VACATIONDIR'];
125 if (is_dir($dir) && is_readable($dir)){
127 /* Look for files and build the vacation array */
128 $dh= opendir($dir);
129 while ($file = readdir($dh)){
130 $description= $this->parse_vacation("$dir/$file");
131 if ($description != ""){
132 $this->vacation["$dir/$file"]= $description;
133 }
134 }
135 closedir($dh);
136 }
137 }
139 /* Get global filter config */
140 if (!is_global("mailfilter")){
141 $ui= get_userinfo();
142 $base= get_base_from_people($ui->dn);
143 $mailfilter= array( "depselect" => $base,
144 "muser" => "",
145 "regex" => "*");
146 register_global("mailfilter", $mailfilter);
147 }
149 /* Save initial account state */
150 $this->initially_was_account= $this->is_account;
151 }
154 function parse_vacation($file)
155 {
156 $desc= "";
158 if (is_file($file)){
159 $fh = fopen($file, "r");
160 $line= fgets($fh, 256);
162 if (!preg_match('/^DESC:/', $line)){
163 print_red (_("No DESC tag in vacation file:")." $file");
164 return $desc;
165 }
166 fclose ($fh);
168 $desc= trim(preg_replace('/^DESC:\s*/', '', $line));
169 }
171 return $desc;
172 }
175 function execute()
176 {
177 /* Call parent execute */
178 plugin::execute();
180 /* Load templating engine */
181 $smarty= get_smarty();
182 $display= "";
184 $mailserver= array();
185 foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
186 $mailserver[]= $key;
187 }
189 /* Do we need to flip is_account state? */
190 if (isset($_POST['modify_state'])){
191 $this->is_account= !$this->is_account;
192 }
194 /* Show main page */
195 $mailserver= array();
196 foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
197 $mailserver[]= $key;
198 }
200 /* Do we represent a valid account? */
201 if (!$this->is_account && $this->parent == NULL){
202 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
203 _("This account has no mail extensions.")."</b>";
205 $display.= back_to_main();
206 return ($display);
207 }
209 /* Show tab dialog headers */
210 if ($this->parent != NULL){
211 if ($this->is_account){
212 $display= $this->show_header(_("Remove mail account"),
213 _("This account has mail features enabled. You can disable them by clicking below."));
214 } else {
215 $display= $this->show_header(_("Create mail account"), _("This account has mail features disabled. You can enable them by clicking below."));
216 return ($display);
217 }
218 }
220 /* Trigger forward add dialog? */
221 if (isset($_POST['add_local_forwarder'])){
222 $this->forward_dialog= TRUE;
223 $this->dialog= TRUE;
224 }
226 /* Cancel forward add dialog? */
227 if (isset($_POST['add_locals_cancel'])){
228 $this->forward_dialog= FALSE;
229 $this->dialog= FALSE;
230 }
232 /* Finished adding of locals? */
233 if (isset($_POST['add_locals_finish'])){
234 if (count ($_POST['local_list']) &&
235 chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
237 /* Walk through list of forwarders, ignore own addresses */
238 foreach ($_POST['local_list'] as $val){
239 if (!in_array ($val, $this->gosaMailAlternateAddress) &&
240 $val != $this->mail){
242 $this->addForwarder($val);
243 $this->is_modified= TRUE;
244 }
245 }
246 }
247 $this->forward_dialog= FALSE;
248 $this->dialog= FALSE;
249 }
251 /* Add forward email addresses */
252 if (isset($_POST['add_forwarder'])){
253 if ($_POST['forward_address'] != ""){
255 /* Valid email address specified? */
256 $address= $_POST['forward_address'];
257 $valid= FALSE;
258 if (!is_email($address)){
259 if (!is_email($address, TRUE)){
260 if ($this->is_template){
261 $valid= TRUE;
262 } else {
263 print_red (_("You're trying to add an invalid email address to the list of forwarders."));
264 }
265 }
266 } elseif ($address == $this->mail
267 || in_array($address, $this->gosaMailAlternateAddress)) {
269 print_red (_("Adding your one of your own addresses to the forwarders makes no sense."));
271 } else {
272 $valid= TRUE;
273 }
275 if ($valid){
276 /* Add it */
277 if (chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
278 $this->addForwarder ($address);
279 $this->is_modified= TRUE;
280 }
282 }
283 }
284 }
286 /* Delete forward email addresses */
287 if (isset($_POST['delete_forwarder'])){
288 if (count($_POST['forwarder_list'])
289 && chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
291 $this->delForwarder ($_POST['forwarder_list']);
292 }
293 }
295 /* Add alternate email addresses */
296 if (isset($_POST['add_alternate'])){
297 if ($_POST['alternate_address'] != "" &&
298 chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
300 $valid= FALSE;
301 if (!is_email($_POST['alternate_address'])){
302 if ($this->is_template){
303 if (!(is_email($_POST['alternate_address'], TRUE))){
304 print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
305 } else {
306 $valid= TRUE;
307 }
308 } else {
309 print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
310 }
312 } else {
313 $valid= TRUE;
314 }
316 if ($valid && ($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
317 $ui= get_userinfo();
318 if ($user != $ui->username){
319 print_red (_("The address you're trying to add is already used by user")." '$user'.");
320 }
321 }
322 }
323 }
325 /* Delete alternate email addresses */
326 if (isset($_POST['delete_alternate']) && isset ($_POST['alternates_list'])){
327 if (count($_POST['alternates_list']) &&
328 chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
330 $this->delAlternate ($_POST['alternates_list']);
331 }
332 }
334 /* Import vacation message? */
335 if (isset($_POST["import_vacation"]) && isset($this->vacation[$_POST["vacation_template"]])){
336 $contents= "";
337 $lines= file($_POST["vacation_template"]);
338 foreach ($lines as $line){
339 if (!preg_match('/^DESC:/', $line)){
340 $contents.= $line;
341 }
342 }
344 /* Replace attributes */
345 $attrs= $this->parent->by_object['user']->attributes;
346 foreach ($attrs as $val){
347 $contents= preg_replace("/%$val/",
348 $this->parent->by_object['user']->$val, $contents);
349 }
351 /* Save message */
352 $this->gosaVacationMessage= htmlspecialchars($contents);
353 }
355 /* Show forward add dialog */
356 if ($this->forward_dialog){
357 $ldap= $this->config->get_ldap_link();
359 /* Save data */
360 $mailfilter= get_global("mailfilter");
361 foreach( array("depselect", "muser", "regex") as $type){
362 if (isset($_POST[$type])){
363 $mailfilter[$type]= $_POST[$type];
364 }
365 }
366 if (isset($_GET['search'])){
367 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
368 if ($s == "**"){
369 $s= "*";
370 }
371 $mailfilter['regex']= $s;
372 }
373 register_global("mailfilter", $mailfilter);
375 /* Get actual list */
376 $mailusers= array ();
377 if ($mailfilter['regex'] != '*' && $mailfilter['regex'] != ""){
378 $regex= $mailfilter['regex'];
379 $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
380 } else {
381 $filter= "";
382 }
383 if ($mailfilter['muser'] != ""){
384 $user= $mailfilter['muser'];
385 $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
386 }
388 /* Add already present people to the filter */
389 $exclude= "";
390 foreach ($this->gosaMailForwardingAddress as $mail){
391 $exclude.= "(mail=$mail)";
392 }
393 if ($exclude != ""){
394 $filter.= "(!(|$exclude))";
395 }
397 $acl= array($this->config->current['BASE'] => ":all");
398 $res= get_list($acl, "(&(objectClass=gosaMailAccount)$filter)", TRUE, $mailfilter['depselect'], array("sn", "mail", "givenName"), TRUE);
399 $ldap->cd($mailfilter['depselect']);
400 $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
401 error_reporting (0);
402 while ($attrs= $ldap->fetch()){
403 if(preg_match('/%/', $attrs['mail'][0])){
404 continue;
405 }
406 $name= $this->make_name($attrs);
407 $mailusers[$attrs['mail'][0]]= $name."<".
408 $attrs['mail'][0].">";
409 }
410 error_reporting (E_ALL);
411 natcasesort ($mailusers);
412 reset ($mailusers);
414 /* Show dialog */
415 $smarty->assign("search_image", get_template_path('images/search.png'));
416 $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
417 $smarty->assign("tree_image", get_template_path('images/tree.png'));
418 $smarty->assign("infoimage", get_template_path('images/info.png'));
419 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
420 $smarty->assign("mailusers", $mailusers);
421 if (isset($_POST['depselect'])){
422 $smarty->assign("depselect", $_POST['depselect']);
423 }
424 $smarty->assign("deplist", $this->config->idepartments);
425 $smarty->assign("apply", apply_filter());
426 $smarty->assign("alphabet", generate_alphabet());
427 $smarty->assign("hint", print_sizelimit_warning());
428 foreach( array("depselect", "muser", "regex") as $type){
429 $smarty->assign("$type", $mailfilter[$type]);
430 }
431 $smarty->assign("hint", print_sizelimit_warning());
433 $display.= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE, dirname(__FILE__)));
434 return ($display);
435 }
437 $smarty->assign("mailServers", $mailserver);
438 foreach(array("gosaMailServer", "gosaMailQuota", "perms", "mail",
439 "gosaMailAlternateAddress", "gosaMailForwardingAddress",
440 "gosaVacationMessage", "gosaMailDeliveryMode",
441 "gosaMailMaxSize", "gosaSpamSortLevel", "gosaSpamMailbox") as $val){
443 $smarty->assign("$val", $this->$val);
444 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
445 }
447 if (is_numeric($this->gosaMailQuota) && $this->gosaMailQuota != 0){
448 $smarty->assign("quotausage", progressbar(round(($this->quotaUsage * 100)/ $this->gosaMailQuota,100,15,true)));
449 $smarty->assign("quotadefined", "true");
450 } else {
451 $smarty->assign("quotadefined", "false");
452 }
454 /* Disable mail field if needed */
455 $method= new $this->method($this->config);
456 if ($method->uattrib == "mail" && $this->initially_was_account){
457 $smarty->assign("mailACL", "disabled");
458 }
460 /* Fill checkboxes */
461 if (!preg_match("/L/", $this->gosaMailDeliveryMode)) {
462 $smarty->assign("drop_own_mails", "checked");
463 } else {
464 $smarty->assign("drop_own_mails", "");
465 }
466 if (preg_match("/V/", $this->gosaMailDeliveryMode)) {
467 $smarty->assign("use_vacation", "checked");
468 } else {
469 $smarty->assign("use_vacation", "");
470 }
471 if (preg_match("/S/", $this->gosaMailDeliveryMode)) {
472 $smarty->assign("use_spam_filter", "checked");
473 } else {
474 $smarty->assign("use_spam_filter", "");
475 }
476 if (preg_match("/R/", $this->gosaMailDeliveryMode)) {
477 $smarty->assign("use_mailsize_limit", "checked");
478 } else {
479 $smarty->assign("use_mailsize_limit", "");
480 }
481 if (preg_match("/I/", $this->gosaMailDeliveryMode)) {
482 $smarty->assign("only_local", "checked");
483 } else {
484 $smarty->assign("only_local", "");
485 }
486 if (preg_match("/C/", $this->gosaMailDeliveryMode)) {
487 $smarty->assign("own_script", "checked");
488 } else {
489 $smarty->assign("own_script", "");
490 }
492 /* Have vacation templates? */
493 $smarty->assign("template", "");
494 if (count($this->vacation)){
495 $smarty->assign("show_templates", "true");
496 $smarty->assign("vacationtemplates", $this->vacation);
497 if (isset($_POST['vacation_template'])){
498 $smarty->assign("template", $_POST['vacation_template']);
499 }
500 } else {
501 $smarty->assign("show_templates", "false");
502 }
504 /* Fill spam selector */
505 $spamlevel= array();
506 for ($i= 0; $i<21; $i++){
507 $spamlevel[]= $i;
508 }
509 $smarty->assign("spamlevel", $spamlevel);
510 $smarty->assign("spambox", $this->mailboxList);
511 $smarty->assign("custom_sieveACL", chkacl($this->acl, "custom_sieve"));
512 $smarty->assign("only_localACL", chkacl($this->acl, "only_local"));
514 $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
515 return ($display);
516 }
519 /* remove object from parent */
520 function remove_from_parent()
521 {
522 /* Cancel if there's nothing to do here */
523 if (!$this->initially_was_account){
524 return;
525 }
527 /* include global link_info */
528 $ldap= $this->config->get_ldap_link();
530 /* Remove and write to LDAP */
531 plugin::remove_from_parent();
533 /* Zero arrays */
534 $this->attrs['gosaMailAlternateAddress']= array();
535 $this->attrs['gosaMailForwardingAddress']= array();
537 /* Adapt attributes if needed */
538 $method= new $this->method($this->config);
539 $method->fixAttributesOnRemove($this);
541 /* Mailmethod wants us to remove the entry from LDAP. Keep uid! */
542 #fixme: || kolab || is differs here, you can't delete all attrs specified in this plugin ....
543 #fixme: there are some attributes we have to keep, i think.
544 unset ($this->attrs['uid']);
548 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
549 $this->attributes, "Save");
550 $ldap->cd($this->dn);
551 $ldap->modify($this->attrs);
552 show_ldap_error($ldap->get_error());
554 /* Connect to IMAP server for account deletion */
555 if ($this->gosaMailServer != ""){
556 $method= new $this->method($this->config);
557 $id= $method->uattrib;
558 if ($method->connect($this->gosaMailServer)){
560 /* Remove account from IMAP server */
561 $method->deleteMailbox($this->folder_prefix.$this->$id);
562 $method->disconnect();
563 }
564 }
566 /* Optionally execute a command after we're done */
567 $this->handle_post_events("remove");
568 }
571 /* Save data to object */
572 function save_object()
573 {
574 if (isset($_POST['mailTab'])){
575 /* Save ldap attributes */
576 plugin::save_object();
578 /* Assemble mail delivery mode
579 The mode field in ldap consists of values between braces, this must
580 be called when 'mail' is set, because checkboxes may not be set when
581 we're in some other dialog.
583 Example for gosaMailDeliveryMode [LR ]
584 L: Local delivery
585 R: Reject when exceeding mailsize limit
586 S: Use spam filter
587 V: Use vacation message
588 C: Use custm sieve script
589 I: Only insider delivery */
591 $tmp= "";
592 if (!isset($_POST["drop_own_mails"])){
593 $tmp.= "L";
594 }
595 if (isset($_POST["use_mailsize_limit"])){
596 $tmp.= "R";
597 }
598 if (isset($_POST["use_spam_filter"])){
599 $tmp.= "S";
600 }
601 if (isset($_POST["use_vacation"])){
602 $tmp.= "V";
603 }
604 if (isset($_POST["own_script"])){
605 $tmp.= "C";
606 }
607 if (isset($_POST["only_local"])){
608 $tmp.= "I";
609 }
610 $tmp= "[$tmp]";
612 if (chkacl ($this->acl, "gosaMailDeliveryMode") == ""){
613 if ($this->gosaMailDeliveryMode != $tmp){
614 $this->is_modified= TRUE;
615 }
616 $this->gosaMailDeliveryMode= $tmp;
617 }
618 }
619 }
622 /* Save data to LDAP, depending on is_account we save or delete */
623 function save()
624 {
625 $ldap= $this->config->get_ldap_link();
627 /* Call parents save to prepare $this->attrs */
628 plugin::save();
630 /* Save arrays */
631 $this->attrs['gosaMailAlternateAddress']= $this->gosaMailAlternateAddress;
632 $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
634 /* Adapt attributes if needed */
635 $method= new $this->method($this->config);
636 $id= $method->uattrib;
637 $method->fixAttributesOnStore($this);
639 /* Remove Mailquota if = "" */
640 if((isset($this->attrs['gosaMailQuota']))&&($this->attrs['gosaMailQuota']=="")) {
641 $this->attrs['gosaMailQuota']=array();
642 }
644 if(empty($this->attrs['gosaSpamMailbox'])){
645 unset($this->attrs['gosaSpamMailbox']);
646 }
648 /* Save data to LDAP */
649 $ldap->cd($this->dn);
650 $ldap->modify($this->attrs);
651 show_ldap_error($ldap->get_error());
653 /* Only do IMAP actions if we are not a template */
654 if (!$this->is_template){
655 if ($method->connect($this->gosaMailServer)){
656 $method->updateMailbox($this->folder_prefix.$this->$id);
657 $method->setQuota($this->folder_prefix.$this->$id, $this->gosaMailQuota);
658 $method->disconnect();
660 /* Write sieve information only if not in C mode */
661 if (!is_integer(strpos($this->gosaMailDeliveryMode, "C"))){
662 $method->configureFilter($this->$id,
663 $this->gosaMailDeliveryMode,
664 $this->mail,
665 $this->gosaMailAlternateAddress,
666 $this->gosaMailMaxSize,
667 $this->gosaSpamMailbox,
668 $this->gosaSpamSortLevel,
669 $this->gosaVacationMessage);
670 }
671 }
672 }
674 /* Optionally execute a command after we're done */
675 if ($this->initially_was_account == $this->is_account){
676 if ($this->is_modified){
677 $this->handle_post_events("modify");
678 }
679 } else {
680 $this->handle_post_events("add");
681 }
683 }
685 /* Check formular input */
686 function check()
687 {
688 $ldap= $this->config->get_ldap_link();
690 $message= array();
692 if(empty($this->gosaMailServer)){
693 $message[]= _("There is no valid mailserver specified, please add one in the system setup.");
694 }
696 /* must: mail */
697 if ($this->mail == ""){
698 $message[]= _("The required field 'Primary address' is not set.");
699 }
700 if ($this->is_template){
701 if (!is_email($this->mail, TRUE)){
702 $message[]= _("Please enter a valid email address in 'Primary address' field.");
703 }
704 } else {
705 if (!is_email($this->mail)){
706 $message[]= _("Please enter a valid email address in 'Primary address' field.");
707 }
708 }
709 $ldap->cd($this->config->current['BASE']);
710 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(|(mail=".$this->mail.")(gosaMailAlternateAddress=".
711 $this->mail."))(!(uid=".$this->uid."))(!(cn=".$this->uid.")))", array("uid"));
712 if ($ldap->count() != 0){
713 $message[]= _("The primary address you've entered is already in use.");
714 }
716 /* Check quota */
717 if ($this->gosaMailQuota != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
718 if (!is_numeric($this->gosaMailQuota)) {
719 $message[]= _("Value in 'Quota size' is not valid.");
720 } else {
721 $this->gosaMailQuota= (int) $this->gosaMailQuota;
722 }
723 }
725 /* Check rejectsize for integer */
726 if ($this->gosaMailMaxSize != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
727 if (!is_numeric($this->gosaMailMaxSize)){
728 $message[]= _("Please specify a vaild mail size for mails to be rejected.");
729 } else {
730 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
731 }
732 }
734 /* Need gosaMailMaxSize if use_mailsize_limit is checked */
735 if (is_integer(strpos($this->gosaMailDeliveryMode, "R")) &&
736 $this->gosaMailMaxSize == ""){
738 $message[]= _("You need to set the maximum mail size in order to reject anything.");
739 }
741 if((preg_match("/S/", $this->gosaMailDeliveryMode))&&(empty($this->gosaSpamMailbox))) {
742 $message[]= _("You specified Spam settings, but there is no Folder specified.");
743 }
745 return ($message);
746 }
748 /* Adapt from template, using 'dn' */
749 function adapt_from_template($dn)
750 {
751 plugin::adapt_from_template($dn);
753 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
754 $this->$val= array();
755 if (isset($this->attrs["$val"]["count"])){
756 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
757 $value= $this->attrs["$val"][$i];
758 foreach (array("sn", "givenName", "uid") as $repl){
759 if (preg_match("/%$repl/i", $value)){
760 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
761 }
762 }
763 array_push($this->$val, strtolower(rewrite($value)));
764 }
765 }
766 }
767 $this->mail= strtolower(rewrite($this->mail));
768 }
770 /* Add entry to forwarder list */
771 function addForwarder($address)
772 {
773 $this->gosaMailForwardingAddress[]= $address;
774 $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
776 sort ($this->gosaMailForwardingAddress);
777 reset ($this->gosaMailForwardingAddress);
778 $this->is_modified= TRUE;
779 }
781 /* Remove list of addresses from forwarder list */
782 function delForwarder($addresses)
783 {
784 $this->gosaMailForwardingAddress= array_remove_entries ($addresses, $this->gosaMailForwardingAddress);
785 $this->is_modified= TRUE;
786 }
790 function addAlternate($address)
791 {
792 $ldap= $this->config->get_ldap_link();
794 $address= strtolower($address);
796 /* Is this address already assigned in LDAP? */
797 $ldap->cd ($this->config->current['BASE']);
798 $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)".
799 "(gosaMailAlternateAddress=$address)))", array("uid"));
801 if ($ldap->count() > 0){
802 $attrs= $ldap->fetch ();
803 return ($attrs["uid"][0]);
804 }
806 /* Add to list of alternates */
807 if (!in_array($address, $this->gosaMailAlternateAddress)){
808 $this->gosaMailAlternateAddress[]= $address;
809 $this->is_modified= TRUE;
810 }
812 sort ($this->gosaMailAlternateAddress);
813 reset ($this->gosaMailAlternateAddress);
815 return ("");
816 }
819 function delAlternate($addresses)
820 {
821 $this->gosaMailAlternateAddress= array_remove_entries ($addresses,
822 $this->gosaMailAlternateAddress);
823 $this->is_modified= TRUE;
824 }
826 function make_name($attrs)
827 {
828 $name= "";
829 if (isset($attrs['sn'][0])){
830 $name= $attrs['sn'][0];
831 }
832 if (isset($attrs['givenName'][0])){
833 if ($name != ""){
834 $name.= ", ".$attrs['givenName'][0];
835 } else {
836 $name.= $attrs['givenName'][0];
837 }
838 }
839 if ($name != ""){
840 $name.= " ";
841 }
843 return ($name);
844 }
846 }
848 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
849 ?>