5492f76edb072dc7a4bb5f69b64eea171424f453
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 if (isset($this->imapacl['%members%'])){
459 $smarty->assign("member_permissions", $this->imapacl['%members%']);
460 }
462 /* Assemble extra attributes */
463 $perm= chkacl($this->acl, "permissions");
464 $tmp= "";
465 $nr= 0;
466 $count= count($this->imapacl);
467 $this->indexed_user= array();
468 $this->indexed_acl= array();
469 foreach($this->imapacl as $user => $acl){
470 if ($user != "anyone" && $user != "%members%"){
471 $tmp.= "<tr><td><input name=\"user_$nr\" size=20 maxlength=60 ".
472 "value=\"$user\" $perm></td><td><select size=\"1\" name=\"perm_$nr\" $perm>";
473 foreach ($this->perms as $key => $value){
474 if ($acl == $key){
475 $tmp.= "<option value=$key selected>$value</option>";
476 } else {
477 $tmp.= "<option value=$key>$value</option>";
478 }
479 }
480 $tmp.= "</select> ";
481 if ($nr == $count - 1){
482 $tmp.= "<input type=submit value=\""._("Add")."\" ".
483 "name=\"add_$nr\" $perm>";
484 }
485 if ($count > 3){
486 $tmp.= "<input type=submit value=\""._("Remove")."\" ".
487 "name=\"del_$nr\" $perm></td></tr>";
488 }
489 }
490 $this->indexed_user[$nr]= $user;
491 $this->indexed_acl[$nr++]= $acl;
492 }
493 $smarty->assign("plusattributes", $tmp);
495 /* Show main page */
496 $mailserver= array();
497 foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
498 $mailserver[]= $key;
499 }
500 $smarty->assign("mailServers", $mailserver);
501 foreach(array("gosaMailServer", "gosaMailQuota", "perms", "mail",
502 "gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
503 $smarty->assign("$val", $this->$val);
504 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
505 }
506 if (is_numeric($this->gosaMailQuota) && $this->gosaMailQuota != 0){
507 $smarty->assign("quotausage", progressbar(round(($this->quotaUsage * 100)/ $this->gosaMailQuota,100,15,true)));
508 $smarty->assign("quotadefined", "true");
509 } else {
510 $smarty->assign("quotadefined", "false");
511 }
513 $display.= $smarty->fetch (get_template_path('mail.tpl', TRUE));
514 return ($display);
515 }
518 /* remove object from parent */
519 function remove_from_parent()
520 {
521 /* Added these ObjectClass and Attributes, because they were not
522 removed correctly, only in case of kolab ...
523 */
524 if(preg_match("/kolab/i",$this->config->current['MAILMETHOD'])){
525 $this->attributes[]="acl";
526 $this->attributes[]="kolabHomeServer";
527 $this->objectclasses[] = "kolabSharedFolder";
528 }
529 /* include global link_info */
530 $ldap= $this->config->get_ldap_link();
532 /* Remove and write to LDAP */
533 plugin::remove_from_parent();
535 /* Zero arrays */
536 $this->attrs['gosaMailAlternateAddress']= array();
537 $this->attrs['gosaMailForwardingAddress']= array();
538 $this->attrs['gosaSharedFolderTarget']= array();
540 /* Keep uid */
541 unset ($this->attrs['uid']);
542 $ldap->cd($this->dn);
543 $ldap->modify($this->attrs);
544 show_ldap_error($ldap->get_error());
546 /* Connect to IMAP server for account deletion */
547 if ($this->is_account){
548 $method= new $this->method($this->config);
549 if ($method->connect($this->attrs["gosaMailServer"][0])){
550 /* Remove account from IMAP server */
551 $method->deleteMailbox($this->uid);
552 $method->disconnect();
553 }
554 $method->fixAttributesOnRemove($this);
555 }
557 /* Optionally execute a command after we're done */
558 $this->handle_post_events("remove");
559 }
562 /* Save data to object */
563 function save_object()
564 {
565 /* Assemble mail delivery mode
566 The mode field in ldap consists of values between braces, this must
567 be called when 'mail' is set, because checkboxes may not be set when
568 we're in some other dialog.
570 Example for gosaMailDeliveryMode [LR ]
571 L: Local delivery
572 R: Reject when exceeding mailsize limit
573 S: Use spam filter
574 V: Use vacation message
575 C: Use custom sieve script
576 I: Only insider delivery */
577 if (isset($_POST['mailedit'])){
579 /* Save ldap attributes */
580 plugin::save_object();
582 $tmp= "";
583 if (!isset($_POST["drop_own_mails"])){
584 $tmp.= "L";
585 }
586 if (isset($_POST["use_mailsize_limit"])){
587 $tmp.= "R";
588 }
589 if (isset($_POST["use_spam_filter"])){
590 $tmp.= "S";
591 }
592 if (isset($_POST["use_vacation"])){
593 $tmp.= "V";
594 }
595 if (isset($_POST["own_script"])){
596 $tmp.= "C";
597 }
598 if (isset($_POST["only_local"])){
599 $tmp.= "I";
600 }
601 $tmp= "[$tmp]";
603 if (chkacl ($this->acl, "gosaMailDeliveryMode") == ""){
604 $this->gosaMailDeliveryMode= $tmp;
605 }
607 /* Collect data and re-assign it to the imapacl array */
608 if (chkacl($this->acl, "permissions") == ""){
609 $this->imapacl= array();
610 $this->imapacl['%members%']= $_POST['member_permissions'];
611 $this->imapacl['anyone']= $_POST['default_permissions'];
612 foreach ($this->indexed_user as $nr => $user){
613 if (!isset($_POST["user_$nr"])){
614 continue;
615 }
616 if ($_POST["user_$nr"] != $user ||
617 $_POST["perm_$nr"] != $this->indexed_acl[$nr]){
618 $this->is_modified= TRUE;
619 }
620 $this->imapacl[$_POST["user_$nr"]]= $_POST["perm_$nr"];
621 }
622 }
623 }
625 }
628 /*
629 Backup for function save
630 Änderungen : fixAttributesOnStore($this) wurde erst nach dem ldap->modify
631 Ausgeführt, deshalb wurden die gemappten Attribute auch nicht
632 gespeichert.
634 Von : Fabian Hickert
635 Datum : 15.12.2005
637 Alter Quellcode :
639 /* Save data to LDAP, depending on is_account we save or delete * /
640 function save()
641 {
642 $ldap= $this->config->get_ldap_link();
644 /* Call parents save to prepare $this->attrs * /
645 plugin::save();
647 /* Save arrays * /
648 $this->attrs['gosaMailAlternateAddress']= $this->gosaMailAlternateAddress;
649 $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
651 /* Save shared folder target * /
652 $this->attrs['gosaSharedFolderTarget']= "share+".$this->uid;
654 /* Save acl's * /
655 $this->attrs['acl']= array();
656 foreach ($this->imapacl as $user => $acl){
657 if ($user == ""){
658 continue;
659 }
660 $this->attrs['acl'][]= "$user $acl";
661 }
663 /* Save data to LDAP * /
664 $ldap->cd($this->dn);
665 $ldap->modify($this->attrs);
666 show_ldap_error($ldap->get_error());
668 /* Only do IMAP actions if we are not a template * /
669 if (!$this->is_template){
670 $method= new $this->method($this->config);
671 $method->fixAttributesOnStore($this);
672 if ($method->connect($this->gosaMailServer)){
673 $method->updateMailbox($this->uid);
674 $method->setQuota($this->uid, $this->gosaMailQuota);
676 /* Exchange '%member%' pseudo entry * /
677 $memberacl= $this->imapacl['%members%'];
678 unset ($this->imapacl['%members%']);
679 foreach ($this->members as $user){
680 if (!isset($this->imapacl[$user])){
681 $this->imapacl[$user]= $memberacl;
682 }
683 }
685 $method->setSharedFolderPermissions($this->uid, $this->imapacl);
686 $method->disconnect();
687 }
688 }
690 /* Optionally execute a command after we're done * /
691 if ($this->initially_was_account == $this->is_account){
692 if ($this->is_modified){
693 $this->handle_post_events("mofify");
694 }
695 } else {
696 $this->handle_post_events("add");
697 }
698 }
700 ENDE Alter Quellcode
701 */
710 /* Save data to LDAP, depending on is_account we save or delete */
711 function save()
712 {
713 $ldap= $this->config->get_ldap_link();
715 /* Call parents save to prepare $this->attrs */
716 plugin::save();
718 /* Save arrays */
719 $this->attrs['gosaMailAlternateAddress']= $this->gosaMailAlternateAddress;
720 $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
722 /* Save shared folder target */
723 $this->attrs['gosaSharedFolderTarget']= "share+".$this->uid;
725 if(preg_match("/kolab/i",$this->config->current['MAILMETHOD'])){
726 /* Save acl's */
727 $this->attrs['acl']= array();
728 foreach ($this->imapacl as $user => $acl){
729 if ($user == ""){
730 continue;
731 }
732 $ldap->search("(&(objectClass=person)(uid=".$user."))",array("mail"));
733 $mail = $ldap->fetch();
734 if($mail){
735 if(isset($mail['mail'][0])){
736 $this->attrs['acl'][]= $mail['mail'][0]." $acl";
737 }
738 }else{
739 $this->attrs['acl'][]= "$user $acl";
740 }
741 }
742 }else{
743 /* Save acl's */
744 $this->attrs['acl']= array();
745 foreach ($this->imapacl as $user => $acl){
746 if ($user == ""){
747 continue;
748 }
749 $this->attrs['acl'][]= "$user $acl";
750 }
751 }
753 /* Only do IMAP actions if we are not a template */
754 if(preg_match("/kolab/i",$this->config->current['MAILMETHOD'])){
755 if (empty($this->gosaMailServer)||is_array($this->gosaMailServer)){
756 if(isset($this->attrs['gosaMailServer'][0])){
757 $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
758 }
759 }
760 }
762 if ((!$this->is_template)&&(!empty($this->gosaMailServer))){
763 $method= new $this->method($this->config);
764 $method->fixAttributesOnStore($this);
765 if ($method->connect($this->gosaMailServer)){
766 $method->updateMailbox($this->uid);
767 $method->setQuota($this->uid, $this->gosaMailQuota);
769 /* Exchange '%member%' pseudo entry */
770 $memberacl= $this->imapacl['%members%'];
771 unset ($this->imapacl['%members%']);
772 foreach ($this->members as $user){
773 if (!isset($this->imapacl[$user])){
774 $this->imapacl[$user]= $memberacl;
775 }
776 }
778 $method->setSharedFolderPermissions($this->uid, $this->imapacl);
779 $method->disconnect();
780 }
781 }
783 /* Save data to LDAP */
784 $ldap->cd($this->dn);
785 $ldap->modify($this->attrs);
786 show_ldap_error($ldap->get_error());
788 /* Optionally execute a command after we're done */
789 if ($this->initially_was_account == $this->is_account){
790 if ($this->is_modified){
791 $this->handle_post_events("mofify");
792 }
793 } else {
794 $this->handle_post_events("add");
795 }
796 }
798 /* Check formular input */
799 function check()
800 {
801 $ldap= $this->config->get_ldap_link();
803 $message= array();
805 /* must: mail */
806 if ($this->mail == ""){
807 $message[]= _("The required field 'Primary address' is not set.");
808 }
809 if (!is_email($this->mail)){
810 $message[]= _("Please enter a valid email addres in 'Primary address' field.");
811 }
812 $ldap->cd($this->config->current['BASE']);
813 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=".$this->mail.")(gosaMailAlternateAddress=".
814 $this->mail."))(!(uid=".$this->cn."))(!(cn=".$this->cn.")))");
815 if ($ldap->count() != 0){
816 $message[]= _("The primary address you've entered is already in use.");
817 }
819 /* Check quota */
820 if ($this->gosaMailQuota != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
821 if (!is_numeric($this->gosaMailQuota)) {
822 $message[]= _("Value in 'Quota size' is not valid.");
823 } else {
824 $this->gosaMailQuota= (int) $this->gosaMailQuota;
825 }
826 }
828 /* Check rejectsize for integer */
829 if ($this->gosaMailMaxSize != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
830 if (!is_numeric($this->gosaMailMaxSize)){
831 $message[]= _("Please specify a vaild mail size for mails to be rejected.");
832 } else {
833 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
834 }
835 }
837 /* Need gosaMailMaxSize if use_mailsize_limit is checked */
838 if (is_integer(strpos($this->gosaMailDeliveryMode, "reject")) && $this->gosaMailMaxSize == ""){
839 $message[]= _("You need to set the maximum mail size in order to reject anything.");
840 }
842 if(ord($this->imapacl['anyone'][0])==194){
843 $message[] = _("Please choose valid permission settings. Default permission can't be emtpy.");
844 }
846 if(empty($this->gosaMailServer)){
847 $message[] = _("Please select a valid mail server.");
848 }
850 return ($message);
851 }
853 /* Adapt from template, using 'dn' */
854 function adapt_from_template($dn)
855 {
856 plugin::adapt_from_template($dn);
858 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
859 $this->$val= array();
860 if (isset($this->attrs["$val"]["count"])){
861 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
862 $value= $this->attrs["$val"][$i];
863 foreach (array("sn", "givenName", "uid") as $repl){
864 if (preg_match("/%$repl/i", $value)){
865 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
866 }
867 }
868 array_push($this->$val, $value);
869 }
870 }
871 }
872 }
874 /* Add entry to forwarder list */
875 function addForwarder($address)
876 {
877 $this->gosaMailForwardingAddress[]= $address;
878 $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
880 sort ($this->gosaMailForwardingAddress);
881 reset ($this->gosaMailForwardingAddress);
882 $this->is_modified= TRUE;
883 }
885 /* Remove list of addresses from forwarder list */
886 function delForwarder($addresses)
887 {
888 $this->gosaMailForwardingAddress= array_remove_entries ($addresses,
889 $this->gosaMailForwardingAddress);
890 $this->is_modified= TRUE;
891 }
895 function addAlternate($address)
896 {
897 $ldap= $this->config->get_ldap_link();
899 $address= strtolower($address);
901 /* Is this address already assigned in LDAP? */
902 $ldap->cd ($this->config->current['BASE']);
903 $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)".
904 "(gosaMailAlternateAddress=$address)))");
906 if ($ldap->count() > 0){
907 $attrs= $ldap->fetch ();
908 return ($attrs["uid"][0]);
909 }
911 /* Add to list of alternates */
912 if (!in_array($address, $this->gosaMailAlternateAddress)){
913 $this->gosaMailAlternateAddress[]= $address;
914 }
916 sort ($this->gosaMailAlternateAddress);
917 reset ($this->gosaMailAlternateAddress);
918 $this->is_modified= TRUE;
920 return ("");
921 }
924 function delAlternate($addresses)
925 {
926 $this->gosaMailAlternateAddress= array_remove_entries ($addresses,
927 $this->gosaMailAlternateAddress);
928 $this->is_modified= TRUE;
929 }
932 function make_name($attrs)
933 {
934 $name= "";
935 if (isset($attrs['sn'][0])){
936 $name= $attrs['sn'][0];
937 }
938 if (isset($attrs['givenName'][0])){
939 if ($name != ""){
940 $name.= ", ".$attrs['givenName'][0];
941 } else {
942 $name.= $attrs['givenName'][0];
943 }
944 }
945 if ($name != ""){
946 $name.= " ";
947 }
949 return ($name);
950 }
952 }
954 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
955 ?>