3273d571155e0fe201c5188527595fe041284ed6
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 $this->attrs['mail'] = strtolower($this->attrs['mail']);
665 /* Save data to LDAP */
666 $ldap->cd($this->dn);
667 $this->cleanup();
668 $ldap->modify ($this->attrs);
670 show_ldap_error($ldap->get_error());
672 /* Only do IMAP actions if we are not a template */
673 if (!$this->is_template){
675 if ($method->connect($this->gosaMailServer)){
676 $method->updateMailbox($this->folder_prefix.$this->$id);
677 $method->setQuota($this->folder_prefix.$this->$id, $this->gosaMailQuota);
678 $method->disconnect();
680 /* Write sieve information only if not in C mode */
681 if (!is_integer(strpos($this->gosaMailDeliveryMode, "C"))){
682 $method->configureFilter($this->$id,
683 $this->gosaMailDeliveryMode,
684 $this->mail,
685 $this->gosaMailAlternateAddress,
686 $this->gosaMailMaxSize,
687 $this->gosaSpamMailbox,
688 $this->gosaSpamSortLevel,
689 $this->gosaVacationMessage);
690 }
691 }
692 }
694 /* Optionally execute a command after we're done */
695 if ($this->initially_was_account == $this->is_account){
696 if ($this->is_modified){
697 $this->handle_post_events("modify");
698 }
699 } else {
700 $this->handle_post_events("add");
701 }
703 }
705 /* Check formular input */
706 function check()
707 {
708 if(!$this->is_account) return(array());
709 $ldap= $this->config->get_ldap_link();
711 $message= array();
713 if(empty($this->gosaMailServer)){
714 $message[]= _("There is no valid mailserver specified, please add one in the system setup.");
715 }
717 /* must: mail */
718 if ($this->mail == ""){
719 $message[]= _("The required field 'Primary address' is not set.");
720 }
721 if ($this->is_template){
722 if (!is_email($this->mail, TRUE)){
723 $message[]= _("Please enter a valid email address in 'Primary address' field.");
724 }
725 } else {
726 if (!is_email($this->mail)){
727 $message[]= _("Please enter a valid email address in 'Primary address' field.");
728 }
729 }
730 $ldap->cd($this->config->current['BASE']);
731 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=".$this->mail.")(gosaMailAlternateAddress=".$this->mail."))(!(uid=".$this->uid."))(!(cn=".$this->uid.")))", array("uid"));
732 if ($ldap->count() != 0){
733 $message[]= _("The primary address you've entered is already in use.");
734 }
736 /* Check quota */
737 if ($this->gosaMailQuota != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
738 if (!is_numeric($this->gosaMailQuota)) {
739 $message[]= _("Value in 'Quota size' is not valid.");
740 } else {
741 $this->gosaMailQuota= (int) $this->gosaMailQuota;
742 }
743 }
745 /* Check rejectsize for integer */
746 if ($this->gosaMailMaxSize != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
747 if (!is_numeric($this->gosaMailMaxSize)){
748 $message[]= _("Please specify a vaild mail size for mails to be rejected.");
749 } else {
750 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
751 }
752 }
754 /* Need gosaMailMaxSize if use_mailsize_limit is checked */
755 if (is_integer(strpos($this->gosaMailDeliveryMode, "R")) &&
756 $this->gosaMailMaxSize == ""){
758 $message[]= _("You need to set the maximum mail size in order to reject anything.");
759 }
761 if((preg_match("/S/", $this->gosaMailDeliveryMode))&&(empty($this->gosaSpamMailbox))) {
762 $message[]= _("You specified Spam settings, but there is no Folder specified.");
763 }
765 return ($message);
766 }
768 /* Adapt from template, using 'dn' */
769 function adapt_from_template($dn)
770 {
771 plugin::adapt_from_template($dn);
773 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
774 $this->$val= array();
775 if (isset($this->attrs["$val"]["count"])){
776 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
777 $value= $this->attrs["$val"][$i];
778 foreach (array("sn", "givenName", "uid") as $repl){
779 if (preg_match("/%$repl/i", $value)){
780 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
781 }
782 }
783 array_push($this->$val, strtolower(rewrite($value)));
784 }
785 }
786 }
787 $this->mail= strtolower(rewrite($this->mail));
788 }
790 /* Add entry to forwarder list */
791 function addForwarder($address)
792 {
793 $this->gosaMailForwardingAddress[]= $address;
794 $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
796 sort ($this->gosaMailForwardingAddress);
797 reset ($this->gosaMailForwardingAddress);
798 $this->is_modified= TRUE;
799 }
801 /* Remove list of addresses from forwarder list */
802 function delForwarder($addresses)
803 {
804 $this->gosaMailForwardingAddress= array_remove_entries ($addresses, $this->gosaMailForwardingAddress);
805 $this->is_modified= TRUE;
806 }
810 function addAlternate($address)
811 {
812 $ldap= $this->config->get_ldap_link();
814 $address= strtolower($address);
816 /* Is this address already assigned in LDAP? */
817 $ldap->cd ($this->config->current['BASE']);
818 $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)"."(gosaMailAlternateAddress=$address)))", array("uid"));
820 if ($ldap->count() > 0){
821 $attrs= $ldap->fetch ();
822 return ($attrs["uid"][0]);
823 }
825 /* Add to list of alternates */
826 if (!in_array($address, $this->gosaMailAlternateAddress)){
827 $this->gosaMailAlternateAddress[]= $address;
828 $this->is_modified= TRUE;
829 }
831 sort ($this->gosaMailAlternateAddress);
832 reset ($this->gosaMailAlternateAddress);
834 return ("");
835 }
838 function delAlternate($addresses)
839 {
840 $this->gosaMailAlternateAddress= array_remove_entries ($addresses,
841 $this->gosaMailAlternateAddress);
842 $this->is_modified= TRUE;
843 }
845 function make_name($attrs)
846 {
847 $name= "";
848 if (isset($attrs['sn'][0])){
849 $name= $attrs['sn'][0];
850 }
851 if (isset($attrs['givenName'][0])){
852 if ($name != ""){
853 $name.= ", ".$attrs['givenName'][0];
854 } else {
855 $name.= $attrs['givenName'][0];
856 }
857 }
858 if ($name != ""){
859 $name.= " ";
860 }
862 return ($name);
863 }
865 function getCopyDialog()
866 {
867 if(!$this->is_account) return("");
868 $smarty = get_smarty();
869 $smarty->assign("mail",$this->mail);
870 $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress);
871 $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress);
872 return($smarty->fetch(get_template_path("copypaste.tpl",TRUE, dirname(__FILE__))));
873 }
875 function saveCopyDialog()
876 {
877 if(!$this->is_account) return;
879 /* Execute to save mailAlternateAddress && gosaMailForwardingAddress */
880 $this->execute();
882 if(isset($_POST['mail'])){
883 $this->mail = $_POST['mail'];
884 }
886 }
887 }
889 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
890 ?>