Code

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