6 * Plugin that adds a new button to the mailbox toolbar
7 * to move messages to a (user selectable) archive folder.
10 * @author Andre Rodier, Thomas Bruederli
12 class archive extends rcube_plugin
14 public $task = 'mail|settings';
18 $this->register_action('plugin.archive', array($this, 'request_action'));
20 # There is no "Archived flags"
21 # $GLOBALS['IMAP_FLAGS']['ARCHIVED'] = 'Archive';
23 $rcmail = rcmail::get_instance();
24 if ($rcmail->task == 'mail' && ($rcmail->action == '' || $rcmail->action == 'show') && ($archive_folder = $rcmail->config->get('archive_mbox'))) {
25 $this->include_script('archive.js');
26 $this->add_texts('localization', true);
29 'command' => 'plugin.archive',
30 'imagepas' => 'archive_pas.png',
31 'imageact' => 'archive_act.png',
32 'title' => 'buttontitle',
33 'domain' => $this->ID,
37 // register hook to localize the archive folder
38 $this->add_hook('render_mailboxlist', array($this, 'render_mailboxlist'));
40 // set env variable for client
41 $rcmail->output->set_env('archive_folder', $archive_folder);
43 // add archive folder to the list of default mailboxes
44 if (($default_folders = $rcmail->config->get('default_imap_folders')) && !in_array($archive_folder, $default_folders)) {
45 $default_folders[] = $archive_folder;
46 $rcmail->config->set('default_imap_folders', $default_folders);
50 else if ($rcmail->task == 'settings') {
51 $dont_override = $rcmail->config->get('dont_override', array());
52 if (!in_array('archive_mbox', $dont_override)) {
53 $this->add_hook('user_preferences', array($this, 'prefs_table'));
54 $this->add_hook('save_preferences', array($this, 'save_prefs'));
59 function render_mailboxlist($p)
61 $rcmail = rcmail::get_instance();
62 $archive_folder = $rcmail->config->get('archive_mbox');
64 // set localized name for the configured archive folder
65 if ($archive_folder) {
66 if (isset($p['list'][$archive_folder]))
67 $p['list'][$archive_folder]['name'] = $this->gettext('archivefolder');
68 else // search in subfolders
69 $this->_mod_folder_name($p['list'], $archive_folder, $this->gettext('archivefolder'));
75 function _mod_folder_name(&$list, $folder, $new_name)
77 foreach ($list as $idx => $item) {
78 if ($item['id'] == $folder) {
79 $list[$idx]['name'] = $new_name;
81 } else if (!empty($item['folders']))
82 if ($this->_mod_folder_name($list[$idx]['folders'], $folder, $new_name))
88 function request_action()
90 $this->add_texts('localization');
92 $uids = get_input_value('_uid', RCUBE_INPUT_POST);
93 $mbox = get_input_value('_mbox', RCUBE_INPUT_POST);
95 $rcmail = rcmail::get_instance();
97 // There is no "Archive flags", but I left this line in case it may be useful
98 // $rcmail->imap->set_flag($uids, 'ARCHIVE');
100 if (($archive_mbox = $rcmail->config->get('archive_mbox')) && $mbox != $archive_mbox) {
101 $rcmail->output->command('move_messages', $archive_mbox);
102 $rcmail->output->command('display_message', $this->gettext('archived'), 'confirmation');
105 $rcmail->output->send();
108 function prefs_table($args)
110 if ($args['section'] == 'folders') {
111 $this->add_texts('localization');
113 $rcmail = rcmail::get_instance();
114 $select = rcmail_mailbox_select(array('noselection' => '---', 'realnames' => true, 'maxlength' => 30));
116 $args['blocks']['main']['options']['archive_mbox'] = array(
117 'title' => $this->gettext('archivefolder'),
118 'content' => $select->show($rcmail->config->get('archive_mbox'), array('name' => "_archive_mbox"))
125 function save_prefs($args)
127 if ($args['section'] == 'folders') {
128 $args['prefs']['archive_mbox'] = get_input_value('_archive_mbox', RCUBE_INPUT_POST);