41e0eae4e28111375c554715c6496ff35a37e75e
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(
23 '%members%' => 'lrspw', // %members% are all group-members
24 'anyone' => 'p', // Set acls for everyone
25 '' => 'p'); // Every user added gets this right
28 var $gosaSpamSortLevel = "";
29 var $gosaSpamMailbox = "";
30 var $gosaSharedFolderTarget ;
32 var $forward_dialog = FALSE;
34 var $members = array(); // Group members
36 var $mailusers = array();
37 var $perms = array();
38 var $gosaMailDeliveryMode = "[L ]"; //
39 var $gosaMailMaxSize = ""; //
41 var $remove_folder_from_imap = true;
43 /* Helper */
44 var $indexed_acl= array();
45 var $indexed_user= array();
47 /* Copy & paste */
48 var $CopyPasteVars = array("quotaUsage","imapacl");
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");
58 var $kolabFolderType_SubType = "";
59 var $kolabFolderType_Type = "";
61 function mailgroup ($config, $dn= NULL, $parent= NULL)
62 {
63 /* Initialise all available attributes ... if possible
64 */
65 plugin::plugin($config, $dn, $parent);
67 /* Save initial cn */
68 $this->orig_cn = $this->cn;
70 /* Set mailMethod to the one defined in gosa.conf
71 */
72 if (isset($this->config->current['MAILMETHOD'])){
73 $this->mmethod= $this->config->current['MAILMETHOD'];
74 }
76 /* Check if selected mail method exists
77 */
78 if (class_exists("mailMethod$this->mmethod")){
79 $this->method= "mailMethod$this->mmethod";
80 } else {
81 print_red(sprintf(_("There is no mail method '%s' specified in your gosa.conf available."), $this->mmethod));
82 }
84 /* Load Mailserver
85 */
86 if(isset($this->attrs['gosaMailServer'][0])){
87 $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
88 }
90 /* Convert cn to uid in case of existing entry
91 */
92 if (isset($this->attrs['cn'][0])){
93 $this->uid= $this->attrs['cn'][0];
94 }
96 /* Get folder type */
97 if(isset($this->config->current['MAILMETHOD'])&&preg_match("/olab/i",$this->config->current['MAILMETHOD'])){
98 if(isset($this->attrs['kolabFolderType'])){
99 $tmp = split("\.",$this->attrs['kolabFolderType'][0]);
100 $this->kolabFolderType_Type = $tmp[0];
101 $this->kolabFolderType_SubType = $tmp[1];
102 }
103 }
105 /* If this ins't new mailgroup, read all required data from ldap
106 */
107 if (($dn != "new")&&($dn != NULL)){
109 /* Load attributes which represent multiple entries
110 */
111 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
112 $this->$val = array();
113 if (isset($this->attrs["$val"]["count"])){
114 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
115 array_push($this->$val, $this->attrs["$val"][$i]);
116 }
117 }
118 }
120 /* Only do IMAP actions if gosaMailServer attribute is set
121 */
122 if (isset ($this->attrs["gosaMailServer"][0])){
124 /* Create new instance of our defined mailclass
125 */
126 $method= new $this->method($this->config);
128 if ($method->connect($this->attrs["gosaMailServer"][0])){
131 /* Maybe the entry is not saved in new style, get
132 permissions from IMAP and convert them to acl attributes */
133 if (!isset($this->attrs['acl'])){
134 $this->imapacl= $method->getSharedFolderPermissions($this->uid);
136 /* Need to filter what a member acl could be... */
137 $vote= array();
138 $peak= 0;
139 $leader= "";
140 foreach ($this->imapacl as $user => $acl){
142 if ($user != "anyone" ){
143 if (!isset($vote[$acl])){
144 $vote[$acl]= 1;
145 } else {
146 $vote[$acl]++;
147 }
148 if ($vote[$acl] > $peak){
149 $leader= $acl;
150 $peek= $vote[$acl];
151 }
152 }
154 }
156 /* Highest count wins as %members%, remove all members
157 with the same acl */
158 if(!empty($leader)){
159 $this->imapacl['%members%']= $leader;
160 }
161 foreach ($this->imapacl as $user => $acl){
162 if ($this->acl == $leader && in_array($user, $this->attrs['memberUid'])){
163 unset($this->imapacl[$user]);
164 }
165 }
167 } // ENDE ! isset ($this->attrs['acl'])
169 /* Adapt attributes if needed */
170 $method->fixAttributesOnLoad($this);
172 /* get Quota */
173 $quota= $method->getQuota($this->uid);
175 /* Update quota values */
176 if(is_array($quota)){
177 if ($quota['gosaMailQuota'] == 2147483647){
178 $this->quotaUsage= "";
179 $this->gosaMailQuota= "";
180 } else {
181 $this->quotaUsage= $quota['quotaUsage'];
182 $this->gosaMailQuota= $quota['gosaMailQuota'];
183 }
184 }else{
185 $this->quotaUsage = "";
186 $this->gosaMailQuota = "";
187 // print_red(sprintf(_("Can't get quota information for '%s'."),$this->uid));
188 }
189 $method->disconnect();
190 } // ENDE $method->connect($this->attrs["gosaMailServer"][0])){
192 } // ENDE gosaMailServer
194 } // ENDE dn != "new"
197 /* Get global filter config */
198 if (!is_global("gmailfilter")){
199 $ui= get_userinfo();
200 $base= get_base_from_people($ui->dn);
201 $gmailfilter= array( "depselect" => $base,
202 "muser" => "",
203 "regex" => "*");
204 register_global("gmailfilter", $gmailfilter);
205 }
207 /* Load permissions */
208 $tmp = array();
209 if(preg_match("/olab/i",$this->mmethod)){
210 $ldap = $this->config->get_ldap_link();
212 if (isset($this->attrs['acl'])){
214 for ($i= 0; $i<$this->attrs['acl']['count']; $i++){
215 list($user, $permission)= split(' ', $this->attrs['acl'][$i]);
217 /* Add to list */
218 $this->imapacl[$user]= $permission;
220 /* Get all user permissions sorted by acl, to detect the most used acl
221 This acl is then used for %members%
222 */
223 if ($user != "anyone" && $user != "%members%"){
224 $tmp[$permission][] = $user;
225 }
227 /* There is an entry in $this->imapacl like this this ...
228 $this->attrs['imapacl']['anyone'] = "p";
229 $this->attrs['imapacl']['%members%'] = "lprs";
230 $this->attrs['imapacl'][''] = ""; <------ This is used to diplay an empty
231 Field for special acls in our template.
232 If there is at least one special acl in out imapacl,
233 we don't need this entry anymore, because it is already displayed.
234 */
235 if ($user != "anyone" && $user != "%members%"){
236 unset($this->imapacl['']);
237 }
238 }
239 }
240 }else{
241 foreach($this->imapacl as $user => $permission){
242 if ($user != "anyone" && $user != "%members%"){
243 $tmp[$permission][] = $user;
244 }
245 if ($user != "anyone" && $user != "%members%"){
246 unset($this->imapacl['']);
247 }
248 }
249 }
252 /**
253 * Detect group member with same acl and replace them with %members%
254 **/
256 /* In this section we dectect which acl is tho most used
257 This will be used as %members% acl
258 */
259 $tmp2 = array();
260 foreach($tmp as $acl => $user){
261 $tmp2[count($tmp[$acl])]=$acl;
262 }
263 /* Most used at last
264 */
265 ksort($tmp2);
267 /* Assign last (most used acl) to %members% acl
268 */
269 $str = array_pop($tmp2);
270 if(!empty($str)) {
271 $this->imapacl['%members%']=$str;
272 }
274 /* Open ldap connection
275 */
276 $ldap = $this->config->get_ldap_link();
277 $ldap->cd($this->config->current['BASE']);
279 /* Remove those users, that use %members% acl && are member of this group. */
280 foreach($this->imapacl as $mail => $permission){
281 $ldap->search("(&(objectClass=person)(|(mail=".$mail.")(uid=".$mail.")))",array("uid"));
282 $atr = $ldap->fetch();
283 if((isset($this->attrs['memberUid'])) && (is_array($this->attrs['memberUid']))){
284 if((isset($atr['uid'][0]))&&(in_array($atr['uid'][0],$this->attrs['memberUid']))&&($permission == $this->imapacl['%members%'])){
285 unset($this->imapacl[$mail]);
286 }
287 }
288 }
290 /**
291 * ENDE: Detect group member with same acl and replace them with %members%
292 **/
293 $this->indexed_user = array("%members%","anyone");
295 /* Append an empty entry, for special acl handling */
296 if(count($this->imapacl)==2){
297 $this->imapacl[''] ="lrsw";
298 $this->indexed_user[] = '';
299 }
301 /* Load Mailserver
302 */
303 if(isset($this->attrs['gosaMailServer'][0])){
304 $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
305 }
306 /* Fill translations */
307 $this->perms["lrsw"]= _("read");
308 $this->perms["lrswp"]= _("post");
309 $this->perms["p"]= _("external post");
310 $this->perms["lrswip"]= _("append");
311 $this->perms["lrswipcd"]= _("write");
312 $this->perms["lrswipcda"]= _("admin");
313 $this->perms[""]= _("none");
314 }
316 function execute()
317 {
318 /* Call parent execute */
319 //plugin::execute();
321 /* Load templating engine */
322 $smarty= get_smarty();
323 $display = "";
324 if ($_SESSION['js']==FALSE){
325 $smarty->assign("javascript", "false");
326 } else {
327 $smarty->assign("javascript", "true");
328 }
330 /* Do we need to flip is_account state? */
331 if (isset($_POST['modify_state'])){
333 /* Onyl change account state if allowed */
334 if($this->is_account && $this->acl == "#all#"){
335 $this->is_account= !$this->is_account;
336 }elseif(!$this->is_account && chkacl($this->acl,"create") == ""){
337 $this->is_account= !$this->is_account;
338 }
339 }
341 /* Do we represent a valid account? */
342 if (!$this->is_account && $this->parent == NULL){
344 $display.= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
345 _("This 'dn' has no valid mail extensions.")."</b>";
346 return ($display);
347 }
349 /* Show tab dialog headers */
350 $display= "";
351 if ($this->parent != NULL){
352 if ($this->is_account){
353 $display= $this->show_header(_("Remove mail account"),
354 _("This account has mail features enabled. You can disable them by clicking below."));
355 } else {
356 $display.= $this->show_header(_("Create mail account"),
357 _("This account has mail features disabled. You can enable them by clicking below."));
359 /* Show checkbox that allows us to remove imap entry too*/
360 if($this->initially_was_account){
362 $c = "";
363 if($this->remove_folder_from_imap){
364 $c= " checked ";
365 }
367 $display .= "<h2>Shared folder delete options</h2>
368 <input class='center' type='checkbox' name='remove_folder_from_imap' value='1' ".$c."
369 title='"._("Remove shared folder from mail server database when entry gets removed in LDAP")."'>";
370 $display .= _("Remove the shared folder and all its contents after saving this account");
371 }
373 return ($display);
374 }
375 }
377 /* Add ACL? */
378 if (isset($_POST["add_acl"])){
379 $this->imapacl[""]= "lrsw";
380 $this->indexed_user[] = "";
381 }
382 foreach ($this->indexed_user as $nr => $user){
383 if (isset($_POST["del_$nr"])){
384 unset ($this->imapacl[$user]);
385 }
386 }
388 /* Trigger forward add dialog? */
389 if (isset($_POST['add_local_forwarder'])){
390 $this->forward_dialog= TRUE;
391 $this->dialog= TRUE;
392 }
394 /* Cancel forward add dialog? */
395 if (isset($_POST['add_locals_cancel'])){
396 $this->forward_dialog= FALSE;
397 $this->dialog= FALSE;
398 }
400 /* Finished adding of locals? */
401 if (isset($_POST['add_locals_finish'])){
402 if (count ($_POST['local_list']) &&
403 chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
405 /* Walk through list of forwarders, ignore own addresses */
406 foreach ($_POST['local_list'] as $val){
407 if (!in_array ($val, $this->gosaMailAlternateAddress) &&
408 $val != $this->mail){
410 $this->addForwarder($val);
411 }
412 }
413 }
414 $this->forward_dialog= FALSE;
415 $this->dialog= FALSE;
416 }
418 /* Add forward email addresses */
419 if (isset($_POST['add_forwarder'])){
420 if ($_POST['forward_address'] != ""){
422 /* Valid email address specified? */
423 $address= $_POST['forward_address'];
424 if (!is_email($address)){
426 print_red (_("You're trying to add an invalid email address ".
427 "to the list of forwarders."));
429 } elseif ($address == $this->mail
430 || in_array($address, $this->gosaMailAlternateAddress)) {
432 print_red (_("Adding your one of your own addresses to the forwarders makes no sense."));
434 } else {
436 /* Add it */
437 if (chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
438 $this->addForwarder ($address);
439 }
441 }
442 }
443 }
445 /* Delete forward email addresses */
446 if (isset($_POST['delete_forwarder'])){
447 if (count($_POST['forwarder_list'])
448 && chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
450 $this->delForwarder ($_POST['forwarder_list']);
451 }
452 }
454 /* Add alternate email addresses */
455 if (isset($_POST['add_alternate'])){
456 if ($_POST['alternate_address'] != "" &&
457 chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
459 if (!is_email($_POST['alternate_address'])){
460 print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
462 } elseif (($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
463 $ui= get_userinfo();
464 if ($user != $ui->username){
465 print_red (_("The address you're trying to add is already used by user")." '$user'.");
466 }
467 }
468 }
469 }
471 /* Delete alternate email addresses */
472 if (isset($_POST['delete_alternate']) && isset ($_POST['alternates_list'])){
473 if (count($_POST['alternates_list']) &&
474 chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
476 $this->delAlternate ($_POST['alternates_list']);
477 }
478 }
480 /* Show forward add dialog */
481 if ($this->forward_dialog){
482 $ldap= $this->config->get_ldap_link();
484 /* Save data */
485 $gmailfilter= get_global("gmailfilter");
486 foreach( array("depselect", "muser", "regex") as $type){
487 if (isset($_POST[$type])){
488 $gmailfilter[$type]= $_POST[$type];
489 }
490 }
491 if (isset($_GET['search'])){
492 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
493 if ($s == "**"){
494 $s= "*";
495 }
496 $gmailfilter['regex']= $s;
497 }
498 register_global("gmailfilter", $gmailfilter);
500 /* Get actual list */
501 $mailusers= array ();
502 if ($gmailfilter['regex'] != '*' && $gmailfilter['regex'] != ""){
503 $regex= $gmailfilter['regex'];
504 $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
505 } else {
506 $filter= "";
507 }
508 if ($gmailfilter['muser'] != ""){
509 $user= $gmailfilter['muser'];
510 $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
511 }
513 /* Add already present people to the filter */
514 $exclude= "";
515 foreach ($this->gosaMailForwardingAddress as $mail){
516 $exclude.= "(mail=$mail)";
517 }
518 if ($exclude != ""){
519 $filter.= "(!(|$exclude))";
520 }
522 $acl= array($this->config->current['BASE'] => ":all");
523 $res= get_list("(&(objectClass=gosaMailAccount)$filter)", $acl, $gmailfilter['depselect'],
524 array("sn", "mail", "givenName"), GL_SUBSEARCH | GL_SIZELIMIT);
525 $ldap->cd($gmailfilter['depselect']);
526 $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
527 error_reporting (0);
528 while ($attrs= $ldap->fetch()){
529 if(preg_match('/%/', $attrs['mail'][0])){
530 continue;
531 }
532 $name= $this->make_name($attrs);
533 $mailusers[$attrs['mail'][0]]= $name."<".
534 $attrs['mail'][0].">";
535 }
536 error_reporting (E_ALL);
537 natcasesort ($mailusers);
538 reset ($mailusers);
540 /* Show dialog */
541 $smarty->assign("search_image", get_template_path('images/search.png'));
542 $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
543 $smarty->assign("tree_image", get_template_path('images/tree.png'));
544 $smarty->assign("infoimage", get_template_path('images/info.png'));
545 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
546 $smarty->assign("mailusers", $mailusers);
547 $smarty->assign("deplist", $this->config->idepartments);
548 $smarty->assign("apply", apply_filter());
549 $smarty->assign("alphabet", generate_alphabet());
550 $smarty->assign("hint", print_sizelimit_warning());
551 foreach( array("depselect", "muser", "regex") as $type){
552 $smarty->assign("$type", $gmailfilter[$type]);
553 }
554 $smarty->assign("hint", print_sizelimit_warning());
555 $display.= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE));
556 return ($display);
557 }
559 /* Assemble normal permissions */
560 $smarty->assign("permissionsACL", chkacl($this->acl, "permissions"));
561 if (isset($this->imapacl['anyone'])){
562 $smarty->assign("default_permissions", $this->imapacl['anyone']);
563 }
564 $smarty->assign("member_permissions", "lrsp");
565 if (isset($this->imapacl['%members%'])){
566 $smarty->assign("member_permissions", $this->imapacl['%members%']);
567 }
569 /* Assemble extra attributes */
570 $perm= chkacl($this->acl, "permissions");
571 $tmp= "";
572 $nr= 0;
573 $count= count($this->imapacl);
574 $this->indexed_user= array();
575 $this->indexed_acl= array();
576 foreach($this->imapacl as $user => $acl){
577 if ($user != "anyone" && $user != "%members%"){
578 $tmp.= "<tr><td><input name=\"user_$nr\" size=20 maxlength=60 ".
579 "value=\"$user\" $perm></td><td><select size=\"1\" name=\"perm_$nr\" $perm>";
580 foreach ($this->perms as $key => $value){
581 if ($acl == $key){
582 $tmp.= "<option value=\"$key\" selected>$value</option>";
583 } else {
584 $tmp.= "<option value=\"$key\">$value</option>";
585 }
586 }
587 $tmp.= "</select> ";
588 if ($nr == $count - 1){
589 }
590 if ($count > 2){
591 $tmp.= "<input type=submit value=\""._("Remove")."\" ".
592 "name=\"del_$nr\" $perm></td></tr>";
593 }
594 }
595 $this->indexed_user[$nr]= $user;
596 $this->indexed_acl[$nr++]= $acl;
597 }
598 $tmp.= "<tr><td></td><td></td><td><input type=submit value='"._("Add")."' name='add_acl' $perm>";
599 $smarty->assign("plusattributes", $tmp);
601 /* Show main page */
602 $mailserver= array();
603 foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
604 $mailserver[]= $key;
605 }
606 $smarty->assign("mailServers", $mailserver);
607 foreach(array("gosaMailServer", "gosaMailQuota", "perms", "mail",
608 "gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
609 $smarty->assign("$val", $this->$val);
610 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
611 }
612 if (is_numeric($this->gosaMailQuota) && $this->gosaMailQuota != 0){
613 $smarty->assign("quotausage", progressbar(round(($this->quotaUsage * 100)/ $this->gosaMailQuota),100,15,true));
614 $smarty->assign("quotadefined", "true");
615 } else {
616 $smarty->assign("quotadefined", "false");
617 }
619 if(isset($this->config->current['MAILMETHOD'])&&preg_match("/olab/i",$this->config->current['MAILMETHOD'])){
621 $smarty->assign("kolab", TRUE);
622 $smarty->assign("JS",$_SESSION['js']);
623 $smarty->assign("kolabFolderType_Types", array ( '' => _('Unspecified'), 'mail' => _('Mails'),
624 'task' => _('Tasks') , 'journal' => _('Journals'),
625 'calendar' => _('Calendar'), 'contact' => _('Contacts'),
626 'note' => _('Notes')));
627 if($this->kolabFolderType_Type == "mail"){
628 $smarty->assign("kolabFolderType_SubTypes", array(
629 '' => _('Unspecified'), 'inbox' => _("Inbox") ,
630 'drafts' => _("Drafts"), 'sentitems' => _("Sent items"),
631 'junkemail' => _("Junk mail")));
632 }else{
633 $smarty->assign("kolabFolderType_SubTypes", array( 'default' => _("Default")));
634 }
635 $smarty->assign("kolabFolderType_Type", $this->kolabFolderType_Type);
636 $smarty->assign("kolabFolderType_SubType", $this->kolabFolderType_SubType);
637 }else{
638 $smarty->assign("kolab", FALSE);
639 }
642 $display.= $smarty->fetch (get_template_path('mail.tpl', TRUE));
643 return ($display);
644 }
647 /* remove object from parent */
648 function remove_from_parent()
649 {
650 /* Added these ObjectClass and Attributes, because they were not
651 removed correctly, only in case of kolab ...
652 */
653 if(isset($this->config->current['MAILMETHOD'])&&preg_match("/olab/i",$this->config->current['MAILMETHOD'])){
654 $this->attributes[]="acl";
655 $this->objectclasses[] = "kolabSharedFolder";
656 }
657 /* include global link_info */
658 $ldap= $this->config->get_ldap_link();
660 /* Remove and write to LDAP */
661 plugin::remove_from_parent();
663 /* Zero arrays */
664 $this->attrs['gosaMailAlternateAddress']= array();
665 $this->attrs['gosaMailForwardingAddress']= array();
666 $this->attrs['gosaSharedFolderTarget']= array();
668 /* Connect to IMAP server for account deletion */
669 if ($this->initially_was_account){
671 $method= new $this->method($this->config);
672 $method->fixAttributesOnRemove($this);
673 if ($method->connect($this->gosaMailServer) && $this->remove_folder_from_imap){
675 /* Remove account from IMAP server */
676 $method->deleteMailbox($this->uid);
677 $method->disconnect();
678 }
679 }
680 /* Keep uid */
681 unset ($this->attrs['uid']);
683 $ldap->cd($this->dn);
684 $ldap->modify ($this->attrs);
685 show_ldap_error($ldap->get_error(), _("Removing group mail settings failed"));
687 /* Optionally execute a command after we're done */
688 $this->handle_post_events("remove");
689 }
692 /* Save data to object */
693 function save_object()
694 {
696 /* Add special kolab attributes */
697 if(isset($this->config->current['MAILMETHOD'])&&preg_match("/olab/i",$this->config->current['MAILMETHOD'])){
698 if(isset($_POST['kolabFolderType_Type'])){
699 $this->kolabFolderType_Type = get_post("kolabFolderType_Type");
700 $this->kolabFolderType_SubType = get_post("kolabFolderType_SubType");
701 }
702 }
704 /* Check if user wants to remove the shared folder from imap too */
705 if($this->initially_was_account && !$this->is_account){
706 if(isset($_POST['remove_folder_from_imap'])){
707 $this->remove_folder_from_imap = true;
708 }else{
709 $this->remove_folder_from_imap = false;
710 }
711 }
713 /* Assemble mail delivery mode
714 The mode field in ldap consists of values between braces, this must
715 be called when 'mail' is set, because checkboxes may not be set when
716 we're in some other dialog.
718 Example for gosaMailDeliveryMode [LR ]
719 L: Local delivery
720 R: Reject when exceeding mailsize limit
721 S: Use spam filter
722 V: Use vacation message
723 C: Use custom sieve script
724 I: Only insider delivery */
725 if (isset($_POST['mailedit'])){
727 /* Save ldap attributes */
728 plugin::save_object();
730 $tmp= "";
731 if (!isset($_POST["drop_own_mails"])){
732 $tmp.= "L";
733 }
734 if (isset($_POST["use_mailsize_limit"])){
735 $tmp.= "R";
736 }
737 if (isset($_POST["use_spam_filter"])){
738 $tmp.= "S";
739 }
740 if (isset($_POST["use_vacation"])){
741 $tmp.= "V";
742 }
743 if (isset($_POST["own_script"])){
744 $tmp.= "C";
745 }
746 if (isset($_POST["only_local"])){
747 $tmp.= "I";
748 }
749 $tmp= "[$tmp]";
751 if (chkacl ($this->acl, "gosaMailDeliveryMode") == ""){
752 $this->gosaMailDeliveryMode= $tmp;
753 }
755 /* Collect data and re-assign it to the imapacl array */
756 if (chkacl($this->acl, "permissions") == ""){
757 $this->imapacl= array();
758 $this->imapacl['%members%']= $_POST['member_permissions'];
759 $this->imapacl['anyone']= $_POST['default_permissions'];
760 foreach ($this->indexed_user as $nr => $user){
761 if (!isset($_POST["user_$nr"])){
762 continue;
763 }
764 if ($_POST["user_$nr"] != $user ||
765 $_POST["perm_$nr"] != $this->indexed_acl[$nr]){
766 $this->is_modified= TRUE;
767 }
768 $this->imapacl[$_POST["user_$nr"]]= $_POST["perm_$nr"];
769 $this->indexed_user[$nr] = $_POST["user_$nr"];
770 }
771 }
772 }
773 }
776 /* Save data to LDAP, depending on is_account we save or delete */
777 function save()
778 {
779 $ldap= $this->config->get_ldap_link();
780 $ldap->cd($this->config->current['BASE']);
782 /* Call parents save to prepare $this->attrs */
783 plugin::save();
785 /* Save arrays */
786 $this->attrs['gosaMailAlternateAddress'] = $this->gosaMailAlternateAddress;
787 $this->attrs['gosaMailForwardingAddress'] = $this->gosaMailForwardingAddress;
788 $this->attrs['gosaSharedFolderTarget'] = "share+".$this->uid;
790 /* Only do IMAP actions if we are not a template */
791 if(preg_match("/olab/i",$this->mmethod)){
792 if (empty($this->gosaMailServer)||is_array($this->gosaMailServer)){
793 if(isset($this->attrs['gosaMailServer'][0])){
794 $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
795 }
796 }
797 }
799 /* Exchange '%member%' pseudo entry */
800 $memberacl= $this->imapacl['%members%'];
801 foreach ($this->members as $user){
802 if (!isset($this->imapacl[$user])){
803 $this->imapacl[$user]= $memberacl;
804 }
805 }
807 /* Prepare kolab attributes to be written */
808 if(preg_match("/olab/i",$this->mmethod)){
809 $this->attrs['acl']= array();
810 if(!empty($this->kolabFolderType_Type)){
811 $this->attrs['kolabFolderType'] = $this->kolabFolderType_Type.".".$this->kolabFolderType_SubType;
812 }else{
813 $this->attrs['kolabFolderType'] = array();
814 }
815 }else{
816 $this->attrs['acl']= array();;
817 unset($this->attrs['acl']);
818 }
820 /* Get naming attribute for mail accounts */
821 $tmp = new $this->method($this->config);
822 $uattrib = $tmp->uattrib;
824 /* Create ACL array
825 * In case of kolab also create attrs['acl'] to save acls in ldap.
826 */
827 foreach ($this->imapacl as $user => $acl){
829 if (empty($user) || $user == ""){
830 unset($this->imapacl[$user]);
831 }
833 /* Skip placeholder */
834 if (empty($user) || $user == "" || preg_match("/%members%/",$user)){
835 continue;
836 }
838 /* Check if your is a real GOsa user
839 * If user is a real GOsa user but do not have an email address - SKIP adding acls
840 * If user is a real GOsa user with an emal address - add acls
841 */
842 $ldap->search("(&(objectClass=person)(|(uid=".$user.")(mail=".$user.")))",array("mail","uid"));
843 if($ldap->count()){
844 $attrs = $ldap->fetch();
846 /* Has the user a valid mail account? */
847 if(isset($attrs['mail'][0])){
849 $name = $attrs[$uattrib][0];
851 /* In case of kolab methods add acl attribute too */
852 if(preg_match("/olab/i",$this->mmethod)){
853 $this->attrs['acl'][]= $name." ".$acl;
854 unset($this->imapacl[$user]);
855 }
856 $this->imapacl[$name] = $acl;
857 }else{
859 /* User has no mail extension */
860 unset($this->imapacl[$user]);
861 }
862 }else{
863 /* Seems to be a manually added acl */
865 /* In case of kolab methods add acl attribute too */
866 if(preg_match("/olab/i",$this->mmethod)){
867 $this->attrs['acl'][]= $user." ".$acl;
868 }
869 $this->imapacl[$user] = $acl;
870 }
871 }
873 if ((!$this->is_template)&&(!empty($this->gosaMailServer))){
874 $method= new $this->method($this->config);
875 $method->fixAttributesOnStore($this);
876 if (($method->connect($this->gosaMailServer))){
877 $method->updateMailbox($this->uid);
878 $method->setQuota($this->uid, $this->gosaMailQuota);
879 $method->setSharedFolderPermissions($this->uid, $this->imapacl);
880 $method->disconnect();
881 }
882 }
884 /* Save data to LDAP */
885 $ldap->cd($this->dn);
886 $this->cleanup();
887 $ldap->modify ($this->attrs);
888 show_ldap_error($ldap->get_error(), _("Saving group mail settings failed"));
890 /* Optionally execute a command after we're done */
891 if ($this->initially_was_account == $this->is_account){
892 if ($this->is_modified){
893 $this->handle_post_events("modify");
894 }
895 } else {
896 $this->handle_post_events("add");
897 }
898 }
900 /* Check formular input */
901 function check()
902 {
903 $ldap= $this->config->get_ldap_link();
905 /* Call common method to give check the hook */
906 $message= plugin::check();
908 if(!$this->is_account) return array();
910 //$message[] = $str;
912 /* must: mail */
913 if ($this->mail == ""){
914 $message[]= _("The required field 'Primary address' is not set.");
915 }
916 if (!is_email($this->mail)){
917 $message[]= _("Please enter a valid email addres in 'Primary address' field.");
918 }
919 $ldap->cd($this->config->current['BASE']);
920 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=".$this->mail.")(gosaMailAlternateAddress=".
921 $this->mail."))(!(uid=".$this->orig_cn."))(!(cn=".$this->orig_cn.")))");
922 if ($ldap->count() != 0){
923 $message[]= _("The primary address you've entered is already in use.");
924 }
926 /* Check quota */
927 if ($this->gosaMailQuota != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
928 if (!is_numeric($this->gosaMailQuota)) {
929 $message[]= _("Value in 'Quota size' is not valid.");
930 } else {
931 $this->gosaMailQuota= (int) $this->gosaMailQuota;
932 }
933 }
935 /* Check rejectsize for integer */
936 if ($this->gosaMailMaxSize != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
937 if (!is_numeric($this->gosaMailMaxSize)){
938 $message[]= _("Please specify a vaild mail size for mails to be rejected.");
939 } else {
940 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
941 }
942 }
944 /* Need gosaMailMaxSize if use_mailsize_limit is checked */
945 if (is_integer(strpos($this->gosaMailDeliveryMode, "reject")) && $this->gosaMailMaxSize == ""){
946 $message[]= _("You need to set the maximum mail size in order to reject anything.");
947 }
949 if(ord($this->imapacl['anyone'][0])==194){
950 $message[] = _("Please choose valid permission settings. Default permission can't be emtpy.");
951 }
953 if(empty($this->gosaMailServer)){
954 $message[] = _("Please select a valid mail server.");
955 }
957 return ($message);
958 }
960 /* Adapt from template, using 'dn' */
961 function adapt_from_template($dn)
962 {
963 plugin::adapt_from_template($dn);
965 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
966 $this->$val= array();
967 if (isset($this->attrs["$val"]["count"])){
968 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
969 $value= $this->attrs["$val"][$i];
970 foreach (array("sn", "givenName", "uid") as $repl){
971 if (preg_match("/%$repl/i", $value)){
972 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
973 }
974 }
975 array_push($this->$val, $value);
976 }
977 }
978 }
979 }
981 /* Add entry to forwarder list */
982 function addForwarder($address)
983 {
984 $this->gosaMailForwardingAddress[]= $address;
985 $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
987 sort ($this->gosaMailForwardingAddress);
988 reset ($this->gosaMailForwardingAddress);
989 $this->is_modified= TRUE;
990 }
992 /* Remove list of addresses from forwarder list */
993 function delForwarder($addresses)
994 {
995 $this->gosaMailForwardingAddress= array_remove_entries ($addresses,
996 $this->gosaMailForwardingAddress);
997 $this->is_modified= TRUE;
998 }
1002 function addAlternate($address)
1003 {
1004 $ldap= $this->config->get_ldap_link();
1006 $address= strtolower($address);
1008 /* Is this address already assigned in LDAP? */
1009 $ldap->cd ($this->config->current['BASE']);
1010 $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)".
1011 "(gosaMailAlternateAddress=$address)))");
1013 if ($ldap->count() > 0){
1014 $attrs= $ldap->fetch ();
1015 return ($attrs["uid"][0]);
1016 }
1018 /* Add to list of alternates */
1019 if (!in_array($address, $this->gosaMailAlternateAddress)){
1020 $this->gosaMailAlternateAddress[]= $address;
1021 }
1023 sort ($this->gosaMailAlternateAddress);
1024 reset ($this->gosaMailAlternateAddress);
1025 $this->is_modified= TRUE;
1027 return ("");
1028 }
1031 function delAlternate($addresses)
1032 {
1033 $this->gosaMailAlternateAddress= array_remove_entries ($addresses,
1034 $this->gosaMailAlternateAddress);
1035 $this->is_modified= TRUE;
1036 }
1039 function make_name($attrs)
1040 {
1041 $name= "";
1042 if (isset($attrs['sn'][0])){
1043 $name= $attrs['sn'][0];
1044 }
1045 if (isset($attrs['givenName'][0])){
1046 if ($name != ""){
1047 $name.= ", ".$attrs['givenName'][0];
1048 } else {
1049 $name.= $attrs['givenName'][0];
1050 }
1051 }
1052 if ($name != ""){
1053 $name.= " ";
1054 }
1056 return ($name);
1057 }
1059 function getCopyDialog()
1060 {
1061 if(!$this->is_account) return("");
1063 $smarty = get_smarty();
1064 $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress);
1065 $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress);
1066 $smarty->assign("mail",$this->mail);
1067 $display= $smarty->fetch (get_template_path('paste_mail.tpl', TRUE));
1068 $ret = array();
1069 $ret['string'] = $display;
1070 $ret['status'] = "";
1071 return($ret);
1072 }
1074 function saveCopyDialog()
1075 {
1076 if(!$this->is_account) return;
1078 /* Perform ADD / REMOVE ... for mail alternate / mail forwarding addresses
1079 */
1080 $this->execute();
1081 if(isset($_POST['mail'])){
1082 $this->mail = $_POST['mail'];
1083 }
1084 }
1086 function PrepareForCopyPaste($source)
1087 {
1088 plugin::PrepareForCopyPaste($source);
1090 /* Reset alternate mail addresses */
1091 $this->gosaMailAlternateAddress = array();
1092 }
1095 /* Remove given ACL for given member (uid,mail) ..
1096 */
1097 function removeUserAcl($index )
1098 {
1099 if(isset($this->imapacl[$index])){
1100 unset($this->imapacl[$index]);
1101 }
1102 }
1104 }
1105 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1106 ?>