eb103aac3ca6cf1adb98d46ae18add46de035f4a
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("(&(objectClass=gosaMailAccount)$filter)", $acl, $gmailfilter['depselect'],
469 array("sn", "mail", "givenName"), GL_SUBSEARCH | GL_SIZELIMIT);
470 $ldap->cd($gmailfilter['depselect']);
471 $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
472 error_reporting (0);
473 while ($attrs= $ldap->fetch()){
474 if(preg_match('/%/', $attrs['mail'][0])){
475 continue;
476 }
477 $name= $this->make_name($attrs);
478 $mailusers[$attrs['mail'][0]]= $name."<".
479 $attrs['mail'][0].">";
480 }
481 error_reporting (E_ALL);
482 natcasesort ($mailusers);
483 reset ($mailusers);
485 /* Show dialog */
486 $smarty->assign("search_image", get_template_path('images/search.png'));
487 $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
488 $smarty->assign("tree_image", get_template_path('images/tree.png'));
489 $smarty->assign("infoimage", get_template_path('images/info.png'));
490 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
491 $smarty->assign("mailusers", $mailusers);
492 $smarty->assign("deplist", $this->config->idepartments);
493 $smarty->assign("apply", apply_filter());
494 $smarty->assign("alphabet", generate_alphabet());
495 $smarty->assign("hint", print_sizelimit_warning());
496 foreach( array("depselect", "muser", "regex") as $type){
497 $smarty->assign("$type", $gmailfilter[$type]);
498 }
499 $smarty->assign("hint", print_sizelimit_warning());
500 $display.= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE));
501 return ($display);
502 }
504 /* Assemble normal permissions */
505 $smarty->assign("permissionsACL", chkacl($this->acl, "permissions"));
506 if (isset($this->imapacl['anyone'])){
507 $smarty->assign("default_permissions", $this->imapacl['anyone']);
508 }
509 $smarty->assign("member_permissions", "lrsp");
510 if (isset($this->imapacl['%members%'])){
511 $smarty->assign("member_permissions", $this->imapacl['%members%']);
512 }
514 /* Assemble extra attributes */
515 $perm= chkacl($this->acl, "permissions");
516 $tmp= "";
517 $nr= 0;
518 $count= count($this->imapacl);
519 $this->indexed_user= array();
520 $this->indexed_acl= array();
521 foreach($this->imapacl as $user => $acl){
522 if ($user != "anyone" && $user != "%members%"){
523 $tmp.= "<tr><td><input name=\"user_$nr\" size=20 maxlength=60 ".
524 "value=\"$user\" $perm></td><td><select size=\"1\" name=\"perm_$nr\" $perm>";
525 foreach ($this->perms as $key => $value){
526 if ($acl == $key){
527 $tmp.= "<option value=$key selected>$value</option>";
528 } else {
529 $tmp.= "<option value=$key>$value</option>";
530 }
531 }
532 $tmp.= "</select> ";
533 if ($nr == $count - 1){
534 $tmp.= "<input type=submit value=\""._("Add")."\" ".
535 "name=\"add_$nr\" $perm>";
536 }
537 if ($count > 3){
538 $tmp.= "<input type=submit value=\""._("Remove")."\" ".
539 "name=\"del_$nr\" $perm></td></tr>";
540 }
541 }
542 $this->indexed_user[$nr]= $user;
543 $this->indexed_acl[$nr++]= $acl;
544 }
545 $smarty->assign("plusattributes", $tmp);
547 /* Show main page */
548 $mailserver= array();
549 foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
550 $mailserver[]= $key;
551 }
552 $smarty->assign("mailServers", $mailserver);
553 foreach(array("gosaMailServer", "gosaMailQuota", "perms", "mail",
554 "gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
555 $smarty->assign("$val", $this->$val);
556 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
557 }
558 if (is_numeric($this->gosaMailQuota) && $this->gosaMailQuota != 0){
559 $smarty->assign("quotausage", progressbar(round(($this->quotaUsage * 100)/ $this->gosaMailQuota),100,15,true));
560 $smarty->assign("quotadefined", "true");
561 } else {
562 $smarty->assign("quotadefined", "false");
563 }
565 $display.= $smarty->fetch (get_template_path('mail.tpl', TRUE));
566 return ($display);
567 }
570 /* remove object from parent */
571 function remove_from_parent()
572 {
573 /* Added these ObjectClass and Attributes, because they were not
574 removed correctly, only in case of kolab ...
575 */
576 if(isset($this->config->current['MAILMETHOD'])&&preg_match("/kolab/i",$this->config->current['MAILMETHOD'])){
577 $this->attributes[]="acl";
578 $this->objectclasses[] = "kolabSharedFolder";
579 }
580 /* include global link_info */
581 $ldap= $this->config->get_ldap_link();
583 /* Remove and write to LDAP */
584 plugin::remove_from_parent();
586 /* Zero arrays */
587 $this->attrs['gosaMailAlternateAddress']= array();
588 $this->attrs['gosaMailForwardingAddress']= array();
589 $this->attrs['gosaSharedFolderTarget']= array();
591 /* Connect to IMAP server for account deletion */
592 if ($this->initially_was_account){
593 $method= new $this->method($this->config);
594 if ($method->connect($this->gosaMailServer)){
595 /* Remove account from IMAP server */
596 $method->deleteMailbox($this->uid);
597 $method->disconnect();
598 }
599 $method->fixAttributesOnRemove($this);
600 }
601 /* Keep uid */
602 unset ($this->attrs['uid']);
605 $ldap->cd($this->dn);
606 $ldap->modify ($this->attrs);
608 show_ldap_error($ldap->get_error());
610 /* Optionally execute a command after we're done */
611 $this->handle_post_events("remove");
612 }
615 /* Save data to object */
616 function save_object()
617 {
618 /* Assemble mail delivery mode
619 The mode field in ldap consists of values between braces, this must
620 be called when 'mail' is set, because checkboxes may not be set when
621 we're in some other dialog.
623 Example for gosaMailDeliveryMode [LR ]
624 L: Local delivery
625 R: Reject when exceeding mailsize limit
626 S: Use spam filter
627 V: Use vacation message
628 C: Use custom sieve script
629 I: Only insider delivery */
630 if (isset($_POST['mailedit'])){
632 /* Save ldap attributes */
633 plugin::save_object();
635 $tmp= "";
636 if (!isset($_POST["drop_own_mails"])){
637 $tmp.= "L";
638 }
639 if (isset($_POST["use_mailsize_limit"])){
640 $tmp.= "R";
641 }
642 if (isset($_POST["use_spam_filter"])){
643 $tmp.= "S";
644 }
645 if (isset($_POST["use_vacation"])){
646 $tmp.= "V";
647 }
648 if (isset($_POST["own_script"])){
649 $tmp.= "C";
650 }
651 if (isset($_POST["only_local"])){
652 $tmp.= "I";
653 }
654 $tmp= "[$tmp]";
656 if (chkacl ($this->acl, "gosaMailDeliveryMode") == ""){
657 $this->gosaMailDeliveryMode= $tmp;
658 }
660 /* Collect data and re-assign it to the imapacl array */
661 if (chkacl($this->acl, "permissions") == ""){
662 $this->imapacl= array();
663 $this->imapacl['%members%']= $_POST['member_permissions'];
664 $this->imapacl['anyone']= $_POST['default_permissions'];
665 foreach ($this->indexed_user as $nr => $user){
666 if (!isset($_POST["user_$nr"])){
667 continue;
668 }
669 if ($_POST["user_$nr"] != $user ||
670 $_POST["perm_$nr"] != $this->indexed_acl[$nr]){
671 $this->is_modified= TRUE;
672 }
673 $this->imapacl[$_POST["user_$nr"]]= $_POST["perm_$nr"];
674 }
675 }
676 }
678 }
682 /* Save data to LDAP, depending on is_account we save or delete */
683 function save()
684 {
685 $ldap= $this->config->get_ldap_link();
686 $ldap->cd($this->config->current['BASE']);
688 /* Call parents save to prepare $this->attrs */
689 plugin::save();
691 /* Save arrays */
692 $this->attrs['gosaMailAlternateAddress'] = $this->gosaMailAlternateAddress;
693 $this->attrs['gosaMailForwardingAddress'] = $this->gosaMailForwardingAddress;
695 /* Save shared folder target */
696 if(preg_match("/kolab/i",$this->mmethod)){
697 /* Kolab style */
698 $this->attrs['gosaSharedFolderTarget']= "kolab+shared.".$this->uid;
699 }else {
700 /* GOsa style */
701 $this->attrs['gosaSharedFolderTarget']= "share+".$this->uid;
702 }
704 if(preg_match("/kolab/i",$this->mmethod)){
705 /* Save acl's */
706 $this->attrs['acl']= array();
707 foreach ($this->imapacl as $user => $acl){
708 if ($user == ""){
709 continue;
710 }
711 $ldap->search("(&(objectClass=person)(|(uid=".$user.")(mail=".$user.")))",array("mail"));
712 $mail = $ldap->fetch();
713 if($mail){
714 if(isset($mail['mail'][0])){
715 $this->attrs['acl'][]= $mail['mail'][0]." $acl";
716 }
717 }else{
718 $this->attrs['acl'][]= "$user $acl";
719 }
720 }
721 }else{
722 /* Save acl's */
723 $this->attrs['acl']= array();
724 foreach ($this->imapacl as $user => $acl){
725 if ($user == ""){
726 continue;
727 }
728 $this->attrs['acl'][]= "$user $acl";
729 }
730 }
732 /* Only do IMAP actions if we are not a template */
733 if(preg_match("/kolab/i",$this->mmethod)){
734 if (empty($this->gosaMailServer)||is_array($this->gosaMailServer)){
735 if(isset($this->attrs['gosaMailServer'][0])){
736 $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
737 }
738 }
739 }
742 if ((!$this->is_template)&&(!empty($this->gosaMailServer))){
743 $method= new $this->method($this->config);
744 $method->fixAttributesOnStore($this);
745 if (($method->connect($this->gosaMailServer))){
746 $method->updateMailbox($this->uid);
747 $method->setQuota($this->uid, $this->gosaMailQuota);
748 $method->setSharedFolderPermissions($this->uid, $this->imapacl);
749 $method->disconnect();
750 }
751 }
753 /* Exchange '%member%' pseudo entry */
754 $memberacl= $this->imapacl['%members%'];
756 foreach ($this->members as $user){
757 if(preg_match("/kolab/i",$this->mmethod)){
758 $ldap->cd($this->config->current['BASE']);
759 $ldap->search("(&(objectClass=person)(|(mail=".$user.")(uid=".$user.")))",array("mail"));
760 $at = $ldap->fetch();
761 if(isset($at['mail'][0])){
762 $user = $at['mail'][0];
763 }
764 }
765 if (!isset($this->imapacl[$user])){
766 $this->imapacl[$user]= $memberacl;
767 }
768 }
769 $this->attrs['acl'] = array();
770 foreach($this->imapacl as $user => $acl){
771 if(preg_match("/%members%/",$user) || empty($user)) continue;
773 $this->attrs['acl'][] = $user." ".$acl;
774 }
776 /* Save data to LDAP */
777 $ldap->cd($this->dn);
778 $this->cleanup();
779 $ldap->modify ($this->attrs);
781 show_ldap_error($ldap->get_error());
783 /* Optionally execute a command after we're done */
784 if ($this->initially_was_account == $this->is_account){
785 if ($this->is_modified){
786 $this->handle_post_events("mofify");
787 }
788 } else {
789 $this->handle_post_events("add");
790 }
791 }
793 /* Check formular input */
794 function check()
795 {
796 $ldap= $this->config->get_ldap_link();
798 /* Call common method to give check the hook */
799 $message= plugin::check();
801 if(!$this->is_account) return array();
803 //$message[] = $str;
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 function getCopyDialog()
953 {
954 if(!$this->is_account) return("");
956 $smarty = get_smarty();
957 $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress);
958 $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress);
959 $smarty->assign("mail",$this->mail);
960 $display= $smarty->fetch (get_template_path('paste_mail.tpl', TRUE));
961 $ret = array();
962 $ret['string'] = $display;
963 $ret['status'] = "";
964 return($ret);
965 }
967 function saveCopyDialog()
968 {
969 if(!$this->is_account) return;
971 /* Perform ADD / REMOVE ... for mail alternate / mail forwarding addresses
972 */
973 $this->execute();
974 if(isset($_POST['mail'])){
975 $this->mail = $_POST['mail'];
976 }
977 }
980 }
982 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
983 ?>