85a800ef64e50160f0bee73386992a7bc081c546
1 <?php
3 class mailgroup extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary= "Manage mail groups/shared folders";
7 var $cli_description= "Some longer text\nfor help";
8 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9 var $method= "mailMethod";
11 /* plugin specific values */
12 var $mail= "";
13 var $uid= "";
14 var $cn= "";
15 var $gosaMailAlternateAddress= array();
16 var $gosaMailForwardingAddress= array();
17 var $gosaMailDeliveryMode= "[L ]";
18 var $gosaMailServer= "";
19 var $gosaMailQuota= "";
20 var $gosaMailMaxSize= "";
21 var $gosaVacationMessage= "";
22 var $gosaSpamSortLevel= "";
23 var $gosaSpamMailbox= "";
25 var $quotaUsage= 0;
26 var $forward_dialog= FALSE;
27 var $members= array();
28 var $mailusers= array();
29 var $perms= array();
30 var $imapacl= array('anyone' => 'p', '%members%' => 'lrsp', '' => 'p');
32 /* Helper */
33 var $indexed_acl= array();
34 var $indexed_user= array();
36 /* attribute list for save action */
37 var $attributes= array("mail", "gosaMailServer", "gosaMailQuota", "gosaMailMaxSize",
38 "gosaMailDeliveryMode", "gosaSpamSortLevel", "gosaSpamMailbox",
39 "gosaVacationMessage");
40 var $objectclasses= array("gosaMailAccount");
43 /* constructor, if 'dn' is set, the node loads the given
44 'dn' from LDAP */
45 function mailgroup ($config, $dn= NULL, $ui= NULL)
46 {
47 /* Configuration is fine, allways */
48 $this->config= $config;
50 /* Load bases attributes */
51 plugin::plugin($config, $dn);
53 /* Set mailMethod to the one defined in gosa.conf */
54 if (isset($this->config->current['MAILMETHOD'])){
55 $method= $this->config->current['MAILMETHOD'];
56 if (class_exists("mailMethod$method")){
57 $this->method= "mailMethod$method";
58 } else {
59 print_red(sprintf(_("There is no mail method '%s' specified in your gosa.conf available."), $method));
60 }
61 }
63 /* Convert cn to uid in case of existing entries */
64 if (isset($this->attrs['cn'][0])){
65 $this->uid= $this->attrs['cn'][0];
66 }
68 if ($dn != NULL){
70 /* Load attributes containing arrays */
71 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
72 if (isset($this->attrs["$val"]["count"])){
73 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
74 array_push($this->$val, $this->attrs["$val"][$i]);
75 }
76 }
77 }
79 /* Only do IMAP actions if gosaMailServer attribute is set */
80 if (isset ($this->attrs["gosaMailServer"][0])){
81 $method= new $this->method($this->config);
82 if ($method->connect($this->attrs["gosaMailServer"][0])){
83 $quota= $method->getQuota($this->uid);
85 /* Maybe the entry is not saved in new style, get
86 permissions from IMAP and convert them to acl attributes */
87 if (!isset($this->attrs['acl'])){
88 $this->imapacl= $method->getSharedFolderPermissions($this->uid);
90 /* Need to filter what a member acl could be... */
91 $vote= array();
92 $peak= 0;
93 $leader= "";
94 foreach ($this->imapacl as $user => $acl){
96 if ($user != "anyone" ){
97 if (!isset($vote[$acl])){
98 $vote[$acl]= 1;
99 } else {
100 $vote[$acl]++;
101 }
102 if ($vote[$acl] > $peak){
103 $leader= $acl;
104 $peek= $vote[$acl];
105 }
106 }
108 }
110 /* Highest count wins as %members%, remove all members
111 with the same acl */
112 $this->imapacl['%members%']= $leader;
113 foreach ($this->imapacl as $user => $acl){
114 if ($this->acl == $leader && in_array($user, $this->attrs['memberUid'])){
115 unset($this->imapacl[$user]);
116 }
117 }
119 }
122 /* Update quota values */
123 if ($quota['gosaMailQuota'] == 2147483647){
124 $this->quotaUsage= "";
125 $this->gosaMailQuota= "";
126 } else {
127 $this->quotaUsage= $quota['quotaUsage'];
128 $this->gosaMailQuota= $quota['gosaMailQuota'];
129 }
130 $method->disconnect();
131 }
133 /* Adapt attributes if needed */
134 $method->fixAttributesOnLoad($this);
135 }
136 }
138 /* Get global filter config */
139 if (!is_global("gmailfilter")){
140 $ui= get_userinfo();
141 $base= get_base_from_people($ui->dn);
142 $gmailfilter= array( "depselect" => $base,
143 "muser" => "",
144 "regex" => "*");
145 register_global("gmailfilter", $gmailfilter);
146 }
148 /* Load permissions */
149 if(preg_match("/kolab/i",$this->config->current['MAILMETHOD'])){
152 /* In case of kolab, we save the permissions in this style
154 mailaddressfromuser rights
156 But we need the userID, so we search for a user, with this mail address.
157 */
158 $ldap = $this->config->get_ldap_link();
159 if (isset($this->attrs['acl'])){
160 for ($i= 0; $i<$this->attrs['acl']['count']; $i++){
161 list($user, $permission)= split(' ', $this->attrs['acl'][$i]);
163 /* Skip entry anyone and %members %*/
164 if ($user != "anyone" && $user != "%members%"){
165 $mail = $ldap->search("(&(objectClass=person)(|(mail=".$user.")(uid=".$user.")))",array("uid"));
166 $mail = $ldap->fetch();
167 if(isset($mail['uid'][0])){
168 $user = $mail['uid'][0];
169 }
170 }
172 /* Add to list */
173 $this->imapacl[$user]= $permission;
175 #fixme What is that ?
176 if ($user != "anyone" && $user != "%members%"){
177 unset($this->imapacl['']);
178 }
179 }
180 }
181 }else{
182 if (isset($this->attrs['acl'])){
183 for ($i= 0; $i<$this->attrs['acl']['count']; $i++){
184 list($user, $permission)= split(' ', $this->attrs['acl'][$i]);
185 $this->imapacl[$user]= $permission;
186 if ($user != "anyone" && $user != "%members%"){
187 unset($this->imapacl['']);
188 }
189 }
190 }
191 }
193 /* Fill translations */
194 $this->perms["lrs"]= _("read");
195 $this->perms["lrsp"]= _("post");
196 $this->perms["p"]= _("external post");
197 $this->perms["lrsip"]= _("append");
198 $this->perms["lrswipcd"]= _("write");
199 }
202 function execute()
203 {
204 /* Call parent execute */
205 plugin::execute();
207 /* Load templating engine */
208 $smarty= get_smarty();
209 if ($_SESSION['js']==FALSE){
210 $smarty->assign("javascript", "false");
211 } else {
212 $smarty->assign("javascript", "true");
213 }
215 /* Do we need to flip is_account state? */
216 if (isset($_POST['modify_state'])){
217 $this->is_account= !$this->is_account;
218 }
220 /* Do we represent a valid account? */
221 if (!$this->is_account && $this->parent == NULL){
222 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
223 _("This 'dn' has no valid mail extensions.")."</b>";
224 return ($display);
225 }
227 /* Show tab dialog headers */
228 $display= "";
229 if ($this->parent != NULL){
230 if ($this->is_account){
231 $display= $this->show_header(_("Remove mail account"),
232 _("This account has mail features enabled. You can disable them by clicking below."));
233 } else {
234 $display= $this->show_header(_("Create mail account"),
235 _("This account has mail features disabled. You can enable them by clicking below."));
236 return ($display);
237 }
238 }
240 /* Add ACL? */
241 foreach ($this->indexed_user as $nr => $user){
242 if (isset($_POST["add_$nr"])){
243 $this->imapacl[""]= "l";
244 }
245 if (isset($_POST["del_$nr"])){
246 unset ($this->imapacl[$user]);
247 }
248 }
250 /* Trigger forward add dialog? */
251 if (isset($_POST['add_local_forwarder'])){
252 $this->forward_dialog= TRUE;
253 $this->dialog= TRUE;
254 }
256 /* Cancel forward add dialog? */
257 if (isset($_POST['add_locals_cancel'])){
258 $this->forward_dialog= FALSE;
259 $this->dialog= FALSE;
260 }
262 /* Finished adding of locals? */
263 if (isset($_POST['add_locals_finish'])){
264 if (count ($_POST['local_list']) &&
265 chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
267 /* Walk through list of forwarders, ignore own addresses */
268 foreach ($_POST['local_list'] as $val){
269 if (!in_array ($val, $this->gosaMailAlternateAddress) &&
270 $val != $this->mail){
272 $this->addForwarder($val);
273 }
274 }
275 }
276 $this->forward_dialog= FALSE;
277 $this->dialog= FALSE;
278 }
280 /* Add forward email addresses */
281 if (isset($_POST['add_forwarder'])){
282 if ($_POST['forward_address'] != ""){
284 /* Valid email address specified? */
285 $address= $_POST['forward_address'];
286 if (!is_email($address)){
288 print_red (_("You're trying to add an invalid email address ".
289 "to the list of forwarders."));
291 } elseif ($address == $this->mail
292 || in_array($address, $this->gosaMailAlternateAddress)) {
294 print_red (_("Adding your one of your own addresses to the forwarders makes no sense."));
296 } else {
298 /* Add it */
299 if (chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
300 $this->addForwarder ($address);
301 }
303 }
304 }
305 }
307 /* Delete forward email addresses */
308 if (isset($_POST['delete_forwarder'])){
309 if (count($_POST['forwarder_list'])
310 && chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
312 $this->delForwarder ($_POST['forwarder_list']);
313 }
314 }
316 /* Add alternate email addresses */
317 if (isset($_POST['add_alternate'])){
318 if ($_POST['alternate_address'] != "" &&
319 chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
321 if (!is_email($_POST['alternate_address'])){
322 print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
324 } elseif (($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
325 $ui= get_userinfo();
326 if ($user != $ui->username){
327 print_red (_("The address you're trying to add is already used by user")." '$user'.");
328 }
329 }
330 }
331 }
333 /* Delete alternate email addresses */
334 if (isset($_POST['delete_alternate']) && isset ($_POST['alternates_list'])){
335 if (count($_POST['alternates_list']) &&
336 chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
338 $this->delAlternate ($_POST['alternates_list']);
339 }
340 }
342 /* Show forward add dialog */
343 if ($this->forward_dialog){
344 $ldap= $this->config->get_ldap_link();
346 /* Save data */
347 $gmailfilter= get_global("gmailfilter");
348 foreach( array("depselect", "muser", "regex") as $type){
349 if (isset($_POST[$type])){
350 $gmailfilter[$type]= $_POST[$type];
351 }
352 }
353 if (isset($_GET['search'])){
354 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
355 if ($s == "**"){
356 $s= "*";
357 }
358 $gmailfilter['regex']= $s;
359 }
360 register_global("gmailfilter", $gmailfilter);
362 /* Get actual list */
363 $mailusers= array ();
364 if ($gmailfilter['regex'] != '*' && $gmailfilter['regex'] != ""){
365 $regex= $gmailfilter['regex'];
366 $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
367 } else {
368 $filter= "";
369 }
370 if ($gmailfilter['muser'] != ""){
371 $user= $gmailfilter['muser'];
372 $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
373 }
375 /* Add already present people to the filter */
376 $exclude= "";
377 foreach ($this->gosaMailForwardingAddress as $mail){
378 $exclude.= "(mail=$mail)";
379 }
380 if ($exclude != ""){
381 $filter.= "(!(|$exclude))";
382 }
384 $acl= array($this->config->current['BASE'] => ":all");
385 $res= get_list($acl, "(&(objectClass=gosaMailAccount)$filter)", TRUE, $gmailfilter['depselect'], array("sn", "mail", "givenName"), TRUE);
386 $ldap->cd($gmailfilter['depselect']);
387 $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
388 error_reporting (0);
389 while ($attrs= $ldap->fetch()){
390 if(preg_match('/%/', $attrs['mail'][0])){
391 continue;
392 }
393 $name= $this->make_name($attrs);
394 $mailusers[$attrs['mail'][0]]= $name."<".
395 $attrs['mail'][0].">";
396 }
397 error_reporting (E_ALL);
398 natcasesort ($mailusers);
399 reset ($mailusers);
401 /* Show dialog */
402 $smarty->assign("search_image", get_template_path('images/search.png'));
403 $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
404 $smarty->assign("tree_image", get_template_path('images/tree.png'));
405 $smarty->assign("infoimage", get_template_path('images/info.png'));
406 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
407 $smarty->assign("mailusers", $mailusers);
408 $smarty->assign("deplist", $this->config->idepartments);
409 $smarty->assign("apply", apply_filter());
410 $smarty->assign("alphabet", generate_alphabet());
411 $smarty->assign("hint", print_sizelimit_warning());
412 foreach( array("depselect", "muser", "regex") as $type){
413 $smarty->assign("$type", $gmailfilter[$type]);
414 }
415 $smarty->assign("hint", print_sizelimit_warning());
416 $display.= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE));
417 return ($display);
418 }
420 /* Assemble normal permissions */
421 $smarty->assign("permissionsACL", chkacl($this->acl, "permissions"));
422 if (isset($this->imapacl['anyone'])){
423 $smarty->assign("default_permissions", $this->imapacl['anyone']);
424 }
425 if (isset($this->imapacl['%members%'])){
426 $smarty->assign("member_permissions", $this->imapacl['%members%']);
427 }
429 /* Assemble extra attributes */
430 $perm= chkacl($this->acl, "permissions");
431 $tmp= "";
432 $nr= 0;
433 $count= count($this->imapacl);
434 $this->indexed_user= array();
435 $this->indexed_acl= array();
436 foreach($this->imapacl as $user => $acl){
437 if ($user != "anyone" && $user != "%members%"){
438 $tmp.= "<tr><td><input name=\"user_$nr\" size=20 maxlength=60 ".
439 "value=\"$user\" $perm></td><td><select size=\"1\" name=\"perm_$nr\" $perm>";
440 foreach ($this->perms as $key => $value){
441 if ($acl == $key){
442 $tmp.= "<option value=$key selected>$value</option>";
443 } else {
444 $tmp.= "<option value=$key>$value</option>";
445 }
446 }
447 $tmp.= "</select> ";
448 if ($nr == $count - 1){
449 $tmp.= "<input type=submit value=\""._("Add")."\" ".
450 "name=\"add_$nr\" $perm>";
451 }
452 if ($count > 3){
453 $tmp.= "<input type=submit value=\""._("Remove")."\" ".
454 "name=\"del_$nr\" $perm></td></tr>";
455 }
456 }
457 $this->indexed_user[$nr]= $user;
458 $this->indexed_acl[$nr++]= $acl;
459 }
460 $smarty->assign("plusattributes", $tmp);
462 /* Show main page */
463 $mailserver= array();
464 foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
465 $mailserver[]= $key;
466 }
467 $smarty->assign("mailServers", $mailserver);
468 foreach(array("gosaMailServer", "gosaMailQuota", "perms", "mail",
469 "gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
470 $smarty->assign("$val", $this->$val);
471 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
472 }
473 if (is_numeric($this->gosaMailQuota) && $this->gosaMailQuota != 0){
474 $smarty->assign("quotausage", progressbar(round(($this->quotaUsage * 100)/ $this->gosaMailQuota),100,15,true));
475 $smarty->assign("quotadefined", "true");
476 } else {
477 $smarty->assign("quotadefined", "false");
478 }
480 $display.= $smarty->fetch (get_template_path('mail.tpl', TRUE));
481 return ($display);
482 }
485 /* remove object from parent */
486 function remove_from_parent()
487 {
488 /* include global link_info */
489 $ldap= $this->config->get_ldap_link();
491 /* Remove and write to LDAP */
492 plugin::remove_from_parent();
494 /* Zero arrays */
495 $this->attrs['gosaMailAlternateAddress']= array();
496 $this->attrs['gosaMailForwardingAddress']= array();
497 $this->attrs['gosaSharedFolderTarget']= array();
499 /* Keep uid */
500 unset ($this->attrs['uid']);
501 $ldap->cd($this->dn);
502 $ldap->modify($this->attrs);
503 show_ldap_error($ldap->get_error());
505 /* Connect to IMAP server for account deletion */
506 if ($this->is_account){
507 $method= new $this->method($this->config);
508 if ($method->connect($this->attrs["gosaMailServer"][0])){
509 /* Remove account from IMAP server */
510 $method->deleteMailbox($this->uid);
511 $method->disconnect();
512 }
513 $method->fixAttributesOnRemove($this);
514 }
516 /* Optionally execute a command after we're done */
517 $this->handle_post_events("remove");
518 }
521 /* Save data to object */
522 function save_object()
523 {
524 /* Assemble mail delivery mode
525 The mode field in ldap consists of values between braces, this must
526 be called when 'mail' is set, because checkboxes may not be set when
527 we're in some other dialog.
529 Example for gosaMailDeliveryMode [LR ]
530 L: Local delivery
531 R: Reject when exceeding mailsize limit
532 S: Use spam filter
533 V: Use vacation message
534 C: Use custom sieve script
535 I: Only insider delivery */
536 if (isset($_POST['mailedit'])){
538 /* Save ldap attributes */
539 plugin::save_object();
541 $tmp= "";
542 if (!isset($_POST["drop_own_mails"])){
543 $tmp.= "L";
544 }
545 if (isset($_POST["use_mailsize_limit"])){
546 $tmp.= "R";
547 }
548 if (isset($_POST["use_spam_filter"])){
549 $tmp.= "S";
550 }
551 if (isset($_POST["use_vacation"])){
552 $tmp.= "V";
553 }
554 if (isset($_POST["own_script"])){
555 $tmp.= "C";
556 }
557 if (isset($_POST["only_local"])){
558 $tmp.= "I";
559 }
560 $tmp= "[$tmp]";
562 if (chkacl ($this->acl, "gosaMailDeliveryMode") == ""){
563 $this->gosaMailDeliveryMode= $tmp;
564 }
566 /* Collect data and re-assign it to the imapacl array */
567 if (chkacl($this->acl, "permissions") == ""){
568 $this->imapacl= array();
569 $this->imapacl['%members%']= $_POST['member_permissions'];
570 $this->imapacl['anyone']= $_POST['default_permissions'];
571 foreach ($this->indexed_user as $nr => $user){
572 if (!isset($_POST["user_$nr"])){
573 continue;
574 }
575 if ($_POST["user_$nr"] != $user ||
576 $_POST["perm_$nr"] != $this->indexed_acl[$nr]){
577 $this->is_modified= TRUE;
578 }
579 $this->imapacl[$_POST["user_$nr"]]= $_POST["perm_$nr"];
580 }
581 }
582 }
584 }
587 /* Save data to LDAP, depending on is_account we save or delete */
588 function save()
589 {
590 $ldap= $this->config->get_ldap_link();
592 /* Call parents save to prepare $this->attrs */
593 plugin::save();
595 /* Save arrays */
596 $this->attrs['gosaMailAlternateAddress']= $this->gosaMailAlternateAddress;
597 $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
599 /* Save shared folder target */
600 $this->attrs['gosaSharedFolderTarget']= "share+".$this->uid;
602 if(preg_match("/kolab/i",$this->config->current['MAILMETHOD'])){
603 /* Save acl's */
604 $this->attrs['acl']= array();
605 foreach ($this->imapacl as $user => $acl){
606 if ($user == ""){
607 continue;
608 }
609 $ldap->search("(&(objectClass=person)(uid=".$user."))",array("mail"));
610 $mail = $ldap->fetch();
611 if($mail){
612 if(isset($mail['mail'][0])){
613 $this->attrs['acl'][]= $mail['mail'][0]." $acl";
614 }
615 }else{
616 $this->attrs['acl'][]= "$user $acl";
617 }
618 }
619 }else{
620 /* Save acl's */
621 $this->attrs['acl']= array();
622 foreach ($this->imapacl as $user => $acl){
623 if ($user == ""){
624 continue;
625 }
626 $this->attrs['acl'][]= "$user $acl";
627 }
628 }
629 /* Save data to LDAP */
630 $ldap->cd($this->dn);
631 $ldap->modify($this->attrs);
632 show_ldap_error($ldap->get_error());
633 /* Only do IMAP actions if we are not a template */
634 if (!$this->is_template){
635 $method= new $this->method($this->config);
636 $method->fixAttributesOnStore($this);
637 if ($method->connect($this->gosaMailServer)){
638 $method->updateMailbox($this->uid);
639 $method->setQuota($this->uid, $this->gosaMailQuota);
641 /* Exchange '%member%' pseudo entry */
642 $memberacl= $this->imapacl['%members%'];
643 unset ($this->imapacl['%members%']);
644 foreach ($this->members as $user){
645 if (!isset($this->imapacl[$user])){
646 $this->imapacl[$user]= $memberacl;
647 }
648 }
650 $method->setSharedFolderPermissions($this->uid, $this->imapacl);
651 $method->disconnect();
652 }
653 }
655 /* Optionally execute a command after we're done */
656 if ($this->initially_was_account == $this->is_account){
657 if ($this->is_modified){
658 $this->handle_post_events("mofify");
659 }
660 } else {
661 $this->handle_post_events("add");
662 }
663 }
665 /* Check formular input */
666 function check()
667 {
668 $ldap= $this->config->get_ldap_link();
670 $message= array();
672 /* must: mail */
673 if ($this->mail == ""){
674 $message[]= _("The required field 'Primary address' is not set.");
675 }
676 if (!is_email($this->mail)){
677 $message[]= _("Please enter a valid email addres in 'Primary address' field.");
678 }
679 $ldap->cd($this->config->current['BASE']);
680 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=".$this->mail.")(gosaMailAlternateAddress=".$this->mail."))(!(uid=".$this->cn."))(!(cn=".$this->cn.")))",array("uid"));
681 if ($ldap->count() != 0){
682 $message[]= _("The primary address you've entered is already in use.");
683 }
685 /* Check quota */
686 if ($this->gosaMailQuota != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
687 if (!is_numeric($this->gosaMailQuota)) {
688 $message[]= _("Value in 'Quota size' is not valid.");
689 } else {
690 $this->gosaMailQuota= (int) $this->gosaMailQuota;
691 }
692 }
694 /* Check rejectsize for integer */
695 if ($this->gosaMailMaxSize != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
696 if (!is_numeric($this->gosaMailMaxSize)){
697 $message[]= _("Please specify a vaild mail size for mails to be rejected.");
698 } else {
699 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
700 }
701 }
703 /* Need gosaMailMaxSize if use_mailsize_limit is checked */
704 if (is_integer(strpos($this->gosaMailDeliveryMode, "reject")) && $this->gosaMailMaxSize == ""){
705 $message[]= _("You need to set the maximum mail size in order to reject anything.");
706 }
708 if(ord($this->imapacl['anyone'][0])==194){
709 $message[] = _("Please choose valid permission settings. Default permission can't be emtpy.");
710 }
712 if(empty($this->gosaMailServer)){
713 $message[] = _("Please select a valid mail server.");
714 }
716 return ($message);
717 }
719 /* Adapt from template, using 'dn' */
720 function adapt_from_template($dn)
721 {
722 plugin::adapt_from_template($dn);
724 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
725 $this->$val= array();
726 if (isset($this->attrs["$val"]["count"])){
727 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
728 $value= $this->attrs["$val"][$i];
729 foreach (array("sn", "givenName", "uid") as $repl){
730 if (preg_match("/%$repl/i", $value)){
731 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
732 }
733 }
734 array_push($this->$val, $value);
735 }
736 }
737 }
738 }
740 /* Add entry to forwarder list */
741 function addForwarder($address)
742 {
743 $this->gosaMailForwardingAddress[]= $address;
744 $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
746 sort ($this->gosaMailForwardingAddress);
747 reset ($this->gosaMailForwardingAddress);
748 $this->is_modified= TRUE;
749 }
751 /* Remove list of addresses from forwarder list */
752 function delForwarder($addresses)
753 {
754 $this->gosaMailForwardingAddress= array_remove_entries ($addresses,
755 $this->gosaMailForwardingAddress);
756 $this->is_modified= TRUE;
757 }
761 function addAlternate($address)
762 {
763 $ldap= $this->config->get_ldap_link();
765 $address= strtolower($address);
767 /* Is this address already assigned in LDAP? */
768 $ldap->cd ($this->config->current['BASE']);
769 $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)"."(gosaMailAlternateAddress=$address)))",array("uid"));
771 if ($ldap->count() > 0){
772 $attrs= $ldap->fetch ();
773 return ($attrs["uid"][0]);
774 }
776 /* Add to list of alternates */
777 if (!in_array($address, $this->gosaMailAlternateAddress)){
778 $this->gosaMailAlternateAddress[]= $address;
779 }
781 sort ($this->gosaMailAlternateAddress);
782 reset ($this->gosaMailAlternateAddress);
783 $this->is_modified= TRUE;
785 return ("");
786 }
789 function delAlternate($addresses)
790 {
791 $this->gosaMailAlternateAddress= array_remove_entries ($addresses,
792 $this->gosaMailAlternateAddress);
793 $this->is_modified= TRUE;
794 }
797 function make_name($attrs)
798 {
799 $name= "";
800 if (isset($attrs['sn'][0])){
801 $name= $attrs['sn'][0];
802 }
803 if (isset($attrs['givenName'][0])){
804 if ($name != ""){
805 $name.= ", ".$attrs['givenName'][0];
806 } else {
807 $name.= $attrs['givenName'][0];
808 }
809 }
810 if ($name != ""){
811 $name.= " ";
812 }
814 return ($name);
815 }
817 }
819 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
820 ?>