Code

Added execute methods
[gosa.git] / plugins / personal / mail / class_mailAccount.inc
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",
58       "gosaMailDeliveryMode", "gosaSpamSortLevel", "gosaSpamMailbox",
59       "gosaVacationMessage", "uid");
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         if (isset($this->attrs["$val"]["count"])){
96           for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
97             array_push($this->$val, $this->attrs["$val"][$i]);
98           }
99         }
100       }
102       /* Only do IMAP actions if gosaMailServer attribute is set */
103       if (isset ($this->attrs["gosaMailServer"][0])){
104         $method= new $this->method($this->config);
105         $id= $method->uattrib;
106         if ($method->connect($this->attrs["gosaMailServer"][0])){
107           $quota= $method->getQuota($this->folder_prefix.$this->$id);
108           $this->quotaUsage= $quota['quotaUsage'];
109           $this->gosaMailQuota= $quota['gosaMailQuota'];
110           $this->mailboxList= $method->getMailboxList(
111               $this->folder_prefix.$this->$id,
112               $this->$id);
113           $method->disconnect();
114         }
116         /* Adapt attributes if needed */
117         $method->fixAttributesOnLoad($this);
118       }
119     }
121     /* Fill vacation array */
122     $this->vacation= array();
123     if (isset($this->config->current['VACATIONDIR'])){
124       $dir= $this->config->current['VACATIONDIR'];
125       if (is_dir($dir) && is_readable($dir)){
127         /* Look for files and build the vacation array */
128         $dh= opendir($dir);
129         while ($file = readdir($dh)){
130           $description= $this->parse_vacation("$dir/$file");
131           if ($description != ""){
132             $this->vacation["$dir/$file"]= $description;
133           }
134         }
135         closedir($dh);
136       }
137     }
139     /* Get global filter config */
140     if (!is_global("mailfilter")){
141       $ui= get_userinfo();
142       $base= get_base_from_people($ui->dn);
143       $mailfilter= array( "depselect"       => $base,
144           "muser"            => "",
145           "regex"           => "*");
146       register_global("mailfilter", $mailfilter);
147     }
149     /* Save initial account state */
150     $this->initially_was_account= $this->is_account;
151   }
154   function parse_vacation($file)
155   {
156     $desc= "";
158     if (is_file($file)){
159       $fh = fopen($file, "r");
160       $line= fgets($fh, 256);
162       if (!preg_match('/^DESC:/', $line)){
163         print_red (_("No DESC tag in vacation file:")." $file");
164         return $desc;
165       }
166       fclose ($fh);
168       $desc= trim(preg_replace('/^DESC:\s*/', '', $line));
169     }
171     return $desc;
172   }
175   function execute()
176   {
177         /* Call parent execute */
178         plugin::execute();
179     /* Load templating engine */
180     $smarty= get_smarty();
181     $display= "";
183     $mailserver= array();
184     foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
185       $mailserver[]= $key;
186     }
188     /* Do we need to flip is_account state? */
189     if (isset($_POST['modify_state'])){
190       $this->is_account= !$this->is_account;
191     }
193     /* Show main page */
194     $mailserver= array();
195     foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
196       $mailserver[]= $key;
197     }
199     /* Do we represent a valid account? */
200     if (!$this->is_account && $this->parent == NULL){
201       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
202         _("This account has no mail extensions.")."</b>";
204       $display.= back_to_main();
205       return ($display);
206     }
208     /* Show tab dialog headers */
209     if ($this->parent != NULL){
210       if ($this->is_account){
211         $display= $this->show_header(_("Remove mail account"),
212             _("This account has mail features enabled. You can disable them by clicking below."));
213       } else {
214         $display= $this->show_header(_("Create mail account"), _("This account has mail features disabled. You can enable them by clicking below."));
215         return ($display);
216       }
217     }
219     /* Trigger forward add dialog? */
220     if (isset($_POST['add_local_forwarder'])){
221       $this->forward_dialog= TRUE;
222       $this->dialog= TRUE;
223     }
225     /* Cancel forward add dialog? */
226     if (isset($_POST['add_locals_cancel'])){
227       $this->forward_dialog= FALSE;
228       $this->dialog= FALSE;
229     }
231     /* Finished adding of locals? */
232     if (isset($_POST['add_locals_finish'])){
233       if (count ($_POST['local_list']) &&
234           chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
236         /* Walk through list of forwarders, ignore own addresses */
237         foreach ($_POST['local_list'] as $val){
238           if (!in_array ($val, $this->gosaMailAlternateAddress) &&
239               $val != $this->mail){
241             $this->addForwarder($val);
242             $this->is_modified= TRUE;
243           }
244         }
245       }
246       $this->forward_dialog= FALSE;
247       $this->dialog= FALSE;
248     }
250     /* Add forward email addresses */
251     if (isset($_POST['add_forwarder'])){
252       if ($_POST['forward_address'] != ""){
254         /* Valid email address specified? */
255         $address= $_POST['forward_address'];
256         $valid= FALSE;
257         if (!is_email($address)){
258           if (!is_email($address, TRUE)){
259             if ($this->is_template){
260               $valid= TRUE;
261             } else {
262               print_red (_("You're trying to add an invalid email address to the list of forwarders."));
263             }
264           }
265         } elseif ($address == $this->mail
266             || in_array($address, $this->gosaMailAlternateAddress)) {
268           print_red (_("Adding your one of your own addresses to the forwarders makes no sense."));
270         } else {
271           $valid= TRUE;
272         }
274         if ($valid){
275           /* Add it */
276           if (chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
277             $this->addForwarder ($address);
278             $this->is_modified= TRUE;
279           }
281         }
282       }
283     }
285     /* Delete forward email addresses */
286     if (isset($_POST['delete_forwarder'])){
287       if (count($_POST['forwarder_list']) 
288           && chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
290         $this->delForwarder ($_POST['forwarder_list']);
291       }
292     }
294     /* Add alternate email addresses */
295     if (isset($_POST['add_alternate'])){
296       if ($_POST['alternate_address'] != "" &&
297           chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
299         $valid= FALSE;
300         if (!is_email($_POST['alternate_address'])){
301           if ($this->is_template){
302             if (!(is_email($_POST['alternate_address'], TRUE))){
303               print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
304             } else {
305               $valid= TRUE;
306             }
307           } else {
308             print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
309           }
311         } else {
312           $valid= TRUE;
313         }
315         if ($valid && ($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
316           $ui= get_userinfo();
317           if ($user != $ui->username){
318             print_red (_("The address you're trying to add is already used by user")." '$user'.");
319           }
320         }
321       }
322     }
324     /* Delete alternate email addresses */
325     if (isset($_POST['delete_alternate']) && isset ($_POST['alternates_list'])){
326       if (count($_POST['alternates_list']) &&
327           chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
329         $this->delAlternate ($_POST['alternates_list']);
330       }
331     }
333     /* Import vacation message? */
334     if (isset($_POST["import_vacation"]) && isset($this->vacation[$_POST["vacation_template"]])){
335       $contents= "";
336       $lines= file($_POST["vacation_template"]);
337       foreach ($lines as $line){
338         if (!preg_match('/^DESC:/', $line)){
339           $contents.= $line;
340         }
341       }
343       /* Replace attributes */
344       $attrs= $this->parent->by_object['user']->attributes;
345       foreach ($attrs as $val){
346         $contents= preg_replace("/%$val/",
347             $this->parent->by_object['user']->$val, $contents);
348       }
350       /* Save message */
351       $this->gosaVacationMessage= htmlspecialchars($contents);
352     }
354     /* Show forward add dialog */
355     if ($this->forward_dialog){
356       $ldap= $this->config->get_ldap_link();
358       /* Save data */
359       $mailfilter= get_global("mailfilter");
360       foreach( array("depselect", "muser", "regex") as $type){
361         if (isset($_POST[$type])){
362           $mailfilter[$type]= $_POST[$type];
363         }
364       }
365       if (isset($_GET['search'])){
366         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
367         if ($s == "**"){
368           $s= "*";
369         }
370         $mailfilter['regex']= $s;
371       }
372       register_global("mailfilter", $mailfilter);
374       /* Get actual list */
375       $mailusers= array ();
376       if ($mailfilter['regex'] != '*' && $mailfilter['regex'] != ""){
377         $regex= $mailfilter['regex'];
378         $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
379       } else {
380         $filter= "";
381       }
382       if ($mailfilter['muser'] != ""){
383         $user= $mailfilter['muser'];
384         $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
385       }
387       /* Add already present people to the filter */
388       $exclude= "";
389       foreach ($this->gosaMailForwardingAddress as $mail){
390         $exclude.= "(mail=$mail)";
391       }
392       if ($exclude != ""){
393         $filter.= "(!(|$exclude))";
394       }
396       $acl= array($this->config->current['BASE'] => ":all");
397       $res= get_list($acl, "(&(objectClass=gosaMailAccount)$filter)", TRUE, $mailfilter['depselect'], array("sn", "mail", "givenName"), TRUE);
398       $ldap->cd($mailfilter['depselect']);
399       $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
400       error_reporting (0);
401       while ($attrs= $ldap->fetch()){
402         if(preg_match('/%/', $attrs['mail'][0])){
403           continue;
404         }
405         $name= $this->make_name($attrs);
406         $mailusers[$attrs['mail'][0]]= $name."&lt;".
407           $attrs['mail'][0]."&gt;";
408       }
409       error_reporting (E_ALL);
410       natcasesort ($mailusers);
411       reset ($mailusers);
413       /* Show dialog */
414       $smarty->assign("search_image", get_template_path('images/search.png'));
415       $smarty->assign("tree_image", get_template_path('images/tree.png'));
416       $smarty->assign("infoimage", get_template_path('images/info.png'));
417       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
418       $smarty->assign("mailusers", $mailusers);
419       if (isset($_POST['depselect'])){
420         $smarty->assign("depselect", $_POST['depselect']);
421       }
422       $smarty->assign("deplist", $this->config->idepartments);
423       $smarty->assign("apply", apply_filter());
424       $smarty->assign("alphabet", generate_alphabet());
425       $smarty->assign("hint", print_sizelimit_warning());
426       foreach( array("depselect", "muser", "regex") as $type){
427         $smarty->assign("$type", $mailfilter[$type]);
428       }
429       $smarty->assign("hint", print_sizelimit_warning());
431       $display.= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE, dirname(__FILE__)));
432       return ($display);
433     }
435     $smarty->assign("mailServers", $mailserver);
436     foreach(array("gosaMailServer", "gosaMailQuota", "perms", "mail",
437           "gosaMailAlternateAddress", "gosaMailForwardingAddress",
438           "gosaVacationMessage", "gosaMailDeliveryMode",
439           "gosaMailMaxSize", "gosaSpamSortLevel", "gosaSpamMailbox") as $val){
441       $smarty->assign("$val", $this->$val);
442       $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
443     }
445     if (is_numeric($this->gosaMailQuota) && $this->gosaMailQuota != 0){
446       $smarty->assign("quotausage", progressbar(round(($this->quotaUsage * 100)/ $this->gosaMailQuota,100,15,true)));
447       $smarty->assign("quotadefined", "true");
448     } else {
449       $smarty->assign("quotadefined", "false");
450     }
452     /* Disable mail field if needed */
453     $method= new $this->method($this->config);
454     if ($method->uattrib == "mail" && $this->initially_was_account){
455       $smarty->assign("mailACL", "disabled");
456     }
458     /* Fill checkboxes */
459     if (!preg_match("/L/", $this->gosaMailDeliveryMode)) {
460       $smarty->assign("drop_own_mails", "checked");
461     } else {
462       $smarty->assign("drop_own_mails", "");
463     }
464     if (preg_match("/V/", $this->gosaMailDeliveryMode)) {
465       $smarty->assign("use_vacation", "checked");
466     } else {
467       $smarty->assign("use_vacation", "");
468     }
469     if (preg_match("/S/", $this->gosaMailDeliveryMode)) {
470       $smarty->assign("use_spam_filter", "checked");
471     } else {
472       $smarty->assign("use_spam_filter", "");
473     }
474     if (preg_match("/R/", $this->gosaMailDeliveryMode)) {
475       $smarty->assign("use_mailsize_limit", "checked");
476     } else {
477       $smarty->assign("use_mailsize_limit", "");
478     }
479     if (preg_match("/I/", $this->gosaMailDeliveryMode)) {
480       $smarty->assign("only_local", "checked");
481     } else {
482       $smarty->assign("only_local", "");
483     }
484     if (preg_match("/C/", $this->gosaMailDeliveryMode)) {
485       $smarty->assign("own_script", "checked");
486     } else {
487       $smarty->assign("own_script", "");
488     }
490     /* Have vacation templates? */
491     $smarty->assign("template", "");
492     if (count($this->vacation)){
493       $smarty->assign("show_templates", "true");
494       $smarty->assign("vacationtemplates", $this->vacation);
495       if (isset($_POST['vacation_template'])){
496         $smarty->assign("template", $_POST['vacation_template']);
497       }
498     } else {
499       $smarty->assign("show_templates", "false");
500     }
502     /* Fill spam selector */
503     $spamlevel= array();
504     for ($i= 0; $i<21; $i++){
505       $spamlevel[]= $i;
506     }
507     $smarty->assign("spamlevel", $spamlevel);
508     $smarty->assign("spambox", $this->mailboxList);
509     $smarty->assign("custom_sieveACL", chkacl($this->acl, "custom_sieve"));     
510     $smarty->assign("only_localACL", chkacl($this->acl, "only_local")); 
512     $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
513     return ($display);
514   }
517   /* remove object from parent */
518   function remove_from_parent()
519   {
520     /* Cancel if there's nothing to do here */
521     if (!$this->initially_was_account){
522       return;
523     }
524     
525     /* include global link_info */
526     $ldap= $this->config->get_ldap_link();
528     /* Remove and write to LDAP */
529     plugin::remove_from_parent();
531     /* Zero arrays */
532     $this->attrs['gosaMailAlternateAddress']= array();
533     $this->attrs['gosaMailForwardingAddress']= array();
535     /* Adapt attributes if needed */
536     $method= new $this->method($this->config);
537     $method->fixAttributesOnRemove($this);
539     /* Mailmethod wants us to remove the entry from LDAP. Keep uid! */
540     #fixme: || kolab || is differs here, you can't delete all attrs specified in this plugin .... 
541     #fixme: there are some attributes we have to keep, i think.
542     unset ($this->attrs['uid']);
546     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
547         $this->attributes, "Save");
548     $ldap->cd($this->dn);
549     $ldap->modify($this->attrs);
550     show_ldap_error($ldap->get_error());
552     /* Connect to IMAP server for account deletion */
553     if ($this->gosaMailServer != ""){
554       $method= new $this->method($this->config);
555       $id= $method->uattrib;
556       if ($method->connect($this->gosaMailServer)){
558         /* Remove account from IMAP server */
559         $method->deleteMailbox($this->folder_prefix.$this->$id);
560         $method->disconnect();
561       }
562     }
564     /* Optionally execute a command after we're done */
565     $this->handle_post_events("remove");
566   }
569   /* Save data to object */
570   function save_object()
571   {
572     if (isset($_POST['mailTab'])){
573       /* Save ldap attributes */
574       plugin::save_object();
576       /* Assemble mail delivery mode
577          The mode field in ldap consists of values between braces, this must
578          be called when 'mail' is set, because checkboxes may not be set when
579          we're in some other dialog.
581          Example for gosaMailDeliveryMode [LR        ]
582          L: Local delivery
583          R: Reject when exceeding mailsize limit
584          S: Use spam filter
585          V: Use vacation message
586          C: Use custm sieve script
587          I: Only insider delivery */
589       $tmp= "";
590       if (!isset($_POST["drop_own_mails"])){
591         $tmp.= "L";
592       }
593       if (isset($_POST["use_mailsize_limit"])){
594         $tmp.= "R";
595       }
596       if (isset($_POST["use_spam_filter"])){
597         $tmp.= "S";
598       }
599       if (isset($_POST["use_vacation"])){
600         $tmp.= "V";
601       }
602       if (isset($_POST["own_script"])){
603         $tmp.= "C";
604       }
605       if (isset($_POST["only_local"])){
606         $tmp.= "I";
607       }
608       $tmp= "[$tmp]";
610       if (chkacl ($this->acl, "gosaMailDeliveryMode") == ""){
611         if ($this->gosaMailDeliveryMode != $tmp){
612           $this->is_modified= TRUE;
613         }
614         $this->gosaMailDeliveryMode= $tmp;
615       }
616     }
617   }
620   /* Save data to LDAP, depending on is_account we save or delete */
621   function save()
622   {
623     $ldap= $this->config->get_ldap_link();
625     /* Call parents save to prepare $this->attrs */
626     plugin::save();
628     /* Save arrays */
629     $this->attrs['gosaMailAlternateAddress']= $this->gosaMailAlternateAddress;
630     $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
632     /* Adapt attributes if needed */
633     $method= new $this->method($this->config);
634     $id= $method->uattrib;
635     $method->fixAttributesOnStore($this);
637     /* Remove Mailquota if = "" */
638     if($this->attrs['gosaMailQuota']=="") {
639       $this->attrs['gosaMailQuota']=array();
640     }
642     if(empty($this->attrs['gosaSpamMailbox'])){
643       unset($this->attrs['gosaSpamMailbox']);
644     }
646     /* Save data to LDAP */
647     $ldap->cd($this->dn);
648     $ldap->modify($this->attrs);
649     show_ldap_error($ldap->get_error());
651     /* Only do IMAP actions if we are not a template */
652     if (!$this->is_template){
653       if ($method->connect($this->gosaMailServer)){
654         $method->updateMailbox($this->folder_prefix.$this->$id);
655         $method->setQuota($this->folder_prefix.$this->$id, $this->gosaMailQuota);
656         $method->disconnect();
658         /* Write sieve information only if not in C mode */
659         if (!is_integer(strpos($this->gosaMailDeliveryMode, "C"))){
660           $method->configureFilter($this->$id,
661               $this->gosaMailDeliveryMode,
662               $this->mail,
663               $this->gosaMailAlternateAddress,
664               $this->gosaMailMaxSize,
665               $this->gosaSpamMailbox,
666               $this->gosaSpamSortLevel,
667               $this->gosaVacationMessage);
668         }
669       }
670     }
672     /* Optionally execute a command after we're done */
673     if ($this->initially_was_account == $this->is_account){
674       if ($this->is_modified){
675         $this->handle_post_events("modify");
676       }
677     } else {
678       $this->handle_post_events("add");
679     }
681   }
683   /* Check formular input */
684   function check()
685   {
686     $ldap= $this->config->get_ldap_link();
688     $message= array();
690     if(empty($this->gosaMailServer)){
691       $message[]= _("There is no valid mailserver specified, please add one in the system setup.");
692     }
694     /* must: mail */
695     if ($this->mail == ""){
696       $message[]= _("The required field 'Primary address' is not set.");
697     }
698     if ($this->is_template){
699       if (!is_email($this->mail, TRUE)){
700         $message[]= _("Please enter a valid email address in 'Primary address' field.");
701       }
702     } else {
703       if (!is_email($this->mail)){
704         $message[]= _("Please enter a valid email address in 'Primary address' field.");
705       }
706     }
707     $ldap->cd($this->config->current['BASE']);
708     $ldap->search ("(&(!(objectClass=gosaUserTemplate))(|(mail=".$this->mail.")(gosaMailAlternateAddress=".
709         $this->mail."))(!(uid=".$this->uid."))(!(cn=".$this->uid.")))", array("uid"));
710     if ($ldap->count() != 0){
711       $message[]= _("The primary address you've entered is already in use.");
712     }
714     /* Check quota */
715     if ($this->gosaMailQuota != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
716       if (!is_numeric($this->gosaMailQuota)) {
717         $message[]= _("Value in 'Quota size' is not valid.");
718       } else {
719         $this->gosaMailQuota= (int) $this->gosaMailQuota;
720       }
721     }
723     /* Check rejectsize for integer */
724     if ($this->gosaMailMaxSize != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
725       if (!is_numeric($this->gosaMailMaxSize)){
726         $message[]= _("Please specify a vaild mail size for mails to be rejected.");
727       } else {
728         $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
729       }
730     }
732     /* Need gosaMailMaxSize if use_mailsize_limit is checked */
733     if (is_integer(strpos($this->gosaMailDeliveryMode, "R")) && 
734         $this->gosaMailMaxSize == ""){
736       $message[]= _("You need to set the maximum mail size in order to reject anything.");
737     }
739     if((preg_match("/S/", $this->gosaMailDeliveryMode))&&(empty($this->gosaSpamMailbox))) {
740       $message[]= _("You specified Spam settings, but there is no Folder specified.");
741     }
743     return ($message);
744   }
746   /* Adapt from template, using 'dn' */
747   function adapt_from_template($dn)
748   {
749     plugin::adapt_from_template($dn);
751     foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
752       $this->$val= array();
753       if (isset($this->attrs["$val"]["count"])){
754         for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
755           $value= $this->attrs["$val"][$i];
756           foreach (array("sn", "givenName", "uid") as $repl){
757             if (preg_match("/%$repl/i", $value)){
758               $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
759             }
760           }
761           array_push($this->$val, strtolower(rewrite($value)));
762         }
763       }
764     }
765     $this->mail= strtolower(rewrite($this->mail));
766   }
768   /* Add entry to forwarder list */
769   function addForwarder($address)
770   {
771     $this->gosaMailForwardingAddress[]= $address;
772     $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
774     sort ($this->gosaMailForwardingAddress);
775     reset ($this->gosaMailForwardingAddress);
776     $this->is_modified= TRUE;
777   }
779   /* Remove list of addresses from forwarder list */
780   function delForwarder($addresses)
781   {
782     $this->gosaMailForwardingAddress= array_remove_entries ($addresses, $this->gosaMailForwardingAddress);
783     $this->is_modified= TRUE;
784   }
788   function addAlternate($address)
789   {
790     $ldap= $this->config->get_ldap_link();
792     $address= strtolower($address);
794     /* Is this address already assigned in LDAP? */
795     $ldap->cd ($this->config->current['BASE']);
796     $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)".
797         "(gosaMailAlternateAddress=$address)))", array("uid"));
799     if ($ldap->count() > 0){
800       $attrs= $ldap->fetch ();
801       return ($attrs["uid"][0]);
802     }
804     /* Add to list of alternates */
805     if (!in_array($address, $this->gosaMailAlternateAddress)){
806       $this->gosaMailAlternateAddress[]= $address;
807       $this->is_modified= TRUE;
808     }
810     sort ($this->gosaMailAlternateAddress);
811     reset ($this->gosaMailAlternateAddress);
813     return ("");
814   }
817   function delAlternate($addresses)
818   {
819     $this->gosaMailAlternateAddress= array_remove_entries ($addresses,
820                                                            $this->gosaMailAlternateAddress);
821     $this->is_modified= TRUE;
822   }
824   function make_name($attrs)
825   {
826     $name= "";
827     if (isset($attrs['sn'][0])){
828       $name= $attrs['sn'][0];
829     }
830     if (isset($attrs['givenName'][0])){
831       if ($name != ""){
832         $name.= ", ".$attrs['givenName'][0];
833       } else {
834         $name.= $attrs['givenName'][0];
835       }
836     }
837     if ($name != ""){
838       $name.= " ";
839     }
841     return ($name);
842   }
846 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
847 ?>