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 $this->cleanup();
547 $ldap->modify ($this->attrs);
549 show_ldap_error($ldap->get_error());
551 /* Connect to IMAP server for account deletion */
552 if ($this->is_account){
553 $method= new $this->method($this->config);
554 if ($method->connect($this->attrs["gosaMailServer"][0])){
555 /* Remove account from IMAP server */
556 $method->deleteMailbox($this->uid);
557 $method->disconnect();
558 }
559 $method->fixAttributesOnRemove($this);
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 /* Assemble mail delivery mode
571 The mode field in ldap consists of values between braces, this must
572 be called when 'mail' is set, because checkboxes may not be set when
573 we're in some other dialog.
575 Example for gosaMailDeliveryMode [LR ]
576 L: Local delivery
577 R: Reject when exceeding mailsize limit
578 S: Use spam filter
579 V: Use vacation message
580 C: Use custom sieve script
581 I: Only insider delivery */
582 if (isset($_POST['mailedit'])){
584 /* Save ldap attributes */
585 plugin::save_object();
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 $this->gosaMailDeliveryMode= $tmp;
610 }
612 /* Collect data and re-assign it to the imapacl array */
613 if (chkacl($this->acl, "permissions") == ""){
614 $this->imapacl= array();
615 $this->imapacl['%members%']= $_POST['member_permissions'];
616 $this->imapacl['anyone']= $_POST['default_permissions'];
617 foreach ($this->indexed_user as $nr => $user){
618 if (!isset($_POST["user_$nr"])){
619 continue;
620 }
621 if ($_POST["user_$nr"] != $user ||
622 $_POST["perm_$nr"] != $this->indexed_acl[$nr]){
623 $this->is_modified= TRUE;
624 }
625 $this->imapacl[$_POST["user_$nr"]]= $_POST["perm_$nr"];
626 }
627 }
628 }
630 }
633 /*
634 Backup for function save
635 Änderungen : fixAttributesOnStore($this) wurde erst nach dem this->cleanup();
636 $ldap->modify
638 Ausgeführt, deshalb wurden die gemappten Attribute auch nicht
639 gespeichert.
641 Von : Fabian Hickert
642 Datum : 15.12.2005
644 Alter Quellcode :
646 /* Save data to LDAP, depending on is_account we save or delete * /
647 function save()
648 {
649 $ldap= $this->config->get_ldap_link();
651 /* Call parents save to prepare $this->attrs * /
652 plugin::save();
654 /* Save arrays * /
655 $this->attrs['gosaMailAlternateAddress']= $this->gosaMailAlternateAddress;
656 $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
658 /* Save shared folder target * /
659 $this->attrs['gosaSharedFolderTarget']= "share+".$this->uid;
661 /* Save acl's * /
662 $this->attrs['acl']= array();
663 foreach ($this->imapacl as $user => $acl){
664 if ($user == ""){
665 continue;
666 }
667 $this->attrs['acl'][]= "$user $acl";
668 }
670 /* Save data to LDAP * /
671 $ldap->cd($this->dn);
672 $this->cleanup();
673 $ldap->modify ($this->attrs);
675 show_ldap_error($ldap->get_error());
677 /* Only do IMAP actions if we are not a template * /
678 if (!$this->is_template){
679 $method= new $this->method($this->config);
680 $method->fixAttributesOnStore($this);
681 if ($method->connect($this->gosaMailServer)){
682 $method->updateMailbox($this->uid);
683 $method->setQuota($this->uid, $this->gosaMailQuota);
685 /* Exchange '%member%' pseudo entry * /
686 $memberacl= $this->imapacl['%members%'];
687 unset ($this->imapacl['%members%']);
688 foreach ($this->members as $user){
689 if (!isset($this->imapacl[$user])){
690 $this->imapacl[$user]= $memberacl;
691 }
692 }
694 $method->setSharedFolderPermissions($this->uid, $this->imapacl);
695 $method->disconnect();
696 }
697 }
699 /* Optionally execute a command after we're done * /
700 if ($this->initially_was_account == $this->is_account){
701 if ($this->is_modified){
702 $this->handle_post_events("mofify");
703 }
704 } else {
705 $this->handle_post_events("add");
706 }
707 }
709 ENDE Alter Quellcode
710 */
719 /* Save data to LDAP, depending on is_account we save or delete */
720 function save()
721 {
722 $ldap= $this->config->get_ldap_link();
724 /* Call parents save to prepare $this->attrs */
725 plugin::save();
727 /* Save arrays */
728 $this->attrs['gosaMailAlternateAddress']= $this->gosaMailAlternateAddress;
729 $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
731 /* Save shared folder target */
732 $this->attrs['gosaSharedFolderTarget']= "share+".$this->uid;
734 if(preg_match("/kolab/i",$this->mmethod)){
735 /* Save acl's */
736 $this->attrs['acl']= array();
737 foreach ($this->imapacl as $user => $acl){
738 if ($user == ""){
739 continue;
740 }
741 $ldap->search("(&(objectClass=person)(uid=".$user."))",array("mail"));
742 $mail = $ldap->fetch();
743 if($mail){
744 if(isset($mail['mail'][0])){
745 $this->attrs['acl'][]= $mail['mail'][0]." $acl";
746 }
747 }else{
748 $this->attrs['acl'][]= "$user $acl";
749 }
750 }
751 }else{
752 /* Save acl's */
753 $this->attrs['acl']= array();
754 foreach ($this->imapacl as $user => $acl){
755 if ($user == ""){
756 continue;
757 }
758 $this->attrs['acl'][]= "$user $acl";
759 }
760 }
762 /* Only do IMAP actions if we are not a template */
763 if(preg_match("/kolab/i",$this->mmethod)){
764 if (empty($this->gosaMailServer)||is_array($this->gosaMailServer)){
765 if(isset($this->attrs['gosaMailServer'][0])){
766 $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
767 }
768 }
769 }
771 if ((!$this->is_template)&&(!empty($this->gosaMailServer))){
772 $method= new $this->method($this->config);
773 $method->fixAttributesOnStore($this);
774 if ($method->connect($this->gosaMailServer)){
775 $method->updateMailbox($this->uid);
776 $method->setQuota($this->uid, $this->gosaMailQuota);
778 /* Exchange '%member%' pseudo entry */
779 $memberacl= $this->imapacl['%members%'];
780 unset ($this->imapacl['%members%']);
781 foreach ($this->members as $user){
782 if (!isset($this->imapacl[$user])){
783 $this->imapacl[$user]= $memberacl;
784 }
785 }
787 $method->setSharedFolderPermissions($this->uid, $this->imapacl);
788 $method->disconnect();
789 }
790 }
792 /* Save data to LDAP */
793 $ldap->cd($this->dn);
794 $this->cleanup();
795 $ldap->modify ($this->attrs);
797 show_ldap_error($ldap->get_error());
799 /* Optionally execute a command after we're done */
800 if ($this->initially_was_account == $this->is_account){
801 if ($this->is_modified){
802 $this->handle_post_events("mofify");
803 }
804 } else {
805 $this->handle_post_events("add");
806 }
807 }
809 /* Check formular input */
810 function check()
811 {
812 $ldap= $this->config->get_ldap_link();
814 $message= array();
816 /* must: mail */
817 if ($this->mail == ""){
818 $message[]= _("The required field 'Primary address' is not set.");
819 }
820 if (!is_email($this->mail)){
821 $message[]= _("Please enter a valid email addres in 'Primary address' field.");
822 }
823 $ldap->cd($this->config->current['BASE']);
824 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=".$this->mail.")(gosaMailAlternateAddress=".
825 $this->mail."))(!(uid=".$this->cn."))(!(cn=".$this->cn.")))");
826 if ($ldap->count() != 0){
827 $message[]= _("The primary address you've entered is already in use.");
828 }
830 /* Check quota */
831 if ($this->gosaMailQuota != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
832 if (!is_numeric($this->gosaMailQuota)) {
833 $message[]= _("Value in 'Quota size' is not valid.");
834 } else {
835 $this->gosaMailQuota= (int) $this->gosaMailQuota;
836 }
837 }
839 /* Check rejectsize for integer */
840 if ($this->gosaMailMaxSize != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
841 if (!is_numeric($this->gosaMailMaxSize)){
842 $message[]= _("Please specify a vaild mail size for mails to be rejected.");
843 } else {
844 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
845 }
846 }
848 /* Need gosaMailMaxSize if use_mailsize_limit is checked */
849 if (is_integer(strpos($this->gosaMailDeliveryMode, "reject")) && $this->gosaMailMaxSize == ""){
850 $message[]= _("You need to set the maximum mail size in order to reject anything.");
851 }
853 if(ord($this->imapacl['anyone'][0])==194){
854 $message[] = _("Please choose valid permission settings. Default permission can't be emtpy.");
855 }
857 if(empty($this->gosaMailServer)){
858 $message[] = _("Please select a valid mail server.");
859 }
861 return ($message);
862 }
864 /* Adapt from template, using 'dn' */
865 function adapt_from_template($dn)
866 {
867 plugin::adapt_from_template($dn);
869 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
870 $this->$val= array();
871 if (isset($this->attrs["$val"]["count"])){
872 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
873 $value= $this->attrs["$val"][$i];
874 foreach (array("sn", "givenName", "uid") as $repl){
875 if (preg_match("/%$repl/i", $value)){
876 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
877 }
878 }
879 array_push($this->$val, $value);
880 }
881 }
882 }
883 }
885 /* Add entry to forwarder list */
886 function addForwarder($address)
887 {
888 $this->gosaMailForwardingAddress[]= $address;
889 $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
891 sort ($this->gosaMailForwardingAddress);
892 reset ($this->gosaMailForwardingAddress);
893 $this->is_modified= TRUE;
894 }
896 /* Remove list of addresses from forwarder list */
897 function delForwarder($addresses)
898 {
899 $this->gosaMailForwardingAddress= array_remove_entries ($addresses,
900 $this->gosaMailForwardingAddress);
901 $this->is_modified= TRUE;
902 }
906 function addAlternate($address)
907 {
908 $ldap= $this->config->get_ldap_link();
910 $address= strtolower($address);
912 /* Is this address already assigned in LDAP? */
913 $ldap->cd ($this->config->current['BASE']);
914 $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)".
915 "(gosaMailAlternateAddress=$address)))");
917 if ($ldap->count() > 0){
918 $attrs= $ldap->fetch ();
919 return ($attrs["uid"][0]);
920 }
922 /* Add to list of alternates */
923 if (!in_array($address, $this->gosaMailAlternateAddress)){
924 $this->gosaMailAlternateAddress[]= $address;
925 }
927 sort ($this->gosaMailAlternateAddress);
928 reset ($this->gosaMailAlternateAddress);
929 $this->is_modified= TRUE;
931 return ("");
932 }
935 function delAlternate($addresses)
936 {
937 $this->gosaMailAlternateAddress= array_remove_entries ($addresses,
938 $this->gosaMailAlternateAddress);
939 $this->is_modified= TRUE;
940 }
943 function make_name($attrs)
944 {
945 $name= "";
946 if (isset($attrs['sn'][0])){
947 $name= $attrs['sn'][0];
948 }
949 if (isset($attrs['givenName'][0])){
950 if ($name != ""){
951 $name.= ", ".$attrs['givenName'][0];
952 } else {
953 $name.= $attrs['givenName'][0];
954 }
955 }
956 if ($name != ""){
957 $name.= " ";
958 }
960 return ($name);
961 }
963 }
965 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
966 ?>