diff --git a/plugins/kolab_folders/kolab_folders.php b/plugins/kolab_folders/kolab_folders.php index ddab6663..b265eea8 100644 --- a/plugins/kolab_folders/kolab_folders.php +++ b/plugins/kolab_folders/kolab_folders.php @@ -3,10 +3,9 @@ /** * Type-aware folder management/listing for Kolab * - * @version @package_version@ * @author Aleksander Machniak * - * Copyright (C) 2011, Kolab Systems AG + * Copyright (C) 2011-2017, Kolab Systems AG * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -42,6 +41,7 @@ class kolab_folders extends rcube_plugin private $rc; private static $instance; + private $expire_annotation = '/shared/vendor/cmu/cyrus-imapd/expire'; /** @@ -206,6 +206,8 @@ class kolab_folders extends rcube_plugin 'value' => sprintf('%s (%s)', $this->gettext('foldertypemail'), $this->gettext('inbox')), ); + $this->add_expire_input($args['form'], 'INBOX'); + return $args; } @@ -260,7 +262,9 @@ class kolab_folders extends rcube_plugin $this->include_script('kolab_folders.js'); // build type SELECT fields - $type_select = new html_select(array('name' => '_ctype', 'id' => '_ctype')); + $type_select = new html_select(array('name' => '_ctype', 'id' => '_ctype', + 'onchange' => "\$('[name=\"_expire\"]').attr('disabled', \$(this).val() != 'mail')" + )); $sub_select = new html_select(array('name' => '_subtype', 'id' => '_subtype')); $sub_select->add('', ''); @@ -291,6 +295,8 @@ class kolab_folders extends rcube_plugin $this->rc->output->set_env('kolab_folder_subtypes', $sub_types); $this->rc->output->set_env('kolab_folder_subtype', isset($new_subtype) ? $new_subtype : $subtype); + $this->add_expire_input($args['form'], $args['name'], $ctype); + return $args; } @@ -373,7 +379,15 @@ class kolab_folders extends rcube_plugin } } - $args['record']['class'] = self::folder_class_name($ctype); + // Set messages expiration in days + if ($result && isset($_POST['_expire'])) { + $expire = trim(rcube_utils::get_input_value('_expire', rcube_utils::INPUT_POST)); + $expire = intval($expire) && preg_match('/^mail/', $ctype) ? intval($expire) : null; + + $storage->set_metadata($mbox, array($this->expire_annotation => $expire)); + } + + $args['record']['class'] = self::folder_class_name($ctype); $args['record']['subscribe'] = $subscribe; $args['result'] = $result; @@ -699,4 +713,53 @@ class kolab_folders extends rcube_plugin { return self::$instance->get_default_folder($type); } + + /** + * Get /shared/vendor/cmu/cyrus-imapd/expire value + * + * @param string $folder IMAP folder name + * + * @return int|false The annotation value or False if not supported + */ + private function get_expire_annotation($folder) + { + $storage = $this->rc->get_storage(); + + if ($storage->get_vendor() != 'cyrus') { + return false; + } + + if (!strlen($folder)) { + return 0; + } + + $value = $storage->get_metadata($folder, $this->expire_annotation); + + if (is_array($value)) { + return $value[$folder] ? intval($value[$folder][$this->expire_annotation]) : 0; + } + + return false; + } + + /** + * Add expiration time input to the form if supported + */ + private function add_expire_input(&$form, $folder, $type = null) + { + if (($expire = $this->get_expire_annotation($folder)) !== false) { + $post = trim(rcube_utils::get_input_value('_expire', rcube_utils::INPUT_POST)); + $is_mail = empty($type) || preg_match('/^mail/i', $type); + $input = new html_inputfield(array('name' => '_expire', 'size' => 3, 'disabled' => !$is_mail)); + + if ($post && $is_mail) { + $expire = (int) $post; + } + + $form['props']['fieldsets']['settings']['content']['kolabexpire'] = array( + 'label' => $this->gettext('folderexpire'), + 'value' => str_replace('$x', $input->show($expire ?: ''), $this->gettext('xdays')), + ); + } + } } diff --git a/plugins/kolab_folders/localization/en_US.inc b/plugins/kolab_folders/localization/en_US.inc index 0c234d65..362c3217 100644 --- a/plugins/kolab_folders/localization/en_US.inc +++ b/plugins/kolab_folders/localization/en_US.inc @@ -31,6 +31,9 @@ $labels['junkemail'] = 'Junk'; $labels['confidential'] = 'Confidential'; $labels['private'] = 'Private'; +$labels['folderexpire'] = 'Delete messages older than'; +$labels['xdays'] = '$x days'; + $messages['defaultfolderexists'] = 'There is already default folder of specified type'; ?>