Code

da7a772b802ac03b38aef7788a2fdb68180afa72
[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     unset ($this->attrs['uid']);
539     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
540         $this->attributes, "Save");
541     $ldap->cd($this->dn);
542     $ldap->modify($this->attrs);
543     show_ldap_error($ldap->get_error());
545     /* Connect to IMAP server for account deletion */
546     if ($this->gosaMailServer != ""){
547       $method= new $this->method($this->config);
548       $id= $method->uattrib;
549       if ($method->connect($this->gosaMailServer)){
551         /* Remove account from IMAP server */
552         $method->deleteMailbox($this->folder_prefix.$this->$id);
553         $method->disconnect();
554       }
555     }
557     /* Optionally execute a command after we're done */
558     $this->handle_post_events("remove");
559   }
562   /* Save data to object */
563   function save_object()
564   {
565     if (isset($_POST['mailTab'])){
566       /* Save ldap attributes */
567       plugin::save_object();
569       /* Assemble mail delivery mode
570          The mode field in ldap consists of values between braces, this must
571          be called when 'mail' is set, because checkboxes may not be set when
572          we're in some other dialog.
574          Example for gosaMailDeliveryMode [LR        ]
575          L: Local delivery
576          R: Reject when exceeding mailsize limit
577          S: Use spam filter
578          V: Use vacation message
579          C: Use custm sieve script
580          I: Only insider delivery */
582       $tmp= "";
583       if (!isset($_POST["drop_own_mails"])){
584         $tmp.= "L";
585       }
586       if (isset($_POST["use_mailsize_limit"])){
587         $tmp.= "R";
588       }
589       if (isset($_POST["use_spam_filter"])){
590         $tmp.= "S";
591       }
592       if (isset($_POST["use_vacation"])){
593         $tmp.= "V";
594       }
595       if (isset($_POST["own_script"])){
596         $tmp.= "C";
597       }
598       if (isset($_POST["only_local"])){
599         $tmp.= "I";
600       }
601       $tmp= "[$tmp]";
603       if (chkacl ($this->acl, "gosaMailDeliveryMode") == ""){
604         if ($this->gosaMailDeliveryMode != $tmp){
605           $this->is_modified= TRUE;
606         }
607         $this->gosaMailDeliveryMode= $tmp;
608       }
609     }
610   }
613   /* Save data to LDAP, depending on is_account we save or delete */
614   function save()
615   {
616     $ldap= $this->config->get_ldap_link();
618     /* Call parents save to prepare $this->attrs */
619     plugin::save();
621     /* Save arrays */
622     $this->attrs['gosaMailAlternateAddress']= $this->gosaMailAlternateAddress;
623     $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
625     /* Adapt attributes if needed */
626     $method= new $this->method($this->config);
627     $id= $method->uattrib;
628     $method->fixAttributesOnStore($this);
630     /* Save data to LDAP */
631     $ldap->cd($this->dn);
632     $ldap->modify($this->attrs);
633     show_ldap_error($ldap->get_error());
635     /* Only do IMAP actions if we are not a template */
636     if (!$this->is_template){
637       if ($method->connect($this->gosaMailServer)){
638         $method->updateMailbox($this->folder_prefix.$this->$id);
639         $method->setQuota($this->folder_prefix.$this->$id, $this->gosaMailQuota);
640         $method->disconnect();
642         /* Write sieve information only if not in C mode */
643         if (!is_integer(strpos($this->gosaMailDeliveryMode, "C"))){
644           $method->configureFilter($this->$id,
645               $this->gosaMailDeliveryMode,
646               $this->mail,
647               $this->gosaMailAlternateAddress,
648               $this->gosaMailMaxSize,
649               $this->gosaSpamMailbox,
650               $this->gosaSpamSortLevel,
651               $this->gosaVacationMessage);
652         }
653       }
654     }
656     /* Optionally execute a command after we're done */
657     if ($this->initially_was_account == $this->is_account){
658       if ($this->is_modified){
659         $this->handle_post_events("mofify");
660       }
661     } else {
662       $this->handle_post_events("add");
663     }
665   }
667   /* Check formular input */
668   function check()
669   {
670     $ldap= $this->config->get_ldap_link();
672     $message= array();
674     if(empty($this->gosaMailServer)){
675       $message[]= _("There is no valid mailserver specified, please add one in the system setup.");
676     }
678     /* must: mail */
679     if ($this->mail == ""){
680       $message[]= _("The required field 'Primary address' is not set.");
681     }
682     if ($this->is_template){
683       if (!is_email($this->mail, TRUE)){
684         $message[]= _("Please enter a valid email address in 'Primary address' field.");
685       }
686     } else {
687       if (!is_email($this->mail)){
688         $message[]= _("Please enter a valid email address in 'Primary address' field.");
689       }
690     }
691     $ldap->cd($this->config->current['BASE']);
692     $ldap->search ("(&(!(objectClass=gosaUserTemplate))(|(mail=".$this->mail.")(gosaMailAlternateAddress=".
693         $this->mail."))(!(uid=".$this->uid."))(!(cn=".$this->uid.")))", array("uid"));
694     if ($ldap->count() != 0){
695       $message[]= _("The primary address you've entered is already in use.");
696     }
698     /* Check quota */
699     if ($this->gosaMailQuota != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
700       if (!is_numeric($this->gosaMailQuota)) {
701         $message[]= _("Value in 'Quota size' is not valid.");
702       } else {
703         $this->gosaMailQuota= (int) $this->gosaMailQuota;
704       }
705     }
707     /* Check rejectsize for integer */
708     if ($this->gosaMailMaxSize != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
709       if (!is_numeric($this->gosaMailMaxSize)){
710         $message[]= _("Please specify a vaild mail size for mails to be rejected.");
711       } else {
712         $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
713       }
714     }
716     /* Need gosaMailMaxSize if use_mailsize_limit is checked */
717     if (is_integer(strpos($this->gosaMailDeliveryMode, "R")) && 
718         $this->gosaMailMaxSize == ""){
720       $message[]= _("You need to set the maximum mail size in order to reject anything.");
721     }
723     return ($message);
724   }
726   /* Adapt from template, using 'dn' */
727   function adapt_from_template($dn)
728   {
729     plugin::adapt_from_template($dn);
731     foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
732       $this->$val= array();
733       if (isset($this->attrs["$val"]["count"])){
734         for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
735           $value= $this->attrs["$val"][$i];
736           foreach (array("sn", "givenName", "uid") as $repl){
737             if (preg_match("/%$repl/i", $value)){
738               $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
739             }
740           }
741           array_push($this->$val, strtolower(rewrite($value)));
742         }
743       }
744     }
745     $this->mail= strtolower(rewrite($this->mail));
746   }
748   /* Add entry to forwarder list */
749   function addForwarder($address)
750   {
751     $this->gosaMailForwardingAddress[]= $address;
752     $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
754     sort ($this->gosaMailForwardingAddress);
755     reset ($this->gosaMailForwardingAddress);
756     $this->is_modified= TRUE;
757   }
759   /* Remove list of addresses from forwarder list */
760   function delForwarder($addresses)
761   {
762     $this->gosaMailForwardingAddress= array_remove_entries ($addresses, $this->gosaMailForwardingAddress);
763     $this->is_modified= TRUE;
764   }
768   function addAlternate($address)
769   {
770     $ldap= $this->config->get_ldap_link();
772     $address= strtolower($address);
774     /* Is this address already assigned in LDAP? */
775     $ldap->cd ($this->config->current['BASE']);
776     $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)".
777         "(gosaMailAlternateAddress=$address)))", array("uid"));
779     if ($ldap->count() > 0){
780       $attrs= $ldap->fetch ();
781       return ($attrs["uid"][0]);
782     }
784     /* Add to list of alternates */
785     if (!in_array($address, $this->gosaMailAlternateAddress)){
786       $this->gosaMailAlternateAddress[]= $address;
787       $this->is_modified= TRUE;
788     }
790     sort ($this->gosaMailAlternateAddress);
791     reset ($this->gosaMailAlternateAddress);
793     return ("");
794   }
797   function delAlternate($addresses)
798   {
799     $this->gosaMailAlternateAddress= array_remove_entries ($addresses,
800                                                            $this->gosaMailAlternateAddress);
801     $this->is_modified= TRUE;
802   }
804   function make_name($attrs)
805   {
806     $name= "";
807     if (isset($attrs['sn'][0])){
808       $name= $attrs['sn'][0];
809     }
810     if (isset($attrs['givenName'][0])){
811       if ($name != ""){
812         $name.= ", ".$attrs['givenName'][0];
813       } else {
814         $name.= $attrs['givenName'][0];
815       }
816     }
817     if ($name != ""){
818       $name.= " ";
819     }
821     return ($name);
822   }
826 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
827 ?>