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