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