58c2a5e663b9deb832da6b62c4bf0ae398395979
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 /* Only do IMAP actions if we are not a template */
782 if(preg_match("/olab/i",$this->mmethod)){
783 if (empty($this->gosaMailServer)||is_array($this->gosaMailServer)){
784 if(isset($this->attrs['gosaMailServer'][0])){
785 $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
786 }
787 }
788 }
790 /* Exchange '%member%' pseudo entry */
791 $memberacl= $this->imapacl['%members%'];
793 foreach ($this->members as $user){
794 if (!isset($this->imapacl[$user])){
795 $this->imapacl[$user]= $memberacl;
796 }
797 }
799 if(preg_match("/olab/i",$this->mmethod)){
801 /* Save acl's */
802 $this->attrs['acl']= array();
803 foreach ($this->imapacl as $user => $acl){
804 if ($user == "" || preg_match("/%members%/",$user)){
805 continue;
806 }
807 $ldap->search("(&(objectClass=person)(|(uid=".$user.")(mail=".$user.")))",array("mail"));
808 $mail = $ldap->fetch();
809 if(isset($mail['mail'][0])){
810 $sacl = $mail['mail'][0]." ".$acl;
811 }else{
812 $sacl= "$user $acl";
813 }
814 if(!in_array($sacl,$this->attrs['acl'])){
815 $this->attrs['acl'][]= $sacl;
816 }
817 }
819 if(!empty($this->kolabFolderType_Type)){
820 $this->attrs['kolabFolderType'] = $this->kolabFolderType_Type.".".$this->kolabFolderType_SubType;
821 }else{
822 $this->attrs['kolabFolderType'] = array();
823 }
824 }else{
826 /* Save acl's */
827 $this->attrs['acl']= array();
828 foreach ($this->imapacl as $user => $acl){
829 if ($user == "" || preg_match("/%members%/",$user)){
830 continue;
831 }
832 $this->attrs['acl'][]= "$user $acl";
833 }
834 }
836 if ((!$this->is_template)&&(!empty($this->gosaMailServer))){
837 $method= new $this->method($this->config);
838 $method->fixAttributesOnStore($this);
839 if (($method->connect($this->gosaMailServer))){
840 $method->updateMailbox($this->uid);
841 $method->setQuota($this->uid, $this->gosaMailQuota);
842 $method->setSharedFolderPermissions($this->uid, $this->imapacl);
843 $method->disconnect();
844 }
845 }
847 /* Save data to LDAP */
848 $ldap->cd($this->dn);
849 $this->cleanup();
850 $ldap->modify ($this->attrs);
851 show_ldap_error($ldap->get_error(), _("Saving group mail settings failed"));
853 /* Optionally execute a command after we're done */
854 if ($this->initially_was_account == $this->is_account){
855 if ($this->is_modified){
856 $this->handle_post_events("modify");
857 }
858 } else {
859 $this->handle_post_events("add");
860 }
861 }
863 /* Check formular input */
864 function check()
865 {
866 $ldap= $this->config->get_ldap_link();
868 /* Call common method to give check the hook */
869 $message= plugin::check();
871 if(!$this->is_account) return array();
873 //$message[] = $str;
875 /* must: mail */
876 if ($this->mail == ""){
877 $message[]= _("The required field 'Primary address' is not set.");
878 }
879 if (!is_email($this->mail)){
880 $message[]= _("Please enter a valid email addres in 'Primary address' field.");
881 }
882 $ldap->cd($this->config->current['BASE']);
883 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=".$this->mail.")(gosaMailAlternateAddress=".
884 $this->mail."))(!(uid=".$this->orig_cn."))(!(cn=".$this->orig_cn.")))");
885 if ($ldap->count() != 0){
886 $message[]= _("The primary address you've entered is already in use.");
887 }
889 /* Check quota */
890 if ($this->gosaMailQuota != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
891 if (!is_numeric($this->gosaMailQuota)) {
892 $message[]= _("Value in 'Quota size' is not valid.");
893 } else {
894 $this->gosaMailQuota= (int) $this->gosaMailQuota;
895 }
896 }
898 /* Check rejectsize for integer */
899 if ($this->gosaMailMaxSize != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
900 if (!is_numeric($this->gosaMailMaxSize)){
901 $message[]= _("Please specify a vaild mail size for mails to be rejected.");
902 } else {
903 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
904 }
905 }
907 /* Need gosaMailMaxSize if use_mailsize_limit is checked */
908 if (is_integer(strpos($this->gosaMailDeliveryMode, "reject")) && $this->gosaMailMaxSize == ""){
909 $message[]= _("You need to set the maximum mail size in order to reject anything.");
910 }
912 if(ord($this->imapacl['anyone'][0])==194){
913 $message[] = _("Please choose valid permission settings. Default permission can't be emtpy.");
914 }
916 if(empty($this->gosaMailServer)){
917 $message[] = _("Please select a valid mail server.");
918 }
920 return ($message);
921 }
923 /* Adapt from template, using 'dn' */
924 function adapt_from_template($dn)
925 {
926 plugin::adapt_from_template($dn);
928 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
929 $this->$val= array();
930 if (isset($this->attrs["$val"]["count"])){
931 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
932 $value= $this->attrs["$val"][$i];
933 foreach (array("sn", "givenName", "uid") as $repl){
934 if (preg_match("/%$repl/i", $value)){
935 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
936 }
937 }
938 array_push($this->$val, $value);
939 }
940 }
941 }
942 }
944 /* Add entry to forwarder list */
945 function addForwarder($address)
946 {
947 $this->gosaMailForwardingAddress[]= $address;
948 $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
950 sort ($this->gosaMailForwardingAddress);
951 reset ($this->gosaMailForwardingAddress);
952 $this->is_modified= TRUE;
953 }
955 /* Remove list of addresses from forwarder list */
956 function delForwarder($addresses)
957 {
958 $this->gosaMailForwardingAddress= array_remove_entries ($addresses,
959 $this->gosaMailForwardingAddress);
960 $this->is_modified= TRUE;
961 }
965 function addAlternate($address)
966 {
967 $ldap= $this->config->get_ldap_link();
969 $address= strtolower($address);
971 /* Is this address already assigned in LDAP? */
972 $ldap->cd ($this->config->current['BASE']);
973 $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)".
974 "(gosaMailAlternateAddress=$address)))");
976 if ($ldap->count() > 0){
977 $attrs= $ldap->fetch ();
978 return ($attrs["uid"][0]);
979 }
981 /* Add to list of alternates */
982 if (!in_array($address, $this->gosaMailAlternateAddress)){
983 $this->gosaMailAlternateAddress[]= $address;
984 }
986 sort ($this->gosaMailAlternateAddress);
987 reset ($this->gosaMailAlternateAddress);
988 $this->is_modified= TRUE;
990 return ("");
991 }
994 function delAlternate($addresses)
995 {
996 $this->gosaMailAlternateAddress= array_remove_entries ($addresses,
997 $this->gosaMailAlternateAddress);
998 $this->is_modified= TRUE;
999 }
1002 function make_name($attrs)
1003 {
1004 $name= "";
1005 if (isset($attrs['sn'][0])){
1006 $name= $attrs['sn'][0];
1007 }
1008 if (isset($attrs['givenName'][0])){
1009 if ($name != ""){
1010 $name.= ", ".$attrs['givenName'][0];
1011 } else {
1012 $name.= $attrs['givenName'][0];
1013 }
1014 }
1015 if ($name != ""){
1016 $name.= " ";
1017 }
1019 return ($name);
1020 }
1022 function getCopyDialog()
1023 {
1024 if(!$this->is_account) return("");
1026 $smarty = get_smarty();
1027 $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress);
1028 $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress);
1029 $smarty->assign("mail",$this->mail);
1030 $display= $smarty->fetch (get_template_path('paste_mail.tpl', TRUE));
1031 $ret = array();
1032 $ret['string'] = $display;
1033 $ret['status'] = "";
1034 return($ret);
1035 }
1037 function saveCopyDialog()
1038 {
1039 if(!$this->is_account) return;
1041 /* Perform ADD / REMOVE ... for mail alternate / mail forwarding addresses
1042 */
1043 $this->execute();
1044 if(isset($_POST['mail'])){
1045 $this->mail = $_POST['mail'];
1046 }
1047 }
1049 function PrepareForCopyPaste($source)
1050 {
1051 plugin::PrepareForCopyPaste($source);
1053 /* Reset alternate mail addresses */
1054 $this->gosaMailAlternateAddress = array();
1055 }
1058 /* Remove given ACL for given member (uid,mail) ..
1059 */
1060 function removeUserAcl($index )
1061 {
1062 if(isset($this->imapacl[$index])){
1063 unset($this->imapacl[$index]);
1064 }
1065 }
1067 }
1068 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1069 ?>