1 <?php
3 class mailgroup extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary = "Manage mail groups/shared folders";
7 var $cli_description = "Some longer text\nfor help";
8 var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10 var $uid = ""; // User id
11 var $cn = ""; // cn
12 var $orig_cn = ""; // cn
14 var $method = "mailMethod"; // Used Mail method
15 var $mmethod = ""; // Contains the gosa.conf MAILMETHOD
16 var $mail = ""; // Default mail address
18 var $gosaMailAlternateAddress = array(); // Set default Alternate Mail Adresses to empty array
19 var $gosaMailForwardingAddress = array(); // Forwarding also empty
21 var $gosaMailServer = ""; // Selected mailserver
22 var $gosaMailQuota = ""; // Defined Quota
23 var $quotaUsage = 0; // Currently used quota
25 var $gosaVacationMessage = ""; // Vocation message
27 var $imapacl = array('anyone' => 'p', // Set acls for everyone
28 '%members%' => 'lrswp', // %members% are all group-members
29 '' => 'p'); // Every user added gets this right
31 var $kolabFolderType_SubType = "";
32 var $kolabFolderType_Type = "";
34 var $gosaSpamSortLevel = "";
35 var $gosaSpamMailbox = "";
36 var $gosaSharedFolderTarget ;
38 var $forward_dialog = FALSE;
40 var $members = array(); // Group members
42 var $mailusers = array();
43 var $perms = array();
44 var $gosaMailDeliveryMode = "[L ]"; //
45 var $gosaMailMaxSize = ""; //
47 var $remove_folder_from_imap = true;
49 /* Helper */
50 var $indexed_acl= array();
51 var $indexed_user= array();
53 var $view_logged = FALSE;
55 /* attribute list for save action */
56 var $attributes= array( "mail", "gosaMailServer", "gosaMailQuota", "gosaMailMaxSize",
57 "gosaMailAlternateAddress", "gosaMailForwardingAddress",
58 "gosaMailDeliveryMode", "gosaSpamSortLevel", "gosaSpamMailbox",
59 "acl","gosaSharedFolderTarget", "gosaVacationMessage");
61 var $objectclasses= array("gosaMailAccount");
62 var $CopyPasteVars = array("quotaUsage","imapacl");
64 function mailgroup (&$config, $dn= NULL, $ui= NULL)
65 {
66 /* Initialise all available attributes ... if possible
67 */
68 plugin::plugin($config, $dn);
69 $this->orig_cn = $this->cn;
71 /* Set mailMethod to the one defined in gosa.conf
72 */
73 if (isset($this->config->current['MAILMETHOD'])){
74 $this->mmethod= $this->config->current['MAILMETHOD'];
75 }
77 /* Check if selected mail method exists
78 */
79 $cls = get_correct_class_name("mailMethod$this->mmethod");
80 if ($cls && class_exists($cls)){
81 $this->method= $cls;
82 } else {
83 print_red(sprintf(_("There is no mail method '%s' specified in your gosa.conf available."), $this->mmethod));
84 }
86 /* Load Mailserver
87 */
88 if(isset($this->attrs['gosaMailServer'][0])){
89 $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
90 }
92 /* Convert cn to uid in case of existing entry
93 */
94 if (isset($this->attrs['cn'][0])){
95 $this->uid= $this->attrs['cn'][0];
96 }
98 /* Get folder type */
99 if(isset($this->config->current['MAILMETHOD'])&&preg_match("/olab/i",$this->config->current['MAILMETHOD'])){
100 if(isset($this->attrs['kolabFolderType'])){
101 $tmp = split("\.",$this->attrs['kolabFolderType'][0]);
102 $this->kolabFolderType_Type = $tmp[0];
103 $this->kolabFolderType_SubType = $tmp[1];
104 }
105 }
107 /* If this ins't new mailgroup, read all required data from ldap
108 */
109 if (($dn != "new")&&($dn !== NULL)){
111 /* Load attributes which represent multiple entries
112 */
113 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
114 $this->$val = array();
115 if (isset($this->attrs["$val"]["count"])){
116 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
117 array_push($this->$val, $this->attrs["$val"][$i]);
118 }
119 }
120 }
122 /* Only do IMAP actions if gosaMailServer attribute is set
123 */
124 if (isset ($this->attrs["gosaMailServer"][0])){
126 /* Create new instance of our defined mailclass
127 */
128 $method= new $this->method($this->config);
130 if ($method->connect($this->attrs["gosaMailServer"][0])){
133 /* Maybe the entry is not saved in new style, get
134 permissions from IMAP and convert them to acl attributes */
135 if (!isset($this->attrs['acl'])){
136 $this->imapacl= $method->getSharedFolderPermissions($this->uid);
138 /* Need to filter what a member acl could be... */
139 $vote= array();
140 $peak= 0;
141 $leader= "";
142 foreach ($this->imapacl as $user => $acl){
144 if ($user != "anyone" ){
145 if (!isset($vote[$acl])){
146 $vote[$acl]= 1;
147 } else {
148 $vote[$acl]++;
149 }
150 if ($vote[$acl] > $peak){
151 $leader= $acl;
152 $peek= $vote[$acl];
153 }
154 }
156 }
158 /* Highest count wins as %members%, remove all members
159 with the same acl */
160 if(!empty($leader)){
161 $this->imapacl['%members%']= $leader;
162 }
163 foreach ($this->imapacl as $user => $acl){
164 if ($this->acl == $leader && in_array($user, $this->attrs['memberUid'])){
165 unset($this->imapacl[$user]);
166 }
167 }
169 } // ENDE ! isset ($this->attrs['acl'])
171 /* Adapt attributes if needed */
172 $method->fixAttributesOnLoad($this);
174 /* get Quota */
175 $quota= $method->getQuota($this->uid);
177 /* Update quota values */
178 if(is_array($quota)){
179 if ($quota['gosaMailQuota'] == 2147483647){
180 $this->quotaUsage= "";
181 $this->gosaMailQuota= "";
182 } else {
183 $this->quotaUsage= $quota['quotaUsage'];
184 $this->gosaMailQuota= $quota['gosaMailQuota'];
185 }
186 }else{
187 $this->quotaUsage = "";
188 $this->gosaMailQuota = "";
189 // print_red(sprintf(_("Can't get quota information for '%s'."),$this->uid));
190 }
191 $method->disconnect();
192 } // ENDE $method->connect($this->attrs["gosaMailServer"][0])){
194 } // ENDE gosaMailServer
196 } // ENDE dn != "new"
199 /* Get global filter config */
200 if (!is_global("gmailfilter")){
201 $ui= get_userinfo();
202 $base= get_base_from_people($ui->dn);
203 $gmailfilter= array( "depselect" => $base,
204 "muser" => "",
205 "regex" => "*");
206 register_global("gmailfilter", $gmailfilter);
207 }
209 /* Load permissions */
210 $tmp = array();
211 if(preg_match("/olab/i",$this->mmethod)){
212 $ldap = $this->config->get_ldap_link();
214 if (isset($this->attrs['acl'])){
216 for ($i= 0; $i<$this->attrs['acl']['count']; $i++){
217 list($user, $permission)= split(' ', $this->attrs['acl'][$i]);
219 /* Add to list */
220 $this->imapacl[$user]= $permission;
222 /* Get all user permissions sorted by acl, to detect the most used acl
223 This acl is then used for %members%
224 */
225 if ($user != "anyone" && $user != "%members%"){
226 $tmp[$permission][] = $user;
227 }
229 /* There is an entry in $this->imapacl like this this ...
230 $this->attrs['imapacl']['anyone'] = "p";
231 $this->attrs['imapacl']['%members%'] = "lprs";
232 $this->attrs['imapacl'][''] = ""; <------ This is used to diplay an empty
233 Field for special acls in our template.
234 If there is at least one special acl in out imapacl,
235 we don't need this entry anymore, because it is already displayed.
236 */
237 if ($user != "anyone" && $user != "%members%"){
238 unset($this->imapacl['']);
239 }
240 }
241 }
243 /* In this section we dectect which acl is tho most used
244 This will be used as %members% acl
245 */
246 $tmp2 = array();
247 foreach($tmp as $acl => $user){
248 $tmp2[count($tmp[$acl])]=$acl;
249 }
250 /* Most used at last
251 */
252 ksort($tmp2);
254 /* Assign last (most used acl) to %members% acl
255 */
256 $str = array_pop($tmp2);
257 if(!empty($str)) {
258 $this->imapacl['%members%']=$str;
259 }
261 /* Open ldap connection
262 */
263 $ldap = $this->config->get_ldap_link();
264 $ldap->cd($this->config->current['BASE']);
266 /* Remove those users, that use %members% acl && are member of this group. */
267 foreach($this->imapacl as $mail => $permission){
268 $ldap->search("(&(objectClass=person)(mail=".$mail."))",array("uid"));
269 $atr = $ldap->fetch();
270 if((isset($this->attrs['memberUid'])) && (is_array($this->attrs['memberUid']))){
271 if((isset($atr['uid'][0]))&&(in_array($atr['uid'][0],$this->attrs['memberUid']))&&($permission == $this->imapacl['%members%'])){
272 unset($this->imapacl[$mail]);
273 }
274 }
275 }
276 /* Append an empty entry, for special acl handling */
277 if(count($this->imapacl)==2){
278 $this->imapacl[''] ="";
279 }
281 }else{ // Not kolab
282 /* Load permissions */
283 if (isset($this->attrs['acl'])){
284 for ($i= 0; $i<$this->attrs['acl']['count']; $i++){
285 list($user, $permission)= split(' ', $this->attrs['acl'][$i]);
286 $this->imapacl[$user]= $permission;
287 if ($user != "anyone" && $user != "%members%"){
288 unset($this->imapacl['']);
289 }
290 }
291 }
292 }
294 /* Load Mailserver
295 */
296 if(isset($this->attrs['gosaMailServer'][0])){
297 $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
298 }
299 /* Fill translations */
300 $this->perms["lrsw"]= _("read");
301 $this->perms["lrspw"]= _("post");
302 $this->perms["p"]= _("external post");
303 $this->perms["lrsipw"]= _("append");
304 $this->perms["lrswipcd"]= _("write");
305 $this->perms["lrswipcda"]= _("admin");
306 $this->perms[""]= _("none");
307 }
309 function execute()
310 {
311 /* Call parent execute */
312 //plugin::execute();
314 /* Log view */
315 if($this->is_account && !$this->view_logged){
316 $this->view_logged = TRUE;
317 new log("view","groups/".get_class($this),$this->dn);
318 }
320 /* Load templating engine */
321 $smarty= get_smarty();
323 /* Assign acls */
324 $tmp = $this->plInfo();
325 foreach($tmp['plProvidedAcls'] as $name => $translation) {
326 $smarty->assign($name."ACL",$this->getacl($name));
327 }
329 if ($_SESSION['js']==FALSE){
330 $smarty->assign("javascript", "false");
331 } else {
332 $smarty->assign("javascript", "true");
333 }
335 /* Do we need to flip is_account state? */
336 if(isset($_POST['modify_state'])){
337 if($this->is_account && $this->acl_is_removeable()){
338 $this->is_account= FALSE;
339 }elseif(!$this->is_account && $this->acl_is_createable()){
340 $this->is_account= TRUE;
341 }
342 }
344 $display = "";
346 /* Do we represent a valid account? */
347 if (!$this->is_account && $this->parent === NULL){
349 $display.= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
350 _("This 'dn' has no valid mail extensions.")."</b>";
351 return ($display);
352 }
354 /* Show tab dialog headers */
355 $display= "";
356 if ($this->parent !== NULL){
357 if ($this->is_account){
358 $display.= $this->show_disable_header(_("Remove mail account"),
359 _("This account has mail features enabled. You can disable them by clicking below."));
360 } else {
361 $display.= $this->show_enable_header(_("Create mail account"),
362 _("This account has mail features disabled. You can enable them by clicking below."));
364 /* Show checkbox that allows us to remove imap entry too*/
365 if($this->initially_was_account){
366 $c = "";
367 if($this->remove_folder_from_imap){
368 $c= " checked ";
369 }
370 $display .= "<h2>Shared folder delete options</h2>
371 <input class='center' type='checkbox' name='remove_folder_from_imap' value='1' ".$c."
372 title='"._("Remove shared folder from mail server database when entry gets removed in LDAP")."'>";
373 $display .= _("Remove the shared folder and all its contents after saving this account");
374 }
375 return ($display);
376 }
377 }
379 /* Add ACL? */
380 if($this->acl_is_writeable("acl")){
381 foreach ($this->indexed_user as $nr => $user){
382 if (isset($_POST["add_$nr"])){
383 $this->imapacl[""]= "l";
384 }
385 if (isset($_POST["del_$nr"])){
386 unset ($this->imapacl[$user]);
387 }
388 }
389 }
391 /* Trigger forward add dialog? */
392 if($this->acl_is_writeable("gosaMailForwardingAddress")){
393 if (isset($_POST['add_local_forwarder'])){
394 $this->forward_dialog= TRUE;
395 $this->dialog= TRUE;
396 }
397 }
399 /* Cancel forward add dialog? */
400 if($this->acl_is_writeable("gosaMailForwardingAddress")){
401 if (isset($_POST['add_locals_cancel'])){
402 $this->forward_dialog= FALSE;
403 $this->dialog= FALSE;
404 }
405 }
407 /* Finished adding of locals? */
408 if ((isset($_POST['add_locals_finish'])) && ($this->acl_is_writeable("gosaMailForwardingAddress"))) {
409 if (count ($_POST['local_list']) && $this->acl_is_writeable("gosaMailForwardingAddress")){
411 /* Walk through list of forwarders, ignore own addresses */
412 foreach ($_POST['local_list'] as $val){
413 if (!in_array ($val, $this->gosaMailAlternateAddress) &&
414 $val != $this->mail){
416 $this->addForwarder($val);
417 }
418 }
419 }
420 $this->forward_dialog= FALSE;
421 $this->dialog= FALSE;
422 }
424 /* Add forward email addresses */
425 if ((isset($_POST['add_forwarder'])) && ($this->acl_is_writeable("gosaMailForwardingAddress"))){
426 if ($_POST['forward_address'] != ""){
428 /* Valid email address specified? */
429 $address= $_POST['forward_address'];
430 if (!is_email($address)){
432 print_red (_("You're trying to add an invalid email address ".
433 "to the list of forwarders."));
435 } elseif ($address == $this->mail
436 || in_array($address, $this->gosaMailAlternateAddress)) {
438 print_red (_("Adding your one of your own addresses to the forwarders makes no sense."));
440 } else {
442 /* Add it */
443 if ($this->acl_is_writeable("gosaMailForwardingAddress")){
444 $this->addForwarder ($address);
445 }
447 }
448 }
449 }
451 /* Delete forward email addresses */
452 if (isset($_POST['delete_forwarder']) && ($this->acl_is_writeable("gosaMailForwardingAddress"))){
453 if (count($_POST['forwarder_list'])&& $this->acl_is_writeable("gosaMailForwardingAddress")){
455 $this->delForwarder ($_POST['forwarder_list']);
456 }
457 }
459 /* Add alternate email addresses */
460 if (isset($_POST['add_alternate'])){
461 if ($_POST['alternate_address'] != "" && $this->acl_is_writeable("gosaMailAlternateAddress")){
463 if (!is_email($_POST['alternate_address'])){
464 print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
466 } elseif (($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
467 $ui= get_userinfo();
468 if ($user != $ui->username){
469 print_red (_("The address you're trying to add is already used by user")." '$user'.");
470 }
471 }
472 }
473 }
475 /* Delete alternate email addresses */
476 if($this->acl_is_writeable("gosaMailAlternateAddress")){
477 if (isset($_POST['delete_alternate']) && isset ($_POST['alternates_list'])){
478 if (count($_POST['alternates_list']) && $this->acl_is_writeable("gosaMailAlternateAddress")){
479 $this->delAlternate ($_POST['alternates_list']);
480 }
481 }
482 }
484 /* Show forward add dialog */
485 if ($this->forward_dialog){
486 $ldap= $this->config->get_ldap_link();
488 /* Save data */
489 $gmailfilter= get_global("gmailfilter");
490 foreach( array("depselect", "muser", "regex") as $type){
491 if (isset($_POST[$type])){
492 $gmailfilter[$type]= $_POST[$type];
493 }
494 }
495 if (isset($_GET['search'])){
496 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
497 if ($s == "**"){
498 $s= "*";
499 }
500 $gmailfilter['regex']= $s;
501 }
502 register_global("gmailfilter", $gmailfilter);
504 /* Get actual list */
505 $mailusers= array ();
506 if ($gmailfilter['regex'] != '*' && $gmailfilter['regex'] != ""){
507 $regex= $gmailfilter['regex'];
508 $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
509 } else {
510 $filter= "";
511 }
512 if ($gmailfilter['muser'] != ""){
513 $user= $gmailfilter['muser'];
514 $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
515 }
517 /* Add already present people to the filter */
518 $exclude= "";
519 foreach ($this->gosaMailForwardingAddress as $mail){
520 $exclude.= "(mail=$mail)";
521 }
522 if ($exclude != ""){
523 $filter.= "(!(|$exclude))";
524 }
526 $res= get_list("(&(objectClass=gosaMailAccount)$filter)", "users", $gmailfilter['depselect'],
527 array("sn", "mail", "givenName"), GL_SUBSEARCH | GL_SIZELIMIT);
528 $ldap->cd($gmailfilter['depselect']);
529 $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
530 error_reporting (0);
531 while ($attrs= $ldap->fetch()){
532 if(preg_match('/%/', $attrs['mail'][0])){
533 continue;
534 }
535 $name= $this->make_name($attrs);
536 $mailusers[$attrs['mail'][0]]= $name."<".
537 $attrs['mail'][0].">";
538 }
539 error_reporting (E_ALL | E_STRICT);
540 natcasesort ($mailusers);
541 reset ($mailusers);
543 /* Show dialog */
544 $smarty->assign("search_image", get_template_path('images/search.png'));
545 $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
546 $smarty->assign("tree_image", get_template_path('images/tree.png'));
547 $smarty->assign("infoimage", get_template_path('images/info.png'));
548 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
549 $smarty->assign("mailusers", $mailusers);
550 $smarty->assign("deplist", $this->config->idepartments);
551 $smarty->assign("apply", apply_filter());
552 $smarty->assign("alphabet", generate_alphabet());
553 $smarty->assign("hint", print_sizelimit_warning());
554 foreach( array("depselect", "muser", "regex") as $type){
555 $smarty->assign("$type", $gmailfilter[$type]);
556 }
557 $smarty->assign("hint", print_sizelimit_warning());
558 $display.= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE));
559 return ($display);
560 }
562 /* Assemble normal permissions */
563 if (isset($this->imapacl['anyone'])){
564 $smarty->assign("default_permissions", $this->imapacl['anyone']);
565 }
566 $smarty->assign("member_permissions", "lrsp");
567 if (isset($this->imapacl['%members%'])){
568 $smarty->assign("member_permissions", $this->imapacl['%members%']);
569 }
571 /* Assemble extra attributes */
572 $perm= $this->getacl( "permissions");
573 $tmp= "";
574 $nr= 0;
575 $count= count($this->imapacl);
576 $this->indexed_user= array();
577 $this->indexed_acl= array();
578 foreach($this->imapacl as $user => $acl){
580 /* Add additional acl settings */
581 if ($user != "anyone" && $user != "%members%"){
583 $Dis = "";
584 if(!preg_match("/w/",$perm)){
585 $Dis = " disabled ";
586 }
588 /* Reset given Acls to ensure that nobody can read username and acls if not allwoed */
589 if(!preg_match("/r/",$perm)){
590 $user = "";
591 $nr = "none";
592 $key = "none";
593 }
595 $tmp.= "<tr>
596 <td>
597 <input name=\"user_$nr\" size=20 maxlength=60 value=\"$user\" ".$Dis.">
598 </td>
599 <td>
600 <select size=\"1\" name=\"perm_$nr\" ".$Dis.">";
602 /* Add acl options for this additional acl setting */
603 if(preg_match("/r/",$perm)){
604 foreach ($this->perms as $key => $value){
605 if ($acl == $key){
606 $tmp.= "<option value=\"$key\" selected>$value</option>";
607 } else {
608 $tmp.= "<option value=\"$key\">$value</option>";
609 }
610 }
611 }
612 $tmp.= "</select> ";
616 if ($nr == $count - 1){
617 if($this->acl_is_writeable("acl")){
618 $tmp.= "<input type=submit value=\""._("Add")."\" ".
619 "name=\"add_$nr\" >";
620 }
621 }
622 if ($count > 3){
623 if($this->acl_is_writeable("acl")){
624 $tmp.= "<input type=submit value=\""._("Remove")."\" ".
625 "name=\"del_$nr\" ></td></tr>";
626 }
627 }
628 }
629 $this->indexed_user[$nr]= $user;
630 $this->indexed_acl[$nr++]= $acl;
631 }
632 $smarty->assign("plusattributes", $tmp);
634 /* Show main page */
635 $mailserver= array();
636 foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
637 $mailserver[]= $key;
638 }
639 $smarty->assign("mailServers", $mailserver);
640 foreach(array("gosaMailServer", "gosaMailQuota", "perms", "mail",
641 "gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
642 $smarty->assign("$val", $this->$val);
643 }
644 if (is_numeric($this->gosaMailQuota) && $this->gosaMailQuota != 0){
645 if($this->acl_is_readable("gosaMailQuota")){
646 $smarty->assign("quotausage", progressbar(round(($this->quotaUsage * 100)/ $this->gosaMailQuota),100,15,true));
647 $smarty->assign("quotadefined", "true");
648 }else{
649 $smarty->assign("quotadefined", "true");
650 $smarty->assign("quotausage", "-");
651 }
652 } else {
653 $smarty->assign("quotadefined", "false");
654 }
656 if(isset($this->config->current['MAILMETHOD'])&&preg_match("/olab/i",$this->config->current['MAILMETHOD'])){
658 $smarty->assign("kolab", TRUE);
659 $smarty->assign("JS",$_SESSION['js']);
660 $smarty->assign("kolabFolderType_Types", array ( '' => _('Unspecified'), 'mail' => _('Mails'),
661 'task' => _('Tasks') , 'journal' => _('Journals'),
662 'calendar' => _('Calendar'), 'contact' => _('Contacts'),
663 'note' => _('Notes')));
664 if($this->kolabFolderType_Type == "mail"){
665 $smarty->assign("kolabFolderType_SubTypes", array(
666 '' => _('Unspecified'), 'inbox' => _("Inbox") ,
667 'drafts' => _("Drafts"), 'sentitems' => _("Sent items"),
668 'junkemail' => _("Junk mail")));
669 }else{
670 $smarty->assign("kolabFolderType_SubTypes", array( 'default' => _("Default")));
671 }
672 $smarty->assign("kolabFolderType_Type", $this->kolabFolderType_Type);
673 $smarty->assign("kolabFolderType_SubType", $this->kolabFolderType_SubType);
674 }else{
675 $smarty->assign("kolab", FALSE);
676 }
679 $display.= $smarty->fetch (get_template_path('mail.tpl', TRUE));
680 return ($display);
681 }
684 /* remove object from parent */
685 function remove_from_parent()
686 {
687 if(!$this->initially_was_account){
688 return;
689 }
691 /* Added these ObjectClass and Attributes, because they were not
692 removed correctly, only in case of kolab ...
693 */
694 if(isset($this->config->current['MAILMETHOD'])&&preg_match("/olab/i",$this->config->current['MAILMETHOD'])){
695 $this->attributes[]="acl";
696 $this->objectclasses[] = "kolabSharedFolder";
697 }
698 /* include global link_info */
699 $ldap= $this->config->get_ldap_link();
701 /* Remove and write to LDAP */
702 plugin::remove_from_parent();
704 /* Zero arrays */
705 $this->attrs['gosaMailAlternateAddress']= array();
706 $this->attrs['gosaMailForwardingAddress']= array();
707 $this->attrs['gosaSharedFolderTarget']= array();
709 /* Connect to IMAP server for account deletion */
710 if ($this->initially_was_account){
712 $method= new $this->method($this->config);
713 $method->fixAttributesOnRemove($this);
714 if ($method->connect($this->gosaMailServer) && $this->remove_folder_from_imap){
716 /* Remove account from IMAP server */
717 $method->deleteMailbox($this->uid);
718 $method->disconnect();
719 }
720 }
721 /* Keep uid */
722 unset ($this->attrs['uid']);
724 $ldap->cd($this->dn);
725 $ldap->modify ($this->attrs);
726 show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/mail with dn '%s' failed."),$this->dn));
729 new log("remove","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
731 /* Optionally execute a command after we're done */
732 $this->handle_post_events("remove");
733 }
736 /* Save data to object */
737 function save_object()
738 {
740 /* Add special kolab attributes */
741 if(isset($this->config->current['MAILMETHOD'])&&preg_match("/olab/i",$this->config->current['MAILMETHOD'])){
742 if(isset($_POST['kolabFolderType_Type'])){
743 $this->kolabFolderType_Type = get_post("kolabFolderType_Type");
744 $this->kolabFolderType_SubType = get_post("kolabFolderType_SubType");
745 }
746 }
748 /* Check if user wants to remove the shared folder from imap too */
749 if($this->initially_was_account && !$this->is_account){
750 if(isset($_POST['remove_folder_from_imap'])){
751 $this->remove_folder_from_imap = true;
752 }else{
753 $this->remove_folder_from_imap = false;
754 }
755 }
757 /* Assemble mail delivery mode
758 The mode field in ldap consists of values between braces, this must
759 be called when 'mail' is set, because checkboxes may not be set when
760 we're in some other dialog.
762 Example for gosaMailDeliveryMode [LR ]
763 L: Local delivery
764 R: Reject when exceeding mailsize limit
765 S: Use spam filter
766 V: Use vacation message
767 C: Use custom sieve script
768 I: Only insider delivery */
769 if (isset($_POST['mailedit'])){
771 plugin::save_object();
773 $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
775 /* Handle delivery flags */
776 if($this->acl_is_writeable("gosaMailDeliveryModeL")){
777 if(!preg_match("/L/",$tmp) && !isset($_POST['drop_own_mails'])){
778 $tmp.="L";
779 }elseif(preg_match("/L/",$tmp) && isset($_POST['drop_own_mails'])){
780 $tmp = preg_replace("/L/","",$tmp);
781 }
782 }
784 $opts = array(
785 "R" => "use_mailsize_limit",
786 "S" => "use_spam_filter",
787 "V" => "use_vacation",
788 "C" => "own_script",
789 "I" => "only_local");
791 foreach($opts as $flag => $post){
792 if($this->acl_is_writeable("gosaMailDeliveryMode".$flag)){
793 if(!preg_match("/".$flag."/",$tmp) && isset($_POST[$post])){
794 $tmp.= $flag;
795 }elseif(preg_match("/".$flag."/",$tmp) && !isset($_POST[$post])){
796 $tmp = preg_replace("/".$flag."/","",$tmp);
797 }
798 }
799 }
801 $tmp= "[$tmp]";
802 if ($this->gosaMailDeliveryMode != $tmp){
803 $this->is_modified= TRUE;
804 }
805 $this->gosaMailDeliveryMode= $tmp;
807 /* Collect data and re-assign it to the imapacl array */
808 if ($this->acl_is_writeable("acl")){
809 $this->imapacl= array();
810 $this->imapacl['%members%']= $_POST['member_permissions'];
811 $this->imapacl['anyone']= $_POST['default_permissions'];
812 foreach ($this->indexed_user as $nr => $user){
813 if (!isset($_POST["user_$nr"])){
814 continue;
815 }
816 if ($_POST["user_$nr"] != $user ||
817 $_POST["perm_$nr"] != $this->indexed_acl[$nr]){
818 $this->is_modified= TRUE;
819 }
820 $this->imapacl[$_POST["user_$nr"]]= $_POST["perm_$nr"];
821 }
822 }
823 }
825 }
829 /* Save data to LDAP, depending on is_account we save or delete */
830 function save()
831 {
832 $ldap= $this->config->get_ldap_link();
833 $ldap->cd($this->config->current['BASE']);
835 /* Call parents save to prepare $this->attrs */
836 plugin::save();
838 /* Save arrays */
839 $this->attrs['gosaMailAlternateAddress'] = $this->gosaMailAlternateAddress;
840 $this->attrs['gosaMailForwardingAddress'] = $this->gosaMailForwardingAddress;
841 $this->attrs['gosaSharedFolderTarget'] = "share+".$this->uid;
843 /* Only do IMAP actions if we are not a template */
844 if(preg_match("/olab/i",$this->mmethod)){
845 if (empty($this->gosaMailServer)||is_array($this->gosaMailServer)){
846 if(isset($this->attrs['gosaMailServer'][0])){
847 $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
848 }
849 }
850 }
852 /* Exchange '%member%' pseudo entry */
853 $memberacl= $this->imapacl['%members%'];
855 foreach ($this->members as $user){
856 if (!isset($this->imapacl[$user])){
857 $this->imapacl[$user]= $memberacl;
858 }
859 }
861 if(preg_match("/olab/i",$this->mmethod)){
863 /* Save acl's */
864 $this->attrs['acl']= array();
865 foreach ($this->imapacl as $user => $acl){
866 if ($user == "" || preg_match("/%members%/",$user)){
867 continue;
868 }
869 $ldap->search("(&(objectClass=person)(|(uid=".$user.")(mail=".$user.")))",array("mail"));
870 $mail = $ldap->fetch();
871 if(isset($mail['mail'][0])){
872 $sacl = $mail['mail'][0]." ".$acl;
873 }else{
874 $sacl= "$user $acl";
875 }
876 if(!in_array($sacl,$this->attrs['acl'])){
877 $this->attrs['acl'][]= $sacl;
878 }
879 }
881 if(!empty($this->kolabFolderType_Type)){
882 $this->attrs['kolabFolderType'] = $this->kolabFolderType_Type.".".$this->kolabFolderType_SubType;
883 }else{
884 $this->attrs['kolabFolderType'] = array();
885 }
886 }else{
888 /* Save acl's */
889 $this->attrs['acl']= array();
890 foreach ($this->imapacl as $user => $acl){
891 if ($user == "" || preg_match("/%members%/",$user)){
892 continue;
893 }
894 $this->attrs['acl'][]= "$user $acl";
895 }
896 }
898 if ((!$this->is_template)&&(!empty($this->gosaMailServer))){
899 $method= new $this->method($this->config);
900 $method->fixAttributesOnStore($this);
901 if (($method->connect($this->gosaMailServer))){
902 $method->updateMailbox($this->uid);
903 $method->setQuota($this->uid, $this->gosaMailQuota);
904 $method->setSharedFolderPermissions($this->uid, $this->imapacl);
905 $method->disconnect();
906 }
907 }
909 /* Save data to LDAP */
910 $ldap->cd($this->dn);
911 $this->cleanup();
912 $ldap->modify ($this->attrs);
913 show_ldap_error($ldap->get_error(), sprintf(_("Saving of groups/mail with dn '%s' failed."),$this->dn));
915 if($this->initially_was_account){
916 new log("modify","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
917 }else{
918 new log("create","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
919 }
922 /* Optionally execute a command after we're done */
923 if ($this->initially_was_account == $this->is_account){
924 if ($this->is_modified){
925 $this->handle_post_events("modify");
926 }
927 } else {
928 $this->handle_post_events("add");
929 }
930 }
932 /* Check formular input */
933 function check()
934 {
935 $ldap= $this->config->get_ldap_link();
937 /* Call common method to give check the hook */
938 $message= plugin::check();
940 if(!$this->is_account) return array();
942 //$message[] = $str;
944 /* must: mail */
945 if ($this->mail == ""){
946 $message[]= _("The required field 'Primary address' is not set.");
947 }
948 if (!is_email($this->mail)){
949 $message[]= _("Please enter a valid email addres in 'Primary address' field.");
950 }
951 $ldap->cd($this->config->current['BASE']);
952 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=".$this->mail.")(gosaMailAlternateAddress=".
953 $this->mail."))(!(uid=".$this->orig_cn."))(!(cn=".$this->orig_cn.")))");
954 if ($ldap->count() != 0){
955 $message[]= _("The primary address you've entered is already in use.");
956 }
958 /* Check quota */
959 if ($this->gosaMailQuota != '' && $this->acl_is_writeable("gosaMailQuota")){
960 if (!is_numeric($this->gosaMailQuota)) {
961 $message[]= _("Value in 'Quota size' is not valid.");
962 } else {
963 $this->gosaMailQuota= (int) $this->gosaMailQuota;
964 }
965 }
967 /* Check rejectsize for integer */
968 if ($this->gosaMailMaxSize != '' && $this->acl_is_writeable("gosaMailQuota")){
969 if (!is_numeric($this->gosaMailMaxSize)){
970 $message[]= _("Please specify a vaild mail size for mails to be rejected.");
971 } else {
972 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
973 }
974 }
976 /* Need gosaMailMaxSize if use_mailsize_limit is checked */
977 if (is_integer(strpos($this->gosaMailDeliveryMode, "reject")) && $this->gosaMailMaxSize == ""){
978 $message[]= _("You need to set the maximum mail size in order to reject anything.");
979 }
981 if(ord($this->imapacl['anyone'][0])==194){
982 $message[] = _("Please choose valid permission settings. Default permission can't be emtpy.");
983 }
985 if(empty($this->gosaMailServer)){
986 $message[] = _("Please select a valid mail server.");
987 }
989 return ($message);
990 }
992 /* Adapt from template, using 'dn' */
993 function adapt_from_template($dn)
994 {
995 plugin::adapt_from_template($dn);
997 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
998 $this->$val= array();
999 if (isset($this->attrs["$val"]["count"])){
1000 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
1001 $value= $this->attrs["$val"][$i];
1002 foreach (array("sn", "givenName", "uid") as $repl){
1003 if (preg_match("/%$repl/i", $value)){
1004 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
1005 }
1006 }
1007 array_push($this->$val, $value);
1008 }
1009 }
1010 }
1011 }
1013 /* Add entry to forwarder list */
1014 function addForwarder($address)
1015 {
1016 $this->gosaMailForwardingAddress[]= $address;
1017 $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
1019 sort ($this->gosaMailForwardingAddress);
1020 reset ($this->gosaMailForwardingAddress);
1021 $this->is_modified= TRUE;
1022 }
1024 /* Remove list of addresses from forwarder list */
1025 function delForwarder($addresses)
1026 {
1027 $this->gosaMailForwardingAddress= array_remove_entries ($addresses,
1028 $this->gosaMailForwardingAddress);
1029 $this->is_modified= TRUE;
1030 }
1034 function addAlternate($address)
1035 {
1036 $ldap= $this->config->get_ldap_link();
1038 $address= strtolower($address);
1040 /* Is this address already assigned in LDAP? */
1041 $ldap->cd ($this->config->current['BASE']);
1042 $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)".
1043 "(gosaMailAlternateAddress=$address)))");
1045 if ($ldap->count() > 0){
1046 $attrs= $ldap->fetch ();
1047 return ($attrs["uid"][0]);
1048 }
1050 /* Add to list of alternates */
1051 if (!in_array($address, $this->gosaMailAlternateAddress)){
1052 $this->gosaMailAlternateAddress[]= $address;
1053 }
1055 sort ($this->gosaMailAlternateAddress);
1056 reset ($this->gosaMailAlternateAddress);
1057 $this->is_modified= TRUE;
1059 return ("");
1060 }
1063 function delAlternate($addresses)
1064 {
1065 $this->gosaMailAlternateAddress= array_remove_entries ($addresses,
1066 $this->gosaMailAlternateAddress);
1067 $this->is_modified= TRUE;
1068 }
1071 function make_name($attrs)
1072 {
1073 $name= "";
1074 if (isset($attrs['sn'][0])){
1075 $name= $attrs['sn'][0];
1076 }
1077 if (isset($attrs['givenName'][0])){
1078 if ($name != ""){
1079 $name.= ", ".$attrs['givenName'][0];
1080 } else {
1081 $name.= $attrs['givenName'][0];
1082 }
1083 }
1084 if ($name != ""){
1085 $name.= " ";
1086 }
1088 return ($name);
1089 }
1091 function getCopyDialog()
1092 {
1093 if(!$this->is_account) return("");
1095 $smarty = get_smarty();
1096 $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress);
1097 $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress);
1098 $smarty->assign("mail",$this->mail);
1099 $display= $smarty->fetch (get_template_path('paste_mail.tpl', TRUE));
1100 $ret = array();
1101 $ret['string'] = $display;
1102 $ret['status'] = "";
1103 return($ret);
1104 }
1106 function saveCopyDialog()
1107 {
1108 if(!$this->is_account) return;
1110 /* Perform ADD / REMOVE ... for mail alternate / mail forwarding addresses
1111 */
1112 $this->execute();
1113 if(isset($_POST['mail'])){
1114 $this->mail = $_POST['mail'];
1115 }
1116 }
1119 function PrepareForCopyPaste($source)
1120 {
1121 plugin::PrepareForCopyPaste($source);
1123 /* Reset alternate mail addresses */
1124 $this->gosaMailAlternateAddress = array();
1125 }
1128 /* Return plugin informations for acl handling */
1129 static function plInfo()
1130 {
1131 return (array(
1132 "plShortName" => _("Mail"),
1133 "plDescription" => _("Group mail"),
1134 "plSelfModify" => FALSE,
1135 "plDepends" => array(),
1136 "plPriority" => 0,
1137 "plSection" => array("administration"),
1138 "plCategory" => array("groups"),
1139 "plProvidedAcls"=> array(
1140 "mail" => _("Mail address"),
1141 "gosaMailAlternateAddress" => _("Alternate addresses"),
1142 "gosaMailForwardingAddress" => _("Forwarding addresses"),
1143 "gosaMailQuota" => _("Quota size"),
1144 "gosaMailServer" => _("Mail server"),
1145 "acl" => _("Permissions"))
1146 ));
1147 }
1150 /* Remove given ACL for given member (uid,mail) ..
1151 */
1152 function removeUserAcl($index )
1153 {
1154 if(isset($this->imapacl[$index])){
1155 unset($this->imapacl[$index]);
1156 }
1157 }
1159 }
1161 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1162 ?>