8b5fa3c81cac479af99267ac5f86c3ef435cdab5
1 <?php
3 class mailgroup extends plugin
4 {
5 var $uid = ""; // User id
6 var $cn = ""; // cn
7 var $orig_cn = ""; // cn
9 var $method = "mailMethod"; // Used Mail method
10 var $mmethod = ""; // Contains the gosa.conf MAILMETHOD
11 var $mail = ""; // Default mail address
13 var $gosaMailAlternateAddress = array(); // Set default Alternate Mail Adresses to empty array
14 var $gosaMailForwardingAddress = array(); // Forwarding also empty
16 var $gosaMailServer = ""; // Selected mailserver
17 var $gosaMailQuota = ""; // Defined Quota
18 var $quotaUsage = 0; // Currently used quota
20 var $gosaVacationMessage = ""; // Vocation message
22 var $imapacl = array('anyone' => 'p', // Set acls for everyone
23 '%members%' => 'lrspw', // %members% are all group-members
24 '' => 'p'); // Every user added gets this right
27 var $gosaSpamSortLevel = "";
28 var $gosaSpamMailbox = "";
29 var $gosaSharedFolderTarget ;
31 var $forward_dialog = FALSE;
33 var $members = array(); // Group members
35 var $mailusers = array();
36 var $perms = array();
37 var $gosaMailDeliveryMode = "[L ]"; //
38 var $gosaMailMaxSize = ""; //
40 var $remove_folder_from_imap = true;
42 /* Helper */
43 var $indexed_acl= array();
44 var $indexed_user= array();
46 /* Copy & paste */
47 var $CopyPasteVars = array("quotaUsage","imapacl");
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");
57 var $kolabFolderType_SubType = "";
58 var $kolabFolderType_Type = "";
60 function mailgroup ($config, $dn= NULL, $parent= NULL)
61 {
62 /* Initialise all available attributes ... if possible
63 */
64 plugin::plugin($config, $dn, $parent);
66 /* Save initial cn */
67 $this->orig_cn = $this->cn;
69 /* Set mailMethod to the one defined in gosa.conf
70 */
71 if (isset($this->config->current['MAILMETHOD'])){
72 $this->mmethod= $this->config->current['MAILMETHOD'];
73 }
75 /* Check if selected mail method exists
76 */
77 if (class_exists("mailMethod$this->mmethod")){
78 $this->method= "mailMethod$this->mmethod";
79 } else {
80 print_red(sprintf(_("There is no mail method '%s' specified in your gosa.conf available."), $this->mmethod));
81 }
83 /* Load Mailserver
84 */
85 if(isset($this->attrs['gosaMailServer'][0])){
86 $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
87 }
89 /* Convert cn to uid in case of existing entry
90 */
91 if (isset($this->attrs['cn'][0])){
92 $this->uid= $this->attrs['cn'][0];
93 }
95 /* Get folder type */
96 if(isset($this->config->current['MAILMETHOD'])&&preg_match("/olab/i",$this->config->current['MAILMETHOD'])){
97 if(isset($this->attrs['kolabFolderType'])){
98 $tmp = split("\.",$this->attrs['kolabFolderType'][0]);
99 $this->kolabFolderType_Type = $tmp[0];
100 $this->kolabFolderType_SubType = $tmp[1];
101 }
102 }
104 /* If this ins't new mailgroup, read all required data from ldap
105 */
106 if (($dn != "new")&&($dn != NULL)){
108 /* Load attributes which represent multiple entries
109 */
110 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
111 $this->$val = array();
112 if (isset($this->attrs["$val"]["count"])){
113 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
114 array_push($this->$val, $this->attrs["$val"][$i]);
115 }
116 }
117 }
119 /* Only do IMAP actions if gosaMailServer attribute is set
120 */
121 if (isset ($this->attrs["gosaMailServer"][0])){
123 /* Create new instance of our defined mailclass
124 */
125 $method= new $this->method($this->config);
127 if ($method->connect($this->attrs["gosaMailServer"][0])){
130 /* Maybe the entry is not saved in new style, get
131 permissions from IMAP and convert them to acl attributes */
132 if (!isset($this->attrs['acl'])){
133 $this->imapacl= $method->getSharedFolderPermissions($this->uid);
135 /* Need to filter what a member acl could be... */
136 $vote= array();
137 $peak= 0;
138 $leader= "";
139 foreach ($this->imapacl as $user => $acl){
141 if ($user != "anyone" ){
142 if (!isset($vote[$acl])){
143 $vote[$acl]= 1;
144 } else {
145 $vote[$acl]++;
146 }
147 if ($vote[$acl] > $peak){
148 $leader= $acl;
149 $peek= $vote[$acl];
150 }
151 }
153 }
155 /* Highest count wins as %members%, remove all members
156 with the same acl */
157 if(!empty($leader)){
158 $this->imapacl['%members%']= $leader;
159 }
160 foreach ($this->imapacl as $user => $acl){
161 if ($this->acl == $leader && in_array($user, $this->attrs['memberUid'])){
162 unset($this->imapacl[$user]);
163 }
164 }
166 } // ENDE ! isset ($this->attrs['acl'])
168 /* Adapt attributes if needed */
169 $method->fixAttributesOnLoad($this);
171 /* get Quota */
172 $quota= $method->getQuota($this->uid);
174 /* Update quota values */
175 if(is_array($quota)){
176 if ($quota['gosaMailQuota'] == 2147483647){
177 $this->quotaUsage= "";
178 $this->gosaMailQuota= "";
179 } else {
180 $this->quotaUsage= $quota['quotaUsage'];
181 $this->gosaMailQuota= $quota['gosaMailQuota'];
182 }
183 }else{
184 $this->quotaUsage = "";
185 $this->gosaMailQuota = "";
186 // print_red(sprintf(_("Can't get quota information for '%s'."),$this->uid));
187 }
188 $method->disconnect();
189 } // ENDE $method->connect($this->attrs["gosaMailServer"][0])){
191 } // ENDE gosaMailServer
193 } // ENDE dn != "new"
196 /* Get global filter config */
197 if (!is_global("gmailfilter")){
198 $ui= get_userinfo();
199 $base= get_base_from_people($ui->dn);
200 $gmailfilter= array( "depselect" => $base,
201 "muser" => "",
202 "regex" => "*");
203 register_global("gmailfilter", $gmailfilter);
204 }
206 /* Load permissions */
207 $tmp = array();
208 if(preg_match("/olab/i",$this->mmethod)){
209 $ldap = $this->config->get_ldap_link();
211 if (isset($this->attrs['acl'])){
213 for ($i= 0; $i<$this->attrs['acl']['count']; $i++){
214 list($user, $permission)= split(' ', $this->attrs['acl'][$i]);
216 /* Add to list */
217 $this->imapacl[$user]= $permission;
219 /* Get all user permissions sorted by acl, to detect the most used acl
220 This acl is then used for %members%
221 */
222 if ($user != "anyone" && $user != "%members%"){
223 $tmp[$permission][] = $user;
224 }
226 /* There is an entry in $this->imapacl like this this ...
227 $this->attrs['imapacl']['anyone'] = "p";
228 $this->attrs['imapacl']['%members%'] = "lprs";
229 $this->attrs['imapacl'][''] = ""; <------ This is used to diplay an empty
230 Field for special acls in our template.
231 If there is at least one special acl in out imapacl,
232 we don't need this entry anymore, because it is already displayed.
233 */
234 if ($user != "anyone" && $user != "%members%"){
235 unset($this->imapacl['']);
236 }
237 }
238 }
240 /* In this section we dectect which acl is tho most used
241 This will be used as %members% acl
242 */
243 $tmp2 = array();
244 foreach($tmp as $acl => $user){
245 $tmp2[count($tmp[$acl])]=$acl;
246 }
247 /* Most used at last
248 */
249 ksort($tmp2);
251 /* Assign last (most used acl) to %members% acl
252 */
253 $str = array_pop($tmp2);
254 if(!empty($str)) {
255 $this->imapacl['%members%']=$str;
256 }
258 /* Open ldap connection
259 */
260 $ldap = $this->config->get_ldap_link();
261 $ldap->cd($this->config->current['BASE']);
263 /* Remove those users, that use %members% acl && are member of this group. */
264 foreach($this->imapacl as $mail => $permission){
265 $ldap->search("(&(objectClass=person)(mail=".$mail."))",array("uid"));
266 $atr = $ldap->fetch();
267 if((isset($this->attrs['memberUid'])) && (is_array($this->attrs['memberUid']))){
268 if((isset($atr['uid'][0]))&&(in_array($atr['uid'][0],$this->attrs['memberUid']))&&($permission == $this->imapacl['%members%'])){
269 unset($this->imapacl[$mail]);
270 }
271 }
272 }
273 /* Append an empty entry, for special acl handling */
274 if(count($this->imapacl)==2){
275 $this->imapacl[''] ="";
276 }
278 }else{ // Not kolab
279 /* Load permissions */
280 if (isset($this->attrs['acl'])){
281 for ($i= 0; $i<$this->attrs['acl']['count']; $i++){
282 list($user, $permission)= split(' ', $this->attrs['acl'][$i]);
283 $this->imapacl[$user]= $permission;
284 if ($user != "anyone" && $user != "%members%"){
285 unset($this->imapacl['']);
286 }
287 }
288 }
289 }
291 /* Load Mailserver
292 */
293 if(isset($this->attrs['gosaMailServer'][0])){
294 $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
295 }
296 /* Fill translations */
297 $this->perms["lrsw"]= _("read");
298 $this->perms["lrswp"]= _("post");
299 $this->perms["p"]= _("external post");
300 $this->perms["lrswip"]= _("append");
301 $this->perms["lrswipcd"]= _("write");
302 $this->perms["lrswipcda"]= _("admin");
303 $this->perms[""]= _("none");
304 }
306 function execute()
307 {
308 /* Call parent execute */
309 //plugin::execute();
311 /* Load templating engine */
312 $smarty= get_smarty();
313 $display = "";
314 if ($_SESSION['js']==FALSE){
315 $smarty->assign("javascript", "false");
316 } else {
317 $smarty->assign("javascript", "true");
318 }
320 /* Do we need to flip is_account state? */
321 if (isset($_POST['modify_state'])){
323 /* Onyl change account state if allowed */
324 if($this->is_account && $this->acl == "#all#"){
325 $this->is_account= !$this->is_account;
326 }elseif(!$this->is_account && chkacl($this->acl,"create") == ""){
327 $this->is_account= !$this->is_account;
328 }
329 }
331 /* Do we represent a valid account? */
332 if (!$this->is_account && $this->parent == NULL){
334 $display.= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
335 _("This 'dn' has no valid mail extensions.")."</b>";
336 return ($display);
337 }
339 /* Show tab dialog headers */
340 $display= "";
341 if ($this->parent != NULL){
342 if ($this->is_account){
343 $display= $this->show_header(_("Remove mail account"),
344 _("This account has mail features enabled. You can disable them by clicking below."));
345 } else {
346 $display.= $this->show_header(_("Create mail account"),
347 _("This account has mail features disabled. You can enable them by clicking below."));
349 /* Show checkbox that allows us to remove imap entry too*/
350 if($this->initially_was_account){
352 $c = "";
353 if($this->remove_folder_from_imap){
354 $c= " checked ";
355 }
357 $display .= "<h2>Shared folder delete options</h2>
358 <input class='center' type='checkbox' name='remove_folder_from_imap' value='1' ".$c."
359 title='"._("Remove shared folder from mail server database when entry gets removed in LDAP")."'>";
360 $display .= _("Remove the shared folder and all its contents after saving this account");
361 }
363 return ($display);
364 }
365 }
367 /* Add ACL? */
368 foreach ($this->indexed_user as $nr => $user){
369 if (isset($_POST["add_$nr"])){
370 $this->imapacl[""]= "l";
371 }
372 if (isset($_POST["del_$nr"])){
373 unset ($this->imapacl[$user]);
374 }
375 }
377 /* Trigger forward add dialog? */
378 if (isset($_POST['add_local_forwarder'])){
379 $this->forward_dialog= TRUE;
380 $this->dialog= TRUE;
381 }
383 /* Cancel forward add dialog? */
384 if (isset($_POST['add_locals_cancel'])){
385 $this->forward_dialog= FALSE;
386 $this->dialog= FALSE;
387 }
389 /* Finished adding of locals? */
390 if (isset($_POST['add_locals_finish'])){
391 if (count ($_POST['local_list']) &&
392 chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
394 /* Walk through list of forwarders, ignore own addresses */
395 foreach ($_POST['local_list'] as $val){
396 if (!in_array ($val, $this->gosaMailAlternateAddress) &&
397 $val != $this->mail){
399 $this->addForwarder($val);
400 }
401 }
402 }
403 $this->forward_dialog= FALSE;
404 $this->dialog= FALSE;
405 }
407 /* Add forward email addresses */
408 if (isset($_POST['add_forwarder'])){
409 if ($_POST['forward_address'] != ""){
411 /* Valid email address specified? */
412 $address= $_POST['forward_address'];
413 if (!is_email($address)){
415 print_red (_("You're trying to add an invalid email address ".
416 "to the list of forwarders."));
418 } elseif ($address == $this->mail
419 || in_array($address, $this->gosaMailAlternateAddress)) {
421 print_red (_("Adding your one of your own addresses to the forwarders makes no sense."));
423 } else {
425 /* Add it */
426 if (chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
427 $this->addForwarder ($address);
428 }
430 }
431 }
432 }
434 /* Delete forward email addresses */
435 if (isset($_POST['delete_forwarder'])){
436 if (count($_POST['forwarder_list'])
437 && chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
439 $this->delForwarder ($_POST['forwarder_list']);
440 }
441 }
443 /* Add alternate email addresses */
444 if (isset($_POST['add_alternate'])){
445 if ($_POST['alternate_address'] != "" &&
446 chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
448 if (!is_email($_POST['alternate_address'])){
449 print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
451 } elseif (($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
452 $ui= get_userinfo();
453 if ($user != $ui->username){
454 print_red (_("The address you're trying to add is already used by user")." '$user'.");
455 }
456 }
457 }
458 }
460 /* Delete alternate email addresses */
461 if (isset($_POST['delete_alternate']) && isset ($_POST['alternates_list'])){
462 if (count($_POST['alternates_list']) &&
463 chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
465 $this->delAlternate ($_POST['alternates_list']);
466 }
467 }
469 /* Show forward add dialog */
470 if ($this->forward_dialog){
471 $ldap= $this->config->get_ldap_link();
473 /* Save data */
474 $gmailfilter= get_global("gmailfilter");
475 foreach( array("depselect", "muser", "regex") as $type){
476 if (isset($_POST[$type])){
477 $gmailfilter[$type]= $_POST[$type];
478 }
479 }
480 if (isset($_GET['search'])){
481 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
482 if ($s == "**"){
483 $s= "*";
484 }
485 $gmailfilter['regex']= $s;
486 }
487 register_global("gmailfilter", $gmailfilter);
489 /* Get actual list */
490 $mailusers= array ();
491 if ($gmailfilter['regex'] != '*' && $gmailfilter['regex'] != ""){
492 $regex= $gmailfilter['regex'];
493 $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
494 } else {
495 $filter= "";
496 }
497 if ($gmailfilter['muser'] != ""){
498 $user= $gmailfilter['muser'];
499 $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
500 }
502 /* Add already present people to the filter */
503 $exclude= "";
504 foreach ($this->gosaMailForwardingAddress as $mail){
505 $exclude.= "(mail=$mail)";
506 }
507 if ($exclude != ""){
508 $filter.= "(!(|$exclude))";
509 }
511 $acl= array($this->config->current['BASE'] => ":all");
512 $res= get_list("(&(objectClass=gosaMailAccount)$filter)", $acl, $gmailfilter['depselect'],
513 array("sn", "mail", "givenName"), GL_SUBSEARCH | GL_SIZELIMIT);
514 $ldap->cd($gmailfilter['depselect']);
515 $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
516 error_reporting (0);
517 while ($attrs= $ldap->fetch()){
518 if(preg_match('/%/', $attrs['mail'][0])){
519 continue;
520 }
521 $name= $this->make_name($attrs);
522 $mailusers[$attrs['mail'][0]]= $name."<".
523 $attrs['mail'][0].">";
524 }
525 error_reporting (E_ALL);
526 natcasesort ($mailusers);
527 reset ($mailusers);
529 /* Show dialog */
530 $smarty->assign("search_image", get_template_path('images/search.png'));
531 $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
532 $smarty->assign("tree_image", get_template_path('images/tree.png'));
533 $smarty->assign("infoimage", get_template_path('images/info.png'));
534 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
535 $smarty->assign("mailusers", $mailusers);
536 $smarty->assign("deplist", $this->config->idepartments);
537 $smarty->assign("apply", apply_filter());
538 $smarty->assign("alphabet", generate_alphabet());
539 $smarty->assign("hint", print_sizelimit_warning());
540 foreach( array("depselect", "muser", "regex") as $type){
541 $smarty->assign("$type", $gmailfilter[$type]);
542 }
543 $smarty->assign("hint", print_sizelimit_warning());
544 $display.= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE));
545 return ($display);
546 }
548 /* Assemble normal permissions */
549 $smarty->assign("permissionsACL", chkacl($this->acl, "permissions"));
550 if (isset($this->imapacl['anyone'])){
551 $smarty->assign("default_permissions", $this->imapacl['anyone']);
552 }
553 $smarty->assign("member_permissions", "lrsp");
554 if (isset($this->imapacl['%members%'])){
555 $smarty->assign("member_permissions", $this->imapacl['%members%']);
556 }
558 /* Assemble extra attributes */
559 $perm= chkacl($this->acl, "permissions");
560 $tmp= "";
561 $nr= 0;
562 $count= count($this->imapacl);
563 $this->indexed_user= array();
564 $this->indexed_acl= array();
565 foreach($this->imapacl as $user => $acl){
566 if ($user != "anyone" && $user != "%members%"){
567 $tmp.= "<tr><td><input name=\"user_$nr\" size=20 maxlength=60 ".
568 "value=\"$user\" $perm></td><td><select size=\"1\" name=\"perm_$nr\" $perm>";
569 foreach ($this->perms as $key => $value){
570 if ($acl == $key){
571 $tmp.= "<option value=\"$key\" selected>$value</option>";
572 } else {
573 $tmp.= "<option value=\"$key\">$value</option>";
574 }
575 }
576 $tmp.= "</select> ";
577 if ($nr == $count - 1){
578 $tmp.= "<input type=submit value=\""._("Add")."\" ".
579 "name=\"add_$nr\" $perm>";
580 }
581 if ($count > 3){
582 $tmp.= "<input type=submit value=\""._("Remove")."\" ".
583 "name=\"del_$nr\" $perm></td></tr>";
584 }
585 }
586 $this->indexed_user[$nr]= $user;
587 $this->indexed_acl[$nr++]= $acl;
588 }
589 $smarty->assign("plusattributes", $tmp);
591 /* Show main page */
592 $mailserver= array();
593 foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
594 $mailserver[]= $key;
595 }
596 $smarty->assign("mailServers", $mailserver);
597 foreach(array("gosaMailServer", "gosaMailQuota", "perms", "mail",
598 "gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
599 $smarty->assign("$val", $this->$val);
600 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
601 }
602 if (is_numeric($this->gosaMailQuota) && $this->gosaMailQuota != 0){
603 $smarty->assign("quotausage", progressbar(round(($this->quotaUsage * 100)/ $this->gosaMailQuota),100,15,true));
604 $smarty->assign("quotadefined", "true");
605 } else {
606 $smarty->assign("quotadefined", "false");
607 }
609 if(isset($this->config->current['MAILMETHOD'])&&preg_match("/olab/i",$this->config->current['MAILMETHOD'])){
611 $smarty->assign("kolab", TRUE);
612 $smarty->assign("JS",$_SESSION['js']);
613 $smarty->assign("kolabFolderType_Types", array ( '' => _('Unspecified'), 'mail' => _('Mails'),
614 'task' => _('Tasks') , 'journal' => _('Journals'),
615 'calendar' => _('Calendar'), 'contact' => _('Contacts'),
616 'note' => _('Notes')));
617 if($this->kolabFolderType_Type == "mail"){
618 $smarty->assign("kolabFolderType_SubTypes", array(
619 '' => _('Unspecified'), 'inbox' => _("Inbox") ,
620 'drafts' => _("Drafts"), 'sentitems' => _("Sent items"),
621 'junkemail' => _("Junk mail")));
622 }else{
623 $smarty->assign("kolabFolderType_SubTypes", array( 'default' => _("Default")));
624 }
625 $smarty->assign("kolabFolderType_Type", $this->kolabFolderType_Type);
626 $smarty->assign("kolabFolderType_SubType", $this->kolabFolderType_SubType);
627 }else{
628 $smarty->assign("kolab", FALSE);
629 }
632 $display.= $smarty->fetch (get_template_path('mail.tpl', TRUE));
633 return ($display);
634 }
637 /* remove object from parent */
638 function remove_from_parent()
639 {
640 /* Added these ObjectClass and Attributes, because they were not
641 removed correctly, only in case of kolab ...
642 */
643 if(isset($this->config->current['MAILMETHOD'])&&preg_match("/olab/i",$this->config->current['MAILMETHOD'])){
644 $this->attributes[]="acl";
645 $this->objectclasses[] = "kolabSharedFolder";
646 }
647 /* include global link_info */
648 $ldap= $this->config->get_ldap_link();
650 /* Remove and write to LDAP */
651 plugin::remove_from_parent();
653 /* Zero arrays */
654 $this->attrs['gosaMailAlternateAddress']= array();
655 $this->attrs['gosaMailForwardingAddress']= array();
656 $this->attrs['gosaSharedFolderTarget']= array();
658 /* Connect to IMAP server for account deletion */
659 if ($this->initially_was_account){
661 $method= new $this->method($this->config);
662 $method->fixAttributesOnRemove($this);
663 if ($method->connect($this->gosaMailServer) && $this->remove_folder_from_imap){
665 /* Remove account from IMAP server */
666 $method->deleteMailbox($this->uid);
667 $method->disconnect();
668 }
669 }
670 /* Keep uid */
671 unset ($this->attrs['uid']);
673 $ldap->cd($this->dn);
674 $ldap->modify ($this->attrs);
675 show_ldap_error($ldap->get_error(), _("Removing group mail settings failed"));
677 /* Optionally execute a command after we're done */
678 $this->handle_post_events("remove");
679 }
682 /* Save data to object */
683 function save_object()
684 {
686 /* Add special kolab attributes */
687 if(isset($this->config->current['MAILMETHOD'])&&preg_match("/olab/i",$this->config->current['MAILMETHOD'])){
688 if(isset($_POST['kolabFolderType_Type'])){
689 $this->kolabFolderType_Type = get_post("kolabFolderType_Type");
690 $this->kolabFolderType_SubType = get_post("kolabFolderType_SubType");
691 }
692 }
694 /* Check if user wants to remove the shared folder from imap too */
695 if($this->initially_was_account && !$this->is_account){
696 if(isset($_POST['remove_folder_from_imap'])){
697 $this->remove_folder_from_imap = true;
698 }else{
699 $this->remove_folder_from_imap = false;
700 }
701 }
703 /* Assemble mail delivery mode
704 The mode field in ldap consists of values between braces, this must
705 be called when 'mail' is set, because checkboxes may not be set when
706 we're in some other dialog.
708 Example for gosaMailDeliveryMode [LR ]
709 L: Local delivery
710 R: Reject when exceeding mailsize limit
711 S: Use spam filter
712 V: Use vacation message
713 C: Use custom sieve script
714 I: Only insider delivery */
715 if (isset($_POST['mailedit'])){
717 /* Save ldap attributes */
718 plugin::save_object();
720 $tmp= "";
721 if (!isset($_POST["drop_own_mails"])){
722 $tmp.= "L";
723 }
724 if (isset($_POST["use_mailsize_limit"])){
725 $tmp.= "R";
726 }
727 if (isset($_POST["use_spam_filter"])){
728 $tmp.= "S";
729 }
730 if (isset($_POST["use_vacation"])){
731 $tmp.= "V";
732 }
733 if (isset($_POST["own_script"])){
734 $tmp.= "C";
735 }
736 if (isset($_POST["only_local"])){
737 $tmp.= "I";
738 }
739 $tmp= "[$tmp]";
741 if (chkacl ($this->acl, "gosaMailDeliveryMode") == ""){
742 $this->gosaMailDeliveryMode= $tmp;
743 }
745 /* Collect data and re-assign it to the imapacl array */
746 if (chkacl($this->acl, "permissions") == ""){
747 $this->imapacl= array();
748 $this->imapacl['%members%']= $_POST['member_permissions'];
749 $this->imapacl['anyone']= $_POST['default_permissions'];
750 foreach ($this->indexed_user as $nr => $user){
751 if (!isset($_POST["user_$nr"])){
752 continue;
753 }
754 if ($_POST["user_$nr"] != $user ||
755 $_POST["perm_$nr"] != $this->indexed_acl[$nr]){
756 $this->is_modified= TRUE;
757 }
758 $this->imapacl[$_POST["user_$nr"]]= $_POST["perm_$nr"];
759 }
760 }
761 }
763 }
767 /* Save data to LDAP, depending on is_account we save or delete */
768 function save()
769 {
770 $ldap= $this->config->get_ldap_link();
771 $ldap->cd($this->config->current['BASE']);
773 /* Call parents save to prepare $this->attrs */
774 plugin::save();
776 /* Save arrays */
777 $this->attrs['gosaMailAlternateAddress'] = $this->gosaMailAlternateAddress;
778 $this->attrs['gosaMailForwardingAddress'] = $this->gosaMailForwardingAddress;
779 $this->attrs['gosaSharedFolderTarget'] = "share+".$this->uid;
781 if(preg_match("/olab/i",$this->mmethod)){
782 /* Save acl's */
783 $this->attrs['acl']= array();
784 foreach ($this->imapacl as $user => $acl){
785 if ($user == ""){
786 continue;
787 }
788 $ldap->search("(&(objectClass=person)(|(uid=".$user.")(mail=".$user.")))",array("mail"));
789 $mail = $ldap->fetch();
790 if($mail){
791 if(isset($mail['mail'][0])){
792 $this->attrs['acl'][]= $mail['mail'][0]." $acl";
793 }
794 }else{
795 $this->attrs['acl'][]= "$user $acl";
796 }
797 }
799 if(!empty($this->kolabFolderType_Type)){
800 $this->attrs['kolabFolderType'] = $this->kolabFolderType_Type.".".$this->kolabFolderType_SubType;
801 }else{
802 $this->attrs['kolabFolderType'] = array();
803 }
804 }else{
805 /* Save acl's */
806 $this->attrs['acl']= array();
807 foreach ($this->imapacl as $user => $acl){
808 if ($user == ""){
809 continue;
810 }
811 $this->attrs['acl'][]= "$user $acl";
812 }
813 }
815 /* Only do IMAP actions if we are not a template */
816 if(preg_match("/olab/i",$this->mmethod)){
817 if (empty($this->gosaMailServer)||is_array($this->gosaMailServer)){
818 if(isset($this->attrs['gosaMailServer'][0])){
819 $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
820 }
821 }
822 }
825 /* Exchange '%member%' pseudo entry */
826 $memberacl= $this->imapacl['%members%'];
828 foreach ($this->members as $user){
829 if(preg_match("/olab/i",$this->mmethod)){
830 $ldap->cd($this->config->current['BASE']);
831 $ldap->search("(&(objectClass=person)(|(mail=".$user.")(uid=".$user.")))",array("mail"));
832 $at = $ldap->fetch();
833 if(isset($at['mail'][0])){
834 $user = $at['mail'][0];
835 }
836 }
837 if (!isset($this->imapacl[$user])){
838 $this->imapacl[$user]= $memberacl;
839 }
840 }
841 $this->attrs['acl'] = array();
844 foreach($this->imapacl as $user => $acl){
846 /* Remove empty user entry, to avoid entry like this im imap
847 * "" lrs
848 */
849 if(empty($user)){
850 unset($this->imapacl[$user]);
851 }
853 /* Skip invalid values */
854 if(preg_match("/%members%/",$user) || empty($user)){
855 continue;
856 }
858 /* Append ldap acl entries */
859 $this->attrs['acl'][] = $user." ".$acl;
860 }
862 if ((!$this->is_template)&&(!empty($this->gosaMailServer))){
863 $method= new $this->method($this->config);
864 $method->fixAttributesOnStore($this);
865 if (($method->connect($this->gosaMailServer))){
866 $method->updateMailbox($this->uid);
867 $method->setQuota($this->uid, $this->gosaMailQuota);
868 $method->setSharedFolderPermissions($this->uid, $this->imapacl);
869 $method->disconnect();
870 }
871 }
873 /* Save data to LDAP */
874 $ldap->cd($this->dn);
875 $this->cleanup();
876 $ldap->modify ($this->attrs);
877 show_ldap_error($ldap->get_error(), _("Saving group mail settings failed"));
879 /* Optionally execute a command after we're done */
880 if ($this->initially_was_account == $this->is_account){
881 if ($this->is_modified){
882 $this->handle_post_events("modify");
883 }
884 } else {
885 $this->handle_post_events("add");
886 }
887 }
889 /* Check formular input */
890 function check()
891 {
892 $ldap= $this->config->get_ldap_link();
894 /* Call common method to give check the hook */
895 $message= plugin::check();
897 if(!$this->is_account) return array();
899 //$message[] = $str;
901 /* must: mail */
902 if ($this->mail == ""){
903 $message[]= _("The required field 'Primary address' is not set.");
904 }
905 if (!is_email($this->mail)){
906 $message[]= _("Please enter a valid email addres in 'Primary address' field.");
907 }
908 $ldap->cd($this->config->current['BASE']);
909 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=".$this->mail.")(gosaMailAlternateAddress=".
910 $this->mail."))(!(uid=".$this->orig_cn."))(!(cn=".$this->orig_cn.")))");
911 if ($ldap->count() != 0){
912 $message[]= _("The primary address you've entered is already in use.");
913 }
915 /* Check quota */
916 if ($this->gosaMailQuota != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
917 if (!is_numeric($this->gosaMailQuota)) {
918 $message[]= _("Value in 'Quota size' is not valid.");
919 } else {
920 $this->gosaMailQuota= (int) $this->gosaMailQuota;
921 }
922 }
924 /* Check rejectsize for integer */
925 if ($this->gosaMailMaxSize != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
926 if (!is_numeric($this->gosaMailMaxSize)){
927 $message[]= _("Please specify a vaild mail size for mails to be rejected.");
928 } else {
929 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
930 }
931 }
933 /* Need gosaMailMaxSize if use_mailsize_limit is checked */
934 if (is_integer(strpos($this->gosaMailDeliveryMode, "reject")) && $this->gosaMailMaxSize == ""){
935 $message[]= _("You need to set the maximum mail size in order to reject anything.");
936 }
938 if(ord($this->imapacl['anyone'][0])==194){
939 $message[] = _("Please choose valid permission settings. Default permission can't be emtpy.");
940 }
942 if(empty($this->gosaMailServer)){
943 $message[] = _("Please select a valid mail server.");
944 }
946 return ($message);
947 }
949 /* Adapt from template, using 'dn' */
950 function adapt_from_template($dn)
951 {
952 plugin::adapt_from_template($dn);
954 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
955 $this->$val= array();
956 if (isset($this->attrs["$val"]["count"])){
957 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
958 $value= $this->attrs["$val"][$i];
959 foreach (array("sn", "givenName", "uid") as $repl){
960 if (preg_match("/%$repl/i", $value)){
961 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
962 }
963 }
964 array_push($this->$val, $value);
965 }
966 }
967 }
968 }
970 /* Add entry to forwarder list */
971 function addForwarder($address)
972 {
973 $this->gosaMailForwardingAddress[]= $address;
974 $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
976 sort ($this->gosaMailForwardingAddress);
977 reset ($this->gosaMailForwardingAddress);
978 $this->is_modified= TRUE;
979 }
981 /* Remove list of addresses from forwarder list */
982 function delForwarder($addresses)
983 {
984 $this->gosaMailForwardingAddress= array_remove_entries ($addresses,
985 $this->gosaMailForwardingAddress);
986 $this->is_modified= TRUE;
987 }
991 function addAlternate($address)
992 {
993 $ldap= $this->config->get_ldap_link();
995 $address= strtolower($address);
997 /* Is this address already assigned in LDAP? */
998 $ldap->cd ($this->config->current['BASE']);
999 $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)".
1000 "(gosaMailAlternateAddress=$address)))");
1002 if ($ldap->count() > 0){
1003 $attrs= $ldap->fetch ();
1004 return ($attrs["uid"][0]);
1005 }
1007 /* Add to list of alternates */
1008 if (!in_array($address, $this->gosaMailAlternateAddress)){
1009 $this->gosaMailAlternateAddress[]= $address;
1010 }
1012 sort ($this->gosaMailAlternateAddress);
1013 reset ($this->gosaMailAlternateAddress);
1014 $this->is_modified= TRUE;
1016 return ("");
1017 }
1020 function delAlternate($addresses)
1021 {
1022 $this->gosaMailAlternateAddress= array_remove_entries ($addresses,
1023 $this->gosaMailAlternateAddress);
1024 $this->is_modified= TRUE;
1025 }
1028 function make_name($attrs)
1029 {
1030 $name= "";
1031 if (isset($attrs['sn'][0])){
1032 $name= $attrs['sn'][0];
1033 }
1034 if (isset($attrs['givenName'][0])){
1035 if ($name != ""){
1036 $name.= ", ".$attrs['givenName'][0];
1037 } else {
1038 $name.= $attrs['givenName'][0];
1039 }
1040 }
1041 if ($name != ""){
1042 $name.= " ";
1043 }
1045 return ($name);
1046 }
1048 function getCopyDialog()
1049 {
1050 if(!$this->is_account) return("");
1052 $smarty = get_smarty();
1053 $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress);
1054 $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress);
1055 $smarty->assign("mail",$this->mail);
1056 $display= $smarty->fetch (get_template_path('paste_mail.tpl', TRUE));
1057 $ret = array();
1058 $ret['string'] = $display;
1059 $ret['status'] = "";
1060 return($ret);
1061 }
1063 function saveCopyDialog()
1064 {
1065 if(!$this->is_account) return;
1067 /* Perform ADD / REMOVE ... for mail alternate / mail forwarding addresses
1068 */
1069 $this->execute();
1070 if(isset($_POST['mail'])){
1071 $this->mail = $_POST['mail'];
1072 }
1073 }
1075 function PrepareForCopyPaste($source)
1076 {
1077 plugin::PrepareForCopyPaste($source);
1079 /* Reset alternate mail addresses */
1080 $this->gosaMailAlternateAddress = array();
1081 }
1082 }
1083 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1084 ?>