Code

2f6a5503c3b582a3087ea0810c688e498908a24a
[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     /* Do we need to flip is_account state? */
182     if (isset($_POST['modify_state'])){
183       $this->is_account= !$this->is_account;
184     }
186     /* Do we represent a valid account? */
187     if (!$this->is_account && $this->parent == NULL){
188       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
189         _("This account has no mail extensions.")."</b>";
190       $display.= back_to_main();
191       return ($display);
192     }
194     /* Show tab dialog headers */
195     if ($this->parent != NULL){
196       if ($this->is_account){
197         $display= $this->show_header(_("Remove mail account"),
198             _("This account has mail features enabled. You can disable them by clicking below."));
199       } else {
200         $display= $this->show_header(_("Create mail account"),
201             _("This account has mail features disabled. You can enable them by clicking below."));
202         return ($display);
203       }
204     }
206     /* Trigger forward add dialog? */
207     if (isset($_POST['add_local_forwarder'])){
208       $this->forward_dialog= TRUE;
209       $this->dialog= TRUE;
210     }
212     /* Cancel forward add dialog? */
213     if (isset($_POST['add_locals_cancel'])){
214       $this->forward_dialog= FALSE;
215       $this->dialog= FALSE;
216     }
218     /* Finished adding of locals? */
219     if (isset($_POST['add_locals_finish'])){
220       if (count ($_POST['local_list']) &&
221           chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
223         /* Walk through list of forwarders, ignore own addresses */
224         foreach ($_POST['local_list'] as $val){
225           if (!in_array ($val, $this->gosaMailAlternateAddress) &&
226               $val != $this->mail){
228             $this->addForwarder($val);
229             $this->is_modified= TRUE;
230           }
231         }
232       }
233       $this->forward_dialog= FALSE;
234       $this->dialog= FALSE;
235     }
237     /* Add forward email addresses */
238     if (isset($_POST['add_forwarder'])){
239       if ($_POST['forward_address'] != ""){
241         /* Valid email address specified? */
242         $address= $_POST['forward_address'];
243         $valid= FALSE;
244         if (!is_email($address)){
245           if (!is_email($address, TRUE)){
246             if ($this->is_template){
247               $valid= TRUE;
248             } else {
249               print_red (_("You're trying to add an invalid email address to the list of forwarders."));
250             }
251           }
252         } elseif ($address == $this->mail
253             || in_array($address, $this->gosaMailAlternateAddress)) {
255           print_red (_("Adding your one of your own addresses to the forwarders makes no sense."));
257         } else {
258           $valid= TRUE;
259         }
261         if ($valid){
262           /* Add it */
263           if (chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
264             $this->addForwarder ($address);
265             $this->is_modified= TRUE;
266           }
268         }
269       }
270     }
272     /* Delete forward email addresses */
273     if (isset($_POST['delete_forwarder'])){
274       if (count($_POST['forwarder_list']) 
275           && chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
277         $this->delForwarder ($_POST['forwarder_list']);
278       }
279     }
281     /* Add alternate email addresses */
282     if (isset($_POST['add_alternate'])){
283       if ($_POST['alternate_address'] != "" &&
284           chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
286         $valid= FALSE;
287         if (!is_email($_POST['alternate_address'])){
288           if ($this->is_template){
289             if (!(is_email($_POST['alternate_address'], TRUE))){
290               print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
291             } else {
292               $valid= TRUE;
293             }
294           } else {
295             print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
296           }
298         } else {
299           $valid= TRUE;
300         }
302         if ($valid && ($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
303           $ui= get_userinfo();
304           if ($user != $ui->username){
305             print_red (_("The address you're trying to add is already used by user")." '$user'.");
306           }
307         }
308       }
309     }
311     /* Delete alternate email addresses */
312     if (isset($_POST['delete_alternate']) && isset ($_POST['alternates_list'])){
313       if (count($_POST['alternates_list']) &&
314           chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
316         $this->delAlternate ($_POST['alternates_list']);
317       }
318     }
320     /* Import vacation message? */
321     if (isset($_POST["import_vacation"]) && isset($this->vacation[$_POST["vacation_template"]])){
322       $contents= "";
323       $lines= file($_POST["vacation_template"]);
324       foreach ($lines as $line){
325         if (!preg_match('/^DESC:/', $line)){
326           $contents.= $line;
327         }
328       }
330       /* Replace attributes */
331       $attrs= $this->parent->by_object['user']->attributes;
332       foreach ($attrs as $val){
333         $contents= preg_replace("/%$val/",
334             $this->parent->by_object['user']->$val, $contents);
335       }
337       /* Save message */
338       $this->gosaVacationMessage= htmlspecialchars($contents);
339     }
341     /* Show forward add dialog */
342     if ($this->forward_dialog){
343       $ldap= $this->config->get_ldap_link();
345       /* Save data */
346       $mailfilter= get_global("mailfilter");
347       foreach( array("depselect", "muser", "regex") as $type){
348         if (isset($_POST[$type])){
349           $mailfilter[$type]= $_POST[$type];
350         }
351       }
352       if (isset($_GET['search'])){
353         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
354         if ($s == "**"){
355           $s= "*";
356         }
357         $mailfilter['regex']= $s;
358       }
359       register_global("mailfilter", $mailfilter);
361       /* Get actual list */
362       $mailusers= array ();
363       if ($mailfilter['regex'] != '*' && $mailfilter['regex'] != ""){
364         $regex= $mailfilter['regex'];
365         $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
366       } else {
367         $filter= "";
368       }
369       if ($mailfilter['muser'] != ""){
370         $user= $mailfilter['muser'];
371         $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
372       }
374       /* Add already present people to the filter */
375       $exclude= "";
376       foreach ($this->gosaMailForwardingAddress as $mail){
377         $exclude.= "(mail=$mail)";
378       }
379       if ($exclude != ""){
380         $filter.= "(!(|$exclude))";
381       }
383       $acl= array($this->config->current['BASE'] => ":all");
384       $res= get_list($acl, "(&(objectClass=gosaMailAccount)$filter)", TRUE, $mailfilter['depselect'], array("sn", "mail", "givenName"), TRUE);
385       $ldap->cd($mailfilter['depselect']);
386       $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
387       error_reporting (0);
388       while ($attrs= $ldap->fetch()){
389         if(preg_match('/%/', $attrs['mail'][0])){
390           continue;
391         }
392         $name= $this->make_name($attrs);
393         $mailusers[$attrs['mail'][0]]= $name."&lt;".
394           $attrs['mail'][0]."&gt;";
395       }
396       error_reporting (E_ALL);
397       natcasesort ($mailusers);
398       reset ($mailusers);
400       /* Show dialog */
401       $smarty->assign("search_image", get_template_path('images/search.png'));
402       $smarty->assign("tree_image", get_template_path('images/tree.png'));
403       $smarty->assign("infoimage", get_template_path('images/info.png'));
404       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
405       $smarty->assign("mailusers", $mailusers);
406       if (isset($_POST['depselect'])){
407         $smarty->assign("depselect", $_POST['depselect']);
408       }
409       $smarty->assign("deplist", $this->config->idepartments);
410       $smarty->assign("apply", apply_filter());
411       $smarty->assign("alphabet", generate_alphabet());
412       $smarty->assign("hint", print_sizelimit_warning());
413       foreach( array("depselect", "muser", "regex") as $type){
414         $smarty->assign("$type", $mailfilter[$type]);
415       }
416       $smarty->assign("hint", print_sizelimit_warning());
418       $display.= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE, dirname(__FILE__)));
419       return ($display);
420     }
422     /* Show main page */
423     $mailserver= array();
424     foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
425       $mailserver[]= $key;
426     }
427     $smarty->assign("mailServers", $mailserver);
428     foreach(array("gosaMailServer", "gosaMailQuota", "perms", "mail",
429           "gosaMailAlternateAddress", "gosaMailForwardingAddress",
430           "gosaVacationMessage", "gosaMailDeliveryMode",
431           "gosaMailMaxSize", "gosaSpamSortLevel", "gosaSpamMailbox") as $val){
433       $smarty->assign("$val", $this->$val);
434       $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
435     }
437     if (is_numeric($this->gosaMailQuota) && $this->gosaMailQuota != 0){
438       $smarty->assign("quotausage", $this->quotaUsage * 100 / $this->gosaMailQuota);
439       $smarty->assign("quotadefined", "true");
440     } else {
441       $smarty->assign("quotadefined", "false");
442     }
444     /* Disable mail field if needed */
445     $method= new $this->method($this->config);
446     if ($method->uattrib == "mail" && $this->initially_was_account){
447       $smarty->assign("mailACL", "disabled");
448     }
450     /* Fill checkboxes */
451     if (!preg_match("/L/", $this->gosaMailDeliveryMode)) {
452       $smarty->assign("drop_own_mails", "checked");
453     } else {
454       $smarty->assign("drop_own_mails", "");
455     }
456     if (preg_match("/V/", $this->gosaMailDeliveryMode)) {
457       $smarty->assign("use_vacation", "checked");
458     } else {
459       $smarty->assign("use_vacation", "");
460     }
461     if (preg_match("/S/", $this->gosaMailDeliveryMode)) {
462       $smarty->assign("use_spam_filter", "checked");
463     } else {
464       $smarty->assign("use_spam_filter", "");
465     }
466     if (preg_match("/R/", $this->gosaMailDeliveryMode)) {
467       $smarty->assign("use_mailsize_limit", "checked");
468     } else {
469       $smarty->assign("use_mailsize_limit", "");
470     }
471     if (preg_match("/I/", $this->gosaMailDeliveryMode)) {
472       $smarty->assign("only_local", "checked");
473     } else {
474       $smarty->assign("only_local", "");
475     }
476     if (preg_match("/C/", $this->gosaMailDeliveryMode)) {
477       $smarty->assign("own_script", "checked");
478     } else {
479       $smarty->assign("own_script", "");
480     }
482     /* Have vacation templates? */
483     $smarty->assign("template", "");
484     if (count($this->vacation)){
485       $smarty->assign("show_templates", "true");
486       $smarty->assign("vacationtemplates", $this->vacation);
487       if (isset($_POST['vacation_template'])){
488         $smarty->assign("template", $_POST['vacation_template']);
489       }
490     } else {
491       $smarty->assign("show_templates", "false");
492     }
494     /* Fill spam selector */
495     $spamlevel= array();
496     for ($i= 0; $i<21; $i++){
497       $spamlevel[]= $i;
498     }
499     $smarty->assign("spamlevel", $spamlevel);
500     $smarty->assign("spambox", $this->mailboxList);
501     $smarty->assign("custom_sieveACL", chkacl($this->acl, "custom_sieve"));     
502     $smarty->assign("only_localACL", chkacl($this->acl, "only_local")); 
504     if(isset($this->gosaMailAlternateAddress)&&($this->gosaMailAlternateAddress)){ 
505       $smarty->assign("SELECT_gosaMailAlternateAddress",true);
506     } else { 
507       $smarty->assign("SELECT_gosaMailAlternateAddress",false);
508     }
510     if(isset($this->spamlevel)&&($this->spamlevel)){
511       $smarty->assign("SELECT_spamlevel",true);
512     } else {
513       $smarty->assign("SELECT_spamlevel",false);
514     }
516     if(isset($this->spambox)&&($this->spambox)){
517       $smarty->assign("SELECT_spambox",true);
518     } else {
519       $smarty->assign("SELECT_spambox",false);
520     }
522     if(isset($this->vacationtemplates)&&($this->vacationtemplates)) {
523       $smarty->assign("SELECT_vacationtemplates",true);
524     } else {
525       $smarty->assign("SELECT_vacationtemplates",false);
526     }
528     if(isset($this->gosaMailForwardingAddress)&&($this->gosaMailForwardingAddress)){
529       $smarty->assign("SELECT_gosaMailForwardingAddress",true);
530     } else {
531       $smarty->assign("SELECT_gosaMailForwardingAddress",false);
532     }
534     if(count($mailserver)){
535       $smarty->assign("SELECT_mailServers",true);
536     } else {
537       $smarty->assign("SELECT_mailServers",false);
538     }
540     $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
541     return ($display);
542   }
545   /* remove object from parent */
546   function remove_from_parent()
547   {
548     /* Cancel if there's nothing to do here */
549     if (!$this->initially_was_account){
550       return;
551     }
552     
553     /* include global link_info */
554     $ldap= $this->config->get_ldap_link();
556     /* Remove and write to LDAP */
557     plugin::remove_from_parent();
559     /* Zero arrays */
560     $this->attrs['gosaMailAlternateAddress']= array();
561     $this->attrs['gosaMailForwardingAddress']= array();
563     /* Adapt attributes if needed */
564     $method= new $this->method($this->config);
565     $method->fixAttributesOnRemove($this);
567     /* Mailmethod wants us to remove the entry from LDAP. Keep uid! */
568     unset ($this->attrs['uid']);
569     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
570         $this->attributes, "Save");
571     $ldap->cd($this->dn);
572     $ldap->modify($this->attrs);
573     show_ldap_error($ldap->get_error());
575     /* Connect to IMAP server for account deletion */
576     if ($this->gosaMailServer != ""){
577       $method= new $this->method($this->config);
578       $id= $method->uattrib;
579       if ($method->connect($this->gosaMailServer)){
581         /* Remove account from IMAP server */
582         $method->deleteMailbox($this->folder_prefix.$this->$id);
583         $method->disconnect();
584       }
585     }
587     /* Optionally execute a command after we're done */
588     $this->handle_post_events("remove");
589   }
592   /* Save data to object */
593   function save_object()
594   {
595     if (isset($_POST['mailTab'])){
596       /* Save ldap attributes */
597       plugin::save_object();
599       /* Assemble mail delivery mode
600          The mode field in ldap consists of values between braces, this must
601          be called when 'mail' is set, because checkboxes may not be set when
602          we're in some other dialog.
604          Example for gosaMailDeliveryMode [LR        ]
605          L: Local delivery
606          R: Reject when exceeding mailsize limit
607          S: Use spam filter
608          V: Use vacation message
609          C: Use custm sieve script
610          I: Only insider delivery */
612       $tmp= "";
613       if (!isset($_POST["drop_own_mails"])){
614         $tmp.= "L";
615       }
616       if (isset($_POST["use_mailsize_limit"])){
617         $tmp.= "R";
618       }
619       if (isset($_POST["use_spam_filter"])){
620         $tmp.= "S";
621       }
622       if (isset($_POST["use_vacation"])){
623         $tmp.= "V";
624       }
625       if (isset($_POST["own_script"])){
626         $tmp.= "C";
627       }
628       if (isset($_POST["only_local"])){
629         $tmp.= "I";
630       }
631       $tmp= "[$tmp]";
633       if (chkacl ($this->acl, "gosaMailDeliveryMode") == ""){
634         if ($this->gosaMailDeliveryMode != $tmp){
635           $this->is_modified= TRUE;
636         }
637         $this->gosaMailDeliveryMode= $tmp;
638       }
639     }
640   }
643   /* Save data to LDAP, depending on is_account we save or delete */
644   function save()
645   {
646     $ldap= $this->config->get_ldap_link();
648     /* Call parents save to prepare $this->attrs */
649     plugin::save();
651     /* Save arrays */
652     $this->attrs['gosaMailAlternateAddress']= $this->gosaMailAlternateAddress;
653     $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
655     /* Adapt attributes if needed */
656     $method= new $this->method($this->config);
657     $id= $method->uattrib;
658     $method->fixAttributesOnStore($this);
660     /* Save data to LDAP */
661     $ldap->cd($this->dn);
662     $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("mofify");
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     /* must: mail */
705     if ($this->mail == ""){
706       $message[]= _("The required field 'Primary address' is not set.");
707     }
708     if ($this->is_template){
709       if (!is_email($this->mail, TRUE)){
710         $message[]= _("Please enter a valid email address in 'Primary address' field.");
711       }
712     } else {
713       if (!is_email($this->mail)){
714         $message[]= _("Please enter a valid email address in 'Primary address' field.");
715       }
716     }
717     $ldap->cd($this->config->current['BASE']);
718     $ldap->search ("(&(objectClass=gosaMailAccount)(!(objectClass=gosaUserTemplate))(|(mail=".$this->mail.")(gosaMailAlternateAddress=".
719         $this->mail."))(!(uid=".$this->uid."))(!(cn=".$this->uid.")))", array("uid"));
720     if ($ldap->count() != 0){
721       $message[]= _("The primary address you've entered is already in use.");
722     }
724     /* Check quota */
725     if ($this->gosaMailQuota != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
726       if (!is_numeric($this->gosaMailQuota)) {
727         $message[]= _("Value in 'Quota size' is not valid.");
728       } else {
729         $this->gosaMailQuota= (int) $this->gosaMailQuota;
730       }
731     }
733     /* Check rejectsize for integer */
734     if ($this->gosaMailMaxSize != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
735       if (!is_numeric($this->gosaMailMaxSize)){
736         $message[]= _("Please specify a vaild mail size for mails to be rejected.");
737       } else {
738         $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
739       }
740     }
742     /* Need gosaMailMaxSize if use_mailsize_limit is checked */
743     if (is_integer(strpos($this->gosaMailDeliveryMode, "R")) && 
744         $this->gosaMailMaxSize == ""){
746       $message[]= _("You need to set the maximum mail size in order to reject anything.");
747     }
749     return ($message);
750   }
752   /* Adapt from template, using 'dn' */
753   function adapt_from_template($dn)
754   {
755     plugin::adapt_from_template($dn);
757     foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
758       $this->$val= array();
759       if (isset($this->attrs["$val"]["count"])){
760         for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
761           $value= $this->attrs["$val"][$i];
762           foreach (array("sn", "givenName", "uid") as $repl){
763             if (preg_match("/%$repl/i", $value)){
764               $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
765             }
766           }
767           array_push($this->$val, strtolower(rewrite($value)));
768         }
769       }
770     }
771     $this->mail= strtolower(rewrite($this->mail));
772   }
774   /* Add entry to forwarder list */
775   function addForwarder($address)
776   {
777     $this->gosaMailForwardingAddress[]= $address;
778     $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
780     sort ($this->gosaMailForwardingAddress);
781     reset ($this->gosaMailForwardingAddress);
782     $this->is_modified= TRUE;
783   }
785   /* Remove list of addresses from forwarder list */
786   function delForwarder($addresses)
787   {
788     $this->gosaMailForwardingAddress= array_remove_entries ($addresses, $this->gosaMailForwardingAddress);
789     $this->is_modified= TRUE;
790   }
794   function addAlternate($address)
795   {
796     $ldap= $this->config->get_ldap_link();
798     $address= strtolower($address);
800     /* Is this address already assigned in LDAP? */
801     $ldap->cd ($this->config->current['BASE']);
802     $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)".
803         "(gosaMailAlternateAddress=$address)))", array("uid"));
805     if ($ldap->count() > 0){
806       $attrs= $ldap->fetch ();
807       return ($attrs["uid"][0]);
808     }
810     /* Add to list of alternates */
811     if (!in_array($address, $this->gosaMailAlternateAddress)){
812       $this->gosaMailAlternateAddress[]= $address;
813       $this->is_modified= TRUE;
814     }
816     sort ($this->gosaMailAlternateAddress);
817     reset ($this->gosaMailAlternateAddress);
819     return ("");
820   }
823   function delAlternate($addresses)
824   {
825     $this->gosaMailAlternateAddress= array_remove_entries ($addresses,
826                                                            $this->gosaMailAlternateAddress);
827     $this->is_modified= TRUE;
828   }
830   function make_name($attrs)
831   {
832     $name= "";
833     if (isset($attrs['sn'][0])){
834       $name= $attrs['sn'][0];
835     }
836     if (isset($attrs['givenName'][0])){
837       if ($name != ""){
838         $name.= ", ".$attrs['givenName'][0];
839       } else {
840         $name.= $attrs['givenName'][0];
841       }
842     }
843     if ($name != ""){
844       $name.= " ";
845     }
847     return ($name);
848   }
852 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
853 ?>