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 /* Load permissions */
242 if (isset($this->attrs['acl'])){
243 for ($i= 0; $i<$this->attrs['acl']['count']; $i++){
244 list($user, $permission)= split(' ', $this->attrs['acl'][$i]);
245 $this->imapacl[$user]= $permission;
246 if ($user != "anyone" && $user != "%members%"){
247 unset($this->imapacl['']);
248 }
249 }
250 }
252 foreach($this->imapacl as $user => $permission){
253 if ($user != "anyone" && $user != "%members%"){
254 $tmp[$permission][] = $user;
255 }
256 if ($user != "anyone" && $user != "%members%"){
257 unset($this->imapacl['']);
258 }
259 }
260 }
263 /**
264 * Detect group member with same acl and replace them with %members%
265 **/
267 /* In this section we dectect which acl is tho most used
268 This will be used as %members% acl
269 */
270 $tmp2 = array();
271 foreach($tmp as $acl => $user){
272 $tmp2[count($tmp[$acl])]=$acl;
273 }
274 /* Most used at last
275 */
276 ksort($tmp2);
278 /* Assign last (most used acl) to %members% acl
279 */
280 $str = array_pop($tmp2);
281 if(!empty($str)) {
282 $this->imapacl['%members%']=$str;
283 }
285 /* Open ldap connection
286 */
287 $ldap = $this->config->get_ldap_link();
288 $ldap->cd($this->config->current['BASE']);
290 /* Remove those users, that use %members% acl && are member of this group. */
291 foreach($this->imapacl as $mail => $permission){
292 $ldap->search("(&(objectClass=person)(|(mail=".$mail.")(uid=".$mail.")))",array("uid"));
293 $atr = $ldap->fetch();
294 if((isset($this->attrs['memberUid'])) && (is_array($this->attrs['memberUid']))){
295 if((isset($atr['uid'][0]))&&(in_array($atr['uid'][0],$this->attrs['memberUid']))&&($permission == $this->imapacl['%members%'])){
296 unset($this->imapacl[$mail]);
297 }
298 }
299 }
301 /**
302 * ENDE: Detect group member with same acl and replace them with %members%
303 **/
304 $this->indexed_user = array("%members%","anyone");
306 /* Append an empty entry, for special acl handling */
307 if(count($this->imapacl)==2){
308 $this->imapacl[''] ="lrsw";
309 $this->indexed_user[] = '';
310 }
312 /* Load Mailserver
313 */
314 if(isset($this->attrs['gosaMailServer'][0])){
315 $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
316 }
317 /* Fill translations */
318 $this->perms["lrsw"]= _("read");
319 $this->perms["lrswp"]= _("post");
320 $this->perms["p"]= _("external post");
321 $this->perms["lrswip"]= _("append");
322 $this->perms["lrswipcd"]= _("write");
323 $this->perms["lrswipcda"]= _("admin");
324 $this->perms[""]= _("none");
325 }
327 function execute()
328 {
329 /* Call parent execute */
330 //plugin::execute();
332 /* Load templating engine */
333 $smarty= get_smarty();
334 $display = "";
335 if ($_SESSION['js']==FALSE){
336 $smarty->assign("javascript", "false");
337 } else {
338 $smarty->assign("javascript", "true");
339 }
341 /* Do we need to flip is_account state? */
342 if (isset($_POST['modify_state'])){
344 /* Onyl change account state if allowed */
345 if($this->is_account && $this->acl == "#all#"){
346 $this->is_account= !$this->is_account;
347 }elseif(!$this->is_account && chkacl($this->acl,"create") == ""){
348 $this->is_account= !$this->is_account;
349 }
350 }
352 /* Do we represent a valid account? */
353 if (!$this->is_account && $this->parent == NULL){
355 $display.= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
356 _("This 'dn' has no valid mail extensions.")."</b>";
357 return ($display);
358 }
360 /* Show tab dialog headers */
361 $display= "";
362 if ($this->parent != NULL){
363 if ($this->is_account){
364 $display= $this->show_header(_("Remove mail account"),
365 _("This account has mail features enabled. You can disable them by clicking below."));
366 } else {
367 $display.= $this->show_header(_("Create mail account"),
368 _("This account has mail features disabled. You can enable them by clicking below."));
370 /* Show checkbox that allows us to remove imap entry too*/
371 if($this->initially_was_account){
373 $c = "";
374 if($this->remove_folder_from_imap){
375 $c= " checked ";
376 }
378 $display .= "<h2>Shared folder delete options</h2>
379 <input class='center' type='checkbox' name='remove_folder_from_imap' value='1' ".$c."
380 title='"._("Remove shared folder from mail server database when entry gets removed in LDAP")."'>";
381 $display .= _("Remove the shared folder and all its contents after saving this account");
382 }
384 return ($display);
385 }
386 }
388 /* Add ACL? */
389 if (isset($_POST["add_acl"])){
390 $this->imapacl[""]= "lrsw";
391 $this->indexed_user[] = "";
392 }
393 foreach ($this->indexed_user as $nr => $user){
394 if (isset($_POST["del_$nr"])){
395 unset ($this->imapacl[$user]);
396 }
397 }
399 /* Trigger forward add dialog? */
400 if (isset($_POST['add_local_forwarder'])){
401 $this->forward_dialog= TRUE;
402 $this->dialog= TRUE;
403 }
405 /* Cancel forward add dialog? */
406 if (isset($_POST['add_locals_cancel'])){
407 $this->forward_dialog= FALSE;
408 $this->dialog= FALSE;
409 }
411 /* Finished adding of locals? */
412 if (isset($_POST['add_locals_finish'])){
413 if (count ($_POST['local_list']) &&
414 chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
416 /* Walk through list of forwarders, ignore own addresses */
417 foreach ($_POST['local_list'] as $val){
418 if (!in_array ($val, $this->gosaMailAlternateAddress) &&
419 $val != $this->mail){
421 $this->addForwarder($val);
422 }
423 }
424 }
425 $this->forward_dialog= FALSE;
426 $this->dialog= FALSE;
427 }
429 /* Add forward email addresses */
430 if (isset($_POST['add_forwarder'])){
431 if ($_POST['forward_address'] != ""){
433 /* Valid email address specified? */
434 $address= $_POST['forward_address'];
435 if (!is_email($address)){
437 print_red (_("You're trying to add an invalid email address ".
438 "to the list of forwarders."));
440 } elseif ($address == $this->mail
441 || in_array($address, $this->gosaMailAlternateAddress)) {
443 print_red (_("Adding your one of your own addresses to the forwarders makes no sense."));
445 } else {
447 /* Add it */
448 if (chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
449 $this->addForwarder ($address);
450 }
452 }
453 }
454 }
456 /* Delete forward email addresses */
457 if (isset($_POST['delete_forwarder'])){
458 if (count($_POST['forwarder_list'])
459 && chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
461 $this->delForwarder ($_POST['forwarder_list']);
462 }
463 }
465 /* Add alternate email addresses */
466 if (isset($_POST['add_alternate'])){
467 if ($_POST['alternate_address'] != "" &&
468 chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
470 if (!is_email($_POST['alternate_address'])){
471 print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
473 } elseif (($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
474 $ui= get_userinfo();
475 if ($user != $ui->username){
476 print_red (_("The address you're trying to add is already used by user")." '$user'.");
477 }
478 }
479 }
480 }
482 /* Delete alternate email addresses */
483 if (isset($_POST['delete_alternate']) && isset ($_POST['alternates_list'])){
484 if (count($_POST['alternates_list']) &&
485 chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
487 $this->delAlternate ($_POST['alternates_list']);
488 }
489 }
491 /* Show forward add dialog */
492 if ($this->forward_dialog){
493 $ldap= $this->config->get_ldap_link();
495 /* Save data */
496 $gmailfilter= get_global("gmailfilter");
497 foreach( array("depselect", "muser", "regex") as $type){
498 if (isset($_POST[$type])){
499 $gmailfilter[$type]= $_POST[$type];
500 }
501 }
502 if (isset($_GET['search'])){
503 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
504 if ($s == "**"){
505 $s= "*";
506 }
507 $gmailfilter['regex']= $s;
508 }
509 register_global("gmailfilter", $gmailfilter);
511 /* Get actual list */
512 $mailusers= array ();
513 if ($gmailfilter['regex'] != '*' && $gmailfilter['regex'] != ""){
514 $regex= $gmailfilter['regex'];
515 $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
516 } else {
517 $filter= "";
518 }
519 if ($gmailfilter['muser'] != ""){
520 $user= $gmailfilter['muser'];
521 $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
522 }
524 /* Add already present people to the filter */
525 $exclude= "";
526 foreach ($this->gosaMailForwardingAddress as $mail){
527 $exclude.= "(mail=$mail)";
528 }
529 if ($exclude != ""){
530 $filter.= "(!(|$exclude))";
531 }
533 $acl= array($this->config->current['BASE'] => ":all");
534 $res= get_list("(&(objectClass=gosaMailAccount)$filter)", $acl, $gmailfilter['depselect'],
535 array("sn", "mail", "givenName"), GL_SUBSEARCH | GL_SIZELIMIT);
536 $ldap->cd($gmailfilter['depselect']);
537 $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
538 error_reporting (0);
539 while ($attrs= $ldap->fetch()){
540 if(preg_match('/%/', $attrs['mail'][0])){
541 continue;
542 }
543 $name= $this->make_name($attrs);
544 $mailusers[$attrs['mail'][0]]= $name."<".
545 $attrs['mail'][0].">";
546 }
547 error_reporting (E_ALL);
548 natcasesort ($mailusers);
549 reset ($mailusers);
551 /* Show dialog */
552 $smarty->assign("search_image", get_template_path('images/search.png'));
553 $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
554 $smarty->assign("tree_image", get_template_path('images/tree.png'));
555 $smarty->assign("infoimage", get_template_path('images/info.png'));
556 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
557 $smarty->assign("mailusers", $mailusers);
558 $smarty->assign("deplist", $this->config->idepartments);
559 $smarty->assign("apply", apply_filter());
560 $smarty->assign("alphabet", generate_alphabet());
561 $smarty->assign("hint", print_sizelimit_warning());
562 foreach( array("depselect", "muser", "regex") as $type){
563 $smarty->assign("$type", $gmailfilter[$type]);
564 }
565 $smarty->assign("hint", print_sizelimit_warning());
566 $display.= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE));
567 return ($display);
568 }
570 /* Assemble normal permissions */
571 $smarty->assign("permissionsACL", chkacl($this->acl, "permissions"));
572 if (isset($this->imapacl['anyone'])){
573 $smarty->assign("default_permissions", $this->imapacl['anyone']);
574 }
575 $smarty->assign("member_permissions", "lrsp");
576 if (isset($this->imapacl['%members%'])){
577 $smarty->assign("member_permissions", $this->imapacl['%members%']);
578 }
580 /* Assemble extra attributes */
581 $perm= chkacl($this->acl, "permissions");
582 $tmp= "";
583 $nr= 0;
584 $count= count($this->imapacl);
585 $this->indexed_user= array();
586 $this->indexed_acl= array();
587 foreach($this->imapacl as $user => $acl){
588 if ($user != "anyone" && $user != "%members%"){
589 $tmp.= "<tr><td><input name=\"user_$nr\" size=20 maxlength=60 ".
590 "value=\"$user\" $perm></td><td><select size=\"1\" name=\"perm_$nr\" $perm>";
591 foreach ($this->perms as $key => $value){
592 if ($acl == $key){
593 $tmp.= "<option value=\"$key\" selected>$value</option>";
594 } else {
595 $tmp.= "<option value=\"$key\">$value</option>";
596 }
597 }
598 $tmp.= "</select> ";
599 if ($nr == $count - 1){
600 }
601 if ($count > 2){
602 $tmp.= "</td><td><input type=submit value=\""._("Remove")."\" ".
603 "name=\"del_$nr\" $perm></td></tr>";
604 }
605 }
606 $this->indexed_user[$nr]= $user;
607 $this->indexed_acl[$nr++]= $acl;
608 }
609 $tmp.= "<tr><td></td><td></td><td><input type=submit value='"._("Add")."' name='add_acl' $perm>";
610 $smarty->assign("plusattributes", $tmp);
612 /* Show main page */
613 $mailserver= array();
614 foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
615 $mailserver[]= $key;
616 }
617 $smarty->assign("mailServers", $mailserver);
618 foreach(array("gosaMailServer", "gosaMailQuota", "perms", "mail",
619 "gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
620 $smarty->assign("$val", $this->$val);
621 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
622 }
623 if (is_numeric($this->gosaMailQuota) && $this->gosaMailQuota != 0){
624 $smarty->assign("quotausage", progressbar(round(($this->quotaUsage * 100)/ $this->gosaMailQuota),100,15,true));
625 $smarty->assign("quotadefined", "true");
626 } else {
627 $smarty->assign("quotadefined", "false");
628 }
630 if(isset($this->config->current['MAILMETHOD'])&&preg_match("/olab/i",$this->config->current['MAILMETHOD'])){
632 $smarty->assign("kolab", TRUE);
633 $smarty->assign("JS",$_SESSION['js']);
634 $smarty->assign("kolabFolderType_Types", array ( '' => _('Unspecified'), 'mail' => _('Mails'),
635 'task' => _('Tasks') , 'journal' => _('Journals'),
636 'calendar' => _('Calendar'), 'contact' => _('Contacts'),
637 'note' => _('Notes')));
638 if($this->kolabFolderType_Type == "mail"){
639 $smarty->assign("kolabFolderType_SubTypes", array(
640 '' => _('Unspecified'), 'inbox' => _("Inbox") ,
641 'drafts' => _("Drafts"), 'sentitems' => _("Sent items"),
642 'junkemail' => _("Junk mail")));
643 }else{
644 $smarty->assign("kolabFolderType_SubTypes", array( 'default' => _("Default")));
645 }
646 $smarty->assign("kolabFolderType_Type", $this->kolabFolderType_Type);
647 $smarty->assign("kolabFolderType_SubType", $this->kolabFolderType_SubType);
648 }else{
649 $smarty->assign("kolab", FALSE);
650 }
653 $display.= $smarty->fetch (get_template_path('mail.tpl', TRUE));
654 return ($display);
655 }
658 /* remove object from parent */
659 function remove_from_parent()
660 {
661 /* Added these ObjectClass and Attributes, because they were not
662 removed correctly, only in case of kolab ...
663 */
664 if(isset($this->config->current['MAILMETHOD'])&&preg_match("/olab/i",$this->config->current['MAILMETHOD'])){
665 $this->attributes[]="acl";
666 $this->objectclasses[] = "kolabSharedFolder";
667 }
668 /* include global link_info */
669 $ldap= $this->config->get_ldap_link();
671 /* Remove and write to LDAP */
672 plugin::remove_from_parent();
674 /* Zero arrays */
675 $this->attrs['gosaMailAlternateAddress']= array();
676 $this->attrs['gosaMailForwardingAddress']= array();
677 $this->attrs['gosaSharedFolderTarget']= array();
679 /* Connect to IMAP server for account deletion */
680 if ($this->initially_was_account){
682 $method= new $this->method($this->config);
683 $method->fixAttributesOnRemove($this);
684 if ($method->connect($this->gosaMailServer) && $this->remove_folder_from_imap){
686 /* Remove account from IMAP server */
687 $method->deleteMailbox($this->uid);
688 $method->disconnect();
689 }
690 }
691 /* Keep uid */
692 unset ($this->attrs['uid']);
694 $ldap->cd($this->dn);
695 $ldap->modify ($this->attrs);
696 show_ldap_error($ldap->get_error(), _("Removing group mail settings failed"));
698 /* Optionally execute a command after we're done */
699 $this->handle_post_events("remove");
700 }
703 /* Save data to object */
704 function save_object()
705 {
707 /* Add special kolab attributes */
708 if(isset($this->config->current['MAILMETHOD'])&&preg_match("/olab/i",$this->config->current['MAILMETHOD'])){
709 if(isset($_POST['kolabFolderType_Type'])){
710 $this->kolabFolderType_Type = get_post("kolabFolderType_Type");
711 $this->kolabFolderType_SubType = get_post("kolabFolderType_SubType");
712 }
713 }
715 /* Check if user wants to remove the shared folder from imap too */
716 if($this->initially_was_account && !$this->is_account){
717 if(isset($_POST['remove_folder_from_imap'])){
718 $this->remove_folder_from_imap = true;
719 }else{
720 $this->remove_folder_from_imap = false;
721 }
722 }
724 /* Assemble mail delivery mode
725 The mode field in ldap consists of values between braces, this must
726 be called when 'mail' is set, because checkboxes may not be set when
727 we're in some other dialog.
729 Example for gosaMailDeliveryMode [LR ]
730 L: Local delivery
731 R: Reject when exceeding mailsize limit
732 S: Use spam filter
733 V: Use vacation message
734 C: Use custom sieve script
735 I: Only insider delivery */
736 if (isset($_POST['mailedit'])){
738 /* Save ldap attributes */
739 plugin::save_object();
741 $tmp= "";
742 if (!isset($_POST["drop_own_mails"])){
743 $tmp.= "L";
744 }
745 if (isset($_POST["use_mailsize_limit"])){
746 $tmp.= "R";
747 }
748 if (isset($_POST["use_spam_filter"])){
749 $tmp.= "S";
750 }
751 if (isset($_POST["use_vacation"])){
752 $tmp.= "V";
753 }
754 if (isset($_POST["own_script"])){
755 $tmp.= "C";
756 }
757 if (isset($_POST["only_local"])){
758 $tmp.= "I";
759 }
760 $tmp= "[$tmp]";
762 if (chkacl ($this->acl, "gosaMailDeliveryMode") == ""){
763 $this->gosaMailDeliveryMode= $tmp;
764 }
766 /* Collect data and re-assign it to the imapacl array */
767 if (chkacl($this->acl, "permissions") == ""){
768 $this->imapacl= array();
769 $this->imapacl['%members%']= $_POST['member_permissions'];
770 $this->imapacl['anyone']= $_POST['default_permissions'];
771 foreach ($this->indexed_user as $nr => $user){
772 if (!isset($_POST["user_$nr"])){
773 continue;
774 }
775 if ($_POST["user_$nr"] != $user ||
776 $_POST["perm_$nr"] != $this->indexed_acl[$nr]){
777 $this->is_modified= TRUE;
778 }
779 $this->imapacl[$_POST["user_$nr"]]= $_POST["perm_$nr"];
780 $this->indexed_user[$nr] = $_POST["user_$nr"];
781 }
782 }
783 }
784 }
787 /* Save data to LDAP, depending on is_account we save or delete */
788 function save()
789 {
790 $ldap= $this->config->get_ldap_link();
791 $ldap->cd($this->config->current['BASE']);
793 /* Call parents save to prepare $this->attrs */
794 plugin::save();
796 /* Save arrays */
797 $this->attrs['gosaMailAlternateAddress'] = $this->gosaMailAlternateAddress;
798 $this->attrs['gosaMailForwardingAddress'] = $this->gosaMailForwardingAddress;
799 $this->attrs['gosaSharedFolderTarget'] = "share+".$this->uid;
801 /* Only do IMAP actions if we are not a template */
802 if(preg_match("/olab/i",$this->mmethod)){
803 if (empty($this->gosaMailServer)||is_array($this->gosaMailServer)){
804 if(isset($this->attrs['gosaMailServer'][0])){
805 $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
806 }
807 }
808 }
810 /* Exchange '%member%' pseudo entry */
811 $memberacl= $this->imapacl['%members%'];
812 foreach ($this->members as $user){
813 if (!isset($this->imapacl[$user])){
814 $this->imapacl[$user]= $memberacl;
815 }
816 }
818 /* Prepare kolab attributes to be written */
819 if(preg_match("/olab/i",$this->mmethod)){
820 $this->attrs['acl']= array();
821 if(!empty($this->kolabFolderType_Type)){
822 $this->attrs['kolabFolderType'] = $this->kolabFolderType_Type.".".$this->kolabFolderType_SubType;
823 }else{
824 $this->attrs['kolabFolderType'] = array();
825 }
826 }else{
827 $this->attrs['acl']= array();;
828 unset($this->attrs['acl']);
829 }
831 /* Get naming attribute for mail accounts */
832 $tmp = new $this->method($this->config);
833 $uattrib = $tmp->uattrib;
835 /* Create ACL array
836 * In case of kolab also create attrs['acl'] to save acls in ldap.
837 */
838 foreach ($this->imapacl as $user => $acl){
840 if (empty($user) || $user == ""){
841 unset($this->imapacl[$user]);
842 }
844 /* Skip placeholder */
845 if (empty($user) || $user == "" || preg_match("/%members%/",$user)){
846 continue;
847 }
849 /* Check if your is a real GOsa user
850 * If user is a real GOsa user but do not have an email address - SKIP adding acls
851 * If user is a real GOsa user with an emal address - add acls
852 */
853 $ldap->search("(&(objectClass=person)(|(uid=".$user.")(mail=".$user.")))",array("mail","uid"));
854 if($ldap->count()){
855 $attrs = $ldap->fetch();
857 /* Has the user a valid mail account? */
858 if(isset($attrs['mail'][0])){
860 $name = $attrs[$uattrib][0];
862 /* In case of kolab methods add acl attribute too */
863 if(preg_match("/olab/i",$this->mmethod)){
864 $this->attrs['acl'][]= $name." ".$acl;
865 unset($this->imapacl[$user]);
866 }
867 $this->imapacl[$name] = $acl;
868 }else{
870 /* User has no mail extension */
871 unset($this->imapacl[$user]);
872 }
873 }else{
874 /* Seems to be a manually added acl */
876 /* In case of kolab methods add acl attribute too */
877 if(preg_match("/olab/i",$this->mmethod)){
878 $this->attrs['acl'][]= $user." ".$acl;
879 }
880 $this->imapacl[$user] = $acl;
881 }
882 }
884 if ((!$this->is_template)&&(!empty($this->gosaMailServer))){
885 $method= new $this->method($this->config);
886 $method->fixAttributesOnStore($this);
887 if (($method->connect($this->gosaMailServer))){
888 $method->updateMailbox($this->uid);
889 $method->setQuota($this->uid, $this->gosaMailQuota);
890 $method->setSharedFolderPermissions($this->uid, $this->imapacl);
891 $method->disconnect();
892 }
893 }
895 /* Save data to LDAP */
896 $ldap->cd($this->dn);
897 $this->cleanup();
898 $ldap->modify ($this->attrs);
899 show_ldap_error($ldap->get_error(), _("Saving group mail settings failed"));
901 /* Optionally execute a command after we're done */
902 if ($this->initially_was_account == $this->is_account){
903 if ($this->is_modified){
904 $this->handle_post_events("modify");
905 }
906 } else {
907 $this->handle_post_events("add");
908 }
909 }
911 /* Check formular input */
912 function check()
913 {
914 $ldap= $this->config->get_ldap_link();
916 /* Call common method to give check the hook */
917 $message= plugin::check();
919 if(!$this->is_account) return array();
921 //$message[] = $str;
923 /* must: mail */
924 if ($this->mail == ""){
925 $message[]= _("The required field 'Primary address' is not set.");
926 }
927 if (!is_email($this->mail)){
928 $message[]= _("Please enter a valid email addres in 'Primary address' field.");
929 }
930 $ldap->cd($this->config->current['BASE']);
931 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=".$this->mail.")(gosaMailAlternateAddress=".
932 $this->mail."))(!(uid=".$this->orig_cn."))(!(cn=".$this->orig_cn.")))");
933 if ($ldap->count() != 0){
934 $message[]= _("The primary address you've entered is already in use.");
935 }
937 /* Check quota */
938 if ($this->gosaMailQuota != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
939 if (!is_numeric($this->gosaMailQuota)) {
940 $message[]= _("Value in 'Quota size' is not valid.");
941 } else {
942 $this->gosaMailQuota= (int) $this->gosaMailQuota;
943 }
944 }
946 /* Check rejectsize for integer */
947 if ($this->gosaMailMaxSize != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
948 if (!is_numeric($this->gosaMailMaxSize)){
949 $message[]= _("Please specify a vaild mail size for mails to be rejected.");
950 } else {
951 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
952 }
953 }
955 /* Need gosaMailMaxSize if use_mailsize_limit is checked */
956 if (is_integer(strpos($this->gosaMailDeliveryMode, "reject")) && $this->gosaMailMaxSize == ""){
957 $message[]= _("You need to set the maximum mail size in order to reject anything.");
958 }
960 if(ord($this->imapacl['anyone'][0])==194){
961 $message[] = _("Please choose valid permission settings. Default permission can't be emtpy.");
962 }
964 if(empty($this->gosaMailServer)){
965 $message[] = _("Please select a valid mail server.");
966 }
968 return ($message);
969 }
971 /* Adapt from template, using 'dn' */
972 function adapt_from_template($dn)
973 {
974 plugin::adapt_from_template($dn);
976 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
977 $this->$val= array();
978 if (isset($this->attrs["$val"]["count"])){
979 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
980 $value= $this->attrs["$val"][$i];
981 foreach (array("sn", "givenName", "uid") as $repl){
982 if (preg_match("/%$repl/i", $value)){
983 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
984 }
985 }
986 array_push($this->$val, $value);
987 }
988 }
989 }
990 }
992 /* Add entry to forwarder list */
993 function addForwarder($address)
994 {
995 $this->gosaMailForwardingAddress[]= $address;
996 $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
998 sort ($this->gosaMailForwardingAddress);
999 reset ($this->gosaMailForwardingAddress);
1000 $this->is_modified= TRUE;
1001 }
1003 /* Remove list of addresses from forwarder list */
1004 function delForwarder($addresses)
1005 {
1006 $this->gosaMailForwardingAddress= array_remove_entries ($addresses,
1007 $this->gosaMailForwardingAddress);
1008 $this->is_modified= TRUE;
1009 }
1013 function addAlternate($address)
1014 {
1015 $ldap= $this->config->get_ldap_link();
1017 $address= strtolower($address);
1019 /* Is this address already assigned in LDAP? */
1020 $ldap->cd ($this->config->current['BASE']);
1021 $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)".
1022 "(gosaMailAlternateAddress=$address)))");
1024 if ($ldap->count() > 0){
1025 $attrs= $ldap->fetch ();
1026 return ($attrs["uid"][0]);
1027 }
1029 /* Add to list of alternates */
1030 if (!in_array($address, $this->gosaMailAlternateAddress)){
1031 $this->gosaMailAlternateAddress[]= $address;
1032 }
1034 sort ($this->gosaMailAlternateAddress);
1035 reset ($this->gosaMailAlternateAddress);
1036 $this->is_modified= TRUE;
1038 return ("");
1039 }
1042 function delAlternate($addresses)
1043 {
1044 $this->gosaMailAlternateAddress= array_remove_entries ($addresses,
1045 $this->gosaMailAlternateAddress);
1046 $this->is_modified= TRUE;
1047 }
1050 function make_name($attrs)
1051 {
1052 $name= "";
1053 if (isset($attrs['sn'][0])){
1054 $name= $attrs['sn'][0];
1055 }
1056 if (isset($attrs['givenName'][0])){
1057 if ($name != ""){
1058 $name.= ", ".$attrs['givenName'][0];
1059 } else {
1060 $name.= $attrs['givenName'][0];
1061 }
1062 }
1063 if ($name != ""){
1064 $name.= " ";
1065 }
1067 return ($name);
1068 }
1070 function getCopyDialog()
1071 {
1072 if(!$this->is_account) return("");
1074 $smarty = get_smarty();
1075 $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress);
1076 $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress);
1077 $smarty->assign("mail",$this->mail);
1078 $display= $smarty->fetch (get_template_path('paste_mail.tpl', TRUE));
1079 $ret = array();
1080 $ret['string'] = $display;
1081 $ret['status'] = "";
1082 return($ret);
1083 }
1085 function saveCopyDialog()
1086 {
1087 if(!$this->is_account) return;
1089 /* Perform ADD / REMOVE ... for mail alternate / mail forwarding addresses
1090 */
1091 $this->execute();
1092 if(isset($_POST['mail'])){
1093 $this->mail = $_POST['mail'];
1094 }
1095 }
1097 function PrepareForCopyPaste($source)
1098 {
1099 plugin::PrepareForCopyPaste($source);
1101 /* Reset alternate mail addresses */
1102 $this->gosaMailAlternateAddress = array();
1103 }
1106 /* Remove given ACL for given member (uid,mail) ..
1107 */
1108 function removeUserAcl($index )
1109 {
1110 if(isset($this->imapacl[$index])){
1111 unset($this->imapacl[$index]);
1112 }
1113 }
1115 }
1116 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1117 ?>