1 <?php
2 /*! \brief mail plugin
3 \author Cajus Pollmeier <pollmeier@gonicus.de>
4 \version 2.00
5 \date 24.07.2003
7 This class provides the functionality to read and write all attributes
8 relevant for gosaMailAccounts from/to the LDAP. It does syntax checking
9 and displays the formulars required.
10 */
12 /* Load sieve support */
13 require_once ("class_sieve.inc");
15 /* Load mail methods */
16 global $BASE_DIR;
17 get_dir_list("$BASE_DIR/include");
19 class mailAccount extends plugin
20 {
21 /* Definitions */
22 var $plHeadline = "Mail";
23 var $plDescription = "This does something";
24 var $method = "mailMethod";
26 /* CLI vars */
27 var $cli_summary = "Manage users mail account";
28 var $cli_description = "Some longer text\nfor help";
29 var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
31 /* plugin specific values */
32 var $mail = "";
33 var $uid = "";
34 var $gosaMailAlternateAddress = array();
35 var $gosaMailForwardingAddress = array();
36 var $gosaMailDeliveryMode = "[L ]";
37 var $gosaMailServer = "";
38 var $gosaMailQuota = "";
39 var $gosaMailMaxSize = "";
40 var $gosaVacationMessage = "";
41 var $gosaSpamSortLevel = "";
42 var $gosaSpamMailbox = "";
44 var $quotaUsage = 0;
45 var $forward_dialog = FALSE;
46 var $folder_prefix = "";
47 var $mailboxList = array();
48 var $default_permissions = "none";
49 var $member_permissions = "post";
50 var $members = array();
51 var $admins = array();
52 var $vacations = array();
53 var $perms = array( "lrs" => "read",
54 "lrsp" => "post",
55 "lrsip" => "append",
56 "lrswipcd" => "write",
57 "lrswipcda" => "all" );
59 /* attribute list for save action */
60 var $attributes= array("mail", "gosaMailServer", "gosaMailQuota", "gosaMailMaxSize","gosaMailForwardingAddress",
61 "gosaMailDeliveryMode", "gosaSpamSortLevel", "gosaSpamMailbox","gosaMailAlternateAddress",
62 "gosaVacationMessage", "gosaMailAlternateAddress", "gosaMailForwardingAddress");
63 var $objectclasses= array("gosaMailAccount");
66 /* constructor, if 'dn' is set, the node loads the given
67 'dn' from LDAP */
68 function mailAccount ($config, $dn= NULL)
69 {
70 /* Load bases attributes */
71 plugin::plugin($config, $dn);
73 if(isset($this->attrs['uid'])){
74 $this->uid = $this->attrs['uid'][0];
75 }
77 if(is_array($this->gosaMailServer) && isset($this->gosaMailServer[0])){
78 $this->gosaMailServer = $this->gosaMailServer[0];
79 }
81 /* Save initial account state */
82 $this->initially_was_account= $this->is_account;
84 /* Set mailMethod to the one defined in gosa.conf */
85 if (isset($this->config->current['MAILMETHOD'])){
86 $method= $this->config->current['MAILMETHOD'];
87 if (class_exists("mailMethod$method")){
88 $this->method= "mailMethod$method";
89 } else {
90 print_red(sprintf(_("There is no mail method '%s' specified in your gosa.conf available."), $method));
91 }
92 }
95 /* Create the account prefix user. user/
96 Preset folder prefix. Will change it later to respect
97 altnamespace. */
98 if (isset($this->config->current['CYRUSUNIXSTYLE']) && $this->config->current['CYRUSUNIXSTYLE'] == "true"){
99 $this->folder_prefix= "user/";
100 }elseif (isset($this->config->data['MAIN']['CYRUSUNIXSTYLE']) && $this->config->data['MAIN']['CYRUSUNIXSTYLE'] == "true"){
101 $this->folder_prefix= "user/";
102 } else {
103 $this->folder_prefix= "user.";
104 }
106 /* This is not a new account, parse additional attributes */
107 if (($dn != NULL) && ($dn != "new") && $this->is_account){
109 /* Load attributes containing arrays */
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 }
120 /* Only do IMAP actions if gosaMailServer attribute is set */
121 if (isset ($this->attrs["gosaMailServer"][0])){
123 $method = new $this->method($this->config);
124 $id = $method->uattrib;
126 /* Adapt attributes if needed */
127 $method->fixAttributesOnLoad($this);
129 /* FixAttributesOnLoad possibly creates an array out of gosaMailServer.
130 If the mail tab wasn't opened once before saving, the account can't be saved */
131 if(is_array($this->gosaMailServer)){
132 $this->gosaMailServer = $this->gosaMailServer[0];
133 }
135 if ($method->connect($this->attrs["gosaMailServer"][0])){
137 /* Update quota values */
138 $quota= $method->getQuota($this->folder_prefix.$this->$id);
140 if($quota){
141 if ($quota['gosaMailQuota'] == 2147483647){
142 $this->quotaUsage = "";
143 $this->gosaMailQuota = "";
144 } else {
145 $this->quotaUsage = $quota['quotaUsage'];
146 $this->gosaMailQuota = $quota['gosaMailQuota'];
147 }
148 }else{
149 $this->quotaUsage = "";
150 $this->gosaMailQuota = "";
151 // print_red(sprintf(_("Can't get quota information for '%s'."),$this->folder_prefix.$this->$id));
152 }
154 /* Get mailboxes / folder like INBOX ..*/
155 $this->mailboxList= $method->getMailboxList($this->folder_prefix.$this->$id,$this->$id);
157 $method->disconnect();
158 }else{
159 /* Could not connect to ldap.
160 */
161 if (isset($this->attrs['gosaMailQuota'][0])){
162 $this->gosaMailQuota = $this->attrs['gosaMailQuota'][0];
163 }
164 }
165 }
166 }
168 /* Fill vacation array */
169 $this->vacation= array();
170 if (isset($this->config->current['VACATIONDIR'])){
171 $dir= $this->config->current['VACATIONDIR'];
172 if (is_dir($dir) && is_readable($dir)){
174 /* Look for files and build the vacation array */
175 $dh= opendir($dir);
176 while ($file = readdir($dh)){
177 $description= $this->parse_vacation("$dir/$file");
178 if ($description != ""){
179 $this->vacation["$dir/$file"]= $description;
180 }
181 }
182 closedir($dh);
183 }
184 }
187 /* Create filter */
189 /* Get global filter config */
190 if (!is_global("mailfilter")){
191 $ui= get_userinfo();
192 $base= get_base_from_people($ui->dn);
193 $mailfilter= array( "depselect" => $base,
194 "muser" => "",
195 "regex" => "*");
196 register_global("mailfilter", $mailfilter);
197 }
198 }
201 function parse_vacation($file)
202 {
203 $desc= "";
205 if (is_file($file)){
206 $fh = fopen($file, "r");
207 $line= fgets($fh, 256);
209 if (!preg_match('/^DESC:/', $line)){
210 print_red (_("No DESC tag in vacation file:")." $file");
211 return $desc;
212 }
213 fclose ($fh);
215 $desc= trim(preg_replace('/^DESC:\s*/', '', $line));
216 }
218 return $desc;
219 }
222 function execute()
223 {
224 /* Call parent execute */
225 plugin::execute();
227 /* Initialise vars */
229 /* Load templating engine */
230 $smarty= get_smarty();
231 $display= "";
233 /* Get available mailserver */
234 $mailserver= array();
235 foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
236 $mailserver[]= $key;
237 }
239 /* Handle account state */
241 /* Do we need to flip is_account state? */
242 if (isset($_POST['modify_state'])){
243 $this->is_account= !$this->is_account;
244 }
246 /* Do we represent a valid account? */
247 if (!$this->is_account && $this->parent == NULL){
248 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
249 _("This account has no mail extensions.")."</b>";
251 $display.= back_to_main();
252 return ($display);
253 }
255 /* Show tab dialog headers */
256 if ($this->parent != NULL){
257 if ($this->is_account){
258 $display= $this->show_disable_header(_("Remove mail account"),
259 _("This account has mail features enabled. You can disable them by clicking below."));
260 } else {
261 $display= $this->show_enable_header(_("Create mail account"), _("This account has mail features disabled. You can enable them by clicking below."));
262 return ($display);
263 }
264 }
267 /* Forwarder subdialog */
269 /* Trigger forward add dialog? */
270 if (isset($_POST['add_local_forwarder'])){
271 $this->forward_dialog= TRUE;
272 $this->dialog= TRUE;
273 }
275 /* Cancel forward add dialog? */
276 if (isset($_POST['add_locals_cancel'])){
277 $this->forward_dialog= FALSE;
278 $this->dialog= FALSE;
279 }
281 /* Finished adding of locals? */
282 if (isset($_POST['add_locals_finish'])){
284 /* Check if we are able to write gosaMailForwardingAddress */
285 if($this->acl_is_writeable("gosaMailForwardingAddress")){
287 /* Walk through list of forwarders, ignore own addresses */
288 foreach ($_POST['local_list'] as $val){
289 if (!in_array ($val, $this->gosaMailAlternateAddress) &&
290 $val != $this->mail){
292 $this->addForwarder($val);
293 $this->is_modified= TRUE;
294 }
295 }
296 }
297 $this->forward_dialog= FALSE;
298 $this->dialog= FALSE;
299 }
301 /* Add forward email addresses */
302 if (isset($_POST['add_forwarder'])){
303 if ($_POST['forward_address'] != ""){
305 /* Valid email address specified? */
306 $address= $_POST['forward_address'];
307 $valid= FALSE;
308 if (!is_email($address)){
309 if (!is_email($address, TRUE)){
310 if ($this->is_template){
311 $valid= TRUE;
312 } else {
313 print_red (_("You're trying to add an invalid email address to the list of forwarders."));
314 }
315 }
316 } elseif ($address == $this->mail
317 || in_array($address, $this->gosaMailAlternateAddress)) {
319 print_red (_("Adding your one of your own addresses to the forwarders makes no sense."));
321 } else {
322 $valid= TRUE;
323 }
325 if ($valid){
327 /* Add it, if we are able to write gosaMailForwardingAddress */
328 if($this->acl_is_writeable("gosaMailForwardingAddress")){
329 $this->addForwarder ($address);
330 $this->is_modified= TRUE;
331 }
332 }
333 }
334 }
336 /* Delete forward email addresses */
337 if (isset($_POST['delete_forwarder'])){
338 $this->delForwarder ($_POST['forwarder_list']);
339 }
342 /* Add alternate email addresses */
343 if (isset($_POST['add_alternate'])){
345 $valid= FALSE;
346 if (!is_email($_POST['alternate_address'])){
347 if ($this->is_template){
348 if (!(is_email($_POST['alternate_address'], TRUE))){
349 print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
350 } else {
351 $valid= TRUE;
352 }
353 } else {
354 print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
355 }
357 } else {
358 $valid= TRUE;
359 }
361 if ($valid && ($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
362 $ui= get_userinfo();
363 if ($user != $ui->username){
364 print_red (_("The address you're trying to add is already used by user")." '$user'.");
365 }
366 }
367 }
369 /* Delete alternate email addresses */
370 if (isset($_POST['delete_alternate']) && isset($_POST['alternates_list'])){
371 $this->delAlternate ($_POST['alternates_list']);
372 }
375 /* Vacation message */
377 /* Import vacation message? */
378 if (isset($_POST["import_vacation"]) && isset($this->vacation[$_POST["vacation_template"]])){
379 $contents= "";
380 $lines= file($_POST["vacation_template"]);
381 foreach ($lines as $line){
382 if (!preg_match('/^DESC:/', $line)){
383 $contents.= $line;
384 }
385 }
387 /* Replace attributes */
388 $attrs= $this->parent->by_object['user']->attributes;
389 foreach ($attrs as $val){
390 $contents= preg_replace("/%$val/",
391 $this->parent->by_object['user']->$val, $contents);
392 }
394 /* Save message */
395 $this->gosaVacationMessage= htmlspecialchars($contents);
396 }
399 /* Display forward dialog if requested above */
401 /* Show forward add dialog */
402 if ($this->forward_dialog){
403 $ldap= $this->config->get_ldap_link();
405 /* Save data */
406 $mailfilter= get_global("mailfilter");
407 foreach( array("depselect", "muser", "regex") as $type){
408 if (isset($_POST[$type])){
409 $mailfilter[$type]= $_POST[$type];
410 }
411 }
412 if (isset($_GET['search'])){
413 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
414 if ($s == "**"){
415 $s= "*";
416 }
417 $mailfilter['regex']= $s;
418 }
419 register_global("mailfilter", $mailfilter);
421 /* Get actual list */
422 $mailusers= array ();
423 if ($mailfilter['regex'] != '*' && $mailfilter['regex'] != ""){
424 $regex= $mailfilter['regex'];
425 $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
426 } else {
427 $filter= "";
428 }
429 if ($mailfilter['muser'] != ""){
430 $user= $mailfilter['muser'];
431 $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
432 }
434 /* Add already present people to the filter */
435 $exclude= "";
436 foreach ($this->gosaMailForwardingAddress as $mail){
437 $exclude.= "(mail=$mail)";
438 }
439 if ($exclude != ""){
440 $filter.= "(!(|$exclude))";
441 }
443 $acl= array($this->config->current['BASE'] => ":all");
444 $res= get_list("(&(objectClass=gosaMailAccount)$filter)", $acl, $mailfilter['depselect'],
445 array("sn", "mail", "givenName"), GL_SIZELIMIT | GL_SUBSEARCH);
446 $ldap->cd($mailfilter['depselect']);
447 $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
448 error_reporting (0);
449 while ($attrs= $ldap->fetch()){
450 if(preg_match('/%/', $attrs['mail'][0])){
451 continue;
452 }
453 $name= $this->make_name($attrs);
454 $mailusers[$attrs['mail'][0]]= $name."<".
455 $attrs['mail'][0].">";
456 }
457 error_reporting (E_ALL);
458 natcasesort ($mailusers);
459 reset ($mailusers);
461 /* Show dialog */
462 $smarty->assign("search_image", get_template_path('images/search.png'));
463 $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
464 $smarty->assign("tree_image", get_template_path('images/tree.png'));
465 $smarty->assign("infoimage", get_template_path('images/info.png'));
466 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
467 $smarty->assign("mailusers", $mailusers);
468 if (isset($_POST['depselect'])){
469 $smarty->assign("depselect", $_POST['depselect']);
470 }
471 $smarty->assign("deplist", $this->config->idepartments);
472 $smarty->assign("apply", apply_filter());
473 $smarty->assign("alphabet", generate_alphabet());
474 $smarty->assign("hint", print_sizelimit_warning());
475 foreach( array("depselect", "muser", "regex") as $type){
476 $smarty->assign("$type", $mailfilter[$type]);
477 }
478 $smarty->assign("hint", print_sizelimit_warning());
480 $display.= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE, dirname(__FILE__)));
481 return ($display);
482 }
484 /* Display mail account tab */
486 $smarty->assign("mailServers", $mailserver);
488 $tmp = $this->plInfo();
489 foreach($tmp['plProvidedAcls'] as $name => $transl){
490 $smarty->assign("$name"."ACL", $this->getacl($name));
491 }
493 foreach(array("gosaMailServer", "gosaMailQuota", "perms", "mail",
494 "gosaMailAlternateAddress", "gosaMailForwardingAddress",
495 "gosaVacationMessage", "gosaMailDeliveryMode",
496 "gosaMailMaxSize", "gosaSpamSortLevel", "gosaSpamMailbox") as $val){
497 $smarty->assign("$val", $this->$val);
498 }
500 if (is_numeric($this->gosaMailQuota) && $this->gosaMailQuota != 0){
501 $smarty->assign("quotausage", progressbar(round(($this->quotaUsage * 100)/ $this->gosaMailQuota),100,15,true));
502 $smarty->assign("quotadefined", "true");
503 } else {
504 $smarty->assign("quotadefined", "false");
505 }
507 /* Disable mail field if needed */
508 $method= new $this->method($this->config);
509 if ($method->uattrib == "mail" && $this->initially_was_account){
510 $smarty->assign("mailACL", "disabled");
511 }
514 if (!preg_match("/L/", $this->gosaMailDeliveryMode)) {
515 $smarty->assign("drop_own_mails", "checked");
516 } else {
517 $smarty->assign("drop_own_mails", "");
518 }
520 $types = array(
521 "V"=>"use_vacation",
522 "S"=>"use_spam_filter",
523 "R"=>"use_mailsize_limit",
524 "I"=>"only_local",
525 "C"=>"own_script");
527 /* Fill checkboxes */
528 foreach($types as $option => $varname){
529 if (preg_match("/".$option."/", $this->gosaMailDeliveryMode)) {
530 $smarty->assign($varname, "checked");
531 } else {
532 $smarty->assign($varname, "");
533 }
534 }
536 if (preg_match("/V/", $this->gosaMailDeliveryMode)) {
537 $smarty->assign("use_vacation", "checked");
538 } else {
539 $smarty->assign("use_vacation", "");
540 }
541 if (preg_match("/S/", $this->gosaMailDeliveryMode)) {
542 $smarty->assign("use_spam_filter", "checked");
543 } else {
544 $smarty->assign("use_spam_filter", "");
545 }
546 if (preg_match("/R/", $this->gosaMailDeliveryMode)) {
547 $smarty->assign("use_mailsize_limit", "checked");
548 } else {
549 $smarty->assign("use_mailsize_limit", "");
550 }
551 if (preg_match("/I/", $this->gosaMailDeliveryMode)) {
552 $smarty->assign("only_local", "checked");
553 } else {
554 $smarty->assign("only_local", "");
555 }
556 if (preg_match("/C/", $this->gosaMailDeliveryMode)) {
557 $smarty->assign("own_script", "checked");
558 } else {
559 $smarty->assign("own_script", "");
560 }
562 /* Have vacation templates? */
563 $smarty->assign("template", "");
564 if (count($this->vacation)){
565 $smarty->assign("show_templates", "true");
566 $smarty->assign("vacationtemplates", $this->vacation);
567 if (isset($_POST['vacation_template'])){
568 $smarty->assign("template", $_POST['vacation_template']);
569 }
570 } else {
571 $smarty->assign("show_templates", "false");
572 }
574 /* Fill spam selector */
575 $spamlevel= array();
576 for ($i= 0; $i<21; $i++){
577 $spamlevel[]= $i;
578 }
579 $smarty->assign("spamlevel", $spamlevel);
580 $smarty->assign("spambox", $this->mailboxList);
582 $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
583 return ($display);
584 }
587 /* remove object from parent */
588 function remove_from_parent()
589 {
590 /* Cancel if there's nothing to do here */
591 if (!$this->initially_was_account){
592 return;
593 }
595 /* include global link_info */
596 $ldap= $this->config->get_ldap_link();
598 /* Remove and write to LDAP */
599 plugin::remove_from_parent();
601 /* Zero arrays */
602 $this->attrs['gosaMailAlternateAddress']= array();
603 $this->attrs['gosaMailForwardingAddress']= array();
605 /* Adapt attributes if needed */
606 $method= new $this->method($this->config);
607 $method->fixAttributesOnRemove($this);
609 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
610 $ldap->cd($this->dn);
611 $this->cleanup();
612 $ldap->modify ($this->attrs);
614 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/mail account with dn '%s' failed."),$this->dn));
616 /* Connect to IMAP server for account deletion */
617 if ($this->gosaMailServer != ""){
618 $method= new $this->method($this->config);
619 $id= $method->uattrib;
620 if ($method->connect($this->gosaMailServer)){
622 /* Remove account from IMAP server */
623 $method->deleteMailbox($this->folder_prefix.$this->$id);
624 $method->disconnect();
625 }
626 }
628 /* Optionally execute a command after we're done */
629 $this->handle_post_events("remove");
630 }
633 /* Save data to object */
634 function save_object()
635 {
636 if (isset($_POST['mailTab'])){
637 /* Save ldap attributes */
638 plugin::save_object();
640 /* Assemble mail delivery mode
641 The mode field in ldap consists of values between braces, this must
642 be called when 'mail' is set, because checkboxes may not be set when
643 we're in some other dialog.
645 Example for gosaMailDeliveryMode [LR ]
646 L: Local delivery
647 R: Reject when exceeding mailsize limit
648 S: Use spam filter
649 V: Use vacation message
650 C: Use custm sieve script
651 I: Only insider delivery */
653 $tmp= "";
654 if (!isset($_POST["drop_own_mails"])){
655 $tmp.= "L";
656 }
657 if (isset($_POST["use_mailsize_limit"])){
658 $tmp.= "R";
659 }
660 if (isset($_POST["use_spam_filter"])){
661 $tmp.= "S";
662 }
663 if (isset($_POST["use_vacation"])){
664 $tmp.= "V";
665 }
666 if (isset($_POST["own_script"])){
667 $tmp.= "C";
668 }
669 if (isset($_POST["only_local"])){
670 $tmp.= "I";
671 }
672 $tmp= "[$tmp]";
674 if ($this->gosaMailDeliveryMode != $tmp){
675 $this->is_modified= TRUE;
676 }
677 $this->gosaMailDeliveryMode= $tmp;
678 }
679 }
682 /* Save data to LDAP, depending on is_account we save or delete */
683 function save()
684 {
685 $ldap= $this->config->get_ldap_link();
687 /* Call parents save to prepare $this->attrs */
688 plugin::save();
690 /* Save arrays */
691 $this->attrs['gosaMailAlternateAddress']= $this->gosaMailAlternateAddress;
692 $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
694 /* Adapt attributes if needed */
695 $method= new $this->method($this->config);
696 $id= $method->uattrib;
698 $method->fixAttributesOnStore($this);
700 /* Remove Mailquota if = "" or "0" */
701 if((isset($this->attrs['gosaMailQuota']))&&(!$this->attrs['gosaMailQuota'])) {
702 $this->attrs['gosaMailQuota']=0;
703 }
705 if(empty($this->attrs['gosaSpamMailbox'])){
706 unset($this->attrs['gosaSpamMailbox']);
707 }
709 $this->attrs['mail'] = strtolower($this->attrs['mail']);
711 /* Save data to LDAP */
712 $ldap->cd($this->dn);
713 $this->cleanup();
714 $ldap->modify ($this->attrs);
716 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/mail account with dn '%s' failed."),$this->dn));
718 /* Only do IMAP actions if we are not a template */
719 if (!$this->is_template){
721 if ($method->connect($this->gosaMailServer)){
722 $method->updateMailbox($this->folder_prefix.$this->$id);
724 $method->setQuota($this->folder_prefix.$this->$id, $this->gosaMailQuota);
725 $method->disconnect();
727 /* Write sieve information only if not in C mode */
728 if (!is_integer(strpos($this->gosaMailDeliveryMode, "C"))){
729 $method->configureFilter($this->$id,
730 $this->gosaMailDeliveryMode,
731 $this->mail,
732 $this->gosaMailAlternateAddress,
733 $this->gosaMailMaxSize,
734 $this->gosaSpamMailbox,
735 $this->gosaSpamSortLevel,
736 $this->gosaVacationMessage);
737 }
738 }
739 }
741 /* Optionally execute a command after we're done */
742 if ($this->initially_was_account == $this->is_account){
743 if ($this->is_modified){
744 $this->handle_post_events("modify");
745 }
746 } else {
747 $this->handle_post_events("add");
748 }
750 }
753 /* Check formular input */
754 function check()
755 {
756 if(!$this->is_account) return(array());
758 $ldap= $this->config->get_ldap_link();
760 /* Call common method to give check the hook */
761 $message= plugin::check();
763 if(empty($this->gosaMailServer)){
764 $message[]= _("There is no valid mailserver specified, please add one in the system setup.");
765 }
767 /* must: mail */
768 if ($this->mail == ""){
769 $message[]= _("The required field 'Primary address' is not set.");
770 }
771 if ($this->is_template){
772 if (!is_email($this->mail, TRUE)){
773 $message[]= _("Please enter a valid email address in 'Primary address' field.");
774 }
775 } else {
776 if (!is_email($this->mail)){
777 $message[]= _("Please enter a valid email address in 'Primary address' field.");
778 }
779 }
780 $ldap->cd($this->config->current['BASE']);
781 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=".$this->mail.")(gosaMailAlternateAddress=".$this->mail."))(!(uid=".$this->uid."))(!(cn=".$this->uid.")))", array("uid"));
782 if ($ldap->count() != 0){
783 $message[]= _("The primary address you've entered is already in use.");
784 }
786 /* Check quota */
787 if ($this->gosaMailQuota != '' && $this->acl_is_writeable("gosaMailQuota")){
788 if (!is_numeric($this->gosaMailQuota)) {
789 $message[]= _("Value in 'Quota size' is not valid.");
790 } else {
791 $this->gosaMailQuota= (int) $this->gosaMailQuota;
792 }
793 }
795 /* Check rejectsize for integer */
796 if ($this->gosaMailMaxSize != '' && $this->acl_is_writeable("gosaMailMaxSize")){
797 if (!is_numeric($this->gosaMailMaxSize)){
798 $message[]= _("Please specify a vaild mail size for mails to be rejected.");
799 } else {
800 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
801 }
802 }
804 /* Need gosaMailMaxSize if use_mailsize_limit is checked */
805 if (is_integer(strpos($this->gosaMailDeliveryMode, "R")) &&
806 $this->gosaMailMaxSize == ""){
808 $message[]= _("You need to set the maximum mail size in order to reject anything.");
809 }
811 if((preg_match("/S/", $this->gosaMailDeliveryMode))&&(empty($this->gosaSpamMailbox))) {
812 $message[]= _("You specified Spam settings, but there is no Folder specified.");
813 }
815 return ($message);
816 }
819 /* Adapt from template, using 'dn' */
820 function adapt_from_template($dn)
821 {
822 plugin::adapt_from_template($dn);
824 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
825 $this->$val= array();
826 if (isset($this->attrs["$val"]["count"])){
827 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
828 $value= $this->attrs["$val"][$i];
829 foreach (array("sn", "givenName", "uid") as $repl){
830 if (preg_match("/%$repl/i", $value)){
831 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
832 }
833 }
834 array_push($this->$val, strtolower(rewrite($value)));
835 }
836 }
837 }
838 $this->mail= strtolower(rewrite($this->mail));
839 }
842 /* Add entry to forwarder list */
843 function addForwarder($address)
844 {
845 if($this->acl_is_writeable("gosaMailForwardingAddress")){
846 $this->gosaMailForwardingAddress[]= $address;
847 $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
848 sort ($this->gosaMailForwardingAddress);
849 reset ($this->gosaMailForwardingAddress);
850 $this->is_modified= TRUE;
851 }else{
852 print_red(_("You are not allowed to write mail forwarding."));
853 }
854 }
857 /* Remove list of addresses from forwarder list */
858 function delForwarder($addresses)
859 {
860 if($this->acl_is_writeable("gosaMailForwardingAddress")){
861 $this->gosaMailForwardingAddress= array_remove_entries ($addresses, $this->gosaMailForwardingAddress);
862 $this->is_modified= TRUE;
863 }else{
864 print_red(_("You are not allowed to write mail forwarding."));
865 }
866 }
869 /* Add given mail address to the list of alternate adresses ,
870 check if this mal address is used, skip adding in this case */
871 function addAlternate($address)
872 {
873 if($this->acl_is_writeable("gosaMailAlternateAddress")){
874 $ldap= $this->config->get_ldap_link();
875 $address= strtolower($address);
877 /* Is this address already assigned in LDAP? */
878 $ldap->cd ($this->config->current['BASE']);
879 $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)"."(gosaMailAlternateAddress=$address)))", array("uid"));
881 if ($ldap->count() > 0){
882 $attrs= $ldap->fetch ();
883 return ($attrs["uid"][0]);
884 }
886 /* Add to list of alternates */
887 if (!in_array($address, $this->gosaMailAlternateAddress)){
888 $this->gosaMailAlternateAddress[]= $address;
889 $this->is_modified= TRUE;
890 }
892 sort ($this->gosaMailAlternateAddress);
893 reset ($this->gosaMailAlternateAddress);
894 return ("");
895 }else{
896 print_red(_("You are not allowed to write mail alternate address."));
897 }
898 }
901 function delAlternate($addresses)
902 {
903 if($this->acl_is_writeable("gosaMailAlternateAddress")){
904 $this->gosaMailAlternateAddress= array_remove_entries ($addresses,$this->gosaMailAlternateAddress);
905 $this->is_modified= TRUE;
906 }else{
907 print_red(_("You are not allowed to write mail alternate address."));
908 }
909 }
911 function make_name($attrs)
912 {
913 $name= "";
914 if (isset($attrs['sn'][0])){
915 $name= $attrs['sn'][0];
916 }
917 if (isset($attrs['givenName'][0])){
918 if ($name != ""){
919 $name.= ", ".$attrs['givenName'][0];
920 } else {
921 $name.= $attrs['givenName'][0];
922 }
923 }
924 if ($name != ""){
925 $name.= " ";
926 }
928 return ($name);
929 }
932 /* Create the mail part for the copy & paste dialog */
933 function getCopyDialog()
934 {
935 if(!$this->is_account) return("");
936 $smarty = get_smarty();
937 $smarty->assign("mail",$this->mail);
938 $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress);
939 $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress);
940 $str = $smarty->fetch(get_template_path("copypaste.tpl",TRUE, dirname(__FILE__)));
942 $ret = array();
943 $ret['status'] = "";
944 $ret['string'] = $str;
945 return($ret);
946 }
948 function saveCopyDialog()
949 {
950 if(!$this->is_account) return;
952 /* Execute to save mailAlternateAddress && gosaMailForwardingAddress */
953 $this->execute();
955 if(isset($_POST['mail'])){
956 $this->mail = $_POST['mail'];
957 }
959 }
961 function allow_remove()
962 {
963 if (isset($this->config->current['MAILMETHOD'])){
964 $method= $this->config->current['MAILMETHOD'];
965 if(preg_match("/kolab/i",$method)){
966 $ldap = $this->config->get_ldap_link();
967 $ldap->cd($this->config->current['BASE']);
968 $ldap->cat($this->dn);
969 if($ldap->count()){
970 $attrs = $ldap->fetch();
971 if(isset($attrs['kolabDeleteFlag'])){
972 return(_("Waiting for kolab to remove mail properties."));
973 }elseif(in_array("gosaMailAccount",$attrs['objectClass'])){
974 return(_("Please remove the mail account first, to allow kolab to call its remove methods."));
975 }
976 }
977 }
978 }
979 }
982 function plInfo()
983 {
984 return (array(
985 "plShortName" => _("Mail"),
986 "plDescription" => _("Mail settings"),
987 "plSelfModify" => TRUE,
988 "plDepends" => array("user"), // This plugin depends on
989 "plPriority" => 4, // Position in tabs
990 "plSection" => "personal", // This belongs to personal
991 "plCategory" => array("users"), // Add to following categories
992 "plOptions" => array(),
994 "plProvidedAcls" => array(
995 "mail" => _("Mail address"),
996 "gosaMailServer" => _("Mail server"),
997 "gosaMailQuota" => _("Quota size"),
999 "gosaMailDeliveryModeV" => _("Add vacation information"), // This is flag of gosaMailDeliveryMode
1000 "gosaVacationMessage" => _("Vacation message"),
1002 "gosaMailDeliveryModes" => _("Use spam filter"), // This is flag of gosaMailDeliveryMode
1003 "gosaSpamSortLevel" => _("Spam level"),
1004 "gosaSpamMailbox" => _("Spam mail box"),
1006 "gosaMailDeliveryModeR" => _("Reject due to mailsize"), // This is flag of gosaMailDeliveryMode
1007 "gosaMailMaxSize" => _("Mail max size"),
1009 "gosaMailForwardingAddress" => _("Forwarding address"),
1010 "gosaMailDeliveryModeL" => _("Local delivery"), // This is flag of gosaMailDeliveryMode
1011 "gosaMailDeliveryModeI" => _("Only insider delivery"), // This is flag of gosaMailDeliveryMode
1012 "gosaMailAlternateAddress" => _("Mail alternative addresses"),
1014 "gosaMailForwardingAddress" => _("Forwarding address"),
1015 "gosaMailDeliveryModeC" => _("Use custom sieve script")) // This is flag of gosaMailDeliveryMode
1016 ));
1017 }
1018 }
1020 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1021 ?>