1 <?php
2 /*!
3 \brief mail plugin
4 \author Fabian Hicker <Fabian.Hickert@GONICUS.de>
5 \version 2.6.2
6 \date 03.12.2007
8 This class provides the functionality to read and write all attributes
9 relevant for gosaMailAccounts from/to the LDAP.
10 It does syntax checking and displays the formulars required.
11 Special handling like sieve or imap actions will be implemented
12 by the mailMethods.
15 Functions :
17 - mailAccount (&$config, $dn= NULL)
18 - execute()
19 - save_object()
20 - get_vacation_templates()
21 - addForwarder($address)
22 - delForwarder($addresses)
23 - addAlternate($address)
24 - delAlternate($addresses)
25 - prepare_vacation_template($contents)
26 - remove_from_parent()
27 - save()
28 - check()
29 - adapt_from_template($dn, $skip= array())
30 - getCopyDialog()
31 - saveCopyDialog()
32 - PrepareForCopyPaste($source)
33 - get_multi_edit_values()
34 - multiple_check()
35 - set_multi_edit_values($values)
36 - init_multiple_support($attrs,$all)
37 - get_multi_init_values()
38 - multiple_execute()
39 - multiple_save_object()
40 - make_name($attrs)
41 - plInfo()
44 */
46 class mailAccount extends plugin
47 {
48 /* Definitions */
49 var $plHeadline = "Mail";
50 var $plDescription = "This does something";
51 var $view_logged = FALSE;
52 var $is_account = FALSE;
53 var $initially_was_account = FALSE;
55 /* GOsa mail attributes */
56 var $mail = "";
57 var $gosaVacationStart = "";
58 var $gosaVacationStop = "";
59 var $gosaMailAlternateAddress = array();
60 var $gosaMailForwardingAddress = array();
61 var $gosaMailDeliveryMode = "[L ]";
62 var $gosaMailServer = "";
63 var $gosaMailQuota = "";
64 var $gosaMailMaxSize = "";
65 var $gosaVacationMessage = "";
66 var $gosaSpamSortLevel = "";
67 var $gosaSpamMailbox = "";
69 /* The methods defaults */
70 var $quotaUsage = -1; // Means unknown
72 var $mailMethod = NULL;
73 var $MailDomain = "";
74 var $sieveManagementUsed = FALSE;
75 var $vacationTemplates = array();
76 var $sieve_management = NULL;
77 var $mailAddressSelect = FALSE;
78 var $initial_uid = "";
79 var $mailDomainPart = "";
80 var $mailDomainParts = array();
81 var $MailBoxes = array("INBOX");
83 /* Used LDAP attributes && classes */
84 var $attributes= array(
85 "mail", "gosaMailServer","gosaMailQuota", "gosaMailMaxSize","gosaMailForwardingAddress",
86 "gosaMailDeliveryMode", "gosaSpamSortLevel", "gosaSpamMailbox","gosaMailAlternateAddress",
87 "gosaVacationStart","gosaVacationStop", "gosaVacationMessage", "gosaMailAlternateAddress",
88 "gosaMailForwardingAddress");
89 var $objectclasses= array("gosaMailAccount");
91 var $multiple_support = TRUE;
93 var $uid = "";
94 var $cn = "";
97 /*! \brief Initialize the mailAccount
98 */
99 function __construct (&$config, $dn= NULL)
100 {
101 plugin::plugin($config,$dn);
103 /* Get attributes from parent object
104 */
105 foreach(array("uid","cn") as $attr){
106 if(isset($this->parent->by_object['group']) && isset($this->parent->by_object['group']->$attr)){
107 $this->$attr = &$this->parent->by_object['group']->$attr;
108 }elseif(isset($this->attrs[$attr])){
109 $this->$attr = $this->attrs[$attr][0];
110 }
111 }
113 /* Intialize the used mailMethod
114 */
115 $tmp = new mailMethod($config,$this);
116 $this->mailMethod = $tmp->get_method();
117 $this->mailMethod->fixAttributesOnLoad();
118 $this->mailDomainParts = $this->mailMethod->getMailDomains();
119 $this->SpamLevels = $this->mailMethod->getSpamLevels();
121 /* Remember account status
122 */
123 $this->initially_was_account = $this->is_account;
125 /* Initialize vacation settings, if enabled.
126 */
127 if(empty($this->gosaVacationStart) && $this->mailMethod->vacationRangeEnabled()){
128 $this->gosaVacationStart = time();
129 $this->gosaVacationStop = time();
130 }
132 /* Read vacation templates
133 */
134 $this->vacationTemplates = $this->get_vacation_templates();
136 /* Initialize configured values
137 */
138 if($this->is_account){
140 if($this->mailMethod->connect() && $this->mailMethod->account_exists()){
142 /* Read quota */
143 $this->gosaMailQuota = $this->mailMethod->getQuota($this->gosaMailQuota);
144 $this->quotaUsage = $this->mailMethod->getQuotaUsage($this->quotaUsage);
145 if($this->mailMethod->is_error()){
146 msg_dialog::display(_("Mail error"), sprintf(_("Cannot read quota settings: %s"),
147 $this->mailMethod->get_error()), ERROR_DIALOG);
148 }
150 /* Read mailboxes */
151 $this->MailBoxes = $this->mailMethod->getMailboxList($this->MailBoxes);
152 if($this->mailMethod->is_error()){
153 msg_dialog::display(_("Mail error"), sprintf(_("Cannot get list of mailboxes: %s"),
154 $this->mailMethod->get_error()), ERROR_DIALOG);
155 }
157 }elseif(!$this->mailMethod->is_connected()){
158 msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"),
159 $this->mailMethod->get_error()), ERROR_DIALOG);
160 }elseif(!$this->mailMethod->account_exists()){
161 msg_dialog::display(_("Mail error"), sprintf(_("Mailbox '%s' doesn't exists on mail server: %s"),
162 $this->mailMethod->get_account_id(),$this->gosaMailServer), ERROR_DIALOG);
163 }
165 /* If the doamin part is selectable, we have to split the mail address
166 */
167 if(!(!$this->mailMethod->isModifyableMail() && $this->is_account)){
168 if($this->mailMethod->domainSelectionEnabled()){
169 $this->mailDomainPart = preg_replace("/^[^@]*+@/","",$this->mail);
170 $this->mail = preg_replace("/@.*$/","\\1",$this->mail);
171 if(!in_array($this->mailDomainPart,$this->mailDomainParts)){
172 $this->mailDomainParts[] = $this->mailDomainPart;
173 }
174 }
175 }
177 /* Load attributes containing arrays */
178 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
179 $this->$val= array();
180 if (isset($this->attrs["$val"]["count"])){
181 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
182 array_push($this->$val, $this->attrs["$val"][$i]);
183 }
184 }
185 }
186 }
188 /* Intialize sieveManagement if necessary */
189 if($this->mailMethod->allowSieveManagement()){
190 $this->mailboxList = &$this->MailBoxes;
191 $this->sieve_management = new sieveManagement($this->config,$this->dn,$this,$this->mailMethod->getUAttrib());
192 }
194 /* Disconnect mailMethod. Connect on demand later.
195 */
196 $this->mailMethod->disconnect();
198 /* Convert start/stop dates */
199 #TODO: use date format
200 $this->gosaVacationStart= date('d.m.Y', $this->gosaVacationStart);
201 $this->gosaVacationStop= date('d.m.Y', $this->gosaVacationStop);
202 }
205 function execute()
206 {
208 /* Call parent execute */
209 $display = plugin::execute();
211 /* Log view */
212 if($this->is_account && !$this->view_logged){
213 $this->view_logged = TRUE;
214 new log("view","users/".get_class($this),$this->dn);
215 }
218 /****************
219 Account status
220 ****************/
222 if(isset($_POST['modify_state'])){
223 if($this->is_account && $this->acl_is_removeable() && $this->mailMethod->accountRemoveAble()){
224 $this->is_account= FALSE;
225 }elseif(!$this->is_account && $this->acl_is_createable() && $this->mailMethod->accountCreateable()){
226 $this->is_account= TRUE;
227 }
228 }
229 if(!$this->multiple_support_active){
230 if (!$this->is_account && $this->parent === NULL){
231 $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\"> <b>".
232 msgPool::noValidExtension(_("Mail"))."</b>";
233 $display.= back_to_main();
234 return ($display);
235 }
236 if ($this->parent !== NULL){
237 if ($this->is_account){
238 $reason = "";
239 if(!$this->mailMethod->accountRemoveable($reason)){
240 $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Mail")),$reason ,TRUE,TRUE);
241 }else{
242 $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Mail")),msgPool::featuresEnabled(_("Mail")));
243 }
244 } else {
245 $reason = "";
246 if(!$this->mailMethod->accountCreateable($reason)){
247 $display= $this->show_disable_header(msgPool::addFeaturesButton(_("Mail")),$reason ,TRUE,TRUE);
248 }else{
249 $display= $this->show_disable_header(msgPool::addFeaturesButton(_("Mail")),msgPool::featuresDisabled(_("Mail")));
250 }
251 return ($display);
252 }
253 }
254 }
256 /****************
257 Sieve Management Dialog
258 ****************/
259 if($this->mailMethod->allowSieveManagement()){
260 if(isset($_POST['sieveManagement'])
261 && preg_match("/C/",$this->gosaMailDeliveryMode)
262 && $this->acl_is_writeable("sieveManagement")
263 && $this->mailMethod->allowSieveManagement()) {
264 $this->dialog = $this->sieve_management;
265 }
266 if(isset($_POST['sieve_cancel'])){
267 $this->dialog = FALSE;
268 }
269 if(isset($_POST['sieve_finish'])){
270 $this->sieve_management = $this->dialog;
271 $this->dialog = FALSE;
272 }
273 if(is_object($this->dialog)){
274 $this->dialog->save_object();
275 return($this->dialog->execute());
276 }
277 }
279 /****************
280 Forward addresses
281 ****************/
283 if (isset($_POST['add_local_forwarder'])){
284 $this->mailAddressSelect= new mailAddressSelect($this->config, get_userinfo());
285 $this->dialog= TRUE;
286 }
287 if (isset($_POST['mailAddressSelect_cancel'])){
288 $this->mailAddressSelect= FALSE;
289 $this->dialog= FALSE;
290 }
292 if (isset($_POST['mailAddressSelect_save']) && $this->mailAddressSelect instanceOf mailAddressSelect){
294 if($this->acl_is_writeable("gosaMailForwardingAddress")){
295 $list = $this->mailAddressSelect->save();
296 foreach ($list as $entry){
297 $val = $entry['mail'][0];
298 if (!in_array ($val, $this->gosaMailAlternateAddress) && $val != $this->mail){
299 $this->addForwarder($val);
300 $this->is_modified= TRUE;
301 }
302 }
303 $this->mailAddressSelect= FALSE;
304 $this->dialog= FALSE;
305 } else {
306 msg_dialog::display(_("Error"), _("Please select an entry!"), ERROR_DIALOG);
307 }
308 }
310 if($this->mailAddressSelect instanceOf mailAddressSelect){
311 $used = array();
312 $used['mail'] = array_values($this->gosaMailAlternateAddress);
313 $used['mail'] = array_merge($used['mail'], array_values($this->gosaMailForwardingAddress));
314 $used['mail'][] = $this->mail;
316 // Build up blocklist
317 session::set('filterBlacklist', $used);
318 return($this->mailAddressSelect->execute());
319 }
321 if (isset($_POST['add_forwarder'])){
322 if ($_POST['forward_address'] != ""){
323 $address= $_POST['forward_address'];
324 $valid= FALSE;
325 if (!tests::is_email($address)){
326 if (!tests::is_email($address, TRUE)){
327 if ($this->is_template){
328 $valid= TRUE;
329 } else {
330 msg_dialog::display(_("Error"), msgPool::invalid(_("Mail address"),
331 "","","your-address@your-domain.com"),ERROR_DIALOG);
332 }
333 }
334 } elseif ($address == $this->mail
335 || in_array($address, $this->gosaMailAlternateAddress)) {
336 msg_dialog::display(_("Error"),_("Cannot add primary address to the list of forwarders!") , ERROR_DIALOG);
337 } else {
338 $valid= TRUE;
339 }
340 if ($valid){
341 if($this->acl_is_writeable("gosaMailForwardingAddress")){
342 $this->addForwarder ($address);
343 $this->is_modified= TRUE;
344 }
345 }
346 }
347 }
348 if (isset($_POST['delete_forwarder'])){
349 $this->delForwarder ($_POST['forwarder_list']);
350 }
351 if ($this->mailAddressSelect instanceOf mailAddressSelect){
353 return($this->mailAddressSelect->execute());
354 }
357 /****************
358 Alternate addresses
359 ****************/
361 if (isset($_POST['add_alternate'])){
362 $valid= FALSE;
363 if (!tests::is_email($_POST['alternate_address'])){
364 if ($this->is_template){
365 if (!(tests::is_email($_POST['alternate_address'], TRUE))){
366 msg_dialog::display(_("Error"),msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com"),ERROR_DIALOG);
367 } else {
368 $valid= TRUE;
369 }
370 } else {
371 msg_dialog::display(_("Error"),msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com"),ERROR_DIALOG);
372 }
373 } else {
374 $valid= TRUE;
375 }
376 if ($valid && ($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
377 $ui= get_userinfo();
378 $addon= "";
379 if ($user[0] == "!") {
380 $addon= sprintf(_("Address is already in use by group '%s'."), mb_substr($user, 1));
381 } else {
382 $addon= sprintf(_("Address is already in use by user '%s'."), $user);
383 }
384 msg_dialog::display(_("Error"), msgPool::duplicated(_("Mail address"))."<br><br><i>".
385 "$addon</i>", ERROR_DIALOG);
386 }
387 }
388 if (isset($_POST['delete_alternate']) && isset($_POST['alternates_list'])){
389 $this->delAlternate ($_POST['alternates_list']);
390 }
392 /****************
393 SMARTY- Assign smarty variables
394 ****************/
395 $smarty = get_smarty();
396 $smarty->assign("usePrototype", "true");
397 $smarty->assign("initially_was_account", $this->initially_was_account);
398 $smarty->assign("isModifyableMail" , $this->mailMethod->isModifyableMail());
399 $smarty->assign("isModifyableServer", $this->mailMethod->isModifyableServer());
400 $smarty->assign("mailEqualsCN", $this->mailMethod->mailEqualsCN());
402 $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
403 $tmp = $this->plInfo();
404 foreach($tmp['plProvidedAcls'] as $name => $transl){
405 $smarty->assign("$name"."ACL", $this->getacl($name,$SkipWrite));
406 }
407 foreach($this->attributes as $attr){
408 $smarty->assign($attr,$this->$attr);
409 }
410 $smarty->assign("quotaEnabled", $this->mailMethod->quotaEnabled());
411 if($this->mailMethod->quotaEnabled()){
412 $smarty->assign("quotaUsage", mailMethod::quota_to_image($this->quotaUsage,$this->gosaMailQuota));
413 $smarty->assign("gosaMailQuota",$this->gosaMailQuota);
414 }
415 $smarty->assign("domainSelectionEnabled", $this->mailMethod->domainSelectionEnabled());
416 $smarty->assign("MailDomains", $this->mailDomainParts);
417 $smarty->assign("MailDomain" , $this->mailDomainPart);
418 $smarty->assign("MailServers", $this->mailMethod->getMailServers());
419 $smarty->assign("allowSieveManagement", $this->mailMethod->allowSieveManagement());
420 $smarty->assign("own_script", $this->sieveManagementUsed);
422 /* _Multiple users vars_ */
423 foreach($this->attributes as $attr){
424 $u_attr = "use_".$attr;
425 $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
426 }
427 foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
428 $u_attr = "use_".$attr;
429 $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
430 }
433 /****************
434 SMARTY- Assign flags
435 ****************/
437 $types = array(
438 "V"=>"use_vacation",
439 "S"=>"use_spam_filter",
440 "R"=>"use_mailsize_limit",
441 "I"=>"drop_own_mails",
442 "C"=>"own_script");
443 foreach($types as $option => $varname){
444 if (preg_match("/".$option."/", $this->gosaMailDeliveryMode)) {
445 $smarty->assign($varname, "checked");
446 } else {
447 $smarty->assign($varname, "");
448 }
449 }
450 if (!preg_match("/L/", $this->gosaMailDeliveryMode)) {
451 $smarty->assign("only_local", "checked");
452 } else {
453 $smarty->assign("only_local", "");
454 }
457 /****************
458 Smarty- Vacation settings
459 ****************/
460 $smarty->assign("rangeEnabled", FALSE);
461 $smarty->assign("template", "");
462 if (count($this->vacationTemplates)){
463 $smarty->assign("show_templates", "true");
464 $smarty->assign("vacationtemplates", $this->vacationTemplates);
465 if (isset($_POST['vacation_template'])){
466 $smarty->assign("template", $_POST['vacation_template']);
467 }
468 } else {
469 $smarty->assign("show_templates", "false");
470 }
472 /* Vacation range assigments
473 */
474 if($this->mailMethod->vacationRangeEnabled()){
475 $smarty->assign("rangeEnabled", TRUE);
476 }
478 /* fill filter settings
479 */
480 $smarty->assign("spamlevel", $this->SpamLevels);
481 $smarty->assign("spambox" , $this->MailBoxes);
483 $smarty->assign("multiple_support",$this->multiple_support_active);
484 return($display.$smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
485 }
489 /* Save data to object */
490 function save_object()
491 {
492 if (isset($_POST['mailTab'])){
494 /* Save ldap attributes */
495 $mail = $this->mail;
496 $server = $this->gosaMailServer;
497 plugin::save_object();
499 if(!$this->mailMethod->isModifyableServer() && $this->initially_was_account){
500 $this->gosaMailServer = $server;
501 }
503 if(!$this->mailMethod->isModifyableMail() && $this->initially_was_account){
504 $this->mail = $mail;
505 }else{
507 /* Get posted mail domain part, if necessary
508 */
509 if($this->mailMethod->domainSelectionEnabled() && isset($_POST['MailDomain'])){
510 if(in_array(get_post('MailDomain'), $this->mailDomainParts)){
511 $this->mailDomainPart = get_post('MailDomain');
512 }
513 }
514 }
516 /* Import vacation message?
517 */
518 if (isset($_POST["import_vacation"]) && isset($this->vacationTemplates[$_POST["vacation_template"]])){
519 if($this->multiple_support_active){
520 $contents = ltrim(preg_replace("/^DESC:.*$/m","",file_get_contents($_POST["vacation_template"])));
521 }else{
522 $contents = $this->prepare_vacation_template(file_get_contents($_POST["vacation_template"]));
523 }
524 $this->gosaVacationMessage= htmlspecialchars($contents);
525 }
527 /* Handle flags
528 */
529 if(isset($_POST['own_script'])){
530 if(!preg_match("/C/",$this->gosaMailDeliveryMode)){
531 $str= preg_replace("/[\[\]]/","",$this->gosaMailDeliveryMode);
532 $this->gosaMailDeliveryMode = "[".$str."C]";
533 }
534 }else{
536 /* Assemble mail delivery mode
537 The mode field in ldap consists of values between braces, this must
538 be called when 'mail' is set, because checkboxes may not be set when
539 we're in some other dialog.
541 Example for gosaMailDeliveryMode [LR ]
542 L - Local delivery
543 R - Reject when exceeding mailsize limit
544 S - Use spam filter
545 V - Use vacation message
546 C - Use custm sieve script
547 I - Only insider delivery */
549 $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
552 /* Handle delivery flags */
553 if($this->acl_is_writeable("gosaMailDeliveryModeL")){
554 if(!preg_match("/L/",$tmp) && !isset($_POST['only_local'])){
555 $tmp.="L";
556 }elseif(preg_match("/L/",$tmp) && isset($_POST['only_local'])){
557 $tmp = preg_replace("/L/","",$tmp);
558 }
559 }
560 $opts = array(
561 "R" => "use_mailsize_limit",
562 "S" => "use_spam_filter",
563 "V" => "use_vacation",
564 "C" => "own_script",
565 "I" => "drop_own_mails");
567 foreach($opts as $flag => $post){
568 if($this->acl_is_writeable("gosaMailDeliveryMode".$flag)){
569 if(!preg_match("/".$flag."/",$tmp) && isset($_POST[$post])){
570 $tmp.= $flag;
571 }elseif(preg_match("/".$flag."/",$tmp) && !isset($_POST[$post])){
572 $tmp = preg_replace("/".$flag."/","",$tmp);
573 }
574 }
575 }
577 $tmp= "[$tmp]";
578 if ($this->gosaMailDeliveryMode != $tmp){
579 $this->is_modified= TRUE;
580 }
581 $this->gosaMailDeliveryMode= $tmp;
583 /* Get start/stop values for vacation scope of application
584 */
585 if($this->mailMethod->vacationRangeEnabled()){
586 if($this->acl_is_writeable("gosaVacationMessage") && preg_match("/V/",$this->gosaMailDeliveryMode)){
587 if(isset($_POST['gosaVacationStart'])){
588 $this->gosaVacationStart = $_POST['gosaVacationStart'];
589 }
590 if(isset($_POST['gosaVacationStop'])){
591 $this->gosaVacationStop = $_POST['gosaVacationStop'];
592 }
593 }
594 }
595 }
596 }
597 }
600 /*! \brief Parse vacation templates and build up an array
601 containing 'filename' => 'description'.
602 Used to fill vacation dropdown box.
603 @return Array All useable vacation templates.
604 */
605 function get_vacation_templates()
606 {
607 $vct = array();
608 if ($this->config->get_cfg_value("vacationTemplateDirectory") != ""){
609 $dir= $this->config->get_cfg_value("vacationTemplateDirectory");
610 if (is_dir($dir) && is_readable($dir)){
611 $dh = opendir($dir);
612 while($file = readdir($dh)){
613 $description= "";
614 if (is_file($dir."/".$file)){
615 $fh = fopen($dir."/".$file, "r");
616 $line= fgets($fh, 256);
617 if (!preg_match('/^DESC:/', $line)){
618 msg_dialog::display(_("Configuration error"), sprintf(_("No DESC tag in vacation template '%s'!"), $file), ERROR_DIALOG);
619 }else{
620 $description= trim(preg_replace('/^DESC:\s*/', '', $line));
621 }
622 fclose ($fh);
623 }
624 if ($description != ""){
625 $vct["$dir/$file"]= $description;
626 }
627 }
628 closedir($dh);
629 }
630 }
631 return($vct);
632 }
635 /*! \brief Adds the given mail address to the list of mail forwarders
636 */
637 function addForwarder($address)
638 {
639 if(empty($address)) return;
640 if($this->acl_is_writeable("gosaMailForwardingAddress")){
641 $this->gosaMailForwardingAddress[]= $address;
642 $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
643 sort ($this->gosaMailForwardingAddress);
644 reset ($this->gosaMailForwardingAddress);
645 $this->is_modified= TRUE;
646 }else{
647 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
648 }
649 }
652 /*! \brief Removes the given mail address from the list of mail forwarders
653 */
654 function delForwarder($addresses)
655 {
656 if($this->acl_is_writeable("gosaMailForwardingAddress")){
657 $this->gosaMailForwardingAddress= array_remove_entries ($addresses, $this->gosaMailForwardingAddress);
658 $this->is_modified= TRUE;
659 }else{
660 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
661 }
662 }
665 /*! \brief Add given mail address to the list of alternate adresses ,
666 . check if this mal address is used, skip adding in this case
667 */
668 function addAlternate($address)
669 {
670 if(empty($address)) return;
671 if($this->acl_is_writeable("gosaMailAlternateAddress")){
672 $ldap= $this->config->get_ldap_link();
673 $address= strtolower($address);
675 /* Is this address already assigned in LDAP? */
676 $ldap->cd ($this->config->current['BASE']);
677 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=$address)".
678 "(alias=$address)(gosaMailAlternateAddress=$address)))", array("uid", "cn"));
679 if ($ldap->count() > 0){
680 $attrs= $ldap->fetch ();
681 if (!isset($attrs["uid"])) {
682 return ("!".$attrs["cn"][0]);
683 }
684 return ($attrs["uid"][0]);
685 }
686 if (!in_array($address, $this->gosaMailAlternateAddress)){
687 $this->gosaMailAlternateAddress[]= $address;
688 $this->is_modified= TRUE;
689 }
690 sort ($this->gosaMailAlternateAddress);
691 reset ($this->gosaMailAlternateAddress);
692 return ("");
693 }else{
694 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
695 }
696 }
699 /*! \brief Removes the given mail address from the alternate addresses list
700 */
701 function delAlternate($addresses)
702 {
703 if($this->acl_is_writeable("gosaMailAlternateAddress")){
704 $this->gosaMailAlternateAddress= array_remove_entries ($addresses,$this->gosaMailAlternateAddress);
705 $this->is_modified= TRUE;
706 }else{
707 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
708 }
709 }
712 /*! \brief Prepare importet vacation string. \
713 . Replace placeholder like %givenName a.s.o.
714 @param string Vacation string
715 @return string Completed vacation string
716 */
717 private function prepare_vacation_template($contents)
718 {
719 /* Replace attributes */
720 $attrs = array();
721 $obj = NULL;
722 if(isset($this->parent->by_object['user'])){
723 $attrs = $this->parent->by_object['user']->attributes;
724 $obj = $this->parent->by_object['user'];
725 }else{
726 $obj = new user($this->config,$this->dn);
727 $attrs = $obj->attributes;
728 }
729 if($obj){
731 /* Replace vacation start and end time */
732 if($this->mailMethod->vacationRangeEnabled()){
733 if(preg_match("/%start/",$contents)){
734 $contents = preg_replace("/%start/",$this->gosaVacationStart,$contents);
735 }
736 if(preg_match("/%end/",$contents)){
737 $contents = preg_replace("/%end/",$this->gosaVacationStop,$contents);
738 }
739 }else{
740 if(preg_match("/%start/",$contents)){
741 $contents = preg_replace("/%start/", _("unknown"),$contents);
742 }
743 if(preg_match("/%end/",$contents)){
744 $contents = preg_replace("/%end/", _("unknown"), $contents);
745 }
746 }
748 foreach ($attrs as $val){
749 if(preg_match("/dateOfBirth/",$val)){
750 if($obj->use_dob){
751 $contents= preg_replace("/%$val/",date("Y-d-m",$obj->dateOfBirth),$contents);
752 }
753 }else {
754 $contents= preg_replace("/%$val/",
755 $obj->$val, $contents);
756 }
758 }
759 }
760 $contents = ltrim(preg_replace("/^DESC:.*$/m","",$contents),"\n ");
761 return($contents);
762 }
765 /*! \brief Removes the mailAccount extension from ldap
766 */
767 function remove_from_parent()
768 {
769 /* Cancel if there's nothing to do here */
770 if (!$this->initially_was_account){
771 return;
772 }
774 /* If domain part was selectable, contruct mail address */
775 if($this->mailMethod->domainSelectionEnabled()){
776 $this->mail = $this->mail."@".$this->mailDomainPart;
777 }
779 /* Update sharedFolder dependencies.
780 Open each shared folder and remove this account.
781 Then Save the group to ensure that all necessary
782 actions will be taken (imap acls updated aso.).
783 */
784 $ldap = $this->config->get_ldap_link();
785 $ldap->cd($this->config->current['BASE']);
786 $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array("dn"));
787 while($attrs = $ldap->fetch()){
788 $grp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
789 if(isset($grp->by_object['mailgroup']) && isset($grp->by_object['group'])){
790 $grp->by_object['group']->removeUser($this->uid);
792 /* Do not save the complete group! This will quit the complete membership
793 */
794 $grp->by_object['mailgroup']->save();
795 }
796 }
798 /* Remove GOsa attributes */
799 plugin::remove_from_parent();
801 /* Zero arrays */
802 $this->attrs['gosaMailAlternateAddress'] = array();
803 $this->attrs['gosaMailForwardingAddress']= array();
806 $this->mailMethod->fixAttributesOnRemove();
807 $this->cleanup();
809 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
810 $ldap= $this->config->get_ldap_link();
811 $ldap->cd($this->dn);
812 $ldap->modify ($this->attrs);
814 /* Add "view" to logging class */
815 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
816 if (!$ldap->success()){
817 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
818 }
820 /* Let the mailMethod remove this mailbox, e.g. from imap and
821 update shared folder membership, ACL may need to be updated.
822 */
823 if (!$this->is_template){
825 if(!$this->mailMethod->connect()){
826 msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"),
827 $this->mailMethod->get_error()), ERROR_DIALOG);
828 }else{
829 if(!$this->mailMethod->deleteMailbox()){
830 msg_dialog::display(_("Mail error"), sprintf(_("Cannot remove mailbox: %s"),
831 $this->mailMethod->get_error()), ERROR_DIALOG);
832 }
833 }
834 }
835 $this->mailMethod->disconnect();
837 /* Optionally execute a command after we're done */
838 $this->handle_post_events("remove",array("uid" => $this->uid));
839 }
842 /*! \brief Save the mailAccount settings to the ldap database.
843 */
844 function save()
845 {
846 $ldap= $this->config->get_ldap_link();
848 /* If domain part was selectable, contruct mail address */
849 if(!(!$this->mailMethod->isModifyableMail() && $this->initially_was_account)){
851 if($this->mailMethod->domainSelectionEnabled()){
852 $this->mail = $this->mail."@".$this->mailDomainPart;
853 }
855 /* Enforce lowercase mail address and trim whitespaces
856 */
857 $this->mail = trim(strtolower($this->mail));
858 }
861 /* Call parents save to prepare $this->attrs */
862 plugin::save();
864 /* Save arrays */
865 $this->attrs['gosaMailAlternateAddress'] = $this->gosaMailAlternateAddress;
866 $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
868 if(!$this->mailMethod->vacationRangeEnabled()){
869 $this->attrs['gosaVacationStart'] = $this->attrs['gosaVacationStop'] = array();
870 }elseif (!preg_match('/V/', $this->gosaMailDeliveryMode)){
871 unset($this->attrs['gosaVacationStart']);
872 unset($this->attrs['gosaVacationStop']);
873 } else {
874 /* Adapt values to be timestamps */
875 list($day, $month, $year)= explode('.', $this->gosaVacationStart);
876 $this->attrs['gosaVacationStart']= mktime(0,0,0,$month, $day, $year);
877 list($day, $month, $year)= explode('.', $this->gosaVacationStop);
878 $this->attrs['gosaVacationStop']= mktime(0,0,0,$month, $day, $year);
879 }
881 /* Map method attributes */
882 $this->mailMethod->fixAttributesOnStore();
884 /* Save data to LDAP */
885 $ldap->cd($this->dn);
886 $this->cleanup();
887 $ldap->modify ($this->attrs);
889 if (!$ldap->success()){
890 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
891 }
893 /* Log last action */
894 if($this->initially_was_account){
895 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
896 }else{
897 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
898 }
900 /* Only do IMAP actions if we are not a template */
901 if (!$this->is_template){
902 $this->mailMethod->connect();
903 if(!$this->mailMethod->is_connected()){
904 msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"),
905 $this->mailMethod->get_error()), ERROR_DIALOG);
906 }else{
907 if(!$this->mailMethod->updateMailbox()){
908 msg_dialog::display(_("Mail error"), sprintf(_("Cannot update mailbox: %s"),
909 $this->mailMethod->get_error()), ERROR_DIALOG);
910 }
911 if(!$this->mailMethod->setQuota($this->gosaMailQuota)){
912 msg_dialog::display(_("Mail error"), sprintf(_("Cannot write quota settings: %s"),
913 $this->mailMethod->get_error()), ERROR_DIALOG);
914 }
916 if (!is_integer(strpos($this->gosaMailDeliveryMode, "C"))){
918 /* Do not write sieve settings if this account is new and
919 doesn't seem to exist.
920 */
921 if(!$this->initially_was_account && !$this->mailMethod->account_exists()){
922 @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,
923 "Skipping sieve settings, the account doesn't seem to be created already.</b>","");
924 }else{
925 if(!$this->mailMethod->saveSieveSettings()){
926 msg_dialog::display(_("Mail error saving sieve settings"), $this->mailMethod->get_error(), ERROR_DIALOG);
927 }
928 }
929 }else{
930 if ($this->sieve_management) {
931 @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,
932 "User uses an own sieve script, skipping sieve update.".$str."</b>","");
933 $this->sieve_management->save();
934 }
935 }
936 }
937 }
938 $this->mailMethod->disconnect();
940 /* Update sharedFolder dependencies.
941 Open each shared folder and remove this account.
942 Then Save the group to ensure that all necessary
943 actions will be taken (imap acls updated aso.).
944 */
945 if(!$this->initially_was_account){
946 $ldap = $this->config->get_ldap_link();
947 $ldap->cd($this->config->current['BASE']);
948 $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array("dn"));
949 while($attrs = $ldap->fetch()){
950 $grp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
951 if(isset($grp->by_object['mailgroup'])){
952 /* Do not save the complete group! This will quit the complete membership
953 */
954 $grp->by_object['mailgroup']->save();
955 }
956 }
957 }
959 /* Optionally execute a command after we're done */
960 if ($this->initially_was_account == $this->is_account){
961 if ($this->is_modified){
962 $this->handle_post_events("modify", array("uid" => $this->uid));
963 }
964 } else {
965 $this->handle_post_events("add", array("uid" => $this->uid));
966 }
967 }
970 /*! \brief Check given values
971 */
972 function check()
973 {
974 if(!$this->is_account){
975 return(array());
976 }
978 $ldap= $this->config->get_ldap_link();
980 /* Call common method to give check the hook */
981 $message= plugin::check();
983 if(empty($this->gosaMailServer)){
984 $message[]= msgPool::noserver(_("Mail"));
985 }
987 /* Mail address checks */
988 $mail = $this->mail;
989 if(!(!$this->mailMethod->isModifyableMail() && $this->initially_was_account)){
991 if($this->mailMethod->domainSelectionEnabled()){
992 $mail.= "@".$this->mailDomainPart;
993 }
995 if (empty($mail)){
996 $message[]= msgPool::required(_("Primary address"));
997 }
998 if ($this->is_template){
999 if (!tests::is_email($mail, TRUE)){
1000 $message[]= msgPool::invalid(_("Mail address"),"","","%givenName.%sn@your-domain.com");
1001 }
1002 } else {
1003 if (!tests::is_email($mail)){
1004 $message[]= msgPool::invalid(_("Mail address"),"","","your-address@your-domain.com");
1005 }
1006 }
1008 /* Check if this mail address is already in use */
1009 $ldap->cd($this->config->current['BASE']);
1010 $filter = "(&(!(objectClass=gosaUserTemplate))(!(uid=".$this->uid."))".
1011 "(objectClass=gosaMailAccount)".
1012 "(|(mail=".$mail.")(alias=".$mail.")(gosaMailAlternateAddress=".$mail.")))";
1013 $ldap->search($filter,array("uid", "cn"));
1014 if ($ldap->count() != 0){
1015 $entry= $ldap->fetch();
1016 $addon= "";
1017 if (!isset($entry['uid'])) {
1018 $addon= sprintf(_("Address is already in use by group '%s'."), $entry['cn'][0]);
1019 } else {
1020 $addon= sprintf(_("Address is already in use by user '%s'."), $entry['uid'][0]);
1021 }
1022 $message[]= msgPool::duplicated(_("Mail address"))."<br><br><i>$addon</i>";
1023 }
1024 }
1027 /* Check quota */
1028 if ($this->gosaMailQuota != '' && $this->acl_is_writeable("gosaMailQuota")){
1029 if (!is_numeric($this->gosaMailQuota)) {
1030 $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
1031 } else {
1032 $this->gosaMailQuota= (int) $this->gosaMailQuota;
1033 }
1034 }
1036 /* Check rejectsize for integer */
1037 if ($this->gosaMailMaxSize != '' && $this->acl_is_writeable("gosaMailMaxSize")){
1038 if (!is_numeric($this->gosaMailMaxSize)){
1039 $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
1040 } else {
1041 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
1042 }
1043 }
1045 /* Need gosaMailMaxSize if use_mailsize_limit is checked */
1046 if (is_integer(strpos($this->gosaMailDeliveryMode, "R")) && $this->gosaMailMaxSize == ""){
1047 $message[]= msgPool::required(_("Mail reject size"));
1048 }
1050 if((preg_match("/S/", $this->gosaMailDeliveryMode))&&(empty($this->gosaSpamMailbox))) {
1051 $message[]= msgPool::required(_("Spam folder"));
1052 }
1054 if ($this->mailMethod->vacationRangeEnabled() && preg_match('/V/', $this->gosaMailDeliveryMode)){
1056 /* Check date strings */
1057 $state= true;
1058 if ($this->gosaVacationStart == "" || !tests::is_date($this->gosaVacationStart)) {
1059 $message[]= msgPool::invalid(_("from"),$this->gosaVacationStart);
1060 $state= false;
1061 }
1062 if ($this->gosaVacationStart == "" || !tests::is_date($this->gosaVacationStop)) {
1063 $message[]= msgPool::invalid(_("to"),$this->gosaVacationStop);
1064 $state= false;
1065 }
1067 #TODO: take care of date format
1068 if ($state) {
1069 list($day, $month, $year)= explode('.', $this->gosaVacationStart);
1070 $start= mktime(0,0,0,$month, $day, $year);
1071 list($day, $month, $year)= explode('.', $this->gosaVacationStop);
1072 $stop= mktime(0,0,0,$month, $day, $year);
1073 if($start > $stop){
1074 $message[]= msgPool::invalid(_("Vacation interval"));
1075 }
1076 }
1077 }
1078 return($message);
1079 }
1082 /*! \brief Adapt from template, using 'dn'
1083 */
1084 function adapt_from_template($dn, $skip= array())
1085 {
1086 plugin::adapt_from_template($dn, $skip);
1088 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
1090 if (in_array($val, $skip)){
1091 continue;
1092 }
1094 $this->$val= array();
1095 if (isset($this->attrs["$val"]["count"])){
1096 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
1097 $value= $this->attrs["$val"][$i];
1098 foreach (array("sn", "givenName", "uid") as $repl){
1099 if (preg_match("/%$repl/i", $value)){
1100 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
1101 }
1102 }
1103 array_push($this->$val, strtolower(rewrite($value)));
1104 }
1105 }
1106 }
1107 $this->mail= strtolower(rewrite($this->mail));
1109 // Fix mail address when using templates
1110 if($this->is_account && $this->mailMethod->domainSelectionEnabled()){
1111 $this->mailDomainPart = preg_replace("/^[^@]*+@/","",$this->mail);
1112 $this->mail = preg_replace("/@.*$/","\\1",$this->mail);
1113 if(!in_array($this->mailDomainPart,$this->mailDomainParts)){
1114 $this->mailDomainParts[] = $this->mailDomainPart;
1115 }
1116 }
1117 }
1120 /*! \brief Creates the mail part for the copy & paste dialog
1121 */
1122 function getCopyDialog()
1123 {
1124 if(!$this->is_account) return("");
1125 $smarty = get_smarty();
1126 $smarty->assign("mail",$this->mail);
1127 $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress);
1128 $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress);
1129 $str = $smarty->fetch(get_template_path("copypaste.tpl",TRUE, dirname(__FILE__)));
1131 $ret = array();
1132 $ret['status'] = "";
1133 $ret['string'] = $str;
1134 return($ret);
1135 }
1138 /*! \brief save_object for copy&paste vars
1139 */
1140 function saveCopyDialog()
1141 {
1142 if(!$this->is_account) return;
1144 /* Execute to save mailAlternateAddress && gosaMailForwardingAddress */
1145 $this->execute();
1146 if(isset($_POST['mail'])){
1147 $this->mail = $_POST['mail'];
1148 }
1149 }
1152 /*! \brief Prepare this account to be copied
1153 */
1154 function PrepareForCopyPaste($source)
1155 {
1156 plugin::PrepareForCopyPaste($source);
1158 /* Reset alternate mail addresses */
1159 $this->gosaMailAlternateAddress = array();
1160 }
1163 /*! \brief Prepare this class the be useable when editing multiple users at once
1164 */
1165 function get_multi_edit_values()
1166 {
1167 $ret = plugin::get_multi_edit_values();
1168 if(in_array("gosaMailQuota",$this->multi_boxes)){
1169 $ret['gosaMailQuota'] = $this->gosaMailQuota;
1170 }
1171 $flag_add = $flag_remove = array();
1172 $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1173 $opts = array(
1174 "R" => "use_mailsize_limit",
1175 "S" => "use_spam_filter",
1176 "L" => "only_local",
1177 "V" => "use_vacation",
1178 "C" => "own_script",
1179 "I" => "drop_own_mails");
1180 foreach($opts as $flag => $post){
1181 if(in_array($post, $this->multi_boxes)){
1182 if(preg_match("/".$flag."/",$tmp)){
1183 $flag_add[] = $flag;
1184 }else{
1185 $flag_remove[] = $flag;
1186 }
1187 }
1188 }
1189 $ret['flag_add'] = $flag_add;
1190 $ret['flag_remove'] = $flag_remove;
1192 if($this->mailMethod->vacationRangeEnabled()){
1193 if(in_array("V",$flag_add)){
1194 $ret['gosaVacationStart'] = $this->gosaVacationStart = $_POST['gosaVacationStart'];
1195 $ret['gosaVacationStop'] = $this->gosaVacationStop = $_POST['gosaVacationStop'];
1196 }
1197 }
1198 return($ret);
1199 }
1202 /*! \brief Check given input for multiple user edit
1203 */
1204 function multiple_check()
1205 {
1206 $message = plugin::multiple_check();
1208 if(empty($this->gosaMailServer) && in_array("gosaMailServer",$this->multi_boxes)){
1209 $message[]= msgPool::noserver(_("Mail"));
1210 }
1212 /* Check quota */
1213 if ($this->gosaMailQuota != '' && in_array("gosaMailQuota",$this->multi_boxes)){
1214 if (!is_numeric($this->gosaMailQuota)) {
1215 $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
1216 } else {
1217 $this->gosaMailQuota= (int) $this->gosaMailQuota;
1218 }
1219 }
1221 /* Check rejectsize for integer */
1222 if ($this->gosaMailMaxSize != '' && in_array("gosaMailMaxSize",$this->multi_boxes)){
1223 if (!is_numeric($this->gosaMailMaxSize)){
1224 $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
1225 } else {
1226 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
1227 }
1228 }
1230 if(empty($this->gosaSpamMailbox) && in_array("gosaSpamMailbox",$this->multi_boxes)){
1231 $message[]= msgPool::required(_("Spam folder"));
1232 }
1234 if ($this->mailMethod->vacationRangeEnabled() && preg_match('/V/', $this->gosaMailDeliveryMode)){
1236 /* Check date strings */
1237 $state= true;
1238 if ($this->gosaVacationStart == "" || !tests::is_date($this->gosaVacationStart)) {
1239 $message[]= msgPool::invalid(_("from"),$this->gosaVacationStart);
1240 $state= false;
1241 }
1242 if ($this->gosaVacationStart == "" || !tests::is_date($this->gosaVacationStop)) {
1243 $message[]= msgPool::invalid(_("to"),$this->gosaVacationStop);
1244 $state= false;
1245 }
1247 #TODO: take care of date format
1248 if ($state) {
1249 list($day, $month, $year)= explode('.', $this->gosaVacationStart);
1250 $start= mktime(0,0,0,$month, $day, $year);
1251 list($day, $month, $year)= explode('.', $this->gosaVacationStop);
1252 $stop= mktime(0,0,0,$month, $day, $year);
1253 if($start > $stop){
1254 $message[]= msgPool::invalid(_("Vacation interval"));
1255 }
1256 }
1257 }
1258 return($message);
1259 }
1262 /*! \brief ...
1263 */
1264 function set_multi_edit_values($values)
1265 {
1266 plugin::set_multi_edit_values($values);
1267 $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1268 if(isset($values['flag_add'])){
1269 foreach($values['flag_add'] as $flag){
1270 if(!preg_match("/".$flag."/",$tmp)){
1271 $tmp .= $flag;
1272 }
1273 }
1274 }
1275 if(isset($values['flag_remove'])){
1276 foreach($values['flag_remove'] as $flag){
1277 if(preg_match("/".$flag."/",$tmp)){
1278 $tmp = preg_replace("/".$flag."/","",$tmp);
1279 }
1280 }
1281 }
1282 $this->gosaMailDeliveryMode = "[".$tmp."]";
1284 /* Set vacation message and replace placeholder like %givenName
1285 */
1286 if(isset($values['gosaVacationMessage'])){
1287 $this->gosaVacationMessage = $this->prepare_vacation_template($values['gosaVacationMessage']);
1288 }
1289 }
1292 /*! \brief Initialize plugin to be used as multiple edit class.
1293 */
1294 function init_multiple_support($attrs,$all)
1295 {
1296 plugin::init_multiple_support($attrs,$all);
1297 if(isset($this->multi_attrs['gosaMailQuota'])){
1298 $this->gosaMailQuota = $this->multi_attrs['gosaMailQuota'];
1299 }
1300 }
1303 /*! \brief
1304 */
1305 function get_multi_init_values()
1306 {
1307 $attrs = plugin::get_multi_init_values();
1308 $attrs['gosaMailQuota'] = $this->gosaMailQuota;
1309 return($attrs);
1310 }
1313 /*! \brief Display multiple edit dialog
1314 */
1315 function multiple_execute()
1316 {
1317 return($this->execute());
1318 }
1321 /*! \brief Save posts from multiple edit dialog
1322 */
1323 function multiple_save_object()
1324 {
1325 plugin::multiple_save_object();
1327 $this->save_object();
1328 foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
1329 if(isset($_POST["use_".$attr])){
1330 $this->multi_boxes[] = $attr;
1331 }
1332 }
1333 }
1336 /*! \brief Creates the user names for the add_local_forward dialog
1337 */
1338 function make_name($attrs)
1339 {
1340 $name= "";
1341 if (isset($attrs['sn'][0])){
1342 $name= $attrs['sn'][0];
1343 }
1344 if (isset($attrs['givenName'][0])){
1345 if ($name != ""){
1346 $name.= ", ".$attrs['givenName'][0];
1347 } else {
1348 $name.= $attrs['givenName'][0];
1349 }
1350 }
1351 if ($name != ""){
1352 $name.= " ";
1353 }
1355 return ($name);
1356 }
1359 function allow_remove()
1360 {
1361 $resason = "";
1362 if(!$this->mailMethod->allow_remove($reason)){
1363 return($reason);
1364 }
1365 return("");
1366 }
1370 /*! \brief ACL settings
1371 */
1372 static function plInfo()
1373 {
1374 return (array(
1375 "plShortName" => _("Mail"),
1376 "plDescription" => _("Mail settings"),
1377 "plSelfModify" => TRUE,
1378 "plDepends" => array("user"), // This plugin depends on
1379 "plPriority" => 4, // Position in tabs
1380 "plSection" => array("personal" => _("My account")),
1381 "plCategory" => array("users"),
1382 "plOptions" => array(),
1384 "plProvidedAcls" => array(
1385 "mail" => _("Mail address"),
1386 "gosaMailServer" => _("Mail server"),
1387 "gosaMailQuota" => _("Quota size"),
1389 "gosaMailDeliveryModeV" => _("Add vacation information"), // This is flag of gosaMailDeliveryMode
1390 "gosaVacationMessage" => _("Vacation message"),
1392 "gosaMailDeliveryModeS" => _("Use spam filter"), // This is flag of gosaMailDeliveryMode
1393 "gosaSpamSortLevel" => _("Spam level"),
1394 "gosaSpamMailbox" => _("Spam mail box"),
1396 "sieveManagement" => _("Sieve management"),
1398 "gosaMailDeliveryModeR" => _("Reject due to mailsize"), // This is flag of gosaMailDeliveryMode
1399 "gosaMailMaxSize" => _("Mail max size"),
1401 "gosaMailForwardingAddress" => _("Forwarding address"),
1402 "gosaMailDeliveryModeL" => _("Local delivery"), // This is flag of gosaMailDeliveryMode
1403 "gosaMailDeliveryModeI" => _("No delivery to own mailbox "), // This is flag of gosaMailDeliveryMode
1404 "gosaMailAlternateAddress" => _("Mail alternative addresses"),
1406 "gosaMailForwardingAddress" => _("Forwarding address"),
1407 "gosaMailDeliveryModeC" => _("Use custom sieve script")) // This is flag of gosaMailDeliveryMode
1408 ));
1409 }
1412 }
1414 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1415 ?>