f759f74357bf8fa70cff38a486f9090bb86df315
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');
31 var $mmethod= "";
33 /* Helper */
34 var $indexed_acl= array();
35 var $indexed_user= array();
37 /* attribute list for save action */
38 var $attributes= array("mail", "gosaMailServer", "gosaMailQuota", "gosaMailMaxSize",
39 "gosaMailDeliveryMode", "gosaSpamSortLevel", "gosaSpamMailbox",
40 "gosaVacationMessage");
41 var $objectclasses= array("gosaMailAccount");
44 /* constructor, if 'dn' is set, the node loads the given
45 'dn' from LDAP */
46 function mailgroup ($config, $dn= NULL, $ui= NULL)
47 {
48 /* Configuration is fine, allways */
49 $this->config= $config;
51 /* Load bases attributes */
52 plugin::plugin($config, $dn);
54 /* Set mailMethod to the one defined in gosa.conf */
55 if (isset($this->config->current['MAILMETHOD'])){
56 $this->mmethod= $this->config->current['MAILMETHOD'];
57 }
59 if (class_exists("mailMethod$this->mmethod")){
60 $this->method= "mailMethod$this->mmethod";
61 } else {
62 print_red(sprintf(_("There is no mail method '%s' specified in your gosa.conf available."), $this->mmethod));
63 }
65 /* Load Mailserver string, only in case of kolab ???? */
66 if(preg_match("/kolab/i",$this->mmethod)){
67 if(isset($this->attrs['gosaMailServer'][0])){
68 $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
69 }
70 }
72 /* Convert cn to uid in case of existing entries */
73 if (isset($this->attrs['cn'][0])){
74 $this->uid= $this->attrs['cn'][0];
75 }
77 if ($dn != NULL){
79 /* Load attributes containing arrays */
80 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
81 if (isset($this->attrs["$val"]["count"])){
82 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
83 array_push($this->$val, $this->attrs["$val"][$i]);
84 }
85 }
86 }
88 /* Only do IMAP actions if gosaMailServer attribute is set */
89 if (isset ($this->attrs["gosaMailServer"][0])){
90 $method= new $this->method($this->config);
91 if ($method->connect($this->attrs["gosaMailServer"][0])){
92 $quota= $method->getQuota($this->uid);
94 /* Maybe the entry is not saved in new style, get
95 permissions from IMAP and convert them to acl attributes */
96 if (!isset($this->attrs['acl'])){
97 $this->imapacl= $method->getSharedFolderPermissions($this->uid);
99 /* Need to filter what a member acl could be... */
100 $vote= array();
101 $peak= 0;
102 $leader= "";
103 foreach ($this->imapacl as $user => $acl){
105 if ($user != "anyone" ){
106 if (!isset($vote[$acl])){
107 $vote[$acl]= 1;
108 } else {
109 $vote[$acl]++;
110 }
111 if ($vote[$acl] > $peak){
112 $leader= $acl;
113 $peek= $vote[$acl];
114 }
115 }
117 }
119 /* Highest count wins as %members%, remove all members
120 with the same acl */
121 $this->imapacl['%members%']= $leader;
122 foreach ($this->imapacl as $user => $acl){
123 if ($this->acl == $leader && in_array($user, $this->attrs['memberUid'])){
124 unset($this->imapacl[$user]);
125 }
126 }
128 }
130 /* Update quota values */
131 if ($quota['gosaMailQuota'] == 2147483647){
132 $this->quotaUsage= "";
133 $this->gosaMailQuota= "";
134 } else {
135 $this->quotaUsage= $quota['quotaUsage'];
136 $this->gosaMailQuota= $quota['gosaMailQuota'];
137 }
138 $method->disconnect();
139 }
141 /* Adapt attributes if needed */
142 $method->fixAttributesOnLoad($this);
143 }
144 }
146 /* Get global filter config */
147 if (!is_global("gmailfilter")){
148 $ui= get_userinfo();
149 $base= get_base_from_people($ui->dn);
150 $gmailfilter= array( "depselect" => $base,
151 "muser" => "",
152 "regex" => "*");
153 register_global("gmailfilter", $gmailfilter);
154 }
156 /* Load permissions */
157 $tmp = array();
158 if(preg_match("/kolab/i",$this->mmethod)){
159 $ldap = $this->config->get_ldap_link();
160 if (isset($this->attrs['acl'])){
161 for ($i= 0; $i<$this->attrs['acl']['count']; $i++){
162 list($user, $permission)= split(' ', $this->attrs['acl'][$i]);
164 /* Add to list */
165 $this->imapacl[$user]= $permission;
167 /* Get all user permissions sorted by acl, to detect the most used acl
168 This acl is then used for %members%
169 */
170 $tmp[$permission][] = $user;
172 /* There is an entry in $this->imapacl like this this ...
173 $this->attrs['imapacl']['anyone'] = "p";
174 $this->attrs['imapacl']['%members%'] = "lprs";
175 $this->attrs['imapacl'][''] = ""; <------ This is used to diplay an empty
176 Field for special acls in our template.
177 If there is at least one special acl in out imapacl,
178 we don't need this entry anymore, because it is already displayed.
179 */
180 if ($user != "anyone" && $user != "%members%"){
181 unset($this->imapacl['']);
182 }
183 }
184 }
186 /* In this section we dectect which acl is tho most used
187 This will be used as %members% acl
188 */
189 $tmp2 = array();
190 foreach($tmp as $acl => $user){
191 $tmp2[count($tmp[$acl])]=$acl;
192 }
193 /* Most used at last */
194 ksort($tmp2);
196 /* Assign last (most used acl) to %members% acl */
197 $this->imapacl['%members%']=array_pop($tmp2);
199 /* Open ldap connection */
200 $ldap = $this->config->get_ldap_link();
201 $ldap->cd($this->config->current['BASE']);
203 /* Remove those users, that use %members% acl && are member of this group. */
204 foreach($this->imapacl as $mail => $permission){
205 $ldap->search("(&(objectClass=person)(mail=".$mail."))",array("uid"));
206 $atr = $ldap->fetch();
207 if((isset($atr['uid'][0]))&&(in_array($atr['uid'][0],$this->attrs['memberUid']))&&($permission == $this->imapacl['%members%'])){
208 unset($this->imapacl[$mail]);
209 }
210 }
212 /* Append an empty entry, for special acl handling */
213 if(count($this->imapacl)==2){
214 $this->imapacl[''] ="";
215 }
216 }else{
217 /* Load permissions */
218 if (isset($this->attrs['acl'])){
219 for ($i= 0; $i<$this->attrs['acl']['count']; $i++){
220 list($user, $permission)= split(' ', $this->attrs['acl'][$i]);
221 $this->imapacl[$user]= $permission;
222 if ($user != "anyone" && $user != "%members%"){
223 unset($this->imapacl['']);
224 }
225 }
226 }
227 }
228 /* Fill translations */
229 $this->perms["lrs"]= _("read");
230 $this->perms["lrsp"]= _("post");
231 $this->perms["p"]= _("external post");
232 $this->perms["lrsip"]= _("append");
233 $this->perms["lrswipcd"]= _("write");
234 }
237 function execute()
238 {
239 /* Call parent execute */
240 //plugin::execute();
242 /* Load templating engine */
243 $smarty= get_smarty();
244 if ($_SESSION['js']==FALSE){
245 $smarty->assign("javascript", "false");
246 } else {
247 $smarty->assign("javascript", "true");
248 }
250 /* Do we need to flip is_account state? */
251 if (isset($_POST['modify_state'])){
252 $this->is_account= !$this->is_account;
253 }
255 /* Do we represent a valid account? */
256 if (!$this->is_account && $this->parent == NULL){
257 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
258 _("This 'dn' has no valid mail extensions.")."</b>";
259 return ($display);
260 }
262 /* Show tab dialog headers */
263 $display= "";
264 if ($this->parent != NULL){
265 if ($this->is_account){
266 $display= $this->show_header(_("Remove mail account"),
267 _("This account has mail features enabled. You can disable them by clicking below."));
268 } else {
269 $display= $this->show_header(_("Create mail account"),
270 _("This account has mail features disabled. You can enable them by clicking below."));
271 return ($display);
272 }
273 }
275 /* Add ACL? */
276 foreach ($this->indexed_user as $nr => $user){
277 if (isset($_POST["add_$nr"])){
278 $this->imapacl[""]= "l";
279 }
280 if (isset($_POST["del_$nr"])){
281 unset ($this->imapacl[$user]);
282 }
283 }
285 /* Trigger forward add dialog? */
286 if (isset($_POST['add_local_forwarder'])){
287 $this->forward_dialog= TRUE;
288 $this->dialog= TRUE;
289 }
291 /* Cancel forward add dialog? */
292 if (isset($_POST['add_locals_cancel'])){
293 $this->forward_dialog= FALSE;
294 $this->dialog= FALSE;
295 }
297 /* Finished adding of locals? */
298 if (isset($_POST['add_locals_finish'])){
299 if (count ($_POST['local_list']) &&
300 chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
302 /* Walk through list of forwarders, ignore own addresses */
303 foreach ($_POST['local_list'] as $val){
304 if (!in_array ($val, $this->gosaMailAlternateAddress) &&
305 $val != $this->mail){
307 $this->addForwarder($val);
308 }
309 }
310 }
311 $this->forward_dialog= FALSE;
312 $this->dialog= FALSE;
313 }
315 /* Add forward email addresses */
316 if (isset($_POST['add_forwarder'])){
317 if ($_POST['forward_address'] != ""){
319 /* Valid email address specified? */
320 $address= $_POST['forward_address'];
321 if (!is_email($address)){
323 print_red (_("You're trying to add an invalid email address ".
324 "to the list of forwarders."));
326 } elseif ($address == $this->mail
327 || in_array($address, $this->gosaMailAlternateAddress)) {
329 print_red (_("Adding your one of your own addresses to the forwarders makes no sense."));
331 } else {
333 /* Add it */
334 if (chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
335 $this->addForwarder ($address);
336 }
338 }
339 }
340 }
342 /* Delete forward email addresses */
343 if (isset($_POST['delete_forwarder'])){
344 if (count($_POST['forwarder_list'])
345 && chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
347 $this->delForwarder ($_POST['forwarder_list']);
348 }
349 }
351 /* Add alternate email addresses */
352 if (isset($_POST['add_alternate'])){
353 if ($_POST['alternate_address'] != "" &&
354 chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
356 if (!is_email($_POST['alternate_address'])){
357 print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
359 } elseif (($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
360 $ui= get_userinfo();
361 if ($user != $ui->username){
362 print_red (_("The address you're trying to add is already used by user")." '$user'.");
363 }
364 }
365 }
366 }
368 /* Delete alternate email addresses */
369 if (isset($_POST['delete_alternate']) && isset ($_POST['alternates_list'])){
370 if (count($_POST['alternates_list']) &&
371 chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
373 $this->delAlternate ($_POST['alternates_list']);
374 }
375 }
377 /* Show forward add dialog */
378 if ($this->forward_dialog){
379 $ldap= $this->config->get_ldap_link();
381 /* Save data */
382 $gmailfilter= get_global("gmailfilter");
383 foreach( array("depselect", "muser", "regex") as $type){
384 if (isset($_POST[$type])){
385 $gmailfilter[$type]= $_POST[$type];
386 }
387 }
388 if (isset($_GET['search'])){
389 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
390 if ($s == "**"){
391 $s= "*";
392 }
393 $gmailfilter['regex']= $s;
394 }
395 register_global("gmailfilter", $gmailfilter);
397 /* Get actual list */
398 $mailusers= array ();
399 if ($gmailfilter['regex'] != '*' && $gmailfilter['regex'] != ""){
400 $regex= $gmailfilter['regex'];
401 $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
402 } else {
403 $filter= "";
404 }
405 if ($gmailfilter['muser'] != ""){
406 $user= $gmailfilter['muser'];
407 $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
408 }
410 /* Add already present people to the filter */
411 $exclude= "";
412 foreach ($this->gosaMailForwardingAddress as $mail){
413 $exclude.= "(mail=$mail)";
414 }
415 if ($exclude != ""){
416 $filter.= "(!(|$exclude))";
417 }
419 $acl= array($this->config->current['BASE'] => ":all");
420 $res= get_list($acl, "(&(objectClass=gosaMailAccount)$filter)", TRUE, $gmailfilter['depselect'], array("sn", "mail", "givenName"), TRUE);
421 $ldap->cd($gmailfilter['depselect']);
422 $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
423 error_reporting (0);
424 while ($attrs= $ldap->fetch()){
425 if(preg_match('/%/', $attrs['mail'][0])){
426 continue;
427 }
428 $name= $this->make_name($attrs);
429 $mailusers[$attrs['mail'][0]]= $name."<".
430 $attrs['mail'][0].">";
431 }
432 error_reporting (E_ALL);
433 natcasesort ($mailusers);
434 reset ($mailusers);
436 /* Show dialog */
437 $smarty->assign("search_image", get_template_path('images/search.png'));
438 $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
439 $smarty->assign("tree_image", get_template_path('images/tree.png'));
440 $smarty->assign("infoimage", get_template_path('images/info.png'));
441 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
442 $smarty->assign("mailusers", $mailusers);
443 $smarty->assign("deplist", $this->config->idepartments);
444 $smarty->assign("apply", apply_filter());
445 $smarty->assign("alphabet", generate_alphabet());
446 $smarty->assign("hint", print_sizelimit_warning());
447 foreach( array("depselect", "muser", "regex") as $type){
448 $smarty->assign("$type", $gmailfilter[$type]);
449 }
450 $smarty->assign("hint", print_sizelimit_warning());
451 $display.= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE));
452 return ($display);
453 }
455 /* Assemble normal permissions */
456 $smarty->assign("permissionsACL", chkacl($this->acl, "permissions"));
457 if (isset($this->imapacl['anyone'])){
458 $smarty->assign("default_permissions", $this->imapacl['anyone']);
459 }
460 $smarty->assign("member_permissions", "lrsp");
461 if (isset($this->imapacl['%members%'])){
462 $smarty->assign("member_permissions", $this->imapacl['%members%']);
463 }
465 /* Assemble extra attributes */
466 $perm= chkacl($this->acl, "permissions");
467 $tmp= "";
468 $nr= 0;
469 $count= count($this->imapacl);
470 $this->indexed_user= array();
471 $this->indexed_acl= array();
472 foreach($this->imapacl as $user => $acl){
473 if ($user != "anyone" && $user != "%members%"){
474 $tmp.= "<tr><td><input name=\"user_$nr\" size=20 maxlength=60 ".
475 "value=\"$user\" $perm></td><td><select size=\"1\" name=\"perm_$nr\" $perm>";
476 foreach ($this->perms as $key => $value){
477 if ($acl == $key){
478 $tmp.= "<option value=$key selected>$value</option>";
479 } else {
480 $tmp.= "<option value=$key>$value</option>";
481 }
482 }
483 $tmp.= "</select> ";
484 if ($nr == $count - 1){
485 $tmp.= "<input type=submit value=\""._("Add")."\" ".
486 "name=\"add_$nr\" $perm>";
487 }
488 if ($count > 3){
489 $tmp.= "<input type=submit value=\""._("Remove")."\" ".
490 "name=\"del_$nr\" $perm></td></tr>";
491 }
492 }
493 $this->indexed_user[$nr]= $user;
494 $this->indexed_acl[$nr++]= $acl;
495 }
496 $smarty->assign("plusattributes", $tmp);
498 /* Show main page */
499 $mailserver= array();
500 foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
501 $mailserver[]= $key;
502 }
503 $smarty->assign("mailServers", $mailserver);
504 foreach(array("gosaMailServer", "gosaMailQuota", "perms", "mail",
505 "gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
506 $smarty->assign("$val", $this->$val);
507 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
508 }
509 if (is_numeric($this->gosaMailQuota) && $this->gosaMailQuota != 0){
510 $smarty->assign("quotausage", progressbar(round(($this->quotaUsage * 100)/ $this->gosaMailQuota,100,15,true)));
511 $smarty->assign("quotadefined", "true");
512 } else {
513 $smarty->assign("quotadefined", "false");
514 }
516 $display.= $smarty->fetch (get_template_path('mail.tpl', TRUE));
517 return ($display);
518 }
521 /* remove object from parent */
522 function remove_from_parent()
523 {
524 /* Added these ObjectClass and Attributes, because they were not
525 removed correctly, only in case of kolab ...
526 */
527 if(preg_match("/kolab/i",$this->config->current['MAILMETHOD'])){
528 $this->attributes[]="acl";
529 $this->attributes[]="kolabHomeServer";
530 $this->objectclasses[] = "kolabSharedFolder";
531 }
532 /* include global link_info */
533 $ldap= $this->config->get_ldap_link();
535 /* Remove and write to LDAP */
536 plugin::remove_from_parent();
538 /* Zero arrays */
539 $this->attrs['gosaMailAlternateAddress']= array();
540 $this->attrs['gosaMailForwardingAddress']= array();
541 $this->attrs['gosaSharedFolderTarget']= array();
543 /* Keep uid */
544 unset ($this->attrs['uid']);
545 $ldap->cd($this->dn);
546 $ldap->modify($this->attrs);
547 show_ldap_error($ldap->get_error());
549 /* Connect to IMAP server for account deletion */
550 if ($this->is_account){
551 $method= new $this->method($this->config);
552 if ($method->connect($this->attrs["gosaMailServer"][0])){
553 /* Remove account from IMAP server */
554 $method->deleteMailbox($this->uid);
555 $method->disconnect();
556 }
557 $method->fixAttributesOnRemove($this);
558 }
560 /* Optionally execute a command after we're done */
561 $this->handle_post_events("remove");
562 }
565 /* Save data to object */
566 function save_object()
567 {
568 /* Assemble mail delivery mode
569 The mode field in ldap consists of values between braces, this must
570 be called when 'mail' is set, because checkboxes may not be set when
571 we're in some other dialog.
573 Example for gosaMailDeliveryMode [LR ]
574 L: Local delivery
575 R: Reject when exceeding mailsize limit
576 S: Use spam filter
577 V: Use vacation message
578 C: Use custom sieve script
579 I: Only insider delivery */
580 if (isset($_POST['mailedit'])){
582 /* Save ldap attributes */
583 plugin::save_object();
585 $tmp= "";
586 if (!isset($_POST["drop_own_mails"])){
587 $tmp.= "L";
588 }
589 if (isset($_POST["use_mailsize_limit"])){
590 $tmp.= "R";
591 }
592 if (isset($_POST["use_spam_filter"])){
593 $tmp.= "S";
594 }
595 if (isset($_POST["use_vacation"])){
596 $tmp.= "V";
597 }
598 if (isset($_POST["own_script"])){
599 $tmp.= "C";
600 }
601 if (isset($_POST["only_local"])){
602 $tmp.= "I";
603 }
604 $tmp= "[$tmp]";
606 if (chkacl ($this->acl, "gosaMailDeliveryMode") == ""){
607 $this->gosaMailDeliveryMode= $tmp;
608 }
610 /* Collect data and re-assign it to the imapacl array */
611 if (chkacl($this->acl, "permissions") == ""){
612 $this->imapacl= array();
613 $this->imapacl['%members%']= $_POST['member_permissions'];
614 $this->imapacl['anyone']= $_POST['default_permissions'];
615 foreach ($this->indexed_user as $nr => $user){
616 if (!isset($_POST["user_$nr"])){
617 continue;
618 }
619 if ($_POST["user_$nr"] != $user ||
620 $_POST["perm_$nr"] != $this->indexed_acl[$nr]){
621 $this->is_modified= TRUE;
622 }
623 $this->imapacl[$_POST["user_$nr"]]= $_POST["perm_$nr"];
624 }
625 }
626 }
628 }
631 /*
632 Backup for function save
633 Änderungen : fixAttributesOnStore($this) wurde erst nach dem ldap->modify
634 Ausgeführt, deshalb wurden die gemappten Attribute auch nicht
635 gespeichert.
637 Von : Fabian Hickert
638 Datum : 15.12.2005
640 Alter Quellcode :
642 /* Save data to LDAP, depending on is_account we save or delete * /
643 function save()
644 {
645 $ldap= $this->config->get_ldap_link();
647 /* Call parents save to prepare $this->attrs * /
648 plugin::save();
650 /* Save arrays * /
651 $this->attrs['gosaMailAlternateAddress']= $this->gosaMailAlternateAddress;
652 $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
654 /* Save shared folder target * /
655 $this->attrs['gosaSharedFolderTarget']= "share+".$this->uid;
657 /* Save acl's * /
658 $this->attrs['acl']= array();
659 foreach ($this->imapacl as $user => $acl){
660 if ($user == ""){
661 continue;
662 }
663 $this->attrs['acl'][]= "$user $acl";
664 }
666 /* Save data to LDAP * /
667 $ldap->cd($this->dn);
668 $ldap->modify($this->attrs);
669 show_ldap_error($ldap->get_error());
671 /* Only do IMAP actions if we are not a template * /
672 if (!$this->is_template){
673 $method= new $this->method($this->config);
674 $method->fixAttributesOnStore($this);
675 if ($method->connect($this->gosaMailServer)){
676 $method->updateMailbox($this->uid);
677 $method->setQuota($this->uid, $this->gosaMailQuota);
679 /* Exchange '%member%' pseudo entry * /
680 $memberacl= $this->imapacl['%members%'];
681 unset ($this->imapacl['%members%']);
682 foreach ($this->members as $user){
683 if (!isset($this->imapacl[$user])){
684 $this->imapacl[$user]= $memberacl;
685 }
686 }
688 $method->setSharedFolderPermissions($this->uid, $this->imapacl);
689 $method->disconnect();
690 }
691 }
693 /* Optionally execute a command after we're done * /
694 if ($this->initially_was_account == $this->is_account){
695 if ($this->is_modified){
696 $this->handle_post_events("mofify");
697 }
698 } else {
699 $this->handle_post_events("add");
700 }
701 }
703 ENDE Alter Quellcode
704 */
713 /* Save data to LDAP, depending on is_account we save or delete */
714 function save()
715 {
716 $ldap= $this->config->get_ldap_link();
718 /* Call parents save to prepare $this->attrs */
719 plugin::save();
721 /* Save arrays */
722 $this->attrs['gosaMailAlternateAddress']= $this->gosaMailAlternateAddress;
723 $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
725 /* Save shared folder target */
726 $this->attrs['gosaSharedFolderTarget']= "share+".$this->uid;
728 if(preg_match("/kolab/i",$this->mmethod)){
729 /* Save acl's */
730 $this->attrs['acl']= array();
731 foreach ($this->imapacl as $user => $acl){
732 if ($user == ""){
733 continue;
734 }
735 $ldap->search("(&(objectClass=person)(uid=".$user."))",array("mail"));
736 $mail = $ldap->fetch();
737 if($mail){
738 if(isset($mail['mail'][0])){
739 $this->attrs['acl'][]= $mail['mail'][0]." $acl";
740 }
741 }else{
742 $this->attrs['acl'][]= "$user $acl";
743 }
744 }
745 }else{
746 /* Save acl's */
747 $this->attrs['acl']= array();
748 foreach ($this->imapacl as $user => $acl){
749 if ($user == ""){
750 continue;
751 }
752 $this->attrs['acl'][]= "$user $acl";
753 }
754 }
756 /* Only do IMAP actions if we are not a template */
757 if(preg_match("/kolab/i",$this->mmethod)){
758 if (empty($this->gosaMailServer)||is_array($this->gosaMailServer)){
759 if(isset($this->attrs['gosaMailServer'][0])){
760 $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
761 }
762 }
763 }
765 if ((!$this->is_template)&&(!empty($this->gosaMailServer))){
766 $method= new $this->method($this->config);
767 $method->fixAttributesOnStore($this);
768 if ($method->connect($this->gosaMailServer)){
769 $method->updateMailbox($this->uid);
770 $method->setQuota($this->uid, $this->gosaMailQuota);
772 /* Exchange '%member%' pseudo entry */
773 $memberacl= $this->imapacl['%members%'];
774 unset ($this->imapacl['%members%']);
775 foreach ($this->members as $user){
776 if (!isset($this->imapacl[$user])){
777 $this->imapacl[$user]= $memberacl;
778 }
779 }
781 $method->setSharedFolderPermissions($this->uid, $this->imapacl);
782 $method->disconnect();
783 }
784 }
786 /* Save data to LDAP */
787 $ldap->cd($this->dn);
788 $ldap->modify($this->attrs);
789 show_ldap_error($ldap->get_error());
791 /* Optionally execute a command after we're done */
792 if ($this->initially_was_account == $this->is_account){
793 if ($this->is_modified){
794 $this->handle_post_events("mofify");
795 }
796 } else {
797 $this->handle_post_events("add");
798 }
799 }
801 /* Check formular input */
802 function check()
803 {
804 $ldap= $this->config->get_ldap_link();
806 $message= array();
808 /* must: mail */
809 if ($this->mail == ""){
810 $message[]= _("The required field 'Primary address' is not set.");
811 }
812 if (!is_email($this->mail)){
813 $message[]= _("Please enter a valid email addres in 'Primary address' field.");
814 }
815 $ldap->cd($this->config->current['BASE']);
816 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=".$this->mail.")(gosaMailAlternateAddress=".
817 $this->mail."))(!(uid=".$this->cn."))(!(cn=".$this->cn.")))");
818 if ($ldap->count() != 0){
819 $message[]= _("The primary address you've entered is already in use.");
820 }
822 /* Check quota */
823 if ($this->gosaMailQuota != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
824 if (!is_numeric($this->gosaMailQuota)) {
825 $message[]= _("Value in 'Quota size' is not valid.");
826 } else {
827 $this->gosaMailQuota= (int) $this->gosaMailQuota;
828 }
829 }
831 /* Check rejectsize for integer */
832 if ($this->gosaMailMaxSize != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
833 if (!is_numeric($this->gosaMailMaxSize)){
834 $message[]= _("Please specify a vaild mail size for mails to be rejected.");
835 } else {
836 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
837 }
838 }
840 /* Need gosaMailMaxSize if use_mailsize_limit is checked */
841 if (is_integer(strpos($this->gosaMailDeliveryMode, "reject")) && $this->gosaMailMaxSize == ""){
842 $message[]= _("You need to set the maximum mail size in order to reject anything.");
843 }
845 if(ord($this->imapacl['anyone'][0])==194){
846 $message[] = _("Please choose valid permission settings. Default permission can't be emtpy.");
847 }
849 if(empty($this->gosaMailServer)){
850 $message[] = _("Please select a valid mail server.");
851 }
853 return ($message);
854 }
856 /* Adapt from template, using 'dn' */
857 function adapt_from_template($dn)
858 {
859 plugin::adapt_from_template($dn);
861 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
862 $this->$val= array();
863 if (isset($this->attrs["$val"]["count"])){
864 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
865 $value= $this->attrs["$val"][$i];
866 foreach (array("sn", "givenName", "uid") as $repl){
867 if (preg_match("/%$repl/i", $value)){
868 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
869 }
870 }
871 array_push($this->$val, $value);
872 }
873 }
874 }
875 }
877 /* Add entry to forwarder list */
878 function addForwarder($address)
879 {
880 $this->gosaMailForwardingAddress[]= $address;
881 $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
883 sort ($this->gosaMailForwardingAddress);
884 reset ($this->gosaMailForwardingAddress);
885 $this->is_modified= TRUE;
886 }
888 /* Remove list of addresses from forwarder list */
889 function delForwarder($addresses)
890 {
891 $this->gosaMailForwardingAddress= array_remove_entries ($addresses,
892 $this->gosaMailForwardingAddress);
893 $this->is_modified= TRUE;
894 }
898 function addAlternate($address)
899 {
900 $ldap= $this->config->get_ldap_link();
902 $address= strtolower($address);
904 /* Is this address already assigned in LDAP? */
905 $ldap->cd ($this->config->current['BASE']);
906 $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)".
907 "(gosaMailAlternateAddress=$address)))");
909 if ($ldap->count() > 0){
910 $attrs= $ldap->fetch ();
911 return ($attrs["uid"][0]);
912 }
914 /* Add to list of alternates */
915 if (!in_array($address, $this->gosaMailAlternateAddress)){
916 $this->gosaMailAlternateAddress[]= $address;
917 }
919 sort ($this->gosaMailAlternateAddress);
920 reset ($this->gosaMailAlternateAddress);
921 $this->is_modified= TRUE;
923 return ("");
924 }
927 function delAlternate($addresses)
928 {
929 $this->gosaMailAlternateAddress= array_remove_entries ($addresses,
930 $this->gosaMailAlternateAddress);
931 $this->is_modified= TRUE;
932 }
935 function make_name($attrs)
936 {
937 $name= "";
938 if (isset($attrs['sn'][0])){
939 $name= $attrs['sn'][0];
940 }
941 if (isset($attrs['givenName'][0])){
942 if ($name != ""){
943 $name.= ", ".$attrs['givenName'][0];
944 } else {
945 $name.= $attrs['givenName'][0];
946 }
947 }
948 if ($name != ""){
949 $name.= " ";
950 }
952 return ($name);
953 }
955 }
957 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
958 ?>