Code

rework of the nagios plugin and interface
[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     /* Load templating engine */
178     $smarty= get_smarty();
179     $display= "";
181     $mailserver= array();
182     foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
183       $mailserver[]= $key;
184     }
186     /* Do we need to flip is_account state? */
187     if (isset($_POST['modify_state'])){
188       $this->is_account= !$this->is_account;
189     }
191     /* Show main page */
192     $mailserver= array();
193     foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
194       $mailserver[]= $key;
195     }
197     /* Do we represent a valid account? */
198     if (!$this->is_account && $this->parent == NULL){
199       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
200         _("This account has no mail extensions.")."</b>";
202       $display.= back_to_main();
203       return ($display);
204     }
206     /* Show tab dialog headers */
207     if ($this->parent != NULL){
208       if ($this->is_account){
209         $display= $this->show_header(_("Remove mail account"),
210             _("This account has mail features enabled. You can disable them by clicking below."));
211       } else {
212         $display= $this->show_header(_("Create mail account"), _("This account has mail features disabled. You can enable them by clicking below."));
213         return ($display);
214       }
215     }
217     /* Trigger forward add dialog? */
218     if (isset($_POST['add_local_forwarder'])){
219       $this->forward_dialog= TRUE;
220       $this->dialog= TRUE;
221     }
223     /* Cancel forward add dialog? */
224     if (isset($_POST['add_locals_cancel'])){
225       $this->forward_dialog= FALSE;
226       $this->dialog= FALSE;
227     }
229     /* Finished adding of locals? */
230     if (isset($_POST['add_locals_finish'])){
231       if (count ($_POST['local_list']) &&
232           chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
234         /* Walk through list of forwarders, ignore own addresses */
235         foreach ($_POST['local_list'] as $val){
236           if (!in_array ($val, $this->gosaMailAlternateAddress) &&
237               $val != $this->mail){
239             $this->addForwarder($val);
240             $this->is_modified= TRUE;
241           }
242         }
243       }
244       $this->forward_dialog= FALSE;
245       $this->dialog= FALSE;
246     }
248     /* Add forward email addresses */
249     if (isset($_POST['add_forwarder'])){
250       if ($_POST['forward_address'] != ""){
252         /* Valid email address specified? */
253         $address= $_POST['forward_address'];
254         $valid= FALSE;
255         if (!is_email($address)){
256           if (!is_email($address, TRUE)){
257             if ($this->is_template){
258               $valid= TRUE;
259             } else {
260               print_red (_("You're trying to add an invalid email address to the list of forwarders."));
261             }
262           }
263         } elseif ($address == $this->mail
264             || in_array($address, $this->gosaMailAlternateAddress)) {
266           print_red (_("Adding your one of your own addresses to the forwarders makes no sense."));
268         } else {
269           $valid= TRUE;
270         }
272         if ($valid){
273           /* Add it */
274           if (chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
275             $this->addForwarder ($address);
276             $this->is_modified= TRUE;
277           }
279         }
280       }
281     }
283     /* Delete forward email addresses */
284     if (isset($_POST['delete_forwarder'])){
285       if (count($_POST['forwarder_list']) 
286           && chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
288         $this->delForwarder ($_POST['forwarder_list']);
289       }
290     }
292     /* Add alternate email addresses */
293     if (isset($_POST['add_alternate'])){
294       if ($_POST['alternate_address'] != "" &&
295           chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
297         $valid= FALSE;
298         if (!is_email($_POST['alternate_address'])){
299           if ($this->is_template){
300             if (!(is_email($_POST['alternate_address'], TRUE))){
301               print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
302             } else {
303               $valid= TRUE;
304             }
305           } else {
306             print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
307           }
309         } else {
310           $valid= TRUE;
311         }
313         if ($valid && ($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
314           $ui= get_userinfo();
315           if ($user != $ui->username){
316             print_red (_("The address you're trying to add is already used by user")." '$user'.");
317           }
318         }
319       }
320     }
322     /* Delete alternate email addresses */
323     if (isset($_POST['delete_alternate']) && isset ($_POST['alternates_list'])){
324       if (count($_POST['alternates_list']) &&
325           chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
327         $this->delAlternate ($_POST['alternates_list']);
328       }
329     }
331     /* Import vacation message? */
332     if (isset($_POST["import_vacation"]) && isset($this->vacation[$_POST["vacation_template"]])){
333       $contents= "";
334       $lines= file($_POST["vacation_template"]);
335       foreach ($lines as $line){
336         if (!preg_match('/^DESC:/', $line)){
337           $contents.= $line;
338         }
339       }
341       /* Replace attributes */
342       $attrs= $this->parent->by_object['user']->attributes;
343       foreach ($attrs as $val){
344         $contents= preg_replace("/%$val/",
345             $this->parent->by_object['user']->$val, $contents);
346       }
348       /* Save message */
349       $this->gosaVacationMessage= htmlspecialchars($contents);
350     }
352     /* Show forward add dialog */
353     if ($this->forward_dialog){
354       $ldap= $this->config->get_ldap_link();
356       /* Save data */
357       $mailfilter= get_global("mailfilter");
358       foreach( array("depselect", "muser", "regex") as $type){
359         if (isset($_POST[$type])){
360           $mailfilter[$type]= $_POST[$type];
361         }
362       }
363       if (isset($_GET['search'])){
364         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
365         if ($s == "**"){
366           $s= "*";
367         }
368         $mailfilter['regex']= $s;
369       }
370       register_global("mailfilter", $mailfilter);
372       /* Get actual list */
373       $mailusers= array ();
374       if ($mailfilter['regex'] != '*' && $mailfilter['regex'] != ""){
375         $regex= $mailfilter['regex'];
376         $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
377       } else {
378         $filter= "";
379       }
380       if ($mailfilter['muser'] != ""){
381         $user= $mailfilter['muser'];
382         $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
383       }
385       /* Add already present people to the filter */
386       $exclude= "";
387       foreach ($this->gosaMailForwardingAddress as $mail){
388         $exclude.= "(mail=$mail)";
389       }
390       if ($exclude != ""){
391         $filter.= "(!(|$exclude))";
392       }
394       $acl= array($this->config->current['BASE'] => ":all");
395       $res= get_list($acl, "(&(objectClass=gosaMailAccount)$filter)", TRUE, $mailfilter['depselect'], array("sn", "mail", "givenName"), TRUE);
396       $ldap->cd($mailfilter['depselect']);
397       $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
398       error_reporting (0);
399       while ($attrs= $ldap->fetch()){
400         if(preg_match('/%/', $attrs['mail'][0])){
401           continue;
402         }
403         $name= $this->make_name($attrs);
404         $mailusers[$attrs['mail'][0]]= $name."&lt;".
405           $attrs['mail'][0]."&gt;";
406       }
407       error_reporting (E_ALL);
408       natcasesort ($mailusers);
409       reset ($mailusers);
411       /* Show dialog */
412       $smarty->assign("search_image", get_template_path('images/search.png'));
413       $smarty->assign("tree_image", get_template_path('images/tree.png'));
414       $smarty->assign("infoimage", get_template_path('images/info.png'));
415       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
416       $smarty->assign("mailusers", $mailusers);
417       if (isset($_POST['depselect'])){
418         $smarty->assign("depselect", $_POST['depselect']);
419       }
420       $smarty->assign("deplist", $this->config->idepartments);
421       $smarty->assign("apply", apply_filter());
422       $smarty->assign("alphabet", generate_alphabet());
423       $smarty->assign("hint", print_sizelimit_warning());
424       foreach( array("depselect", "muser", "regex") as $type){
425         $smarty->assign("$type", $mailfilter[$type]);
426       }
427       $smarty->assign("hint", print_sizelimit_warning());
429       $display.= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE, dirname(__FILE__)));
430       return ($display);
431     }
433     $smarty->assign("mailServers", $mailserver);
434     foreach(array("gosaMailServer", "gosaMailQuota", "perms", "mail",
435           "gosaMailAlternateAddress", "gosaMailForwardingAddress",
436           "gosaVacationMessage", "gosaMailDeliveryMode",
437           "gosaMailMaxSize", "gosaSpamSortLevel", "gosaSpamMailbox") as $val){
439       $smarty->assign("$val", $this->$val);
440       $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
441     }
443     if (is_numeric($this->gosaMailQuota) && $this->gosaMailQuota != 0){
444       $smarty->assign("quotausage", progressbar(($this->quotaUsage * 100)/ $this->gosaMailQuota,100,15,true));
445       $smarty->assign("quotadefined", "true");
446     } else {
447       $smarty->assign("quotadefined", "false");
448     }
450     /* Disable mail field if needed */
451     $method= new $this->method($this->config);
452     if ($method->uattrib == "mail" && $this->initially_was_account){
453       $smarty->assign("mailACL", "disabled");
454     }
456     /* Fill checkboxes */
457     if (!preg_match("/L/", $this->gosaMailDeliveryMode)) {
458       $smarty->assign("drop_own_mails", "checked");
459     } else {
460       $smarty->assign("drop_own_mails", "");
461     }
462     if (preg_match("/V/", $this->gosaMailDeliveryMode)) {
463       $smarty->assign("use_vacation", "checked");
464     } else {
465       $smarty->assign("use_vacation", "");
466     }
467     if (preg_match("/S/", $this->gosaMailDeliveryMode)) {
468       $smarty->assign("use_spam_filter", "checked");
469     } else {
470       $smarty->assign("use_spam_filter", "");
471     }
472     if (preg_match("/R/", $this->gosaMailDeliveryMode)) {
473       $smarty->assign("use_mailsize_limit", "checked");
474     } else {
475       $smarty->assign("use_mailsize_limit", "");
476     }
477     if (preg_match("/I/", $this->gosaMailDeliveryMode)) {
478       $smarty->assign("only_local", "checked");
479     } else {
480       $smarty->assign("only_local", "");
481     }
482     if (preg_match("/C/", $this->gosaMailDeliveryMode)) {
483       $smarty->assign("own_script", "checked");
484     } else {
485       $smarty->assign("own_script", "");
486     }
488     /* Have vacation templates? */
489     $smarty->assign("template", "");
490     if (count($this->vacation)){
491       $smarty->assign("show_templates", "true");
492       $smarty->assign("vacationtemplates", $this->vacation);
493       if (isset($_POST['vacation_template'])){
494         $smarty->assign("template", $_POST['vacation_template']);
495       }
496     } else {
497       $smarty->assign("show_templates", "false");
498     }
500     /* Fill spam selector */
501     $spamlevel= array();
502     for ($i= 0; $i<21; $i++){
503       $spamlevel[]= $i;
504     }
505     $smarty->assign("spamlevel", $spamlevel);
506     $smarty->assign("spambox", $this->mailboxList);
507     $smarty->assign("custom_sieveACL", chkacl($this->acl, "custom_sieve"));     
508     $smarty->assign("only_localACL", chkacl($this->acl, "only_local")); 
510     $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
511     return ($display);
512   }
515   /* remove object from parent */
516   function remove_from_parent()
517   {
518     /* Cancel if there's nothing to do here */
519     if (!$this->initially_was_account){
520       return;
521     }
522     
523     /* include global link_info */
524     $ldap= $this->config->get_ldap_link();
526     /* Remove and write to LDAP */
527     plugin::remove_from_parent();
529     /* Zero arrays */
530     $this->attrs['gosaMailAlternateAddress']= array();
531     $this->attrs['gosaMailForwardingAddress']= array();
533     /* Adapt attributes if needed */
534     $method= new $this->method($this->config);
535     $method->fixAttributesOnRemove($this);
537     /* Mailmethod wants us to remove the entry from LDAP. Keep uid! */
538     #fixme: || kolab || is differs here, you can't delete all attrs specified in this plugin .... 
539     #fixme: there are some attributes we have to keep, i think.
540     unset ($this->attrs['uid']);
544     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
545         $this->attributes, "Save");
546     $ldap->cd($this->dn);
547     $ldap->modify($this->attrs);
548     show_ldap_error($ldap->get_error());
550     /* Connect to IMAP server for account deletion */
551     if ($this->gosaMailServer != ""){
552       $method= new $this->method($this->config);
553       $id= $method->uattrib;
554       if ($method->connect($this->gosaMailServer)){
556         /* Remove account from IMAP server */
557         $method->deleteMailbox($this->folder_prefix.$this->$id);
558         $method->disconnect();
559       }
560     }
562     /* Optionally execute a command after we're done */
563     $this->handle_post_events("remove");
564   }
567   /* Save data to object */
568   function save_object()
569   {
570     if (isset($_POST['mailTab'])){
571       /* Save ldap attributes */
572       plugin::save_object();
574       /* Assemble mail delivery mode
575          The mode field in ldap consists of values between braces, this must
576          be called when 'mail' is set, because checkboxes may not be set when
577          we're in some other dialog.
579          Example for gosaMailDeliveryMode [LR        ]
580          L: Local delivery
581          R: Reject when exceeding mailsize limit
582          S: Use spam filter
583          V: Use vacation message
584          C: Use custm sieve script
585          I: Only insider delivery */
587       $tmp= "";
588       if (!isset($_POST["drop_own_mails"])){
589         $tmp.= "L";
590       }
591       if (isset($_POST["use_mailsize_limit"])){
592         $tmp.= "R";
593       }
594       if (isset($_POST["use_spam_filter"])){
595         $tmp.= "S";
596       }
597       if (isset($_POST["use_vacation"])){
598         $tmp.= "V";
599       }
600       if (isset($_POST["own_script"])){
601         $tmp.= "C";
602       }
603       if (isset($_POST["only_local"])){
604         $tmp.= "I";
605       }
606       $tmp= "[$tmp]";
608       if (chkacl ($this->acl, "gosaMailDeliveryMode") == ""){
609         if ($this->gosaMailDeliveryMode != $tmp){
610           $this->is_modified= TRUE;
611         }
612         $this->gosaMailDeliveryMode= $tmp;
613       }
614     }
615   }
618   /* Save data to LDAP, depending on is_account we save or delete */
619   function save()
620   {
621     $ldap= $this->config->get_ldap_link();
623     /* Call parents save to prepare $this->attrs */
624     plugin::save();
626     /* Save arrays */
627     $this->attrs['gosaMailAlternateAddress']= $this->gosaMailAlternateAddress;
628     $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
630     /* Adapt attributes if needed */
631     $method= new $this->method($this->config);
632     $id= $method->uattrib;
633     $method->fixAttributesOnStore($this);
635     /* Remove Mailquota if = "" */
636     if($this->attrs['gosaMailQuota']=="") {
637       $this->attrs['gosaMailQuota']=array();
638     }
640     if(empty($this->attrs['gosaSpamMailbox'])){
641       unset($this->attrs['gosaSpamMailbox']);
642     }
644     /* Save data to LDAP */
645     $ldap->cd($this->dn);
646     $ldap->modify($this->attrs);
647     show_ldap_error($ldap->get_error());
649     /* Only do IMAP actions if we are not a template */
650     if (!$this->is_template){
651       if ($method->connect($this->gosaMailServer)){
652         $method->updateMailbox($this->folder_prefix.$this->$id);
653         $method->setQuota($this->folder_prefix.$this->$id, $this->gosaMailQuota);
654         $method->disconnect();
656         /* Write sieve information only if not in C mode */
657         if (!is_integer(strpos($this->gosaMailDeliveryMode, "C"))){
658           $method->configureFilter($this->$id,
659               $this->gosaMailDeliveryMode,
660               $this->mail,
661               $this->gosaMailAlternateAddress,
662               $this->gosaMailMaxSize,
663               $this->gosaSpamMailbox,
664               $this->gosaSpamSortLevel,
665               $this->gosaVacationMessage);
666         }
667       }
668     }
670     /* Optionally execute a command after we're done */
671     if ($this->initially_was_account == $this->is_account){
672       if ($this->is_modified){
673         $this->handle_post_events("modify");
674       }
675     } else {
676       $this->handle_post_events("add");
677     }
679   }
681   /* Check formular input */
682   function check()
683   {
684     $ldap= $this->config->get_ldap_link();
686     $message= array();
688     if(empty($this->gosaMailServer)){
689       $message[]= _("There is no valid mailserver specified, please add one in the system setup.");
690     }
692     /* must: mail */
693     if ($this->mail == ""){
694       $message[]= _("The required field 'Primary address' is not set.");
695     }
696     if ($this->is_template){
697       if (!is_email($this->mail, TRUE)){
698         $message[]= _("Please enter a valid email address in 'Primary address' field.");
699       }
700     } else {
701       if (!is_email($this->mail)){
702         $message[]= _("Please enter a valid email address in 'Primary address' field.");
703       }
704     }
705     $ldap->cd($this->config->current['BASE']);
706     $ldap->search ("(&(!(objectClass=gosaUserTemplate))(|(mail=".$this->mail.")(gosaMailAlternateAddress=".
707         $this->mail."))(!(uid=".$this->uid."))(!(cn=".$this->uid.")))", array("uid"));
708     if ($ldap->count() != 0){
709       $message[]= _("The primary address you've entered is already in use.");
710     }
712     /* Check quota */
713     if ($this->gosaMailQuota != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
714       if (!is_numeric($this->gosaMailQuota)) {
715         $message[]= _("Value in 'Quota size' is not valid.");
716       } else {
717         $this->gosaMailQuota= (int) $this->gosaMailQuota;
718       }
719     }
721     /* Check rejectsize for integer */
722     if ($this->gosaMailMaxSize != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
723       if (!is_numeric($this->gosaMailMaxSize)){
724         $message[]= _("Please specify a vaild mail size for mails to be rejected.");
725       } else {
726         $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
727       }
728     }
730     /* Need gosaMailMaxSize if use_mailsize_limit is checked */
731     if (is_integer(strpos($this->gosaMailDeliveryMode, "R")) && 
732         $this->gosaMailMaxSize == ""){
734       $message[]= _("You need to set the maximum mail size in order to reject anything.");
735     }
737     if((preg_match("/S/", $this->gosaMailDeliveryMode))&&(empty($this->gosaSpamMailbox))) {
738       $message[]= _("You specified Spam settings, but there is no Folder specified.");
739     }
741     return ($message);
742   }
744   /* Adapt from template, using 'dn' */
745   function adapt_from_template($dn)
746   {
747     plugin::adapt_from_template($dn);
749     foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
750       $this->$val= array();
751       if (isset($this->attrs["$val"]["count"])){
752         for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
753           $value= $this->attrs["$val"][$i];
754           foreach (array("sn", "givenName", "uid") as $repl){
755             if (preg_match("/%$repl/i", $value)){
756               $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
757             }
758           }
759           array_push($this->$val, strtolower(rewrite($value)));
760         }
761       }
762     }
763     $this->mail= strtolower(rewrite($this->mail));
764   }
766   /* Add entry to forwarder list */
767   function addForwarder($address)
768   {
769     $this->gosaMailForwardingAddress[]= $address;
770     $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
772     sort ($this->gosaMailForwardingAddress);
773     reset ($this->gosaMailForwardingAddress);
774     $this->is_modified= TRUE;
775   }
777   /* Remove list of addresses from forwarder list */
778   function delForwarder($addresses)
779   {
780     $this->gosaMailForwardingAddress= array_remove_entries ($addresses, $this->gosaMailForwardingAddress);
781     $this->is_modified= TRUE;
782   }
786   function addAlternate($address)
787   {
788     $ldap= $this->config->get_ldap_link();
790     $address= strtolower($address);
792     /* Is this address already assigned in LDAP? */
793     $ldap->cd ($this->config->current['BASE']);
794     $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)".
795         "(gosaMailAlternateAddress=$address)))", array("uid"));
797     if ($ldap->count() > 0){
798       $attrs= $ldap->fetch ();
799       return ($attrs["uid"][0]);
800     }
802     /* Add to list of alternates */
803     if (!in_array($address, $this->gosaMailAlternateAddress)){
804       $this->gosaMailAlternateAddress[]= $address;
805       $this->is_modified= TRUE;
806     }
808     sort ($this->gosaMailAlternateAddress);
809     reset ($this->gosaMailAlternateAddress);
811     return ("");
812   }
815   function delAlternate($addresses)
816   {
817     $this->gosaMailAlternateAddress= array_remove_entries ($addresses,
818                                                            $this->gosaMailAlternateAddress);
819     $this->is_modified= TRUE;
820   }
822   function make_name($attrs)
823   {
824     $name= "";
825     if (isset($attrs['sn'][0])){
826       $name= $attrs['sn'][0];
827     }
828     if (isset($attrs['givenName'][0])){
829       if ($name != ""){
830         $name.= ", ".$attrs['givenName'][0];
831       } else {
832         $name.= $attrs['givenName'][0];
833       }
834     }
835     if ($name != ""){
836       $name.= " ";
837     }
839     return ($name);
840   }
844 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
845 ?>