02eb27896ab02b1fd911786292cde060beb6ba71
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 - display_forward_dialog()
27 - remove_from_parent()
28 - save()
29 - check()
30 - adapt_from_template($dn, $skip= array())
31 - getCopyDialog()
32 - saveCopyDialog()
33 - PrepareForCopyPaste($source)
34 - get_multi_edit_values()
35 - multiple_check()
36 - set_multi_edit_values($values)
37 - init_multiple_support($attrs,$all)
38 - get_multi_init_values()
39 - multiple_execute()
40 - multiple_save_object()
41 - make_name($attrs)
42 - plInfo()
45 */
47 class mailAccount extends plugin
48 {
49 /* Definitions */
50 var $plHeadline = "Mail";
51 var $plDescription = "This does something";
52 var $view_logged = FALSE;
53 var $is_account = FALSE;
54 var $initially_was_account = FALSE;
56 /* GOsa mail attributes */
57 var $mail = "";
58 var $gosaVacationStart = 0;
59 var $gosaVacationStop = 0;
60 var $gosaMailAlternateAddress = array();
61 var $gosaMailForwardingAddress = array();
62 var $gosaMailDeliveryMode = "[L ]";
63 var $gosaMailServer = "";
64 var $gosaMailQuota = "";
65 var $gosaMailMaxSize = "";
66 var $gosaVacationMessage = "";
67 var $gosaSpamSortLevel = "";
68 var $gosaSpamMailbox = "";
70 /* The methods defaults */
71 var $quotaUsage = -1; // Means unknown
73 var $mailMethod = NULL;
74 var $MailDomain = "";
75 var $sieveManagementUsed = FALSE;
76 var $vacationTemplates = array();
77 var $sieve_management = NULL;
78 var $forward_dialog = FALSE;
79 var $initial_uid = "";
80 var $mailDomainPart = "";
81 var $mailDomainParts = array();
82 var $MailBoxes = array("INBOX");
84 /* Used LDAP attributes && classes */
85 var $attributes= array(
86 "mail", "gosaMailServer","gosaMailQuota", "gosaMailMaxSize","gosaMailForwardingAddress",
87 "gosaMailDeliveryMode", "gosaSpamSortLevel", "gosaSpamMailbox","gosaMailAlternateAddress",
88 "gosaVacationStart","gosaVacationStop", "gosaVacationMessage", "gosaMailAlternateAddress",
89 "gosaMailForwardingAddress");
90 var $objectclasses= array("gosaMailAccount");
92 var $multiple_support = TRUE;
94 var $uid = "";
95 var $cn = "";
98 /*! \brief Initialize the mailAccount
99 */
100 function __construct (&$config, $dn= NULL)
101 {
102 plugin::plugin($config,$dn);
104 /* Get attributes from parent object
105 */
106 foreach(array("uid","cn") as $attr){
107 if(isset($this->parent->by_object['group']) && isset($this->parent->by_object['group']->$attr)){
108 $this->$attr = &$this->parent->by_object['group']->$attr;
109 }elseif(isset($this->attrs[$attr])){
110 $this->$attr = $this->attrs[$attr][0];
111 }
112 }
114 /* Intialize the used mailMethod
115 */
116 $tmp = new mailMethod($config,$this);
117 $this->mailMethod = $tmp->get_method();
118 $this->mailMethod->fixAttributesOnLoad();
119 $this->mailDomainParts = $this->mailMethod->getMailDomains();
120 $this->SpamLevels = $this->mailMethod->getSpamLevels();
122 /* Remember account status
123 */
124 $this->initially_was_account = $this->is_account;
126 /* Initialize vacation settings, if enabled.
127 */
128 if(empty($this->gosaVacationStart) && $this->mailMethod->vacationRangeEnabled()){
129 $this->gosaVacationStart = time();
130 $this->gosaVacationStop = time();
131 }
133 /* Read vacation templates
134 */
135 $this->vacationTemplates = $this->get_vacation_templates();
137 /* Initialize configured values
138 */
139 if($this->is_account){
141 if($this->mailMethod->connect() && $this->mailMethod->account_exists()){
143 /* Read quota */
144 $this->gosaMailQuota = $this->mailMethod->getQuota($this->gosaMailQuota);
145 $this->quotaUsage = $this->mailMethod->getQuotaUsage($this->quotaUsage);
146 if($this->mailMethod->is_error()){
147 msg_dialog::display(_("Mail error"), sprintf(_("Cannot read quota settings: %s"),
148 $this->mailMethod->get_error()), ERROR_DIALOG);
149 }
151 /* Read mailboxes */
152 $this->MailBoxes = $this->mailMethod->getMailboxList($this->MailBoxes);
153 if($this->mailMethod->is_error()){
154 msg_dialog::display(_("Mail error"), sprintf(_("Cannot get list of mailboxes: %s"),
155 $this->mailMethod->get_error()), ERROR_DIALOG);
156 }
158 }elseif(!$this->mailMethod->is_connected()){
159 msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"),
160 $this->mailMethod->get_error()), ERROR_DIALOG);
161 }elseif(!$this->mailMethod->account_exists()){
162 msg_dialog::display(_("Mail error"), sprintf(_("Mailbox '%s' doesn't exists on mail server: %s"),
163 $this->mailMethod->get_account_id(),$this->gosaMailServer), ERROR_DIALOG);
164 }
166 /* If the doamin part is selectable, we have to split the mail address
167 */
168 if(!(!$this->mailMethod->isModifyableMail() && $this->is_account)){
169 if($this->mailMethod->domainSelectionEnabled()){
170 $this->mailDomainPart = preg_replace("/^[^@]*+@/","",$this->mail);
171 $this->mail = preg_replace("/@.*$/","\\1",$this->mail);
172 if(!in_array($this->mailDomainPart,$this->mailDomainParts)){
173 $this->mailDomainParts[] = $this->mailDomainPart;
174 }
175 }
176 }
178 /* Load attributes containing arrays */
179 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
180 $this->$val= array();
181 if (isset($this->attrs["$val"]["count"])){
182 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
183 array_push($this->$val, $this->attrs["$val"][$i]);
184 }
185 }
186 }
187 }
189 /* Intialize sieveManagement if necessary */
190 if($this->mailMethod->allowSieveManagement()){
191 $this->mailboxList = &$this->MailBoxes;
192 $this->sieve_management = new sieveManagement($this->config,$this->dn,$this,$this->mailMethod->getUAttrib());
193 }
195 /* Get global filter config used in add local forward
196 */
197 if (!session::is_set("mailfilter")){
198 $ui= get_userinfo();
199 $base= get_base_from_people($ui->dn);
200 $mailfilter= array( "depselect" => $base,
201 "muser" => "",
202 "regex" => "*");
203 session::set("mailfilter", $mailfilter);
204 }
206 /* Disconnect mailMethod. Connect on demand later.
207 */
208 $this->mailMethod->disconnect();
209 }
212 function execute()
213 {
215 /* Call parent execute */
216 $display = plugin::execute();
218 /* Log view */
219 if($this->is_account && !$this->view_logged){
220 $this->view_logged = TRUE;
221 new log("view","users/".get_class($this),$this->dn);
222 }
225 /****************
226 Account status
227 ****************/
229 if(isset($_POST['modify_state'])){
230 if($this->is_account && $this->acl_is_removeable() && $this->mailMethod->accountRemoveAble()){
231 $this->is_account= FALSE;
232 }elseif(!$this->is_account && $this->acl_is_createable() && $this->mailMethod->accountCreateable()){
233 $this->is_account= TRUE;
234 }
235 }
236 if(!$this->multiple_support_active){
237 if (!$this->is_account && $this->parent === NULL){
238 $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\"> <b>".
239 msgPool::noValidExtension(_("Mail"))."</b>";
240 $display.= back_to_main();
241 return ($display);
242 }
243 if ($this->parent !== NULL){
244 if ($this->is_account){
245 $reason = "";
246 if(!$this->mailMethod->accountRemoveable($reason)){
247 $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Mail")),$reason ,TRUE,TRUE);
248 }else{
249 $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Mail")),msgPool::featuresEnabled(_("Mail")));
250 }
251 } else {
252 $reason = "";
253 if(!$this->mailMethod->accountCreateable($reason)){
254 $display= $this->show_disable_header(msgPool::addFeaturesButton(_("Mail")),$reason ,TRUE,TRUE);
255 }else{
256 $display= $this->show_disable_header(msgPool::addFeaturesButton(_("Mail")),msgPool::featuresDisabled(_("Mail")));
257 }
258 return ($display);
259 }
260 }
261 }
263 /****************
264 Sieve Management Dialog
265 ****************/
266 if($this->mailMethod->allowSieveManagement()){
267 if(isset($_POST['sieveManagement'])
268 && preg_match("/C/",$this->gosaMailDeliveryMode)
269 && $this->acl_is_writeable("sieveManagement")
270 && $this->mailMethod->allowSieveManagement()) {
271 $this->dialog = $this->sieve_management;
272 }
273 if(isset($_POST['sieve_cancel'])){
274 $this->dialog = FALSE;
275 }
276 if(isset($_POST['sieve_finish'])){
277 $this->sieve_management = $this->dialog;
278 $this->dialog = FALSE;
279 }
280 if(is_object($this->dialog)){
281 $this->dialog->save_object();
282 return($this->dialog->execute());
283 }
284 }
286 /****************
287 Forward addresses
288 ****************/
289 if (isset($_POST['add_local_forwarder'])){
290 $this->forward_dialog= TRUE;
291 $this->dialog= TRUE;
292 }
293 if (isset($_POST['add_locals_cancel'])){
294 $this->forward_dialog= FALSE;
295 $this->dialog= FALSE;
296 }
297 if (isset($_POST['add_locals_finish'])){
298 if (isset($_POST['local_list'])){
299 if($this->acl_is_writeable("gosaMailForwardingAddress")){
300 foreach ($_POST['local_list'] as $val){
301 if (!in_array ($val, $this->gosaMailAlternateAddress) &&
302 $val != $this->mail){
303 $this->addForwarder($val);
304 $this->is_modified= TRUE;
305 }
306 }
307 }
308 $this->forward_dialog= FALSE;
309 $this->dialog= FALSE;
310 } else {
311 msg_dialog::display(_("Error"), _("Please select an entry!"), ERROR_DIALOG);
312 }
313 }
314 if (isset($_POST['add_forwarder'])){
315 if ($_POST['forward_address'] != ""){
316 $address= $_POST['forward_address'];
317 $valid= FALSE;
318 if (!tests::is_email($address)){
319 if (!tests::is_email($address, TRUE)){
320 if ($this->is_template){
321 $valid= TRUE;
322 } else {
323 msg_dialog::display(_("Error"), msgPool::invalid(_("Mail address"),
324 "","","your-address@your-domain.com"),ERROR_DIALOG);
325 }
326 }
327 } elseif ($address == $this->mail
328 || in_array($address, $this->gosaMailAlternateAddress)) {
329 msg_dialog::display(_("Error"),_("Cannot add primary address to the list of forwarders!") , ERROR_DIALOG);
330 } else {
331 $valid= TRUE;
332 }
333 if ($valid){
334 if($this->acl_is_writeable("gosaMailForwardingAddress")){
335 $this->addForwarder ($address);
336 $this->is_modified= TRUE;
337 }
338 }
339 }
340 }
341 if (isset($_POST['delete_forwarder'])){
342 $this->delForwarder ($_POST['forwarder_list']);
343 }
344 if ($this->forward_dialog){
345 return($this->display_forward_dialog());
346 }
349 /****************
350 Alternate addresses
351 ****************/
353 if (isset($_POST['add_alternate'])){
354 $valid= FALSE;
355 if (!tests::is_email($_POST['alternate_address'])){
356 if ($this->is_template){
357 if (!(tests::is_email($_POST['alternate_address'], TRUE))){
358 msg_dialog::display(_("Error"),msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com"),ERROR_DIALOG);
359 } else {
360 $valid= TRUE;
361 }
362 } else {
363 msg_dialog::display(_("Error"),msgPool::invalid(_("Mail address"),"","","your-domain@your-domain.com"),ERROR_DIALOG);
364 }
365 } else {
366 $valid= TRUE;
367 }
368 if ($valid && ($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
369 $ui= get_userinfo();
370 msg_dialog::display(_("Error"), msgPool::duplicated(_("Mail address"))." ".
371 sprintf(_("Address is already in use by user '%s'."), $user), ERROR_DIALOG);
372 }
373 }
374 if (isset($_POST['delete_alternate']) && isset($_POST['alternates_list'])){
375 $this->delAlternate ($_POST['alternates_list']);
376 }
378 /****************
379 SMARTY- Assign smarty variables
380 ****************/
381 $smarty = get_smarty();
382 $smarty->assign("usePrototype", "true");
383 $smarty->assign("initially_was_account", $this->initially_was_account);
384 $smarty->assign("isModifyableMail" , $this->mailMethod->isModifyableMail());
385 $smarty->assign("isModifyableServer", $this->mailMethod->isModifyableServer());
386 $smarty->assign("mailEqualsCN", $this->mailMethod->mailEqualsCN());
388 $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
389 $tmp = $this->plInfo();
390 foreach($tmp['plProvidedAcls'] as $name => $transl){
391 $smarty->assign("$name"."ACL", $this->getacl($name,$SkipWrite));
392 }
393 foreach($this->attributes as $attr){
394 $smarty->assign($attr,$this->$attr);
395 }
396 $smarty->assign("quotaEnabled", $this->mailMethod->quotaEnabled());
397 if($this->mailMethod->quotaEnabled()){
398 $smarty->assign("quotaUsage", mailMethod::quota_to_image($this->quotaUsage,$this->gosaMailQuota));
399 $smarty->assign("gosaMailQuota",$this->gosaMailQuota);
400 }
401 $smarty->assign("domainSelectionEnabled", $this->mailMethod->domainSelectionEnabled());
402 $smarty->assign("MailDomains", $this->mailDomainParts);
403 $smarty->assign("MailDomain" , $this->mailDomainPart);
404 $smarty->assign("MailServers", $this->mailMethod->getMailServers());
405 $smarty->assign("allowSieveManagement", $this->mailMethod->allowSieveManagement());
406 $smarty->assign("own_script", $this->sieveManagementUsed);
408 /* _Multiple users vars_ */
409 foreach($this->attributes as $attr){
410 $u_attr = "use_".$attr;
411 $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
412 }
413 foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
414 $u_attr = "use_".$attr;
415 $smarty->assign($u_attr,in_array($attr,$this->multi_boxes));
416 }
419 /****************
420 SMARTY- Assign flags
421 ****************/
423 $types = array(
424 "V"=>"use_vacation",
425 "S"=>"use_spam_filter",
426 "R"=>"use_mailsize_limit",
427 "I"=>"drop_own_mails",
428 "C"=>"own_script");
429 foreach($types as $option => $varname){
430 if (preg_match("/".$option."/", $this->gosaMailDeliveryMode)) {
431 $smarty->assign($varname, "checked");
432 } else {
433 $smarty->assign($varname, "");
434 }
435 }
436 if (!preg_match("/L/", $this->gosaMailDeliveryMode)) {
437 $smarty->assign("only_local", "checked");
438 } else {
439 $smarty->assign("only_local", "");
440 }
443 /****************
444 Smarty- Vacation settings
445 ****************/
446 $smarty->assign("rangeEnabled", FALSE);
447 $smarty->assign("template", "");
448 if (count($this->vacationTemplates)){
449 $smarty->assign("show_templates", "true");
450 $smarty->assign("vacationtemplates", $this->vacationTemplates);
451 if (isset($_POST['vacation_template'])){
452 $smarty->assign("template", $_POST['vacation_template']);
453 }
454 } else {
455 $smarty->assign("show_templates", "false");
456 }
458 /* Vacation range assigments
459 */
460 if($this->mailMethod->vacationRangeEnabled()){
461 $smarty->assign("rangeEnabled", TRUE);
462 if($this->gosaVacationStop ==0){
463 $date= getdate(time());
464 $date["mday"]++;
465 }else{
466 $date= getdate($this->gosaVacationStop);
467 }
468 $smarty->assign("end_day", $date["mday"]);
469 $smarty->assign("end_month", $date["mon"]-1);
470 $smarty->assign("end_year", $date["year"]);
472 if($this->gosaVacationStart == 0){
473 $date= getdate(time());
474 }else{
475 $date= getdate($this->gosaVacationStart);
476 }
477 $smarty->assign("start_day", $date["mday"]);
478 $smarty->assign("start_month", $date["mon"]-1);
479 $smarty->assign("start_year", $date["year"]);
480 $days= array();
481 for($d= 1; $d<32; $d++){
482 $days[$d]= $d;
483 }
484 $years= array();
485 for($y= $date['year']-10; $y<$date['year']+10; $y++){
486 $years[]= $y;
487 }
488 $months= msgPool::months();
489 $smarty->assign("months", $months);
490 $smarty->assign("years", $years);
491 $smarty->assign("days", $days);
492 }
494 /* fill filter settings
495 */
496 $smarty->assign("spamlevel", $this->SpamLevels);
497 $smarty->assign("spambox" , $this->MailBoxes);
499 $smarty->assign("multiple_support",$this->multiple_support_active);
500 return($display.$smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
501 }
505 /* Save data to object */
506 function save_object()
507 {
508 if (isset($_POST['mailTab'])){
510 /* Save ldap attributes */
511 $mail = $this->mail;
512 $server = $this->gosaMailServer;
513 plugin::save_object();
515 if(!$this->mailMethod->isModifyableServer() && $this->initially_was_account){
516 $this->gosaMailServer = $server;
517 }
519 if(!$this->mailMethod->isModifyableMail() && $this->initially_was_account){
520 $this->mail = $mail;
521 }else{
523 /* Get posted mail domain part, if necessary
524 */
525 if($this->mailMethod->domainSelectionEnabled() && isset($_POST['MailDomain'])){
526 if(in_array(get_post('MailDomain'), $this->mailDomainParts)){
527 $this->mailDomainPart = get_post('MailDomain');
528 }
529 }
530 }
532 /* Import vacation message?
533 */
534 if (isset($_POST["import_vacation"]) && isset($this->vacationTemplates[$_POST["vacation_template"]])){
535 if($this->multiple_support_active){
536 $contents = ltrim(preg_replace("/^DESC:.*$/m","",file_get_contents($_POST["vacation_template"])));
537 }else{
538 $contents = $this->prepare_vacation_template(file_get_contents($_POST["vacation_template"]));
539 }
540 $this->gosaVacationMessage= htmlspecialchars($contents);
541 }
543 /* Handle flags
544 */
545 if(isset($_POST['own_script'])){
546 if(!preg_match("/C/",$this->gosaMailDeliveryMode)){
547 $str= preg_replace("/[\[\]]/","",$this->gosaMailDeliveryMode);
548 $this->gosaMailDeliveryMode = "[".$str."C]";
549 }
550 }else{
552 /* Assemble mail delivery mode
553 The mode field in ldap consists of values between braces, this must
554 be called when 'mail' is set, because checkboxes may not be set when
555 we're in some other dialog.
557 Example for gosaMailDeliveryMode [LR ]
558 L - Local delivery
559 R - Reject when exceeding mailsize limit
560 S - Use spam filter
561 V - Use vacation message
562 C - Use custm sieve script
563 I - Only insider delivery */
565 $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
568 /* Handle delivery flags */
569 if($this->acl_is_writeable("gosaMailDeliveryModeL")){
570 if(!preg_match("/L/",$tmp) && !isset($_POST['only_local'])){
571 $tmp.="L";
572 }elseif(preg_match("/L/",$tmp) && isset($_POST['only_local'])){
573 $tmp = preg_replace("/L/","",$tmp);
574 }
575 }
576 $opts = array(
577 "R" => "use_mailsize_limit",
578 "S" => "use_spam_filter",
579 "V" => "use_vacation",
580 "C" => "own_script",
581 "I" => "drop_own_mails");
583 foreach($opts as $flag => $post){
584 if($this->acl_is_writeable("gosaMailDeliveryMode".$flag)){
585 if(!preg_match("/".$flag."/",$tmp) && isset($_POST[$post])){
586 $tmp.= $flag;
587 }elseif(preg_match("/".$flag."/",$tmp) && !isset($_POST[$post])){
588 $tmp = preg_replace("/".$flag."/","",$tmp);
589 }
590 }
591 }
593 $tmp= "[$tmp]";
594 if ($this->gosaMailDeliveryMode != $tmp){
595 $this->is_modified= TRUE;
596 }
597 $this->gosaMailDeliveryMode= $tmp;
599 /* Get start/stop values for vacation scope of application
600 */
601 if($this->mailMethod->vacationRangeEnabled()){
602 if($this->acl_is_writeable("gosaVacationMessage") && preg_match("/V/",$this->gosaMailDeliveryMode)){
603 if(isset($_POST['gosaVacationStart'])){
604 $this->gosaVacationStart = $_POST['gosaVacationStart'];
605 }
606 if(isset($_POST['gosaVacationStop'])){
607 $this->gosaVacationStop = $_POST['gosaVacationStop'];
608 }
609 }
610 }
611 }
612 }
613 }
616 /*! \brief Parse vacation templates and build up an array
617 containing 'filename' => 'description'.
618 Used to fill vacation dropdown box.
619 @return Array All useable vacation templates.
620 */
621 function get_vacation_templates()
622 {
623 $vct = array();
624 if ($this->config->get_cfg_value("vacationTemplateDirectory") != ""){
625 $dir= $this->config->get_cfg_value("vacationTemplateDirectory");
626 if (is_dir($dir) && is_readable($dir)){
627 $dh = opendir($dir);
628 while($file = readdir($dh)){
629 $description= "";
630 if (is_file($dir."/".$file)){
631 $fh = fopen($dir."/".$file, "r");
632 $line= fgets($fh, 256);
633 if (!preg_match('/^DESC:/', $line)){
634 msg_dialog::display(_("Configuration error"), sprintf(_("No DESC tag in vacation template '%s'!"), $file), ERROR_DIALOG);
635 }else{
636 $description= trim(preg_replace('/^DESC:\s*/', '', $line));
637 }
638 fclose ($fh);
639 }
640 if ($description != ""){
641 $vct["$dir/$file"]= $description;
642 }
643 }
644 closedir($dh);
645 }
646 }
647 return($vct);
648 }
651 /*! \brief Adds the given mail address to the list of mail forwarders
652 */
653 function addForwarder($address)
654 {
655 if(empty($address)) return;
656 if($this->acl_is_writeable("gosaMailForwardingAddress")){
657 $this->gosaMailForwardingAddress[]= $address;
658 $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
659 sort ($this->gosaMailForwardingAddress);
660 reset ($this->gosaMailForwardingAddress);
661 $this->is_modified= TRUE;
662 }else{
663 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
664 }
665 }
668 /*! \brief Removes the given mail address from the list of mail forwarders
669 */
670 function delForwarder($addresses)
671 {
672 if($this->acl_is_writeable("gosaMailForwardingAddress")){
673 $this->gosaMailForwardingAddress= array_remove_entries ($addresses, $this->gosaMailForwardingAddress);
674 $this->is_modified= TRUE;
675 }else{
676 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
677 }
678 }
681 /*! \brief Add given mail address to the list of alternate adresses ,
682 . check if this mal address is used, skip adding in this case
683 */
684 function addAlternate($address)
685 {
686 if(empty($address)) return;
687 if($this->acl_is_writeable("gosaMailAlternateAddress")){
688 $ldap= $this->config->get_ldap_link();
689 $address= strtolower($address);
691 /* Is this address already assigned in LDAP? */
692 $ldap->cd ($this->config->current['BASE']);
693 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=$address)".
694 "(alias=$address)(gosaMailAlternateAddress=$address)))", array("uid"));
695 if ($ldap->count() > 0){
696 $attrs= $ldap->fetch ();
697 return ($attrs["uid"][0]);
698 }
699 if (!in_array($address, $this->gosaMailAlternateAddress)){
700 $this->gosaMailAlternateAddress[]= $address;
701 $this->is_modified= TRUE;
702 }
703 sort ($this->gosaMailAlternateAddress);
704 reset ($this->gosaMailAlternateAddress);
705 return ("");
706 }else{
707 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
708 }
709 }
712 /*! \brief Removes the given mail address from the alternate addresses list
713 */
714 function delAlternate($addresses)
715 {
716 if($this->acl_is_writeable("gosaMailAlternateAddress")){
717 $this->gosaMailAlternateAddress= array_remove_entries ($addresses,$this->gosaMailAlternateAddress);
718 $this->is_modified= TRUE;
719 }else{
720 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
721 }
722 }
725 /*! \brief Prepare importet vacation string. \
726 . Replace placeholder like %givenName a.s.o.
727 @param string Vacation string
728 @return string Completed vacation string
729 */
730 private function prepare_vacation_template($contents)
731 {
732 /* Replace attributes */
733 $attrs = array();
734 $obj = NULL;
735 if(isset($this->parent->by_object['user'])){
736 $attrs = $this->parent->by_object['user']->attributes;
737 $obj = $this->parent->by_object['user'];
738 }else{
739 $obj = new user($this->config,$this->dn);
740 $attrs = $obj->attributes;
741 }
742 if($obj){
744 /* Replace vacation start and end time */
745 if($this->mailMethod->vacationRangeEnabled()){
746 if(preg_match("/%start/",$contents)){
747 $contents = preg_replace("/%start/",date("d.m.Y",$this->gosaVacationStart),$contents);
748 }
749 if(preg_match("/%end/",$contents)){
750 $contents = preg_replace("/%end/",date("d.m.Y",$this->gosaVacationStop),$contents);
751 }
752 }else{
753 if(preg_match("/%start/",$contents)){
754 $contents = preg_replace("/%start/", _("unknown"),$contents);
755 }
756 if(preg_match("/%end/",$contents)){
757 $contents = preg_replace("/%end/", _("unknown"), $contents);
758 }
759 }
761 foreach ($attrs as $val){
762 if(preg_match("/dateOfBirth/",$val)){
763 if($obj->use_dob){
764 $contents= preg_replace("/%$val/",date("Y-d-m",$obj->dateOfBirth),$contents);
765 }
766 }else {
767 $contents= preg_replace("/%$val/",
768 $obj->$val, $contents);
769 }
771 }
772 }
773 $contents = ltrim(preg_replace("/^DESC:.*$/m","",$contents),"\n ");
774 return($contents);
775 }
778 /*! \brief Displays a dialog that allows mail address selection.
779 */
780 function display_forward_dialog()
781 {
782 restore_error_handler();
784 $smarty = get_smarty();
785 $ldap= $this->config->get_ldap_link();
787 /* Save data */
788 $mailfilter= session::get("mailfilter");
789 foreach( array("depselect", "muser", "regex") as $type){
790 if (isset($_POST[$type])){
791 $mailfilter[$type]= $_POST[$type];
792 }
793 }
794 if (isset($_GET['search'])){
795 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
796 if ($s == "**"){
797 $s= "*";
798 }
799 $mailfilter['regex']= $s;
800 }
801 session::set("mailfilter", $mailfilter);
803 /* Get actual list */
804 $mailusers= array ();
805 if ($mailfilter['regex'] != '*' && $mailfilter['regex'] != ""){
806 $regex= $mailfilter['regex'];
807 $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
808 } else {
809 $filter= "";
810 }
811 if ($mailfilter['muser'] != ""){
812 $user= $mailfilter['muser'];
813 $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
814 }
816 /* Add already present people to the filter */
817 $exclude= "";
818 foreach ($this->gosaMailForwardingAddress as $mail){
819 $exclude.= "(mail=$mail)";
820 }
821 if ($exclude != ""){
822 $filter.= "(!(|$exclude))";
823 }
824 $res= get_list("(&(objectClass=gosaMailAccount)$filter)", "users", $mailfilter['depselect'],
825 array("sn", "mail", "givenName"), GL_SIZELIMIT | GL_SUBSEARCH);
826 $ldap->cd($mailfilter['depselect']);
827 $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
828 while ($attrs= $ldap->fetch()){
829 if(preg_match('/%/', $attrs['mail'][0])){
830 continue;
831 }
832 $name= $this->make_name($attrs);
833 $mailusers[$attrs['mail'][0]]= $name."<".
834 $attrs['mail'][0].">";
835 }
836 natcasesort ($mailusers);
837 reset ($mailusers);
839 /* Show dialog */
840 $smarty->assign("search_image", get_template_path('images/lists/search.png'));
841 $smarty->assign("usearch_image", get_template_path('images/lists/search-user.png'));
842 $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
843 $smarty->assign("infoimage", get_template_path('images/info.png'));
844 $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
845 $smarty->assign("mailusers", $mailusers);
846 if (isset($_POST['depselect'])){
847 $smarty->assign("depselect", $_POST['depselect']);
848 }
849 $smarty->assign("deplist", $this->config->idepartments);
850 $smarty->assign("apply", apply_filter());
851 $smarty->assign("alphabet", generate_alphabet());
852 $smarty->assign("hint", print_sizelimit_warning());
853 foreach( array("depselect", "muser", "regex") as $type){
854 $smarty->assign("$type", $mailfilter[$type]);
855 }
856 $smarty->assign("hint", print_sizelimit_warning());
857 $display= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE, dirname(__FILE__)));
858 return ($display);
859 }
862 /*! \brief Removes the mailAccount extension from ldap
863 */
864 function remove_from_parent()
865 {
866 /* Cancel if there's nothing to do here */
867 if (!$this->initially_was_account){
868 return;
869 }
871 /* If domain part was selectable, contruct mail address */
872 if($this->mailMethod->domainSelectionEnabled()){
873 $this->mail = $this->mail."@".$this->mailDomainPart;
874 }
876 /* Update sharedFolder dependencies.
877 Open each shared folder and remove this account.
878 Then Save the group to ensure that all necessary
879 actions will be taken (imap acls updated aso.).
880 */
881 $ldap = $this->config->get_ldap_link();
882 $ldap->cd($this->config->current['BASE']);
883 $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array("dn"));
884 while($attrs = $ldap->fetch()){
885 $grp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
886 if(isset($grp->by_object['mailgroup']) && isset($grp->by_object['group'])){
887 $grp->by_object['group']->removeUser($this->uid);
889 /* Do not save the complete group! This will quit the complete membership
890 */
891 $grp->by_object['mailgroup']->save();
892 }
893 }
895 /* Remove GOsa attributes */
896 plugin::remove_from_parent();
898 /* Zero arrays */
899 $this->attrs['gosaMailAlternateAddress'] = array();
900 $this->attrs['gosaMailForwardingAddress']= array();
903 $this->mailMethod->fixAttributesOnRemove();
904 $this->cleanup();
906 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
907 $ldap= $this->config->get_ldap_link();
908 $ldap->cd($this->dn);
909 $ldap->modify ($this->attrs);
911 /* Add "view" to logging class */
912 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
913 if (!$ldap->success()){
914 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
915 }
917 /* Let the mailMethod remove this mailbox, e.g. from imap and
918 update shared folder membership, ACL may need to be updated.
919 */
920 if (!$this->is_template){
922 if(!$this->mailMethod->connect()){
923 msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"),
924 $this->mailMethod->get_error()), ERROR_DIALOG);
925 }else{
926 if(!$this->mailMethod->deleteMailbox()){
927 msg_dialog::display(_("Mail error"), sprintf(_("Cannot remove mailbox: %s"),
928 $this->mailMethod->get_error()), ERROR_DIALOG);
929 }
930 }
931 }
932 $this->mailMethod->disconnect();
934 /* Optionally execute a command after we're done */
935 $this->handle_post_events("remove",array("uid" => $this->uid));
936 }
939 /*! \brief Save the mailAccount settings to the ldap database.
940 */
941 function save()
942 {
943 $ldap= $this->config->get_ldap_link();
945 /* If domain part was selectable, contruct mail address */
946 if(!(!$this->mailMethod->isModifyableMail() && $this->initially_was_account)){
948 if($this->mailMethod->domainSelectionEnabled()){
949 $this->mail = $this->mail."@".$this->mailDomainPart;
950 }
952 /* Enforce lowercase mail address and trim whitespaces
953 */
954 $this->mail = trim(strtolower($this->mail));
955 }
958 /* Call parents save to prepare $this->attrs */
959 plugin::save();
961 /* Save arrays */
962 $this->attrs['gosaMailAlternateAddress'] = $this->gosaMailAlternateAddress;
963 $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
965 if(!$this->mailMethod->vacationRangeEnabled()){
966 $this->attrs['gosaVacationStart'] = $this->attrs['gosaVacationStop'] = array();
967 }elseif (!preg_match('/V/', $this->gosaMailDeliveryMode)){
968 unset($this->attrs['gosaVacationStart']);
969 unset($this->attrs['gosaVacationStop']);
970 }
972 /* Map method attributes */
973 $this->mailMethod->fixAttributesOnStore();
975 /* Save data to LDAP */
976 $ldap->cd($this->dn);
977 $this->cleanup();
978 $ldap->modify ($this->attrs);
980 if (!$ldap->success()){
981 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
982 }
984 /* Log last action */
985 if($this->initially_was_account){
986 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
987 }else{
988 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
989 }
991 /* Only do IMAP actions if we are not a template */
992 if (!$this->is_template){
993 $this->mailMethod->connect();
994 if(!$this->mailMethod->is_connected()){
995 msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"),
996 $this->mailMethod->get_error()), ERROR_DIALOG);
997 }else{
998 if(!$this->mailMethod->updateMailbox()){
999 msg_dialog::display(_("Mail error"), sprintf(_("Cannot update mailbox: %s"),
1000 $this->mailMethod->get_error()), ERROR_DIALOG);
1001 }
1002 if(!$this->mailMethod->setQuota($this->gosaMailQuota)){
1003 msg_dialog::display(_("Mail error"), sprintf(_("Cannot write quota settings: %s"),
1004 $this->mailMethod->get_error()), ERROR_DIALOG);
1005 }
1007 if (!is_integer(strpos($this->gosaMailDeliveryMode, "C"))){
1009 /* Do not write sieve settings if this account is new and
1010 doesn't seem to exist.
1011 */
1012 if(!$this->initially_was_account && !$this->mailMethod->account_exists()){
1013 @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,
1014 "Skipping sieve settings, the account doesn't seem to be created already.</b>","");
1015 }else{
1016 if(!$this->mailMethod->saveSieveSettings()){
1017 msg_dialog::display(_("Mail error saving sieve settings"), $this->mailMethod->get_error(), ERROR_DIALOG);
1018 }
1019 }
1020 }else{
1021 @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,
1022 "User uses an own sieve script, skipping sieve update.".$str."</b>","");
1023 $this->sieve_management->save();
1024 }
1025 }
1026 }
1027 $this->mailMethod->disconnect();
1029 /* Update sharedFolder dependencies.
1030 Open each shared folder and remove this account.
1031 Then Save the group to ensure that all necessary
1032 actions will be taken (imap acls updated aso.).
1033 */
1034 if(!$this->initially_was_account){
1035 $ldap = $this->config->get_ldap_link();
1036 $ldap->cd($this->config->current['BASE']);
1037 $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array("dn"));
1038 while($attrs = $ldap->fetch()){
1039 $grp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
1040 if(isset($grp->by_object['mailgroup'])){
1041 /* Do not save the complete group! This will quit the complete membership
1042 */
1043 $grp->by_object['mailgroup']->save();
1044 }
1045 }
1046 }
1048 /* Optionally execute a command after we're done */
1049 if ($this->initially_was_account == $this->is_account){
1050 if ($this->is_modified){
1051 $this->handle_post_events("modify", array("uid" => $this->uid));
1052 }
1053 } else {
1054 $this->handle_post_events("add", array("uid" => $this->uid));
1055 }
1056 }
1059 /*! \brief Check given values
1060 */
1061 function check()
1062 {
1063 if(!$this->is_account){
1064 return(array());
1065 }
1067 $ldap= $this->config->get_ldap_link();
1069 /* Call common method to give check the hook */
1070 $message= plugin::check();
1072 if(empty($this->gosaMailServer)){
1073 $message[]= msgPool::noserver(_("Mail"));
1074 }
1076 /* Mail address checks */
1077 $mail = $this->mail;
1078 if(!(!$this->mailMethod->isModifyableMail() && $this->initially_was_account)){
1080 if($this->mailMethod->domainSelectionEnabled()){
1081 $mail.= "@".$this->mailDomainPart;
1082 }
1084 if (empty($mail)){
1085 $message[]= msgPool::required(_("Primary address"));
1086 }
1087 if ($this->is_template){
1088 if (!tests::is_email($mail, TRUE)){
1089 $message[]= msgPool::invalid(_("Mail address"),"","","%givenName.%sn@your-domain.com");
1090 }
1091 } else {
1092 if (!tests::is_email($mail)){
1093 $message[]= msgPool::invalid(_("Mail address"),"","","your-address@your-domain.com");
1094 }
1095 }
1097 /* Check if this mail address is already in use */
1098 $ldap->cd($this->config->current['BASE']);
1099 $filter = "(&(!(objectClass=gosaUserTemplate))(!(uid=".$this->uid."))".
1100 "(objectClass=gosaMailAccount)".
1101 "(|(mail=".$mail.")(alias=".$mail.")(gosaMailAlternateAddress=".$mail.")))";
1102 $ldap->search($filter,array("uid"));
1103 if ($ldap->count() != 0){
1104 $message[]= msgPool::duplicated(_("Mail address"));
1105 }
1106 }
1109 /* Check quota */
1110 if ($this->gosaMailQuota != '' && $this->acl_is_writeable("gosaMailQuota")){
1111 if (!is_numeric($this->gosaMailQuota)) {
1112 $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
1113 } else {
1114 $this->gosaMailQuota= (int) $this->gosaMailQuota;
1115 }
1116 }
1118 /* Check rejectsize for integer */
1119 if ($this->gosaMailMaxSize != '' && $this->acl_is_writeable("gosaMailMaxSize")){
1120 if (!is_numeric($this->gosaMailMaxSize)){
1121 $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
1122 } else {
1123 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
1124 }
1125 }
1127 /* Need gosaMailMaxSize if use_mailsize_limit is checked */
1128 if (is_integer(strpos($this->gosaMailDeliveryMode, "R")) && $this->gosaMailMaxSize == ""){
1129 $message[]= msgPool::required(_("Mail reject size"));
1130 }
1132 if((preg_match("/S/", $this->gosaMailDeliveryMode))&&(empty($this->gosaSpamMailbox))) {
1133 $message[]= msgPool::required(_("Spam folder"));
1134 }
1136 if ($this->mailMethod->vacationRangeEnabled()
1137 && preg_match('/V/', $this->gosaMailDeliveryMode)
1138 && $this->gosaVacationStart > $this->gosaVacationStop){
1139 $message[]= msgPool::invalid(_("Vacation interval"));
1140 }
1141 return($message);
1142 }
1145 /*! \brief Adapt from template, using 'dn'
1146 */
1147 function adapt_from_template($dn, $skip= array())
1148 {
1149 plugin::adapt_from_template($dn, $skip);
1151 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
1153 if (in_array($val, $skip)){
1154 continue;
1155 }
1157 $this->$val= array();
1158 if (isset($this->attrs["$val"]["count"])){
1159 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
1160 $value= $this->attrs["$val"][$i];
1161 foreach (array("sn", "givenName", "uid") as $repl){
1162 if (preg_match("/%$repl/i", $value)){
1163 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
1164 }
1165 }
1166 array_push($this->$val, strtolower(rewrite($value)));
1167 }
1168 }
1169 }
1170 $this->mail= strtolower(rewrite($this->mail));
1171 }
1174 /*! \brief Creates the mail part for the copy & paste dialog
1175 */
1176 function getCopyDialog()
1177 {
1178 if(!$this->is_account) return("");
1179 $smarty = get_smarty();
1180 $smarty->assign("mail",$this->mail);
1181 $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress);
1182 $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress);
1183 $str = $smarty->fetch(get_template_path("copypaste.tpl",TRUE, dirname(__FILE__)));
1185 $ret = array();
1186 $ret['status'] = "";
1187 $ret['string'] = $str;
1188 return($ret);
1189 }
1192 /*! \brief save_object for copy&paste vars
1193 */
1194 function saveCopyDialog()
1195 {
1196 if(!$this->is_account) return;
1198 /* Execute to save mailAlternateAddress && gosaMailForwardingAddress */
1199 $this->execute();
1200 if(isset($_POST['mail'])){
1201 $this->mail = $_POST['mail'];
1202 }
1203 }
1206 /*! \brief Prepare this account to be copied
1207 */
1208 function PrepareForCopyPaste($source)
1209 {
1210 plugin::PrepareForCopyPaste($source);
1212 /* Reset alternate mail addresses */
1213 $this->gosaMailAlternateAddress = array();
1214 }
1217 /*! \brief Prepare this class the be useable when editing multiple users at once
1218 */
1219 function get_multi_edit_values()
1220 {
1221 $ret = plugin::get_multi_edit_values();
1222 if(in_array("gosaMailQuota",$this->multi_boxes)){
1223 $ret['gosaMailQuota'] = $this->gosaMailQuota;
1224 }
1225 $flag_add = $flag_remove = array();
1226 $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1227 $opts = array(
1228 "R" => "use_mailsize_limit",
1229 "S" => "use_spam_filter",
1230 "L" => "only_local",
1231 "V" => "use_vacation",
1232 "C" => "own_script",
1233 "I" => "drop_own_mails");
1234 foreach($opts as $flag => $post){
1235 if(in_array($post, $this->multi_boxes)){
1236 if(preg_match("/".$flag."/",$tmp)){
1237 $flag_add[] = $flag;
1238 }else{
1239 $flag_remove[] = $flag;
1240 }
1241 }
1242 }
1243 $ret['flag_add'] = $flag_add;
1244 $ret['flag_remove'] = $flag_remove;
1246 if($this->mailMethod->vacationRangeEnabled()){
1247 if(in_array("V",$flag_add)){
1248 $ret['gosaVacationStart'] = $this->gosaVacationStart = $_POST['gosaVacationStart'];
1249 $ret['gosaVacationStop'] = $this->gosaVacationStop = $_POST['gosaVacationStop'];
1250 }
1251 }
1252 return($ret);
1253 }
1256 /*! \brief Check given input for multiple user edit
1257 */
1258 function multiple_check()
1259 {
1260 $message = plugin::multiple_check();
1262 if(empty($this->gosaMailServer) && in_array("gosaMailServer",$this->multi_boxes)){
1263 $message[]= msgPool::noserver(_("Mail"));
1264 }
1266 /* Check quota */
1267 if ($this->gosaMailQuota != '' && in_array("gosaMailQuota",$this->multi_boxes)){
1268 if (!is_numeric($this->gosaMailQuota)) {
1269 $message[]= msgPool::invalid(_("Quota size"),$this->gosaMailQuota,"/^[0-9]*/");
1270 } else {
1271 $this->gosaMailQuota= (int) $this->gosaMailQuota;
1272 }
1273 }
1275 /* Check rejectsize for integer */
1276 if ($this->gosaMailMaxSize != '' && in_array("gosaMailMaxSize",$this->multi_boxes)){
1277 if (!is_numeric($this->gosaMailMaxSize)){
1278 $message[]= msgPool::invalid(_("Mail reject size"),$this->gosaMailMaxSize,"/^[0-9]*/");
1279 } else {
1280 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
1281 }
1282 }
1284 if(empty($this->gosaSpamMailbox) && in_array("gosaSpamMailbox",$this->multi_boxes)){
1285 $message[]= msgPool::required(_("Spam folder"));
1286 }
1288 if ($this->mailMethod->vacationRangeEnabled() && in_array("use_vacation",$this->multi_boxes) &&
1289 preg_match('/V/', $this->gosaMailDeliveryMode) && $this->gosaVacationStart > $this->gosaVacationStop){
1290 $message[]= msgPool::invalid(_("Vacation interval"));
1291 }
1292 return($message);
1293 }
1296 /*! \brief ...
1297 */
1298 function set_multi_edit_values($values)
1299 {
1300 plugin::set_multi_edit_values($values);
1301 $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
1302 if(isset($values['flag_add'])){
1303 foreach($values['flag_add'] as $flag){
1304 if(!preg_match("/".$flag."/",$tmp)){
1305 $tmp .= $flag;
1306 }
1307 }
1308 }
1309 if(isset($values['flag_remove'])){
1310 foreach($values['flag_remove'] as $flag){
1311 if(preg_match("/".$flag."/",$tmp)){
1312 $tmp = preg_replace("/".$flag."/","",$tmp);
1313 }
1314 }
1315 }
1316 $this->gosaMailDeliveryMode = "[".$tmp."]";
1318 /* Set vacation message and replace placeholder like %givenName
1319 */
1320 if(isset($values['gosaVacationMessage'])){
1321 $this->gosaVacationMessage = $this->prepare_vacation_template($values['gosaVacationMessage']);
1322 }
1323 }
1326 /*! \brief Initialize plugin to be used as multiple edit class.
1327 */
1328 function init_multiple_support($attrs,$all)
1329 {
1330 plugin::init_multiple_support($attrs,$all);
1331 if(isset($this->multi_attrs['gosaMailQuota'])){
1332 $this->gosaMailQuota = $this->multi_attrs['gosaMailQuota'];
1333 }
1334 }
1337 /*! \brief
1338 */
1339 function get_multi_init_values()
1340 {
1341 $attrs = plugin::get_multi_init_values();
1342 $attrs['gosaMailQuota'] = $this->gosaMailQuota;
1343 return($attrs);
1344 }
1347 /*! \brief Display multiple edit dialog
1348 */
1349 function multiple_execute()
1350 {
1351 return($this->execute());
1352 }
1355 /*! \brief Save posts from multiple edit dialog
1356 */
1357 function multiple_save_object()
1358 {
1359 plugin::multiple_save_object();
1361 $this->save_object();
1362 foreach(array("only_local","gosaMailForwardingAddress","use_mailsize_limit","drop_own_mails","use_vacation","use_spam_filter") as $attr){
1363 if(isset($_POST["use_".$attr])){
1364 $this->multi_boxes[] = $attr;
1365 }
1366 }
1367 }
1370 /*! \brief Creates the user names for the add_local_forward dialog
1371 */
1372 function make_name($attrs)
1373 {
1374 $name= "";
1375 if (isset($attrs['sn'][0])){
1376 $name= $attrs['sn'][0];
1377 }
1378 if (isset($attrs['givenName'][0])){
1379 if ($name != ""){
1380 $name.= ", ".$attrs['givenName'][0];
1381 } else {
1382 $name.= $attrs['givenName'][0];
1383 }
1384 }
1385 if ($name != ""){
1386 $name.= " ";
1387 }
1389 return ($name);
1390 }
1393 function allow_remove()
1394 {
1395 $resason = "";
1396 if(!$this->mailMethod->allow_remove($reason)){
1397 return($reason);
1398 }
1399 return("");
1400 }
1404 /*! \brief ACL settings
1405 */
1406 static function plInfo()
1407 {
1408 return (array(
1409 "plShortName" => _("Mail"),
1410 "plDescription" => _("Mail settings"),
1411 "plSelfModify" => TRUE,
1412 "plDepends" => array("user"), // This plugin depends on
1413 "plPriority" => 4, // Position in tabs
1414 "plSection" => array("personal" => _("My account")),
1415 "plCategory" => array("users"),
1416 "plOptions" => array(),
1418 "plProvidedAcls" => array(
1419 "mail" => _("Mail address"),
1420 "gosaMailServer" => _("Mail server"),
1421 "gosaMailQuota" => _("Quota size"),
1423 "gosaMailDeliveryModeV" => _("Add vacation information"), // This is flag of gosaMailDeliveryMode
1424 "gosaVacationMessage" => _("Vacation message"),
1426 "gosaMailDeliveryModeS" => _("Use spam filter"), // This is flag of gosaMailDeliveryMode
1427 "gosaSpamSortLevel" => _("Spam level"),
1428 "gosaSpamMailbox" => _("Spam mail box"),
1430 "sieveManagement" => _("Sieve management"),
1432 "gosaMailDeliveryModeR" => _("Reject due to mailsize"), // This is flag of gosaMailDeliveryMode
1433 "gosaMailMaxSize" => _("Mail max size"),
1435 "gosaMailForwardingAddress" => _("Forwarding address"),
1436 "gosaMailDeliveryModeL" => _("Local delivery"), // This is flag of gosaMailDeliveryMode
1437 "gosaMailDeliveryModeI" => _("No delivery to own mailbox "), // This is flag of gosaMailDeliveryMode
1438 "gosaMailAlternateAddress" => _("Mail alternative addresses"),
1440 "gosaMailForwardingAddress" => _("Forwarding address"),
1441 "gosaMailDeliveryModeC" => _("Use custom sieve script")) // This is flag of gosaMailDeliveryMode
1442 ));
1443 }
1446 }
1448 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1449 ?>