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");
10 var $uid = ""; // User id
11 var $cn = ""; // cn
13 var $method = "mailMethod"; // Used Mail method
14 var $mmethod = ""; // Contains the gosa.conf MAILMETHOD
15 var $mail = ""; // Default mail address
17 var $gosaMailAlternateAddress = array(); // Set default Alternate Mail Adresses to empty array
18 var $gosaMailForwardingAddress = array(); // Forwarding also empty
20 var $gosaMailServer = ""; // Selected mailserver
21 var $gosaMailQuota = ""; // Defined Quota
22 var $quotaUsage = 0; // Currently used quota
24 var $gosaVacationMessage = ""; // Vocation message
26 var $imapacl = array('anyone' => 'p', // Set acls for everyone
27 '%members%' => 'lrsp', // %members% are all group-members
28 '' => 'p'); // Every user added gets this right
31 var $gosaSpamSortLevel = "";
32 var $gosaSpamMailbox = "";
33 var $gosaSharedFolderTarget ;
35 var $forward_dialog = FALSE;
37 var $members = array(); // Group members
39 var $mailusers = array();
40 var $perms = array();
41 var $gosaMailDeliveryMode = "[L ]"; //
42 var $gosaMailMaxSize = ""; //
45 /* Helper */
46 var $indexed_acl= array();
47 var $indexed_user= array();
49 /* attribute list for save action */
50 var $attributes= array( "mail", "gosaMailServer", "gosaMailQuota", "gosaMailMaxSize",
51 "gosaMailAlternateAddress", "gosaMailForwardingAddress",
52 "gosaMailDeliveryMode", "gosaSpamSortLevel", "gosaSpamMailbox",
53 "acl","gosaSharedFolderTarget", "gosaVacationMessage");
55 var $objectclasses= array("gosaMailAccount");
58 function mailgroup ($config, $dn= NULL, $ui= NULL)
59 {
60 /* Initialise all available attributes ... if possible
61 */
62 plugin::plugin($config, $dn);
64 /* Set mailMethod to the one defined in gosa.conf
65 */
66 if (isset($this->config->current['MAILMETHOD'])){
67 $this->mmethod= $this->config->current['MAILMETHOD'];
68 }
70 /* Check if selected mail method exists
71 */
72 if (class_exists("mailMethod$this->mmethod")){
73 $this->method= "mailMethod$this->mmethod";
74 } else {
75 print_red(sprintf(_("There is no mail method '%s' specified in your gosa.conf available."), $this->mmethod));
76 }
78 /* Load Mailserver
79 */
80 if(isset($this->attrs['gosaMailServer'][0])){
81 $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
82 }
84 /* Convert cn to uid in case of existing entry
85 */
86 if (isset($this->attrs['cn'][0])){
87 $this->uid= $this->attrs['cn'][0];
88 }
91 /* If this ins't new mailgroup, read all required data from ldap
92 */
93 if (($dn != "new")&&($dn != NULL)){
95 /* Load attributes which represent multiple entries
96 */
97 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
98 $this->$val = array();
99 if (isset($this->attrs["$val"]["count"])){
100 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
101 array_push($this->$val, $this->attrs["$val"][$i]);
102 }
103 }
104 }
106 /* Only do IMAP actions if gosaMailServer attribute is set
107 */
108 if (isset ($this->attrs["gosaMailServer"][0])){
110 /* Create new instance of our defined mailclass
111 */
112 $method= new $this->method($this->config);
114 if ($method->connect($this->attrs["gosaMailServer"][0])){
116 /* get Quota
117 */
118 $quota= $method->getQuota($this->uid);
120 /* Maybe the entry is not saved in new style, get
121 permissions from IMAP and convert them to acl attributes */
122 if (!isset($this->attrs['acl'])){
123 $this->imapacl= $method->getSharedFolderPermissions($this->uid);
125 /* Need to filter what a member acl could be... */
126 $vote= array();
127 $peak= 0;
128 $leader= "";
129 foreach ($this->imapacl as $user => $acl){
131 if ($user != "anyone" ){
132 if (!isset($vote[$acl])){
133 $vote[$acl]= 1;
134 } else {
135 $vote[$acl]++;
136 }
137 if ($vote[$acl] > $peak){
138 $leader= $acl;
139 $peek= $vote[$acl];
140 }
141 }
143 }
145 /* Highest count wins as %members%, remove all members
146 with the same acl */
147 if(!empty($leader)){
148 $this->imapacl['%members%']= $leader;
149 }
150 foreach ($this->imapacl as $user => $acl){
151 if ($this->acl == $leader && in_array($user, $this->attrs['memberUid'])){
152 unset($this->imapacl[$user]);
153 }
154 }
156 } // ENDE ! isset ($this->attrs['acl'])
158 /* Update quota values */
159 if ($quota['gosaMailQuota'] == 2147483647){
160 $this->quotaUsage= "";
161 $this->gosaMailQuota= "";
162 } else {
163 $this->quotaUsage= $quota['quotaUsage'];
164 $this->gosaMailQuota= $quota['gosaMailQuota'];
165 }
166 $method->disconnect();
167 } // ENDE $method->connect($this->attrs["gosaMailServer"][0])){
169 /* Adapt attributes if needed */
170 $method->fixAttributesOnLoad($this);
172 } // ENDE gosaMailServer
174 } // ENDE dn != "new"
177 /* Get global filter config */
178 if (!is_global("gmailfilter")){
179 $ui= get_userinfo();
180 $base= get_base_from_people($ui->dn);
181 $gmailfilter= array( "depselect" => $base,
182 "muser" => "",
183 "regex" => "*");
184 register_global("gmailfilter", $gmailfilter);
185 }
187 /* Load permissions */
188 $tmp = array();
189 if(preg_match("/kolab/i",$this->mmethod)){
190 $ldap = $this->config->get_ldap_link();
192 if (isset($this->attrs['acl'])){
194 for ($i= 0; $i<$this->attrs['acl']['count']; $i++){
195 list($user, $permission)= split(' ', $this->attrs['acl'][$i]);
197 /* Add to list */
198 $this->imapacl[$user]= $permission;
200 /* Get all user permissions sorted by acl, to detect the most used acl
201 This acl is then used for %members%
202 */
203 if ($user != "anyone" && $user != "%members%"){
204 $tmp[$permission][] = $user;
205 }
207 /* There is an entry in $this->imapacl like this this ...
208 $this->attrs['imapacl']['anyone'] = "p";
209 $this->attrs['imapacl']['%members%'] = "lprs";
210 $this->attrs['imapacl'][''] = ""; <------ This is used to diplay an empty
211 Field for special acls in our template.
212 If there is at least one special acl in out imapacl,
213 we don't need this entry anymore, because it is already displayed.
214 */
215 if ($user != "anyone" && $user != "%members%"){
216 unset($this->imapacl['']);
217 }
218 }
219 }
221 /* In this section we dectect which acl is tho most used
222 This will be used as %members% acl
223 */
224 $tmp2 = array();
225 foreach($tmp as $acl => $user){
226 $tmp2[count($tmp[$acl])]=$acl;
227 }
228 /* Most used at last
229 */
230 ksort($tmp2);
232 /* Assign last (most used acl) to %members% acl
233 */
234 $str = array_pop($tmp2);
235 if(!empty($str)) {
236 $this->imapacl['%members%']=$str;
237 }
239 /* Open ldap connection
240 */
241 $ldap = $this->config->get_ldap_link();
242 $ldap->cd($this->config->current['BASE']);
244 /* Remove those users, that use %members% acl && are member of this group. */
245 foreach($this->imapacl as $mail => $permission){
246 $ldap->search("(&(objectClass=person)(mail=".$mail."))",array("uid"));
247 $atr = $ldap->fetch();
248 if((isset($this->attrs['memberUid'])) && (is_array($this->attrs['memberUid']))){
249 if((isset($atr['uid'][0]))&&(in_array($atr['uid'][0],$this->attrs['memberUid']))&&($permission == $this->imapacl['%members%'])){
250 unset($this->imapacl[$mail]);
251 }
252 }
253 }
254 /* Append an empty entry, for special acl handling */
255 if(count($this->imapacl)==2){
256 $this->imapacl[''] ="";
257 }
259 }else{ // Not kolab
260 /* Load permissions */
261 if (isset($this->attrs['acl'])){
262 for ($i= 0; $i<$this->attrs['acl']['count']; $i++){
263 list($user, $permission)= split(' ', $this->attrs['acl'][$i]);
264 $this->imapacl[$user]= $permission;
265 if ($user != "anyone" && $user != "%members%"){
266 unset($this->imapacl['']);
267 }
268 }
269 }
270 }
272 /* Load Mailserver
273 */
274 if(isset($this->attrs['gosaMailServer'][0])){
275 $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
276 }
277 /* Fill translations */
278 $this->perms["lrs"]= _("read");
279 $this->perms["lrsp"]= _("post");
280 $this->perms["p"]= _("external post");
281 $this->perms["lrsip"]= _("append");
282 $this->perms["lrswipcd"]= _("write");
283 }
285 function execute()
286 {
287 /* Call parent execute */
288 //plugin::execute();
290 /* Load templating engine */
291 $smarty= get_smarty();
292 if ($_SESSION['js']==FALSE){
293 $smarty->assign("javascript", "false");
294 } else {
295 $smarty->assign("javascript", "true");
296 }
298 /* Do we need to flip is_account state? */
299 if (isset($_POST['modify_state'])){
300 $this->is_account= !$this->is_account;
301 }
303 /* Do we represent a valid account? */
304 if (!$this->is_account && $this->parent == NULL){
305 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
306 _("This 'dn' has no valid mail extensions.")."</b>";
307 return ($display);
308 }
310 /* Show tab dialog headers */
311 $display= "";
312 if ($this->parent != NULL){
313 if ($this->is_account){
314 $display= $this->show_header(_("Remove mail account"),
315 _("This account has mail features enabled. You can disable them by clicking below."));
316 } else {
317 $display= $this->show_header(_("Create mail account"),
318 _("This account has mail features disabled. You can enable them by clicking below."));
319 return ($display);
320 }
321 }
323 /* Add ACL? */
324 foreach ($this->indexed_user as $nr => $user){
325 if (isset($_POST["add_$nr"])){
326 $this->imapacl[""]= "l";
327 }
328 if (isset($_POST["del_$nr"])){
329 unset ($this->imapacl[$user]);
330 }
331 }
333 /* Trigger forward add dialog? */
334 if (isset($_POST['add_local_forwarder'])){
335 $this->forward_dialog= TRUE;
336 $this->dialog= TRUE;
337 }
339 /* Cancel forward add dialog? */
340 if (isset($_POST['add_locals_cancel'])){
341 $this->forward_dialog= FALSE;
342 $this->dialog= FALSE;
343 }
345 /* Finished adding of locals? */
346 if (isset($_POST['add_locals_finish'])){
347 if (count ($_POST['local_list']) &&
348 chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
350 /* Walk through list of forwarders, ignore own addresses */
351 foreach ($_POST['local_list'] as $val){
352 if (!in_array ($val, $this->gosaMailAlternateAddress) &&
353 $val != $this->mail){
355 $this->addForwarder($val);
356 }
357 }
358 }
359 $this->forward_dialog= FALSE;
360 $this->dialog= FALSE;
361 }
363 /* Add forward email addresses */
364 if (isset($_POST['add_forwarder'])){
365 if ($_POST['forward_address'] != ""){
367 /* Valid email address specified? */
368 $address= $_POST['forward_address'];
369 if (!is_email($address)){
371 print_red (_("You're trying to add an invalid email address ".
372 "to the list of forwarders."));
374 } elseif ($address == $this->mail
375 || in_array($address, $this->gosaMailAlternateAddress)) {
377 print_red (_("Adding your one of your own addresses to the forwarders makes no sense."));
379 } else {
381 /* Add it */
382 if (chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
383 $this->addForwarder ($address);
384 }
386 }
387 }
388 }
390 /* Delete forward email addresses */
391 if (isset($_POST['delete_forwarder'])){
392 if (count($_POST['forwarder_list'])
393 && chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
395 $this->delForwarder ($_POST['forwarder_list']);
396 }
397 }
399 /* Add alternate email addresses */
400 if (isset($_POST['add_alternate'])){
401 if ($_POST['alternate_address'] != "" &&
402 chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
404 if (!is_email($_POST['alternate_address'])){
405 print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
407 } elseif (($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
408 $ui= get_userinfo();
409 if ($user != $ui->username){
410 print_red (_("The address you're trying to add is already used by user")." '$user'.");
411 }
412 }
413 }
414 }
416 /* Delete alternate email addresses */
417 if (isset($_POST['delete_alternate']) && isset ($_POST['alternates_list'])){
418 if (count($_POST['alternates_list']) &&
419 chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
421 $this->delAlternate ($_POST['alternates_list']);
422 }
423 }
425 /* Show forward add dialog */
426 if ($this->forward_dialog){
427 $ldap= $this->config->get_ldap_link();
429 /* Save data */
430 $gmailfilter= get_global("gmailfilter");
431 foreach( array("depselect", "muser", "regex") as $type){
432 if (isset($_POST[$type])){
433 $gmailfilter[$type]= $_POST[$type];
434 }
435 }
436 if (isset($_GET['search'])){
437 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
438 if ($s == "**"){
439 $s= "*";
440 }
441 $gmailfilter['regex']= $s;
442 }
443 register_global("gmailfilter", $gmailfilter);
445 /* Get actual list */
446 $mailusers= array ();
447 if ($gmailfilter['regex'] != '*' && $gmailfilter['regex'] != ""){
448 $regex= $gmailfilter['regex'];
449 $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
450 } else {
451 $filter= "";
452 }
453 if ($gmailfilter['muser'] != ""){
454 $user= $gmailfilter['muser'];
455 $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
456 }
458 /* Add already present people to the filter */
459 $exclude= "";
460 foreach ($this->gosaMailForwardingAddress as $mail){
461 $exclude.= "(mail=$mail)";
462 }
463 if ($exclude != ""){
464 $filter.= "(!(|$exclude))";
465 }
467 $acl= array($this->config->current['BASE'] => ":all");
468 $res= get_list($acl, "(&(objectClass=gosaMailAccount)$filter)", TRUE, $gmailfilter['depselect'], array("sn", "mail", "givenName"), TRUE);
469 $ldap->cd($gmailfilter['depselect']);
470 $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
471 error_reporting (0);
472 while ($attrs= $ldap->fetch()){
473 if(preg_match('/%/', $attrs['mail'][0])){
474 continue;
475 }
476 $name= $this->make_name($attrs);
477 $mailusers[$attrs['mail'][0]]= $name."<".
478 $attrs['mail'][0].">";
479 }
480 error_reporting (E_ALL);
481 natcasesort ($mailusers);
482 reset ($mailusers);
484 /* Show dialog */
485 $smarty->assign("search_image", get_template_path('images/search.png'));
486 $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
487 $smarty->assign("tree_image", get_template_path('images/tree.png'));
488 $smarty->assign("infoimage", get_template_path('images/info.png'));
489 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
490 $smarty->assign("mailusers", $mailusers);
491 $smarty->assign("deplist", $this->config->idepartments);
492 $smarty->assign("apply", apply_filter());
493 $smarty->assign("alphabet", generate_alphabet());
494 $smarty->assign("hint", print_sizelimit_warning());
495 foreach( array("depselect", "muser", "regex") as $type){
496 $smarty->assign("$type", $gmailfilter[$type]);
497 }
498 $smarty->assign("hint", print_sizelimit_warning());
499 $display.= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE));
500 return ($display);
501 }
503 /* Assemble normal permissions */
504 $smarty->assign("permissionsACL", chkacl($this->acl, "permissions"));
505 if (isset($this->imapacl['anyone'])){
506 $smarty->assign("default_permissions", $this->imapacl['anyone']);
507 }
508 $smarty->assign("member_permissions", "lrsp");
509 if (isset($this->imapacl['%members%'])){
510 $smarty->assign("member_permissions", $this->imapacl['%members%']);
511 }
513 /* Assemble extra attributes */
514 $perm= chkacl($this->acl, "permissions");
515 $tmp= "";
516 $nr= 0;
517 $count= count($this->imapacl);
518 $this->indexed_user= array();
519 $this->indexed_acl= array();
520 foreach($this->imapacl as $user => $acl){
521 if ($user != "anyone" && $user != "%members%"){
522 $tmp.= "<tr><td><input name=\"user_$nr\" size=20 maxlength=60 ".
523 "value=\"$user\" $perm></td><td><select size=\"1\" name=\"perm_$nr\" $perm>";
524 foreach ($this->perms as $key => $value){
525 if ($acl == $key){
526 $tmp.= "<option value=$key selected>$value</option>";
527 } else {
528 $tmp.= "<option value=$key>$value</option>";
529 }
530 }
531 $tmp.= "</select> ";
532 if ($nr == $count - 1){
533 $tmp.= "<input type=submit value=\""._("Add")."\" ".
534 "name=\"add_$nr\" $perm>";
535 }
536 if ($count > 3){
537 $tmp.= "<input type=submit value=\""._("Remove")."\" ".
538 "name=\"del_$nr\" $perm></td></tr>";
539 }
540 }
541 $this->indexed_user[$nr]= $user;
542 $this->indexed_acl[$nr++]= $acl;
543 }
544 $smarty->assign("plusattributes", $tmp);
546 /* Show main page */
547 $mailserver= array();
548 foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
549 $mailserver[]= $key;
550 }
551 $smarty->assign("mailServers", $mailserver);
552 foreach(array("gosaMailServer", "gosaMailQuota", "perms", "mail",
553 "gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
554 $smarty->assign("$val", $this->$val);
555 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
556 }
557 if (is_numeric($this->gosaMailQuota) && $this->gosaMailQuota != 0){
558 $smarty->assign("quotausage", progressbar(round(($this->quotaUsage * 100)/ $this->gosaMailQuota),100,15,true));
559 $smarty->assign("quotadefined", "true");
560 } else {
561 $smarty->assign("quotadefined", "false");
562 }
564 $display.= $smarty->fetch (get_template_path('mail.tpl', TRUE));
565 return ($display);
566 }
569 /* remove object from parent */
570 function remove_from_parent()
571 {
572 /* Added these ObjectClass and Attributes, because they were not
573 removed correctly, only in case of kolab ...
574 */
575 if(isset($this->config->current['MAILMETHOD'])&&preg_match("/kolab/i",$this->config->current['MAILMETHOD'])){
576 $this->attributes[]="acl";
577 $this->objectclasses[] = "kolabSharedFolder";
578 }
579 /* include global link_info */
580 $ldap= $this->config->get_ldap_link();
582 /* Remove and write to LDAP */
583 plugin::remove_from_parent();
585 /* Zero arrays */
586 $this->attrs['gosaMailAlternateAddress']= array();
587 $this->attrs['gosaMailForwardingAddress']= array();
588 $this->attrs['gosaSharedFolderTarget']= array();
590 /* Connect to IMAP server for account deletion */
591 if ($this->initially_was_account){
592 $method= new $this->method($this->config);
593 if ($method->connect($this->gosaMailServer)){
594 /* Remove account from IMAP server */
595 $method->deleteMailbox($this->uid);
596 $method->disconnect();
597 }
598 $method->fixAttributesOnRemove($this);
599 }
600 /* Keep uid */
601 unset ($this->attrs['uid']);
604 $ldap->cd($this->dn);
605 $ldap->modify ($this->attrs);
607 show_ldap_error($ldap->get_error());
609 /* Optionally execute a command after we're done */
610 $this->handle_post_events("remove");
611 }
614 /* Save data to object */
615 function save_object()
616 {
617 /* Assemble mail delivery mode
618 The mode field in ldap consists of values between braces, this must
619 be called when 'mail' is set, because checkboxes may not be set when
620 we're in some other dialog.
622 Example for gosaMailDeliveryMode [LR ]
623 L: Local delivery
624 R: Reject when exceeding mailsize limit
625 S: Use spam filter
626 V: Use vacation message
627 C: Use custom sieve script
628 I: Only insider delivery */
629 if (isset($_POST['mailedit'])){
631 /* Save ldap attributes */
632 plugin::save_object();
634 $tmp= "";
635 if (!isset($_POST["drop_own_mails"])){
636 $tmp.= "L";
637 }
638 if (isset($_POST["use_mailsize_limit"])){
639 $tmp.= "R";
640 }
641 if (isset($_POST["use_spam_filter"])){
642 $tmp.= "S";
643 }
644 if (isset($_POST["use_vacation"])){
645 $tmp.= "V";
646 }
647 if (isset($_POST["own_script"])){
648 $tmp.= "C";
649 }
650 if (isset($_POST["only_local"])){
651 $tmp.= "I";
652 }
653 $tmp= "[$tmp]";
655 if (chkacl ($this->acl, "gosaMailDeliveryMode") == ""){
656 $this->gosaMailDeliveryMode= $tmp;
657 }
659 /* Collect data and re-assign it to the imapacl array */
660 if (chkacl($this->acl, "permissions") == ""){
661 $this->imapacl= array();
662 $this->imapacl['%members%']= $_POST['member_permissions'];
663 $this->imapacl['anyone']= $_POST['default_permissions'];
664 foreach ($this->indexed_user as $nr => $user){
665 if (!isset($_POST["user_$nr"])){
666 continue;
667 }
668 if ($_POST["user_$nr"] != $user ||
669 $_POST["perm_$nr"] != $this->indexed_acl[$nr]){
670 $this->is_modified= TRUE;
671 }
672 $this->imapacl[$_POST["user_$nr"]]= $_POST["perm_$nr"];
673 }
674 }
675 }
677 }
681 /* Save data to LDAP, depending on is_account we save or delete */
682 function save()
683 {
684 $ldap= $this->config->get_ldap_link();
685 $ldap->cd($this->config->current['BASE']);
687 /* Call parents save to prepare $this->attrs */
688 plugin::save();
690 /* Save arrays */
691 $this->attrs['gosaMailAlternateAddress'] = $this->gosaMailAlternateAddress;
692 $this->attrs['gosaMailForwardingAddress'] = $this->gosaMailForwardingAddress;
694 /* Save shared folder target */
695 $this->attrs['gosaSharedFolderTarget']= "share+".$this->uid;
697 if(preg_match("/kolab/i",$this->mmethod)){
698 /* Save acl's */
699 $this->attrs['acl']= array();
700 foreach ($this->imapacl as $user => $acl){
701 if ($user == ""){
702 continue;
703 }
704 $ldap->search("(&(objectClass=person)(|(uid=".$user.")(mail=".$user.")))",array("mail"));
705 $mail = $ldap->fetch();
706 if($mail){
707 if(isset($mail['mail'][0])){
708 $this->attrs['acl'][]= $mail['mail'][0]." $acl";
709 }
710 }else{
711 $this->attrs['acl'][]= "$user $acl";
712 }
713 }
714 }else{
715 /* Save acl's */
716 $this->attrs['acl']= array();
717 foreach ($this->imapacl as $user => $acl){
718 if ($user == ""){
719 continue;
720 }
721 $this->attrs['acl'][]= "$user $acl";
722 }
723 }
725 /* Only do IMAP actions if we are not a template */
726 if(preg_match("/kolab/i",$this->mmethod)){
727 if (empty($this->gosaMailServer)||is_array($this->gosaMailServer)){
728 if(isset($this->attrs['gosaMailServer'][0])){
729 $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
730 }
731 }
732 }
735 if ((!$this->is_template)&&(!empty($this->gosaMailServer))){
736 $method= new $this->method($this->config);
737 $method->fixAttributesOnStore($this);
738 if (($method->connect($this->gosaMailServer))){
739 $method->updateMailbox($this->uid);
740 $method->setQuota($this->uid, $this->gosaMailQuota);
741 $method->setSharedFolderPermissions($this->uid, $this->imapacl);
742 $method->disconnect();
743 }
744 }
746 /* Exchange '%member%' pseudo entry */
747 $memberacl= $this->imapacl['%members%'];
749 if(empty($memberacl)){
750 print_a($this);
751 exit();
752 }
754 foreach ($this->members as $user){
755 if(preg_match("/kolab/i",$this->mmethod)){
756 $ldap->cd($this->config->current['BASE']);
757 $ldap->search("(&(objectClass=person)(|(mail=".$user.")(uid=".$user.")))",array("mail"));
758 $at = $ldap->fetch();
759 if(isset($at['mail'][0])){
760 $user = $at['mail'][0];
761 }
762 }
763 if (!isset($this->imapacl[$user])){
764 $this->imapacl[$user]= $memberacl;
765 }
766 }
767 $this->attrs['acl'] = array();
768 foreach($this->imapacl as $user => $acl){
769 if(preg_match("/%members%/",$user) || empty($user)) continue;
771 $this->attrs['acl'][] = $user." ".$acl;
772 }
774 /* Save data to LDAP */
775 $ldap->cd($this->dn);
776 $this->cleanup();
777 $ldap->modify ($this->attrs);
779 show_ldap_error($ldap->get_error());
781 /* Optionally execute a command after we're done */
782 if ($this->initially_was_account == $this->is_account){
783 if ($this->is_modified){
784 $this->handle_post_events("mofify");
785 }
786 } else {
787 $this->handle_post_events("add");
788 }
789 }
791 /* Check formular input */
792 function check()
793 {
794 $ldap= $this->config->get_ldap_link();
796 $message= array();
798 /* must: mail */
799 if ($this->mail == ""){
800 $message[]= _("The required field 'Primary address' is not set.");
801 }
802 if (!is_email($this->mail)){
803 $message[]= _("Please enter a valid email addres in 'Primary address' field.");
804 }
805 $ldap->cd($this->config->current['BASE']);
806 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=".$this->mail.")(gosaMailAlternateAddress=".
807 $this->mail."))(!(uid=".$this->cn."))(!(cn=".$this->cn.")))");
808 if ($ldap->count() != 0){
809 $message[]= _("The primary address you've entered is already in use.");
810 }
812 /* Check quota */
813 if ($this->gosaMailQuota != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
814 if (!is_numeric($this->gosaMailQuota)) {
815 $message[]= _("Value in 'Quota size' is not valid.");
816 } else {
817 $this->gosaMailQuota= (int) $this->gosaMailQuota;
818 }
819 }
821 /* Check rejectsize for integer */
822 if ($this->gosaMailMaxSize != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
823 if (!is_numeric($this->gosaMailMaxSize)){
824 $message[]= _("Please specify a vaild mail size for mails to be rejected.");
825 } else {
826 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
827 }
828 }
830 /* Need gosaMailMaxSize if use_mailsize_limit is checked */
831 if (is_integer(strpos($this->gosaMailDeliveryMode, "reject")) && $this->gosaMailMaxSize == ""){
832 $message[]= _("You need to set the maximum mail size in order to reject anything.");
833 }
835 if(ord($this->imapacl['anyone'][0])==194){
836 $message[] = _("Please choose valid permission settings. Default permission can't be emtpy.");
837 }
839 if(empty($this->gosaMailServer)){
840 $message[] = _("Please select a valid mail server.");
841 }
843 return ($message);
844 }
846 /* Adapt from template, using 'dn' */
847 function adapt_from_template($dn)
848 {
849 plugin::adapt_from_template($dn);
851 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
852 $this->$val= array();
853 if (isset($this->attrs["$val"]["count"])){
854 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
855 $value= $this->attrs["$val"][$i];
856 foreach (array("sn", "givenName", "uid") as $repl){
857 if (preg_match("/%$repl/i", $value)){
858 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
859 }
860 }
861 array_push($this->$val, $value);
862 }
863 }
864 }
865 }
867 /* Add entry to forwarder list */
868 function addForwarder($address)
869 {
870 $this->gosaMailForwardingAddress[]= $address;
871 $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
873 sort ($this->gosaMailForwardingAddress);
874 reset ($this->gosaMailForwardingAddress);
875 $this->is_modified= TRUE;
876 }
878 /* Remove list of addresses from forwarder list */
879 function delForwarder($addresses)
880 {
881 $this->gosaMailForwardingAddress= array_remove_entries ($addresses,
882 $this->gosaMailForwardingAddress);
883 $this->is_modified= TRUE;
884 }
888 function addAlternate($address)
889 {
890 $ldap= $this->config->get_ldap_link();
892 $address= strtolower($address);
894 /* Is this address already assigned in LDAP? */
895 $ldap->cd ($this->config->current['BASE']);
896 $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)".
897 "(gosaMailAlternateAddress=$address)))");
899 if ($ldap->count() > 0){
900 $attrs= $ldap->fetch ();
901 return ($attrs["uid"][0]);
902 }
904 /* Add to list of alternates */
905 if (!in_array($address, $this->gosaMailAlternateAddress)){
906 $this->gosaMailAlternateAddress[]= $address;
907 }
909 sort ($this->gosaMailAlternateAddress);
910 reset ($this->gosaMailAlternateAddress);
911 $this->is_modified= TRUE;
913 return ("");
914 }
917 function delAlternate($addresses)
918 {
919 $this->gosaMailAlternateAddress= array_remove_entries ($addresses,
920 $this->gosaMailAlternateAddress);
921 $this->is_modified= TRUE;
922 }
925 function make_name($attrs)
926 {
927 $name= "";
928 if (isset($attrs['sn'][0])){
929 $name= $attrs['sn'][0];
930 }
931 if (isset($attrs['givenName'][0])){
932 if ($name != ""){
933 $name.= ", ".$attrs['givenName'][0];
934 } else {
935 $name.= $attrs['givenName'][0];
936 }
937 }
938 if ($name != ""){
939 $name.= " ";
940 }
942 return ($name);
943 }
945 function getCopyDialog()
946 {
947 if(!$this->is_account) return("");
949 $str =" <table width='100%'>
950 <tr>
951 <td style='width:150px;'>".
952 _("Primary mail address").
953 "</td>
954 <td>
955 <input id='mail' name='mail' size='16' maxlength='160'
956 value='".$this->mail."'
957 title='"._("Primary mail address for this shared folder")."'>
958 </td>
959 </tr>
960 </table>";
961 return($str);
962 }
964 function saveCopyDialog()
965 {
966 if(!$this->is_account) return;
967 if(isset($_POST['mail'])){
968 $this->mail = $_POST['mail'];
969 }
970 }
973 }
975 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
976 ?>