f7dbb724a4282ce06e9ea3801ae6ad471107f63d
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 = ""; //
44 var $remove_folder_from_imap = true;
46 /* Helper */
47 var $indexed_acl= array();
48 var $indexed_user= array();
50 /* attribute list for save action */
51 var $attributes= array( "mail", "gosaMailServer", "gosaMailQuota", "gosaMailMaxSize",
52 "gosaMailAlternateAddress", "gosaMailForwardingAddress",
53 "gosaMailDeliveryMode", "gosaSpamSortLevel", "gosaSpamMailbox",
54 "acl","gosaSharedFolderTarget", "gosaVacationMessage");
56 var $objectclasses= array("gosaMailAccount");
59 function mailgroup ($config, $dn= NULL, $parent= NULL)
60 {
61 /* Initialise all available attributes ... if possible
62 */
63 plugin::plugin($config, $dn, $parent);
65 /* Set mailMethod to the one defined in gosa.conf
66 */
67 if (isset($this->config->current['MAILMETHOD'])){
68 $this->mmethod= $this->config->current['MAILMETHOD'];
69 }
71 /* Check if selected mail method exists
72 */
73 if (class_exists("mailMethod$this->mmethod")){
74 $this->method= "mailMethod$this->mmethod";
75 } else {
76 print_red(sprintf(_("There is no mail method '%s' specified in your gosa.conf available."), $this->mmethod));
77 }
79 /* Load Mailserver
80 */
81 if(isset($this->attrs['gosaMailServer'][0])){
82 $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
83 }
85 /* Convert cn to uid in case of existing entry
86 */
87 if (isset($this->attrs['cn'][0])){
88 $this->uid= $this->attrs['cn'][0];
89 }
92 /* If this ins't new mailgroup, read all required data from ldap
93 */
94 if (($dn != "new")&&($dn != NULL)){
96 /* Load attributes which represent multiple entries
97 */
98 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
99 $this->$val = array();
100 if (isset($this->attrs["$val"]["count"])){
101 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
102 array_push($this->$val, $this->attrs["$val"][$i]);
103 }
104 }
105 }
107 /* Only do IMAP actions if gosaMailServer attribute is set
108 */
109 if (isset ($this->attrs["gosaMailServer"][0])){
111 /* Create new instance of our defined mailclass
112 */
113 $method= new $this->method($this->config);
115 if ($method->connect($this->attrs["gosaMailServer"][0])){
118 /* Maybe the entry is not saved in new style, get
119 permissions from IMAP and convert them to acl attributes */
120 if (!isset($this->attrs['acl'])){
121 $this->imapacl= $method->getSharedFolderPermissions($this->uid);
123 /* Need to filter what a member acl could be... */
124 $vote= array();
125 $peak= 0;
126 $leader= "";
127 foreach ($this->imapacl as $user => $acl){
129 if ($user != "anyone" ){
130 if (!isset($vote[$acl])){
131 $vote[$acl]= 1;
132 } else {
133 $vote[$acl]++;
134 }
135 if ($vote[$acl] > $peak){
136 $leader= $acl;
137 $peek= $vote[$acl];
138 }
139 }
141 }
143 /* Highest count wins as %members%, remove all members
144 with the same acl */
145 if(!empty($leader)){
146 $this->imapacl['%members%']= $leader;
147 }
148 foreach ($this->imapacl as $user => $acl){
149 if ($this->acl == $leader && in_array($user, $this->attrs['memberUid'])){
150 unset($this->imapacl[$user]);
151 }
152 }
154 } // ENDE ! isset ($this->attrs['acl'])
156 /* Adapt attributes if needed */
157 $method->fixAttributesOnLoad($this);
159 /* get Quota */
160 $quota= $method->getQuota($this->uid);
162 /* Update quota values */
163 if(is_array($quota)){
164 if ($quota['gosaMailQuota'] == 2147483647){
165 $this->quotaUsage= "";
166 $this->gosaMailQuota= "";
167 } else {
168 $this->quotaUsage= $quota['quotaUsage'];
169 $this->gosaMailQuota= $quota['gosaMailQuota'];
170 }
171 }else{
172 $this->quotaUsage = "";
173 $this->gosaMailQuota = "";
174 // print_red(sprintf(_("Can't get quota information for '%s'."),$this->uid));
175 }
176 $method->disconnect();
177 } // ENDE $method->connect($this->attrs["gosaMailServer"][0])){
179 } // ENDE gosaMailServer
181 } // ENDE dn != "new"
184 /* Get global filter config */
185 if (!is_global("gmailfilter")){
186 $ui= get_userinfo();
187 $base= get_base_from_people($ui->dn);
188 $gmailfilter= array( "depselect" => $base,
189 "muser" => "",
190 "regex" => "*");
191 register_global("gmailfilter", $gmailfilter);
192 }
194 /* Load permissions */
195 $tmp = array();
196 if(preg_match("/kolab/i",$this->mmethod)){
197 $ldap = $this->config->get_ldap_link();
199 if (isset($this->attrs['acl'])){
201 for ($i= 0; $i<$this->attrs['acl']['count']; $i++){
202 list($user, $permission)= split(' ', $this->attrs['acl'][$i]);
204 /* Add to list */
205 $this->imapacl[$user]= $permission;
207 /* Get all user permissions sorted by acl, to detect the most used acl
208 This acl is then used for %members%
209 */
210 if ($user != "anyone" && $user != "%members%"){
211 $tmp[$permission][] = $user;
212 }
214 /* There is an entry in $this->imapacl like this this ...
215 $this->attrs['imapacl']['anyone'] = "p";
216 $this->attrs['imapacl']['%members%'] = "lprs";
217 $this->attrs['imapacl'][''] = ""; <------ This is used to diplay an empty
218 Field for special acls in our template.
219 If there is at least one special acl in out imapacl,
220 we don't need this entry anymore, because it is already displayed.
221 */
222 if ($user != "anyone" && $user != "%members%"){
223 unset($this->imapacl['']);
224 }
225 }
226 }
228 /* In this section we dectect which acl is tho most used
229 This will be used as %members% acl
230 */
231 $tmp2 = array();
232 foreach($tmp as $acl => $user){
233 $tmp2[count($tmp[$acl])]=$acl;
234 }
235 /* Most used at last
236 */
237 ksort($tmp2);
239 /* Assign last (most used acl) to %members% acl
240 */
241 $str = array_pop($tmp2);
242 if(!empty($str)) {
243 $this->imapacl['%members%']=$str;
244 }
246 /* Open ldap connection
247 */
248 $ldap = $this->config->get_ldap_link();
249 $ldap->cd($this->config->current['BASE']);
251 /* Remove those users, that use %members% acl && are member of this group. */
252 foreach($this->imapacl as $mail => $permission){
253 $ldap->search("(&(objectClass=person)(mail=".$mail."))",array("uid"));
254 $atr = $ldap->fetch();
255 if((isset($this->attrs['memberUid'])) && (is_array($this->attrs['memberUid']))){
256 if((isset($atr['uid'][0]))&&(in_array($atr['uid'][0],$this->attrs['memberUid']))&&($permission == $this->imapacl['%members%'])){
257 unset($this->imapacl[$mail]);
258 }
259 }
260 }
261 /* Append an empty entry, for special acl handling */
262 if(count($this->imapacl)==2){
263 $this->imapacl[''] ="";
264 }
266 }else{ // Not kolab
267 /* Load permissions */
268 if (isset($this->attrs['acl'])){
269 for ($i= 0; $i<$this->attrs['acl']['count']; $i++){
270 list($user, $permission)= split(' ', $this->attrs['acl'][$i]);
271 $this->imapacl[$user]= $permission;
272 if ($user != "anyone" && $user != "%members%"){
273 unset($this->imapacl['']);
274 }
275 }
276 }
277 }
279 /* Load Mailserver
280 */
281 if(isset($this->attrs['gosaMailServer'][0])){
282 $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
283 }
284 /* Fill translations */
285 $this->perms["lrs"]= _("read");
286 $this->perms["lrsp"]= _("post");
287 $this->perms["p"]= _("external post");
288 $this->perms["lrsip"]= _("append");
289 $this->perms["lrswipcd"]= _("write");
290 }
292 function execute()
293 {
294 /* Call parent execute */
295 //plugin::execute();
297 /* Load templating engine */
298 $smarty= get_smarty();
299 $display = "";
300 if ($_SESSION['js']==FALSE){
301 $smarty->assign("javascript", "false");
302 } else {
303 $smarty->assign("javascript", "true");
304 }
306 /* Do we need to flip is_account state? */
307 if (isset($_POST['modify_state'])){
308 $this->is_account= !$this->is_account;
309 }
311 /* Do we represent a valid account? */
312 if (!$this->is_account && $this->parent == NULL){
314 $display.= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
315 _("This 'dn' has no valid mail extensions.")."</b>";
316 return ($display);
317 }
319 /* Show tab dialog headers */
320 $display= "";
321 if ($this->parent != NULL){
322 if ($this->is_account){
323 $display= $this->show_header(_("Remove mail account"),
324 _("This account has mail features enabled. You can disable them by clicking below."));
325 } else {
326 $display.= $this->show_header(_("Create mail account"),
327 _("This account has mail features disabled. You can enable them by clicking below."));
329 /* Show checkbox that allows us to remove imap entry too*/
330 if($this->initially_was_account){
332 $c = "";
333 if($this->remove_folder_from_imap){
334 $c= " checked ";
335 }
337 $display .= "<h2>Shared folder delete options</h2>
338 <input class='center' type='checkbox' name='remove_folder_from_imap' value='1' ".$c."
339 title='"._("Remove shared folder from mail server database when entry gets removed in LDAP")."'>";
340 $display .= _("Remove the shared folder and all its contents after saving this account");
341 }
343 return ($display);
344 }
345 }
347 /* Add ACL? */
348 foreach ($this->indexed_user as $nr => $user){
349 if (isset($_POST["add_$nr"])){
350 $this->imapacl[""]= "l";
351 }
352 if (isset($_POST["del_$nr"])){
353 unset ($this->imapacl[$user]);
354 }
355 }
357 /* Trigger forward add dialog? */
358 if (isset($_POST['add_local_forwarder'])){
359 $this->forward_dialog= TRUE;
360 $this->dialog= TRUE;
361 }
363 /* Cancel forward add dialog? */
364 if (isset($_POST['add_locals_cancel'])){
365 $this->forward_dialog= FALSE;
366 $this->dialog= FALSE;
367 }
369 /* Finished adding of locals? */
370 if (isset($_POST['add_locals_finish'])){
371 if (count ($_POST['local_list']) &&
372 chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
374 /* Walk through list of forwarders, ignore own addresses */
375 foreach ($_POST['local_list'] as $val){
376 if (!in_array ($val, $this->gosaMailAlternateAddress) &&
377 $val != $this->mail){
379 $this->addForwarder($val);
380 }
381 }
382 }
383 $this->forward_dialog= FALSE;
384 $this->dialog= FALSE;
385 }
387 /* Add forward email addresses */
388 if (isset($_POST['add_forwarder'])){
389 if ($_POST['forward_address'] != ""){
391 /* Valid email address specified? */
392 $address= $_POST['forward_address'];
393 if (!is_email($address)){
395 print_red (_("You're trying to add an invalid email address ".
396 "to the list of forwarders."));
398 } elseif ($address == $this->mail
399 || in_array($address, $this->gosaMailAlternateAddress)) {
401 print_red (_("Adding your one of your own addresses to the forwarders makes no sense."));
403 } else {
405 /* Add it */
406 if (chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
407 $this->addForwarder ($address);
408 }
410 }
411 }
412 }
414 /* Delete forward email addresses */
415 if (isset($_POST['delete_forwarder'])){
416 if (count($_POST['forwarder_list'])
417 && chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
419 $this->delForwarder ($_POST['forwarder_list']);
420 }
421 }
423 /* Add alternate email addresses */
424 if (isset($_POST['add_alternate'])){
425 if ($_POST['alternate_address'] != "" &&
426 chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
428 if (!is_email($_POST['alternate_address'])){
429 print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
431 } elseif (($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
432 $ui= get_userinfo();
433 if ($user != $ui->username){
434 print_red (_("The address you're trying to add is already used by user")." '$user'.");
435 }
436 }
437 }
438 }
440 /* Delete alternate email addresses */
441 if (isset($_POST['delete_alternate']) && isset ($_POST['alternates_list'])){
442 if (count($_POST['alternates_list']) &&
443 chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
445 $this->delAlternate ($_POST['alternates_list']);
446 }
447 }
449 /* Show forward add dialog */
450 if ($this->forward_dialog){
451 $ldap= $this->config->get_ldap_link();
453 /* Save data */
454 $gmailfilter= get_global("gmailfilter");
455 foreach( array("depselect", "muser", "regex") as $type){
456 if (isset($_POST[$type])){
457 $gmailfilter[$type]= $_POST[$type];
458 }
459 }
460 if (isset($_GET['search'])){
461 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
462 if ($s == "**"){
463 $s= "*";
464 }
465 $gmailfilter['regex']= $s;
466 }
467 register_global("gmailfilter", $gmailfilter);
469 /* Get actual list */
470 $mailusers= array ();
471 if ($gmailfilter['regex'] != '*' && $gmailfilter['regex'] != ""){
472 $regex= $gmailfilter['regex'];
473 $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
474 } else {
475 $filter= "";
476 }
477 if ($gmailfilter['muser'] != ""){
478 $user= $gmailfilter['muser'];
479 $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
480 }
482 /* Add already present people to the filter */
483 $exclude= "";
484 foreach ($this->gosaMailForwardingAddress as $mail){
485 $exclude.= "(mail=$mail)";
486 }
487 if ($exclude != ""){
488 $filter.= "(!(|$exclude))";
489 }
491 $acl= array($this->config->current['BASE'] => ":all");
492 $res= get_list("(&(objectClass=gosaMailAccount)$filter)", $acl, $gmailfilter['depselect'],
493 array("sn", "mail", "givenName"), GL_SUBSEARCH | GL_SIZELIMIT);
494 $ldap->cd($gmailfilter['depselect']);
495 $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
496 error_reporting (0);
497 while ($attrs= $ldap->fetch()){
498 if(preg_match('/%/', $attrs['mail'][0])){
499 continue;
500 }
501 $name= $this->make_name($attrs);
502 $mailusers[$attrs['mail'][0]]= $name."<".
503 $attrs['mail'][0].">";
504 }
505 error_reporting (E_ALL);
506 natcasesort ($mailusers);
507 reset ($mailusers);
509 /* Show dialog */
510 $smarty->assign("search_image", get_template_path('images/search.png'));
511 $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
512 $smarty->assign("tree_image", get_template_path('images/tree.png'));
513 $smarty->assign("infoimage", get_template_path('images/info.png'));
514 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
515 $smarty->assign("mailusers", $mailusers);
516 $smarty->assign("deplist", $this->config->idepartments);
517 $smarty->assign("apply", apply_filter());
518 $smarty->assign("alphabet", generate_alphabet());
519 $smarty->assign("hint", print_sizelimit_warning());
520 foreach( array("depselect", "muser", "regex") as $type){
521 $smarty->assign("$type", $gmailfilter[$type]);
522 }
523 $smarty->assign("hint", print_sizelimit_warning());
524 $display.= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE));
525 return ($display);
526 }
528 /* Assemble normal permissions */
529 $smarty->assign("permissionsACL", chkacl($this->acl, "permissions"));
530 if (isset($this->imapacl['anyone'])){
531 $smarty->assign("default_permissions", $this->imapacl['anyone']);
532 }
533 $smarty->assign("member_permissions", "lrsp");
534 if (isset($this->imapacl['%members%'])){
535 $smarty->assign("member_permissions", $this->imapacl['%members%']);
536 }
538 /* Assemble extra attributes */
539 $perm= chkacl($this->acl, "permissions");
540 $tmp= "";
541 $nr= 0;
542 $count= count($this->imapacl);
543 $this->indexed_user= array();
544 $this->indexed_acl= array();
545 foreach($this->imapacl as $user => $acl){
546 if ($user != "anyone" && $user != "%members%"){
547 $tmp.= "<tr><td><input name=\"user_$nr\" size=20 maxlength=60 ".
548 "value=\"$user\" $perm></td><td><select size=\"1\" name=\"perm_$nr\" $perm>";
549 foreach ($this->perms as $key => $value){
550 if ($acl == $key){
551 $tmp.= "<option value=$key selected>$value</option>";
552 } else {
553 $tmp.= "<option value=$key>$value</option>";
554 }
555 }
556 $tmp.= "</select> ";
557 if ($nr == $count - 1){
558 $tmp.= "<input type=submit value=\""._("Add")."\" ".
559 "name=\"add_$nr\" $perm>";
560 }
561 if ($count > 3){
562 $tmp.= "<input type=submit value=\""._("Remove")."\" ".
563 "name=\"del_$nr\" $perm></td></tr>";
564 }
565 }
566 $this->indexed_user[$nr]= $user;
567 $this->indexed_acl[$nr++]= $acl;
568 }
569 $smarty->assign("plusattributes", $tmp);
571 /* Show main page */
572 $mailserver= array();
573 foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
574 $mailserver[]= $key;
575 }
576 $smarty->assign("mailServers", $mailserver);
577 foreach(array("gosaMailServer", "gosaMailQuota", "perms", "mail",
578 "gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
579 $smarty->assign("$val", $this->$val);
580 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
581 }
582 if (is_numeric($this->gosaMailQuota) && $this->gosaMailQuota != 0){
583 $smarty->assign("quotausage", progressbar(round(($this->quotaUsage * 100)/ $this->gosaMailQuota),100,15,true));
584 $smarty->assign("quotadefined", "true");
585 } else {
586 $smarty->assign("quotadefined", "false");
587 }
589 $display.= $smarty->fetch (get_template_path('mail.tpl', TRUE));
590 return ($display);
591 }
594 /* remove object from parent */
595 function remove_from_parent()
596 {
597 /* Added these ObjectClass and Attributes, because they were not
598 removed correctly, only in case of kolab ...
599 */
600 if(isset($this->config->current['MAILMETHOD'])&&preg_match("/kolab/i",$this->config->current['MAILMETHOD'])){
601 $this->attributes[]="acl";
602 $this->objectclasses[] = "kolabSharedFolder";
603 }
604 /* include global link_info */
605 $ldap= $this->config->get_ldap_link();
607 /* Remove and write to LDAP */
608 plugin::remove_from_parent();
610 /* Zero arrays */
611 $this->attrs['gosaMailAlternateAddress']= array();
612 $this->attrs['gosaMailForwardingAddress']= array();
613 $this->attrs['gosaSharedFolderTarget']= array();
615 /* Connect to IMAP server for account deletion */
616 if ($this->initially_was_account){
618 $method= new $this->method($this->config);
619 $method->fixAttributesOnRemove($this);
620 if ($method->connect($this->gosaMailServer) && $this->remove_folder_from_imap){
622 /* Remove account from IMAP server */
623 $method->deleteMailbox($this->uid);
624 $method->disconnect();
625 }
626 }
627 /* Keep uid */
628 unset ($this->attrs['uid']);
630 $ldap->cd($this->dn);
631 $ldap->modify ($this->attrs);
632 show_ldap_error($ldap->get_error(), _("Removing group mail settings failed"));
634 /* Optionally execute a command after we're done */
635 $this->handle_post_events("remove");
636 }
639 /* Save data to object */
640 function save_object()
641 {
643 /* Check if user wants to remove the shared folder from imap too */
644 if($this->initially_was_account && !$this->is_account){
645 if(isset($_POST['remove_folder_from_imap'])){
646 $this->remove_folder_from_imap = true;
647 }else{
648 $this->remove_folder_from_imap = false;
649 }
650 }
652 /* Assemble mail delivery mode
653 The mode field in ldap consists of values between braces, this must
654 be called when 'mail' is set, because checkboxes may not be set when
655 we're in some other dialog.
657 Example for gosaMailDeliveryMode [LR ]
658 L: Local delivery
659 R: Reject when exceeding mailsize limit
660 S: Use spam filter
661 V: Use vacation message
662 C: Use custom sieve script
663 I: Only insider delivery */
664 if (isset($_POST['mailedit'])){
666 /* Save ldap attributes */
667 plugin::save_object();
669 $tmp= "";
670 if (!isset($_POST["drop_own_mails"])){
671 $tmp.= "L";
672 }
673 if (isset($_POST["use_mailsize_limit"])){
674 $tmp.= "R";
675 }
676 if (isset($_POST["use_spam_filter"])){
677 $tmp.= "S";
678 }
679 if (isset($_POST["use_vacation"])){
680 $tmp.= "V";
681 }
682 if (isset($_POST["own_script"])){
683 $tmp.= "C";
684 }
685 if (isset($_POST["only_local"])){
686 $tmp.= "I";
687 }
688 $tmp= "[$tmp]";
690 if (chkacl ($this->acl, "gosaMailDeliveryMode") == ""){
691 $this->gosaMailDeliveryMode= $tmp;
692 }
694 /* Collect data and re-assign it to the imapacl array */
695 if (chkacl($this->acl, "permissions") == ""){
696 $this->imapacl= array();
697 $this->imapacl['%members%']= $_POST['member_permissions'];
698 $this->imapacl['anyone']= $_POST['default_permissions'];
699 foreach ($this->indexed_user as $nr => $user){
700 if (!isset($_POST["user_$nr"])){
701 continue;
702 }
703 if ($_POST["user_$nr"] != $user ||
704 $_POST["perm_$nr"] != $this->indexed_acl[$nr]){
705 $this->is_modified= TRUE;
706 }
707 $this->imapacl[$_POST["user_$nr"]]= $_POST["perm_$nr"];
708 }
709 }
710 }
712 }
716 /* Save data to LDAP, depending on is_account we save or delete */
717 function save()
718 {
719 $ldap= $this->config->get_ldap_link();
720 $ldap->cd($this->config->current['BASE']);
722 /* Call parents save to prepare $this->attrs */
723 plugin::save();
725 /* Save arrays */
726 $this->attrs['gosaMailAlternateAddress'] = $this->gosaMailAlternateAddress;
727 $this->attrs['gosaMailForwardingAddress'] = $this->gosaMailForwardingAddress;
728 $this->attrs['gosaSharedFolderTarget'] = "share+".$this->uid;
730 if(preg_match("/kolab/i",$this->mmethod)){
731 /* Save acl's */
732 $this->attrs['acl']= array();
733 foreach ($this->imapacl as $user => $acl){
734 if ($user == ""){
735 continue;
736 }
737 $ldap->search("(&(objectClass=person)(|(uid=".$user.")(mail=".$user.")))",array("mail"));
738 $mail = $ldap->fetch();
739 if($mail){
740 if(isset($mail['mail'][0])){
741 $this->attrs['acl'][]= $mail['mail'][0]." $acl";
742 }
743 }else{
744 $this->attrs['acl'][]= "$user $acl";
745 }
746 }
747 }else{
748 /* Save acl's */
749 $this->attrs['acl']= array();
750 foreach ($this->imapacl as $user => $acl){
751 if ($user == ""){
752 continue;
753 }
754 $this->attrs['acl'][]= "$user $acl";
755 }
756 }
758 /* Only do IMAP actions if we are not a template */
759 if(preg_match("/kolab/i",$this->mmethod)){
760 if (empty($this->gosaMailServer)||is_array($this->gosaMailServer)){
761 if(isset($this->attrs['gosaMailServer'][0])){
762 $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
763 }
764 }
765 }
768 if ((!$this->is_template)&&(!empty($this->gosaMailServer))){
769 $method= new $this->method($this->config);
770 $method->fixAttributesOnStore($this);
771 if (($method->connect($this->gosaMailServer))){
772 $method->updateMailbox($this->uid);
773 $method->setQuota($this->uid, $this->gosaMailQuota);
774 $method->setSharedFolderPermissions($this->uid, $this->imapacl);
775 $method->disconnect();
776 }
777 }
779 /* Exchange '%member%' pseudo entry */
780 $memberacl= $this->imapacl['%members%'];
782 foreach ($this->members as $user){
783 if(preg_match("/kolab/i",$this->mmethod)){
784 $ldap->cd($this->config->current['BASE']);
785 $ldap->search("(&(objectClass=person)(|(mail=".$user.")(uid=".$user.")))",array("mail"));
786 $at = $ldap->fetch();
787 if(isset($at['mail'][0])){
788 $user = $at['mail'][0];
789 }
790 }
791 if (!isset($this->imapacl[$user])){
792 $this->imapacl[$user]= $memberacl;
793 }
794 }
795 $this->attrs['acl'] = array();
796 foreach($this->imapacl as $user => $acl){
797 if(preg_match("/%members%/",$user) || empty($user)) continue;
799 $this->attrs['acl'][] = $user." ".$acl;
800 }
802 /* Save data to LDAP */
803 $ldap->cd($this->dn);
804 $this->cleanup();
805 $ldap->modify ($this->attrs);
806 show_ldap_error($ldap->get_error(), _("Saving group mail settings failed"));
808 /* Optionally execute a command after we're done */
809 if ($this->initially_was_account == $this->is_account){
810 if ($this->is_modified){
811 $this->handle_post_events("modify");
812 }
813 } else {
814 $this->handle_post_events("add");
815 }
816 }
818 /* Check formular input */
819 function check()
820 {
821 $ldap= $this->config->get_ldap_link();
823 /* Call common method to give check the hook */
824 $message= plugin::check();
826 if(!$this->is_account) return array();
828 //$message[] = $str;
830 /* must: mail */
831 if ($this->mail == ""){
832 $message[]= _("The required field 'Primary address' is not set.");
833 }
834 if (!is_email($this->mail)){
835 $message[]= _("Please enter a valid email addres in 'Primary address' field.");
836 }
837 $ldap->cd($this->config->current['BASE']);
838 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=".$this->mail.")(gosaMailAlternateAddress=".
839 $this->mail."))(!(uid=".$this->cn."))(!(cn=".$this->cn.")))");
840 if ($ldap->count() != 0){
841 $message[]= _("The primary address you've entered is already in use.");
842 }
844 /* Check quota */
845 if ($this->gosaMailQuota != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
846 if (!is_numeric($this->gosaMailQuota)) {
847 $message[]= _("Value in 'Quota size' is not valid.");
848 } else {
849 $this->gosaMailQuota= (int) $this->gosaMailQuota;
850 }
851 }
853 /* Check rejectsize for integer */
854 if ($this->gosaMailMaxSize != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
855 if (!is_numeric($this->gosaMailMaxSize)){
856 $message[]= _("Please specify a vaild mail size for mails to be rejected.");
857 } else {
858 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
859 }
860 }
862 /* Need gosaMailMaxSize if use_mailsize_limit is checked */
863 if (is_integer(strpos($this->gosaMailDeliveryMode, "reject")) && $this->gosaMailMaxSize == ""){
864 $message[]= _("You need to set the maximum mail size in order to reject anything.");
865 }
867 if(ord($this->imapacl['anyone'][0])==194){
868 $message[] = _("Please choose valid permission settings. Default permission can't be emtpy.");
869 }
871 if(empty($this->gosaMailServer)){
872 $message[] = _("Please select a valid mail server.");
873 }
875 return ($message);
876 }
878 /* Adapt from template, using 'dn' */
879 function adapt_from_template($dn)
880 {
881 plugin::adapt_from_template($dn);
883 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
884 $this->$val= array();
885 if (isset($this->attrs["$val"]["count"])){
886 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
887 $value= $this->attrs["$val"][$i];
888 foreach (array("sn", "givenName", "uid") as $repl){
889 if (preg_match("/%$repl/i", $value)){
890 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
891 }
892 }
893 array_push($this->$val, $value);
894 }
895 }
896 }
897 }
899 /* Add entry to forwarder list */
900 function addForwarder($address)
901 {
902 $this->gosaMailForwardingAddress[]= $address;
903 $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
905 sort ($this->gosaMailForwardingAddress);
906 reset ($this->gosaMailForwardingAddress);
907 $this->is_modified= TRUE;
908 }
910 /* Remove list of addresses from forwarder list */
911 function delForwarder($addresses)
912 {
913 $this->gosaMailForwardingAddress= array_remove_entries ($addresses,
914 $this->gosaMailForwardingAddress);
915 $this->is_modified= TRUE;
916 }
920 function addAlternate($address)
921 {
922 $ldap= $this->config->get_ldap_link();
924 $address= strtolower($address);
926 /* Is this address already assigned in LDAP? */
927 $ldap->cd ($this->config->current['BASE']);
928 $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)".
929 "(gosaMailAlternateAddress=$address)))");
931 if ($ldap->count() > 0){
932 $attrs= $ldap->fetch ();
933 return ($attrs["uid"][0]);
934 }
936 /* Add to list of alternates */
937 if (!in_array($address, $this->gosaMailAlternateAddress)){
938 $this->gosaMailAlternateAddress[]= $address;
939 }
941 sort ($this->gosaMailAlternateAddress);
942 reset ($this->gosaMailAlternateAddress);
943 $this->is_modified= TRUE;
945 return ("");
946 }
949 function delAlternate($addresses)
950 {
951 $this->gosaMailAlternateAddress= array_remove_entries ($addresses,
952 $this->gosaMailAlternateAddress);
953 $this->is_modified= TRUE;
954 }
957 function make_name($attrs)
958 {
959 $name= "";
960 if (isset($attrs['sn'][0])){
961 $name= $attrs['sn'][0];
962 }
963 if (isset($attrs['givenName'][0])){
964 if ($name != ""){
965 $name.= ", ".$attrs['givenName'][0];
966 } else {
967 $name.= $attrs['givenName'][0];
968 }
969 }
970 if ($name != ""){
971 $name.= " ";
972 }
974 return ($name);
975 }
977 function getCopyDialog()
978 {
979 if(!$this->is_account) return("");
981 $smarty = get_smarty();
982 $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress);
983 $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress);
984 $smarty->assign("mail",$this->mail);
985 $display= $smarty->fetch (get_template_path('paste_mail.tpl', TRUE));
986 $ret = array();
987 $ret['string'] = $display;
988 $ret['status'] = "";
989 return($ret);
990 }
992 function saveCopyDialog()
993 {
994 if(!$this->is_account) return;
996 /* Perform ADD / REMOVE ... for mail alternate / mail forwarding addresses
997 */
998 $this->execute();
999 if(isset($_POST['mail'])){
1000 $this->mail = $_POST['mail'];
1001 }
1002 }
1005 }
1007 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1008 ?>