13256a3cf56ddcb7a858c82e0b653cd5a9f7bbe4
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", "lrsp" => "post", "lrsip" => "append",
54 "lrswipcd" => "write", "lrswipcda" => "all" );
56 /* attribute list for save action */
57 var $attributes= array("mail", "gosaMailServer", "gosaMailQuota", "gosaMailMaxSize","gosaMailForwardingAddress",
58 "gosaMailDeliveryMode", "gosaSpamSortLevel", "gosaSpamMailbox","gosaMailAlternateAddress",
59 "gosaVacationMessage", "uid", "gosaMailAlternateAddress", "gosaMailForwardingAddress");
60 var $objectclasses= array("gosaMailAccount");
63 /* constructor, if 'dn' is set, the node loads the given
64 'dn' from LDAP */
65 function mailAccount ($config, $dn= NULL)
66 {
67 /* Configuration is fine, allways */
68 $this->config= $config;
70 /* Load bases attributes */
71 plugin::plugin($config, $dn);
73 /* Set mailMethod to the one defined in gosa.conf */
74 if (isset($this->config->current['MAILMETHOD'])){
75 $method= $this->config->current['MAILMETHOD'];
76 if (class_exists("mailMethod$method")){
77 $this->method= "mailMethod$method";
78 } else {
79 print_red(sprintf(_("There is no mail method '%s' specified in your gosa.conf available."), $method));
80 }
81 }
83 /* Preset folder prefix. Will change it later to respect
84 altnamespace. */
85 if (isset($this->config->current['CYRUSUNIXSTYLE']) && $this->config->current['CYRUSUNIXSTYLE'] == "true"){
86 $this->folder_prefix= "user/";
87 } else {
88 $this->folder_prefix= "user.";
89 }
91 if ($dn != NULL){
93 /* Load attributes containing arrays */
94 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
95 $this->$val= array();
96 if (isset($this->attrs["$val"]["count"])){
97 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
98 array_push($this->$val, $this->attrs["$val"][$i]);
99 }
100 }
101 }
103 /* Only do IMAP actions if gosaMailServer attribute is set */
104 if (isset ($this->attrs["gosaMailServer"][0])){
106 $method= new $this->method($this->config);
107 $id= $method->uattrib;
108 if ($method->connect($this->attrs["gosaMailServer"][0])){
109 $quota= $method->getQuota($this->folder_prefix.$this->$id);
111 /* Update quota values */
112 if ($quota['gosaMailQuota'] == 2147483647){
113 $this->quotaUsage= "";
114 $this->gosaMailQuota= "";
115 } else {
116 $this->quotaUsage= $quota['quotaUsage'];
117 $this->gosaMailQuota= $quota['gosaMailQuota'];
118 }
119 $this->mailboxList= $method->getMailboxList(
120 $this->folder_prefix.$this->$id,
121 $this->$id);
122 $method->disconnect();
123 }
125 /* Adapt attributes if needed */
126 $method->fixAttributesOnLoad($this);
127 }
128 }
130 /* Fill vacation array */
131 $this->vacation= array();
132 if (isset($this->config->current['VACATIONDIR'])){
133 $dir= $this->config->current['VACATIONDIR'];
134 if (is_dir($dir) && is_readable($dir)){
136 /* Look for files and build the vacation array */
137 $dh= opendir($dir);
138 while ($file = readdir($dh)){
139 $description= $this->parse_vacation("$dir/$file");
140 if ($description != ""){
141 $this->vacation["$dir/$file"]= $description;
142 }
143 }
144 closedir($dh);
145 }
146 }
148 /* Get global filter config */
149 if (!is_global("mailfilter")){
150 $ui= get_userinfo();
151 $base= get_base_from_people($ui->dn);
152 $mailfilter= array( "depselect" => $base,
153 "muser" => "",
154 "regex" => "*");
155 register_global("mailfilter", $mailfilter);
156 }
158 if(is_array($this->gosaMailServer) && isset($this->gosaMailServer[0])){
159 $this->gosaMailServer = $this->gosaMailServer[0];
160 }
162 /* Save initial account state */
163 $this->initially_was_account= $this->is_account;
164 }
167 function parse_vacation($file)
168 {
169 $desc= "";
171 if (is_file($file)){
172 $fh = fopen($file, "r");
173 $line= fgets($fh, 256);
175 if (!preg_match('/^DESC:/', $line)){
176 print_red (_("No DESC tag in vacation file:")." $file");
177 return $desc;
178 }
179 fclose ($fh);
181 $desc= trim(preg_replace('/^DESC:\s*/', '', $line));
182 }
184 return $desc;
185 }
188 function execute()
189 {
190 /* Call parent execute */
191 plugin::execute();
193 /* Load templating engine */
194 $smarty= get_smarty();
195 $display= "";
197 $mailserver= array();
198 foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
199 $mailserver[]= $key;
200 }
202 /* Do we need to flip is_account state? */
203 if (isset($_POST['modify_state'])){
204 $this->is_account= !$this->is_account;
205 }
207 /* Show main page */
208 $mailserver= array();
209 foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
210 $mailserver[]= $key;
211 }
213 /* Do we represent a valid account? */
214 if (!$this->is_account && $this->parent == NULL){
215 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
216 _("This account has no mail extensions.")."</b>";
218 $display.= back_to_main();
219 return ($display);
220 }
222 /* Show tab dialog headers */
223 if ($this->parent != NULL){
224 if ($this->is_account){
225 $display= $this->show_header(_("Remove mail account"),
226 _("This account has mail features enabled. You can disable them by clicking below."));
227 } else {
228 $display= $this->show_header(_("Create mail account"), _("This account has mail features disabled. You can enable them by clicking below."));
229 return ($display);
230 }
231 }
233 /* Trigger forward add dialog? */
234 if (isset($_POST['add_local_forwarder'])){
235 $this->forward_dialog= TRUE;
236 $this->dialog= TRUE;
237 }
239 /* Cancel forward add dialog? */
240 if (isset($_POST['add_locals_cancel'])){
241 $this->forward_dialog= FALSE;
242 $this->dialog= FALSE;
243 }
245 /* Finished adding of locals? */
246 if (isset($_POST['add_locals_finish'])){
247 if (count ($_POST['local_list']) &&
248 chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
250 /* Walk through list of forwarders, ignore own addresses */
251 foreach ($_POST['local_list'] as $val){
252 if (!in_array ($val, $this->gosaMailAlternateAddress) &&
253 $val != $this->mail){
255 $this->addForwarder($val);
256 $this->is_modified= TRUE;
257 }
258 }
259 }
260 $this->forward_dialog= FALSE;
261 $this->dialog= FALSE;
262 }
264 /* Add forward email addresses */
265 if (isset($_POST['add_forwarder'])){
266 if ($_POST['forward_address'] != ""){
268 /* Valid email address specified? */
269 $address= $_POST['forward_address'];
270 $valid= FALSE;
271 if (!is_email($address)){
272 if (!is_email($address, TRUE)){
273 if ($this->is_template){
274 $valid= TRUE;
275 } else {
276 print_red (_("You're trying to add an invalid email address to the list of forwarders."));
277 }
278 }
279 } elseif ($address == $this->mail
280 || in_array($address, $this->gosaMailAlternateAddress)) {
282 print_red (_("Adding your one of your own addresses to the forwarders makes no sense."));
284 } else {
285 $valid= TRUE;
286 }
288 if ($valid){
289 /* Add it */
290 if (chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
291 $this->addForwarder ($address);
292 $this->is_modified= TRUE;
293 }
295 }
296 }
297 }
299 /* Delete forward email addresses */
300 if (isset($_POST['delete_forwarder'])){
301 if (count($_POST['forwarder_list'])
302 && chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
304 $this->delForwarder ($_POST['forwarder_list']);
305 }
306 }
308 /* Add alternate email addresses */
309 if (isset($_POST['add_alternate'])){
310 if ($_POST['alternate_address'] != "" &&
311 chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
313 $valid= FALSE;
314 if (!is_email($_POST['alternate_address'])){
315 if ($this->is_template){
316 if (!(is_email($_POST['alternate_address'], TRUE))){
317 print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
318 } else {
319 $valid= TRUE;
320 }
321 } else {
322 print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
323 }
325 } else {
326 $valid= TRUE;
327 }
329 if ($valid && ($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
330 $ui= get_userinfo();
331 if ($user != $ui->username){
332 print_red (_("The address you're trying to add is already used by user")." '$user'.");
333 }
334 }
335 }
336 }
338 /* Delete alternate email addresses */
339 if (isset($_POST['delete_alternate']) && isset ($_POST['alternates_list'])){
340 if (count($_POST['alternates_list']) &&
341 chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
343 $this->delAlternate ($_POST['alternates_list']);
344 }
345 }
347 /* Import vacation message? */
348 if (isset($_POST["import_vacation"]) && isset($this->vacation[$_POST["vacation_template"]])){
349 $contents= "";
350 $lines= file($_POST["vacation_template"]);
351 foreach ($lines as $line){
352 if (!preg_match('/^DESC:/', $line)){
353 $contents.= $line;
354 }
355 }
357 /* Replace attributes */
358 $attrs= $this->parent->by_object['user']->attributes;
359 foreach ($attrs as $val){
360 $contents= preg_replace("/%$val/",
361 $this->parent->by_object['user']->$val, $contents);
362 }
364 /* Save message */
365 $this->gosaVacationMessage= htmlspecialchars($contents);
366 }
368 /* Show forward add dialog */
369 if ($this->forward_dialog){
370 $ldap= $this->config->get_ldap_link();
372 /* Save data */
373 $mailfilter= get_global("mailfilter");
374 foreach( array("depselect", "muser", "regex") as $type){
375 if (isset($_POST[$type])){
376 $mailfilter[$type]= $_POST[$type];
377 }
378 }
379 if (isset($_GET['search'])){
380 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
381 if ($s == "**"){
382 $s= "*";
383 }
384 $mailfilter['regex']= $s;
385 }
386 register_global("mailfilter", $mailfilter);
388 /* Get actual list */
389 $mailusers= array ();
390 if ($mailfilter['regex'] != '*' && $mailfilter['regex'] != ""){
391 $regex= $mailfilter['regex'];
392 $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
393 } else {
394 $filter= "";
395 }
396 if ($mailfilter['muser'] != ""){
397 $user= $mailfilter['muser'];
398 $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
399 }
401 /* Add already present people to the filter */
402 $exclude= "";
403 foreach ($this->gosaMailForwardingAddress as $mail){
404 $exclude.= "(mail=$mail)";
405 }
406 if ($exclude != ""){
407 $filter.= "(!(|$exclude))";
408 }
410 $acl= array($this->config->current['BASE'] => ":all");
411 $res= get_list($acl, "(&(objectClass=gosaMailAccount)$filter)", TRUE, $mailfilter['depselect'], array("sn", "mail", "givenName"), TRUE);
412 $ldap->cd($mailfilter['depselect']);
413 $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
414 error_reporting (0);
415 while ($attrs= $ldap->fetch()){
416 if(preg_match('/%/', $attrs['mail'][0])){
417 continue;
418 }
419 $name= $this->make_name($attrs);
420 $mailusers[$attrs['mail'][0]]= $name."<".
421 $attrs['mail'][0].">";
422 }
423 error_reporting (E_ALL);
424 natcasesort ($mailusers);
425 reset ($mailusers);
427 /* Show dialog */
428 $smarty->assign("search_image", get_template_path('images/search.png'));
429 $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
430 $smarty->assign("tree_image", get_template_path('images/tree.png'));
431 $smarty->assign("infoimage", get_template_path('images/info.png'));
432 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
433 $smarty->assign("mailusers", $mailusers);
434 if (isset($_POST['depselect'])){
435 $smarty->assign("depselect", $_POST['depselect']);
436 }
437 $smarty->assign("deplist", $this->config->idepartments);
438 $smarty->assign("apply", apply_filter());
439 $smarty->assign("alphabet", generate_alphabet());
440 $smarty->assign("hint", print_sizelimit_warning());
441 foreach( array("depselect", "muser", "regex") as $type){
442 $smarty->assign("$type", $mailfilter[$type]);
443 }
444 $smarty->assign("hint", print_sizelimit_warning());
446 $display.= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE, dirname(__FILE__)));
447 return ($display);
448 }
450 $smarty->assign("mailServers", $mailserver);
451 foreach(array("gosaMailServer", "gosaMailQuota", "perms", "mail",
452 "gosaMailAlternateAddress", "gosaMailForwardingAddress",
453 "gosaVacationMessage", "gosaMailDeliveryMode",
454 "gosaMailMaxSize", "gosaSpamSortLevel", "gosaSpamMailbox") as $val){
456 $smarty->assign("$val", $this->$val);
457 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
458 }
460 if (is_numeric($this->gosaMailQuota) && $this->gosaMailQuota != 0){
461 $smarty->assign("quotausage", progressbar(round(($this->quotaUsage * 100)/ $this->gosaMailQuota),100,15,true));
462 $smarty->assign("quotadefined", "true");
463 } else {
464 $smarty->assign("quotadefined", "false");
465 }
467 /* Disable mail field if needed */
468 $method= new $this->method($this->config);
469 if ($method->uattrib == "mail" && $this->initially_was_account){
470 $smarty->assign("mailACL", "disabled");
471 }
473 /* Fill checkboxes */
474 if (!preg_match("/L/", $this->gosaMailDeliveryMode)) {
475 $smarty->assign("drop_own_mails", "checked");
476 } else {
477 $smarty->assign("drop_own_mails", "");
478 }
479 if (preg_match("/V/", $this->gosaMailDeliveryMode)) {
480 $smarty->assign("use_vacation", "checked");
481 } else {
482 $smarty->assign("use_vacation", "");
483 }
484 if (preg_match("/S/", $this->gosaMailDeliveryMode)) {
485 $smarty->assign("use_spam_filter", "checked");
486 } else {
487 $smarty->assign("use_spam_filter", "");
488 }
489 if (preg_match("/R/", $this->gosaMailDeliveryMode)) {
490 $smarty->assign("use_mailsize_limit", "checked");
491 } else {
492 $smarty->assign("use_mailsize_limit", "");
493 }
494 if (preg_match("/I/", $this->gosaMailDeliveryMode)) {
495 $smarty->assign("only_local", "checked");
496 } else {
497 $smarty->assign("only_local", "");
498 }
499 if (preg_match("/C/", $this->gosaMailDeliveryMode)) {
500 $smarty->assign("own_script", "checked");
501 } else {
502 $smarty->assign("own_script", "");
503 }
505 /* Have vacation templates? */
506 $smarty->assign("template", "");
507 if (count($this->vacation)){
508 $smarty->assign("show_templates", "true");
509 $smarty->assign("vacationtemplates", $this->vacation);
510 if (isset($_POST['vacation_template'])){
511 $smarty->assign("template", $_POST['vacation_template']);
512 }
513 } else {
514 $smarty->assign("show_templates", "false");
515 }
517 /* Fill spam selector */
518 $spamlevel= array();
519 for ($i= 0; $i<21; $i++){
520 $spamlevel[]= $i;
521 }
522 $smarty->assign("spamlevel", $spamlevel);
523 $smarty->assign("spambox", $this->mailboxList);
524 $smarty->assign("custom_sieveACL", chkacl($this->acl, "custom_sieve"));
525 $smarty->assign("only_localACL", chkacl($this->acl, "only_local"));
527 $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
528 return ($display);
529 }
532 /* remove object from parent */
533 function remove_from_parent()
534 {
535 /* Cancel if there's nothing to do here */
536 if (!$this->initially_was_account){
537 return;
538 }
540 /* include global link_info */
541 $ldap= $this->config->get_ldap_link();
543 /* Remove and write to LDAP */
544 plugin::remove_from_parent();
546 /* Zero arrays */
547 $this->attrs['gosaMailAlternateAddress']= array();
548 $this->attrs['gosaMailForwardingAddress']= array();
550 /* Adapt attributes if needed */
551 $method= new $this->method($this->config);
552 $method->fixAttributesOnRemove($this);
554 /* Mailmethod wants us to remove the entry from LDAP. Keep uid! */
555 #fixme: || kolab || is differs here, you can't delete all attrs specified in this plugin ....
556 #fixme: there are some attributes we have to keep, i think.
557 unset ($this->attrs['uid']);
561 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
562 $this->attributes, "Save");
563 $ldap->cd($this->dn);
564 $this->cleanup();
565 $ldap->modify ($this->attrs);
567 show_ldap_error($ldap->get_error());
569 /* Connect to IMAP server for account deletion */
570 if ($this->gosaMailServer != ""){
571 $method= new $this->method($this->config);
572 $id= $method->uattrib;
573 if ($method->connect($this->gosaMailServer)){
575 /* Remove account from IMAP server */
576 $method->deleteMailbox($this->folder_prefix.$this->$id);
577 $method->disconnect();
578 }
579 }
581 /* Optionally execute a command after we're done */
582 $this->handle_post_events("remove");
583 }
586 /* Save data to object */
587 function save_object()
588 {
589 if (isset($_POST['mailTab'])){
590 /* Save ldap attributes */
591 plugin::save_object();
593 /* Assemble mail delivery mode
594 The mode field in ldap consists of values between braces, this must
595 be called when 'mail' is set, because checkboxes may not be set when
596 we're in some other dialog.
598 Example for gosaMailDeliveryMode [LR ]
599 L: Local delivery
600 R: Reject when exceeding mailsize limit
601 S: Use spam filter
602 V: Use vacation message
603 C: Use custm sieve script
604 I: Only insider delivery */
606 $tmp= "";
607 if (!isset($_POST["drop_own_mails"])){
608 $tmp.= "L";
609 }
610 if (isset($_POST["use_mailsize_limit"])){
611 $tmp.= "R";
612 }
613 if (isset($_POST["use_spam_filter"])){
614 $tmp.= "S";
615 }
616 if (isset($_POST["use_vacation"])){
617 $tmp.= "V";
618 }
619 if (isset($_POST["own_script"])){
620 $tmp.= "C";
621 }
622 if (isset($_POST["only_local"])){
623 $tmp.= "I";
624 }
625 $tmp= "[$tmp]";
627 if (chkacl ($this->acl, "gosaMailDeliveryMode") == ""){
628 if ($this->gosaMailDeliveryMode != $tmp){
629 $this->is_modified= TRUE;
630 }
631 $this->gosaMailDeliveryMode= $tmp;
632 }
633 }
634 }
637 /* Save data to LDAP, depending on is_account we save or delete */
638 function save()
639 {
640 $ldap= $this->config->get_ldap_link();
642 /* Call parents save to prepare $this->attrs */
643 plugin::save();
645 /* Save arrays */
646 $this->attrs['gosaMailAlternateAddress']= $this->gosaMailAlternateAddress;
647 $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
649 /* Adapt attributes if needed */
650 $method= new $this->method($this->config);
651 $id= $method->uattrib;
652 $method->fixAttributesOnStore($this);
654 /* Remove Mailquota if = "" */
655 if((isset($this->attrs['gosaMailQuota']))&&($this->attrs['gosaMailQuota']=="")) {
656 $this->attrs['gosaMailQuota']=array();
657 }
659 if(empty($this->attrs['gosaSpamMailbox'])){
660 unset($this->attrs['gosaSpamMailbox']);
661 }
663 /* Save data to LDAP */
664 $ldap->cd($this->dn);
665 $this->cleanup();
666 $ldap->modify ($this->attrs);
668 show_ldap_error($ldap->get_error());
670 /* Only do IMAP actions if we are not a template */
671 if (!$this->is_template){
673 if ($method->connect($this->gosaMailServer)){
674 $method->updateMailbox($this->folder_prefix.$this->$id);
675 $method->setQuota($this->folder_prefix.$this->$id, $this->gosaMailQuota);
676 $method->disconnect();
678 /* Write sieve information only if not in C mode */
679 if (!is_integer(strpos($this->gosaMailDeliveryMode, "C"))){
680 $method->configureFilter($this->$id,
681 $this->gosaMailDeliveryMode,
682 $this->mail,
683 $this->gosaMailAlternateAddress,
684 $this->gosaMailMaxSize,
685 $this->gosaSpamMailbox,
686 $this->gosaSpamSortLevel,
687 $this->gosaVacationMessage);
688 }
689 }
690 }
692 /* Optionally execute a command after we're done */
693 if ($this->initially_was_account == $this->is_account){
694 if ($this->is_modified){
695 $this->handle_post_events("modify");
696 }
697 } else {
698 $this->handle_post_events("add");
699 }
701 }
703 /* Check formular input */
704 function check()
705 {
706 if(!$this->is_account) return(array());
707 $ldap= $this->config->get_ldap_link();
709 $message= array();
711 if(empty($this->gosaMailServer)){
712 $message[]= _("There is no valid mailserver specified, please add one in the system setup.");
713 }
715 /* must: mail */
716 if ($this->mail == ""){
717 $message[]= _("The required field 'Primary address' is not set.");
718 }
719 if ($this->is_template){
720 if (!is_email($this->mail, TRUE)){
721 $message[]= _("Please enter a valid email address in 'Primary address' field.");
722 }
723 } else {
724 if (!is_email($this->mail)){
725 $message[]= _("Please enter a valid email address in 'Primary address' field.");
726 }
727 }
728 $ldap->cd($this->config->current['BASE']);
729 echo "(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=".$this->mail.")(gosaMailAlternateAddress=".$this->mail."))(! (uid=".$this->uid."))(!(cn=".$this->uid.")))";
730 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=".$this->mail.")(gosaMailAlternateAddress=".$this->mail."))(!(uid=".$this->uid."))(!(cn=".$this->uid.")))", array("uid"));
731 if ($ldap->count() != 0){
732 $message[]= _("The primary address you've entered is already in use.");
733 }
735 /* Check quota */
736 if ($this->gosaMailQuota != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
737 if (!is_numeric($this->gosaMailQuota)) {
738 $message[]= _("Value in 'Quota size' is not valid.");
739 } else {
740 $this->gosaMailQuota= (int) $this->gosaMailQuota;
741 }
742 }
744 /* Check rejectsize for integer */
745 if ($this->gosaMailMaxSize != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
746 if (!is_numeric($this->gosaMailMaxSize)){
747 $message[]= _("Please specify a vaild mail size for mails to be rejected.");
748 } else {
749 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
750 }
751 }
753 /* Need gosaMailMaxSize if use_mailsize_limit is checked */
754 if (is_integer(strpos($this->gosaMailDeliveryMode, "R")) &&
755 $this->gosaMailMaxSize == ""){
757 $message[]= _("You need to set the maximum mail size in order to reject anything.");
758 }
760 if((preg_match("/S/", $this->gosaMailDeliveryMode))&&(empty($this->gosaSpamMailbox))) {
761 $message[]= _("You specified Spam settings, but there is no Folder specified.");
762 }
764 return ($message);
765 }
767 /* Adapt from template, using 'dn' */
768 function adapt_from_template($dn)
769 {
770 plugin::adapt_from_template($dn);
772 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
773 $this->$val= array();
774 if (isset($this->attrs["$val"]["count"])){
775 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
776 $value= $this->attrs["$val"][$i];
777 foreach (array("sn", "givenName", "uid") as $repl){
778 if (preg_match("/%$repl/i", $value)){
779 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
780 }
781 }
782 array_push($this->$val, strtolower(rewrite($value)));
783 }
784 }
785 }
786 $this->mail= strtolower(rewrite($this->mail));
787 }
789 /* Add entry to forwarder list */
790 function addForwarder($address)
791 {
792 $this->gosaMailForwardingAddress[]= $address;
793 $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
795 sort ($this->gosaMailForwardingAddress);
796 reset ($this->gosaMailForwardingAddress);
797 $this->is_modified= TRUE;
798 }
800 /* Remove list of addresses from forwarder list */
801 function delForwarder($addresses)
802 {
803 $this->gosaMailForwardingAddress= array_remove_entries ($addresses, $this->gosaMailForwardingAddress);
804 $this->is_modified= TRUE;
805 }
809 function addAlternate($address)
810 {
811 $ldap= $this->config->get_ldap_link();
813 $address= strtolower($address);
815 /* Is this address already assigned in LDAP? */
816 $ldap->cd ($this->config->current['BASE']);
817 $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)"."(gosaMailAlternateAddress=$address)))", array("uid"));
819 if ($ldap->count() > 0){
820 $attrs= $ldap->fetch ();
821 return ($attrs["uid"][0]);
822 }
824 /* Add to list of alternates */
825 if (!in_array($address, $this->gosaMailAlternateAddress)){
826 $this->gosaMailAlternateAddress[]= $address;
827 $this->is_modified= TRUE;
828 }
830 sort ($this->gosaMailAlternateAddress);
831 reset ($this->gosaMailAlternateAddress);
833 return ("");
834 }
837 function delAlternate($addresses)
838 {
839 $this->gosaMailAlternateAddress= array_remove_entries ($addresses,
840 $this->gosaMailAlternateAddress);
841 $this->is_modified= TRUE;
842 }
844 function make_name($attrs)
845 {
846 $name= "";
847 if (isset($attrs['sn'][0])){
848 $name= $attrs['sn'][0];
849 }
850 if (isset($attrs['givenName'][0])){
851 if ($name != ""){
852 $name.= ", ".$attrs['givenName'][0];
853 } else {
854 $name.= $attrs['givenName'][0];
855 }
856 }
857 if ($name != ""){
858 $name.= " ";
859 }
861 return ($name);
862 }
864 function getCopyDialog()
865 {
866 if(!$this->is_account) return("");
867 $smarty = get_smarty();
868 $smarty->assign("mail",$this->mail);
869 $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress);
870 $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress);
871 return($smarty->fetch(get_template_path("copypaste.tpl",TRUE, dirname(__FILE__))));
872 }
874 function saveCopyDialog()
875 {
876 if(!$this->is_account) return;
878 /* Execute to save mailAlternateAddress && gosaMailForwardingAddress */
879 $this->execute();
881 if(isset($_POST['mail'])){
882 $this->mail = $_POST['mail'];
883 }
885 }
886 }
888 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
889 ?>