6 * Plugin that adds a new button to the mailbox toolbar
7 * to move messages to a (user selectable) archive folder.
9 * @version @package_version@
10 * @author Andre Rodier, Thomas Bruederli
12 class archive extends rcube_plugin
14 public $task = 'mail|settings';
18 $rcmail = rcmail::get_instance();
20 // There is no "Archived flags"
21 // $GLOBALS['IMAP_FLAGS']['ARCHIVED'] = 'Archive';
22 if ($rcmail->task == 'mail' && ($rcmail->action == '' || $rcmail->action == 'show')
23 && ($archive_folder = $rcmail->config->get('archive_mbox'))) {
24 $skin_path = $this->local_skin_path();
26 $this->include_script('archive.js');
27 $this->add_texts('localization', true);
30 'command' => 'plugin.archive',
31 'imagepas' => $skin_path.'/archive_pas.png',
32 'imageact' => $skin_path.'/archive_act.png',
35 'title' => 'buttontitle',
36 'domain' => $this->ID,
40 // register hook to localize the archive folder
41 $this->add_hook('render_mailboxlist', array($this, 'render_mailboxlist'));
43 // set env variable for client
44 $rcmail->output->set_env('archive_folder', $archive_folder);
45 $rcmail->output->set_env('archive_folder_icon', $this->url($skin_path.'/foldericon.png'));
47 // add archive folder to the list of default mailboxes
48 if (($default_folders = $rcmail->config->get('default_imap_folders')) && !in_array($archive_folder, $default_folders)) {
49 $default_folders[] = $archive_folder;
50 $rcmail->config->set('default_imap_folders', $default_folders);
53 else if ($rcmail->task == 'settings') {
54 $dont_override = $rcmail->config->get('dont_override', array());
55 if (!in_array('archive_mbox', $dont_override)) {
56 $this->add_hook('preferences_list', array($this, 'prefs_table'));
57 $this->add_hook('preferences_save', array($this, 'save_prefs'));
62 function render_mailboxlist($p)
64 $rcmail = rcmail::get_instance();
65 $archive_folder = $rcmail->config->get('archive_mbox');
67 // set localized name for the configured archive folder
68 if ($archive_folder) {
69 if (isset($p['list'][$archive_folder]))
70 $p['list'][$archive_folder]['name'] = $this->gettext('archivefolder');
71 else // search in subfolders
72 $this->_mod_folder_name($p['list'], $archive_folder, $this->gettext('archivefolder'));
78 function _mod_folder_name(&$list, $folder, $new_name)
80 foreach ($list as $idx => $item) {
81 if ($item['id'] == $folder) {
82 $list[$idx]['name'] = $new_name;
84 } else if (!empty($item['folders']))
85 if ($this->_mod_folder_name($list[$idx]['folders'], $folder, $new_name))
91 function prefs_table($args)
95 if ($args['section'] == 'folders') {
96 $this->add_texts('localization');
98 $rcmail = rcmail::get_instance();
100 // load folders list when needed
102 $select = rcmail_mailbox_select(array('noselection' => '---', 'realnames' => true,
103 'maxlength' => 30, 'exceptions' => array('INBOX')));
105 $select = new html_select();
107 $args['blocks']['main']['options']['archive_mbox'] = array(
108 'title' => $this->gettext('archivefolder'),
109 'content' => $select->show($rcmail->config->get('archive_mbox'), array('name' => "_archive_mbox"))
116 function save_prefs($args)
118 if ($args['section'] == 'folders') {
119 $args['prefs']['archive_mbox'] = get_input_value('_archive_mbox', RCUBE_INPUT_POST);