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 /* Load templating engine */
178 $smarty= get_smarty();
179 $display= "";
181 $mailserver= array();
182 foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
183 $mailserver[]= $key;
184 }
186 /* Do we need to flip is_account state? */
187 if (isset($_POST['modify_state'])){
188 $this->is_account= !$this->is_account;
189 }
191 /* Show main page */
192 $mailserver= array();
193 foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
194 $mailserver[]= $key;
195 }
197 /* Do we represent a valid account? */
198 if (!$this->is_account && $this->parent == NULL){
199 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
200 _("This account has no mail extensions.")."</b>";
202 $display.= back_to_main();
203 return ($display);
204 }
206 /* Show tab dialog headers */
207 if ($this->parent != NULL){
208 if ($this->is_account){
209 $display= $this->show_header(_("Remove mail account"),
210 _("This account has mail features enabled. You can disable them by clicking below."));
211 } else {
212 $display= $this->show_header(_("Create mail account"), _("This account has mail features disabled. You can enable them by clicking below."));
213 return ($display);
214 }
215 }
217 /* Trigger forward add dialog? */
218 if (isset($_POST['add_local_forwarder'])){
219 $this->forward_dialog= TRUE;
220 $this->dialog= TRUE;
221 }
223 /* Cancel forward add dialog? */
224 if (isset($_POST['add_locals_cancel'])){
225 $this->forward_dialog= FALSE;
226 $this->dialog= FALSE;
227 }
229 /* Finished adding of locals? */
230 if (isset($_POST['add_locals_finish'])){
231 if (count ($_POST['local_list']) &&
232 chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
234 /* Walk through list of forwarders, ignore own addresses */
235 foreach ($_POST['local_list'] as $val){
236 if (!in_array ($val, $this->gosaMailAlternateAddress) &&
237 $val != $this->mail){
239 $this->addForwarder($val);
240 $this->is_modified= TRUE;
241 }
242 }
243 }
244 $this->forward_dialog= FALSE;
245 $this->dialog= FALSE;
246 }
248 /* Add forward email addresses */
249 if (isset($_POST['add_forwarder'])){
250 if ($_POST['forward_address'] != ""){
252 /* Valid email address specified? */
253 $address= $_POST['forward_address'];
254 $valid= FALSE;
255 if (!is_email($address)){
256 if (!is_email($address, TRUE)){
257 if ($this->is_template){
258 $valid= TRUE;
259 } else {
260 print_red (_("You're trying to add an invalid email address to the list of forwarders."));
261 }
262 }
263 } elseif ($address == $this->mail
264 || in_array($address, $this->gosaMailAlternateAddress)) {
266 print_red (_("Adding your one of your own addresses to the forwarders makes no sense."));
268 } else {
269 $valid= TRUE;
270 }
272 if ($valid){
273 /* Add it */
274 if (chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
275 $this->addForwarder ($address);
276 $this->is_modified= TRUE;
277 }
279 }
280 }
281 }
283 /* Delete forward email addresses */
284 if (isset($_POST['delete_forwarder'])){
285 if (count($_POST['forwarder_list'])
286 && chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
288 $this->delForwarder ($_POST['forwarder_list']);
289 }
290 }
292 /* Add alternate email addresses */
293 if (isset($_POST['add_alternate'])){
294 if ($_POST['alternate_address'] != "" &&
295 chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
297 $valid= FALSE;
298 if (!is_email($_POST['alternate_address'])){
299 if ($this->is_template){
300 if (!(is_email($_POST['alternate_address'], TRUE))){
301 print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
302 } else {
303 $valid= TRUE;
304 }
305 } else {
306 print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
307 }
309 } else {
310 $valid= TRUE;
311 }
313 if ($valid && ($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
314 $ui= get_userinfo();
315 if ($user != $ui->username){
316 print_red (_("The address you're trying to add is already used by user")." '$user'.");
317 }
318 }
319 }
320 }
322 /* Delete alternate email addresses */
323 if (isset($_POST['delete_alternate']) && isset ($_POST['alternates_list'])){
324 if (count($_POST['alternates_list']) &&
325 chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
327 $this->delAlternate ($_POST['alternates_list']);
328 }
329 }
331 /* Import vacation message? */
332 if (isset($_POST["import_vacation"]) && isset($this->vacation[$_POST["vacation_template"]])){
333 $contents= "";
334 $lines= file($_POST["vacation_template"]);
335 foreach ($lines as $line){
336 if (!preg_match('/^DESC:/', $line)){
337 $contents.= $line;
338 }
339 }
341 /* Replace attributes */
342 $attrs= $this->parent->by_object['user']->attributes;
343 foreach ($attrs as $val){
344 $contents= preg_replace("/%$val/",
345 $this->parent->by_object['user']->$val, $contents);
346 }
348 /* Save message */
349 $this->gosaVacationMessage= htmlspecialchars($contents);
350 }
352 /* Show forward add dialog */
353 if ($this->forward_dialog){
354 $ldap= $this->config->get_ldap_link();
356 /* Save data */
357 $mailfilter= get_global("mailfilter");
358 foreach( array("depselect", "muser", "regex") as $type){
359 if (isset($_POST[$type])){
360 $mailfilter[$type]= $_POST[$type];
361 }
362 }
363 if (isset($_GET['search'])){
364 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
365 if ($s == "**"){
366 $s= "*";
367 }
368 $mailfilter['regex']= $s;
369 }
370 register_global("mailfilter", $mailfilter);
372 /* Get actual list */
373 $mailusers= array ();
374 if ($mailfilter['regex'] != '*' && $mailfilter['regex'] != ""){
375 $regex= $mailfilter['regex'];
376 $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
377 } else {
378 $filter= "";
379 }
380 if ($mailfilter['muser'] != ""){
381 $user= $mailfilter['muser'];
382 $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
383 }
385 /* Add already present people to the filter */
386 $exclude= "";
387 foreach ($this->gosaMailForwardingAddress as $mail){
388 $exclude.= "(mail=$mail)";
389 }
390 if ($exclude != ""){
391 $filter.= "(!(|$exclude))";
392 }
394 $acl= array($this->config->current['BASE'] => ":all");
395 $res= get_list($acl, "(&(objectClass=gosaMailAccount)$filter)", TRUE, $mailfilter['depselect'], array("sn", "mail", "givenName"), TRUE);
396 $ldap->cd($mailfilter['depselect']);
397 $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
398 error_reporting (0);
399 while ($attrs= $ldap->fetch()){
400 if(preg_match('/%/', $attrs['mail'][0])){
401 continue;
402 }
403 $name= $this->make_name($attrs);
404 $mailusers[$attrs['mail'][0]]= $name."<".
405 $attrs['mail'][0].">";
406 }
407 error_reporting (E_ALL);
408 natcasesort ($mailusers);
409 reset ($mailusers);
411 /* Show dialog */
412 $smarty->assign("search_image", get_template_path('images/search.png'));
413 $smarty->assign("tree_image", get_template_path('images/tree.png'));
414 $smarty->assign("infoimage", get_template_path('images/info.png'));
415 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
416 $smarty->assign("mailusers", $mailusers);
417 if (isset($_POST['depselect'])){
418 $smarty->assign("depselect", $_POST['depselect']);
419 }
420 $smarty->assign("deplist", $this->config->idepartments);
421 $smarty->assign("apply", apply_filter());
422 $smarty->assign("alphabet", generate_alphabet());
423 $smarty->assign("hint", print_sizelimit_warning());
424 foreach( array("depselect", "muser", "regex") as $type){
425 $smarty->assign("$type", $mailfilter[$type]);
426 }
427 $smarty->assign("hint", print_sizelimit_warning());
429 $display.= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE, dirname(__FILE__)));
430 return ($display);
431 }
433 $smarty->assign("mailServers", $mailserver);
434 foreach(array("gosaMailServer", "gosaMailQuota", "perms", "mail",
435 "gosaMailAlternateAddress", "gosaMailForwardingAddress",
436 "gosaVacationMessage", "gosaMailDeliveryMode",
437 "gosaMailMaxSize", "gosaSpamSortLevel", "gosaSpamMailbox") as $val){
439 $smarty->assign("$val", $this->$val);
440 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
441 }
443 if (is_numeric($this->gosaMailQuota) && $this->gosaMailQuota != 0){
444 $smarty->assign("quotausage", progressbar(($this->quotaUsage * 100)/ $this->gosaMailQuota,100,15,true));
445 $smarty->assign("quotadefined", "true");
446 } else {
447 $smarty->assign("quotadefined", "false");
448 }
450 /* Disable mail field if needed */
451 $method= new $this->method($this->config);
452 if ($method->uattrib == "mail" && $this->initially_was_account){
453 $smarty->assign("mailACL", "disabled");
454 }
456 /* Fill checkboxes */
457 if (!preg_match("/L/", $this->gosaMailDeliveryMode)) {
458 $smarty->assign("drop_own_mails", "checked");
459 } else {
460 $smarty->assign("drop_own_mails", "");
461 }
462 if (preg_match("/V/", $this->gosaMailDeliveryMode)) {
463 $smarty->assign("use_vacation", "checked");
464 } else {
465 $smarty->assign("use_vacation", "");
466 }
467 if (preg_match("/S/", $this->gosaMailDeliveryMode)) {
468 $smarty->assign("use_spam_filter", "checked");
469 } else {
470 $smarty->assign("use_spam_filter", "");
471 }
472 if (preg_match("/R/", $this->gosaMailDeliveryMode)) {
473 $smarty->assign("use_mailsize_limit", "checked");
474 } else {
475 $smarty->assign("use_mailsize_limit", "");
476 }
477 if (preg_match("/I/", $this->gosaMailDeliveryMode)) {
478 $smarty->assign("only_local", "checked");
479 } else {
480 $smarty->assign("only_local", "");
481 }
482 if (preg_match("/C/", $this->gosaMailDeliveryMode)) {
483 $smarty->assign("own_script", "checked");
484 } else {
485 $smarty->assign("own_script", "");
486 }
488 /* Have vacation templates? */
489 $smarty->assign("template", "");
490 if (count($this->vacation)){
491 $smarty->assign("show_templates", "true");
492 $smarty->assign("vacationtemplates", $this->vacation);
493 if (isset($_POST['vacation_template'])){
494 $smarty->assign("template", $_POST['vacation_template']);
495 }
496 } else {
497 $smarty->assign("show_templates", "false");
498 }
500 /* Fill spam selector */
501 $spamlevel= array();
502 for ($i= 0; $i<21; $i++){
503 $spamlevel[]= $i;
504 }
505 $smarty->assign("spamlevel", $spamlevel);
506 $smarty->assign("spambox", $this->mailboxList);
507 $smarty->assign("custom_sieveACL", chkacl($this->acl, "custom_sieve"));
508 $smarty->assign("only_localACL", chkacl($this->acl, "only_local"));
510 $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
511 return ($display);
512 }
515 /* remove object from parent */
516 function remove_from_parent()
517 {
518 /* Cancel if there's nothing to do here */
519 if (!$this->initially_was_account){
520 return;
521 }
523 /* include global link_info */
524 $ldap= $this->config->get_ldap_link();
526 /* Remove and write to LDAP */
527 plugin::remove_from_parent();
529 /* Zero arrays */
530 $this->attrs['gosaMailAlternateAddress']= array();
531 $this->attrs['gosaMailForwardingAddress']= array();
533 /* Adapt attributes if needed */
534 $method= new $this->method($this->config);
535 $method->fixAttributesOnRemove($this);
537 /* Mailmethod wants us to remove the entry from LDAP. Keep uid! */
538 #fixme: || kolab || is differs here, you can't delete all attrs specified in this plugin ....
539 #fixme: there are some attributes we have to keep, i think.
540 unset ($this->attrs['uid']);
544 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
545 $this->attributes, "Save");
546 $ldap->cd($this->dn);
547 $ldap->modify($this->attrs);
548 show_ldap_error($ldap->get_error());
550 /* Connect to IMAP server for account deletion */
551 if ($this->gosaMailServer != ""){
552 $method= new $this->method($this->config);
553 $id= $method->uattrib;
554 if ($method->connect($this->gosaMailServer)){
556 /* Remove account from IMAP server */
557 $method->deleteMailbox($this->folder_prefix.$this->$id);
558 $method->disconnect();
559 }
560 }
562 /* Optionally execute a command after we're done */
563 $this->handle_post_events("remove");
564 }
567 /* Save data to object */
568 function save_object()
569 {
570 if (isset($_POST['mailTab'])){
571 /* Save ldap attributes */
572 plugin::save_object();
574 /* Assemble mail delivery mode
575 The mode field in ldap consists of values between braces, this must
576 be called when 'mail' is set, because checkboxes may not be set when
577 we're in some other dialog.
579 Example for gosaMailDeliveryMode [LR ]
580 L: Local delivery
581 R: Reject when exceeding mailsize limit
582 S: Use spam filter
583 V: Use vacation message
584 C: Use custm sieve script
585 I: Only insider delivery */
587 $tmp= "";
588 if (!isset($_POST["drop_own_mails"])){
589 $tmp.= "L";
590 }
591 if (isset($_POST["use_mailsize_limit"])){
592 $tmp.= "R";
593 }
594 if (isset($_POST["use_spam_filter"])){
595 $tmp.= "S";
596 }
597 if (isset($_POST["use_vacation"])){
598 $tmp.= "V";
599 }
600 if (isset($_POST["own_script"])){
601 $tmp.= "C";
602 }
603 if (isset($_POST["only_local"])){
604 $tmp.= "I";
605 }
606 $tmp= "[$tmp]";
608 if (chkacl ($this->acl, "gosaMailDeliveryMode") == ""){
609 if ($this->gosaMailDeliveryMode != $tmp){
610 $this->is_modified= TRUE;
611 }
612 $this->gosaMailDeliveryMode= $tmp;
613 }
614 }
615 }
618 /* Save data to LDAP, depending on is_account we save or delete */
619 function save()
620 {
621 $ldap= $this->config->get_ldap_link();
623 /* Call parents save to prepare $this->attrs */
624 plugin::save();
626 /* Save arrays */
627 $this->attrs['gosaMailAlternateAddress']= $this->gosaMailAlternateAddress;
628 $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
630 /* Adapt attributes if needed */
631 $method= new $this->method($this->config);
632 $id= $method->uattrib;
633 $method->fixAttributesOnStore($this);
635 if(empty($this->attrs['gosaSpamMailbox'])){
636 unset($this->attrs['gosaSpamMailbox']);
637 }
639 /* Save data to LDAP */
640 $ldap->cd($this->dn);
641 $ldap->modify($this->attrs);
642 show_ldap_error($ldap->get_error());
644 /* Only do IMAP actions if we are not a template */
645 if (!$this->is_template){
646 if ($method->connect($this->gosaMailServer)){
647 $method->updateMailbox($this->folder_prefix.$this->$id);
648 $method->setQuota($this->folder_prefix.$this->$id, $this->gosaMailQuota);
649 $method->disconnect();
651 /* Write sieve information only if not in C mode */
652 if (!is_integer(strpos($this->gosaMailDeliveryMode, "C"))){
653 $method->configureFilter($this->$id,
654 $this->gosaMailDeliveryMode,
655 $this->mail,
656 $this->gosaMailAlternateAddress,
657 $this->gosaMailMaxSize,
658 $this->gosaSpamMailbox,
659 $this->gosaSpamSortLevel,
660 $this->gosaVacationMessage);
661 }
662 }
663 }
665 /* Optionally execute a command after we're done */
666 if ($this->initially_was_account == $this->is_account){
667 if ($this->is_modified){
668 $this->handle_post_events("mofify");
669 }
670 } else {
671 $this->handle_post_events("add");
672 }
674 }
676 /* Check formular input */
677 function check()
678 {
679 $ldap= $this->config->get_ldap_link();
681 $message= array();
683 if(empty($this->gosaMailServer)){
684 $message[]= _("There is no valid mailserver specified, please add one in the system setup.");
685 }
687 /* must: mail */
688 if ($this->mail == ""){
689 $message[]= _("The required field 'Primary address' is not set.");
690 }
691 if ($this->is_template){
692 if (!is_email($this->mail, TRUE)){
693 $message[]= _("Please enter a valid email address in 'Primary address' field.");
694 }
695 } else {
696 if (!is_email($this->mail)){
697 $message[]= _("Please enter a valid email address in 'Primary address' field.");
698 }
699 }
700 $ldap->cd($this->config->current['BASE']);
701 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(|(mail=".$this->mail.")(gosaMailAlternateAddress=".
702 $this->mail."))(!(uid=".$this->uid."))(!(cn=".$this->uid.")))", array("uid"));
703 if ($ldap->count() != 0){
704 $message[]= _("The primary address you've entered is already in use.");
705 }
707 /* Check quota */
708 if ($this->gosaMailQuota != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
709 if (!is_numeric($this->gosaMailQuota)) {
710 $message[]= _("Value in 'Quota size' is not valid.");
711 } else {
712 $this->gosaMailQuota= (int) $this->gosaMailQuota;
713 }
714 }
716 /* Check rejectsize for integer */
717 if ($this->gosaMailMaxSize != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
718 if (!is_numeric($this->gosaMailMaxSize)){
719 $message[]= _("Please specify a vaild mail size for mails to be rejected.");
720 } else {
721 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
722 }
723 }
725 /* Need gosaMailMaxSize if use_mailsize_limit is checked */
726 if (is_integer(strpos($this->gosaMailDeliveryMode, "R")) &&
727 $this->gosaMailMaxSize == ""){
729 $message[]= _("You need to set the maximum mail size in order to reject anything.");
730 }
732 if((preg_match("/S/", $this->gosaMailDeliveryMode))&&(empty($this->gosaSpamMailbox))) {
733 $message[]= _("You specified Spam settings, but there is no Folder specified.");
734 }
736 return ($message);
737 }
739 /* Adapt from template, using 'dn' */
740 function adapt_from_template($dn)
741 {
742 plugin::adapt_from_template($dn);
744 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
745 $this->$val= array();
746 if (isset($this->attrs["$val"]["count"])){
747 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
748 $value= $this->attrs["$val"][$i];
749 foreach (array("sn", "givenName", "uid") as $repl){
750 if (preg_match("/%$repl/i", $value)){
751 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
752 }
753 }
754 array_push($this->$val, strtolower(rewrite($value)));
755 }
756 }
757 }
758 $this->mail= strtolower(rewrite($this->mail));
759 }
761 /* Add entry to forwarder list */
762 function addForwarder($address)
763 {
764 $this->gosaMailForwardingAddress[]= $address;
765 $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
767 sort ($this->gosaMailForwardingAddress);
768 reset ($this->gosaMailForwardingAddress);
769 $this->is_modified= TRUE;
770 }
772 /* Remove list of addresses from forwarder list */
773 function delForwarder($addresses)
774 {
775 $this->gosaMailForwardingAddress= array_remove_entries ($addresses, $this->gosaMailForwardingAddress);
776 $this->is_modified= TRUE;
777 }
781 function addAlternate($address)
782 {
783 $ldap= $this->config->get_ldap_link();
785 $address= strtolower($address);
787 /* Is this address already assigned in LDAP? */
788 $ldap->cd ($this->config->current['BASE']);
789 $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)".
790 "(gosaMailAlternateAddress=$address)))", array("uid"));
792 if ($ldap->count() > 0){
793 $attrs= $ldap->fetch ();
794 return ($attrs["uid"][0]);
795 }
797 /* Add to list of alternates */
798 if (!in_array($address, $this->gosaMailAlternateAddress)){
799 $this->gosaMailAlternateAddress[]= $address;
800 $this->is_modified= TRUE;
801 }
803 sort ($this->gosaMailAlternateAddress);
804 reset ($this->gosaMailAlternateAddress);
806 return ("");
807 }
810 function delAlternate($addresses)
811 {
812 $this->gosaMailAlternateAddress= array_remove_entries ($addresses,
813 $this->gosaMailAlternateAddress);
814 $this->is_modified= TRUE;
815 }
817 function make_name($attrs)
818 {
819 $name= "";
820 if (isset($attrs['sn'][0])){
821 $name= $attrs['sn'][0];
822 }
823 if (isset($attrs['givenName'][0])){
824 if ($name != ""){
825 $name.= ", ".$attrs['givenName'][0];
826 } else {
827 $name.= $attrs['givenName'][0];
828 }
829 }
830 if ($name != ""){
831 $name.= " ";
832 }
834 return ($name);
835 }
837 }
839 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
840 ?>