533347ddaf66b0cdf6caa000702d85475da0ed65
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 foreach ($this->members as $user){
750 if(preg_match("/kolab/i",$this->mmethod)){
751 $ldap->cd($this->config->current['BASE']);
752 $ldap->search("(&(objectClass=person)(|(mail=".$user.")(uid=".$user.")))",array("mail"));
753 $at = $ldap->fetch();
754 if(isset($at['mail'][0])){
755 $user = $at['mail'][0];
756 }
757 }
758 if (!isset($this->imapacl[$user])){
759 $this->imapacl[$user]= $memberacl;
760 }
761 }
762 $this->attrs['acl'] = array();
763 foreach($this->imapacl as $user => $acl){
764 if(preg_match("/%members%/",$user) || empty($user)) continue;
766 $this->attrs['acl'][] = $user." ".$acl;
767 }
769 /* Save data to LDAP */
770 $ldap->cd($this->dn);
771 $this->cleanup();
772 $ldap->modify ($this->attrs);
774 show_ldap_error($ldap->get_error());
776 /* Optionally execute a command after we're done */
777 if ($this->initially_was_account == $this->is_account){
778 if ($this->is_modified){
779 $this->handle_post_events("mofify");
780 }
781 } else {
782 $this->handle_post_events("add");
783 }
784 }
786 /* Check formular input */
787 function check()
788 {
789 $ldap= $this->config->get_ldap_link();
791 $message= array();
792 if(!$this->is_account) return array();
794 //$message[] = $str;
796 /* must: mail */
797 if ($this->mail == ""){
798 $message[]= _("The required field 'Primary address' is not set.");
799 }
800 if (!is_email($this->mail)){
801 $message[]= _("Please enter a valid email addres in 'Primary address' field.");
802 }
803 $ldap->cd($this->config->current['BASE']);
804 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=".$this->mail.")(gosaMailAlternateAddress=".
805 $this->mail."))(!(uid=".$this->cn."))(!(cn=".$this->cn.")))");
806 if ($ldap->count() != 0){
807 $message[]= _("The primary address you've entered is already in use.");
808 }
810 /* Check quota */
811 if ($this->gosaMailQuota != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
812 if (!is_numeric($this->gosaMailQuota)) {
813 $message[]= _("Value in 'Quota size' is not valid.");
814 } else {
815 $this->gosaMailQuota= (int) $this->gosaMailQuota;
816 }
817 }
819 /* Check rejectsize for integer */
820 if ($this->gosaMailMaxSize != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
821 if (!is_numeric($this->gosaMailMaxSize)){
822 $message[]= _("Please specify a vaild mail size for mails to be rejected.");
823 } else {
824 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
825 }
826 }
828 /* Need gosaMailMaxSize if use_mailsize_limit is checked */
829 if (is_integer(strpos($this->gosaMailDeliveryMode, "reject")) && $this->gosaMailMaxSize == ""){
830 $message[]= _("You need to set the maximum mail size in order to reject anything.");
831 }
833 if(ord($this->imapacl['anyone'][0])==194){
834 $message[] = _("Please choose valid permission settings. Default permission can't be emtpy.");
835 }
837 if(empty($this->gosaMailServer)){
838 $message[] = _("Please select a valid mail server.");
839 }
841 return ($message);
842 }
844 /* Adapt from template, using 'dn' */
845 function adapt_from_template($dn)
846 {
847 plugin::adapt_from_template($dn);
849 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
850 $this->$val= array();
851 if (isset($this->attrs["$val"]["count"])){
852 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
853 $value= $this->attrs["$val"][$i];
854 foreach (array("sn", "givenName", "uid") as $repl){
855 if (preg_match("/%$repl/i", $value)){
856 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
857 }
858 }
859 array_push($this->$val, $value);
860 }
861 }
862 }
863 }
865 /* Add entry to forwarder list */
866 function addForwarder($address)
867 {
868 $this->gosaMailForwardingAddress[]= $address;
869 $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
871 sort ($this->gosaMailForwardingAddress);
872 reset ($this->gosaMailForwardingAddress);
873 $this->is_modified= TRUE;
874 }
876 /* Remove list of addresses from forwarder list */
877 function delForwarder($addresses)
878 {
879 $this->gosaMailForwardingAddress= array_remove_entries ($addresses,
880 $this->gosaMailForwardingAddress);
881 $this->is_modified= TRUE;
882 }
886 function addAlternate($address)
887 {
888 $ldap= $this->config->get_ldap_link();
890 $address= strtolower($address);
892 /* Is this address already assigned in LDAP? */
893 $ldap->cd ($this->config->current['BASE']);
894 $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)".
895 "(gosaMailAlternateAddress=$address)))");
897 if ($ldap->count() > 0){
898 $attrs= $ldap->fetch ();
899 return ($attrs["uid"][0]);
900 }
902 /* Add to list of alternates */
903 if (!in_array($address, $this->gosaMailAlternateAddress)){
904 $this->gosaMailAlternateAddress[]= $address;
905 }
907 sort ($this->gosaMailAlternateAddress);
908 reset ($this->gosaMailAlternateAddress);
909 $this->is_modified= TRUE;
911 return ("");
912 }
915 function delAlternate($addresses)
916 {
917 $this->gosaMailAlternateAddress= array_remove_entries ($addresses,
918 $this->gosaMailAlternateAddress);
919 $this->is_modified= TRUE;
920 }
923 function make_name($attrs)
924 {
925 $name= "";
926 if (isset($attrs['sn'][0])){
927 $name= $attrs['sn'][0];
928 }
929 if (isset($attrs['givenName'][0])){
930 if ($name != ""){
931 $name.= ", ".$attrs['givenName'][0];
932 } else {
933 $name.= $attrs['givenName'][0];
934 }
935 }
936 if ($name != ""){
937 $name.= " ";
938 }
940 return ($name);
941 }
943 function getCopyDialog()
944 {
945 if(!$this->is_account) return("");
947 $smarty = get_smarty();
948 $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress);
949 $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress);
950 $smarty->assign("mail",$this->mail);
951 $display= $smarty->fetch (get_template_path('paste_mail.tpl', TRUE));
952 return($display);
953 }
955 function saveCopyDialog()
956 {
957 if(!$this->is_account) return;
959 /* Perform ADD / REMOVE ... for mail alternate / mail forwarding addresses
960 */
961 $this->execute();
962 if(isset($_POST['mail'])){
963 $this->mail = $_POST['mail'];
964 }
965 }
968 }
970 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
971 ?>