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',
33 'title' => 'buttontitle',
34 'domain' => $this->ID,
38 // register hook to localize the archive folder
39 $this->add_hook('render_mailboxlist', array($this, 'render_mailboxlist'));
41 // set env variable for client
42 $rcmail->output->set_env('archive_folder', $archive_folder);
43 $rcmail->output->set_env('archive_folder_icon', $this->url($skin_path.'/foldericon.png'));
45 // add archive folder to the list of default mailboxes
46 if (($default_folders = $rcmail->config->get('default_imap_folders')) && !in_array($archive_folder, $default_folders)) {
47 $default_folders[] = $archive_folder;
48 $rcmail->config->set('default_imap_folders', $default_folders);
51 else if ($rcmail->task == 'settings') {
52 $dont_override = $rcmail->config->get('dont_override', array());
53 if (!in_array('archive_mbox', $dont_override)) {
54 $this->add_hook('preferences_list', array($this, 'prefs_table'));
55 $this->add_hook('preferences_save', array($this, 'save_prefs'));
60 function render_mailboxlist($p)
62 $rcmail = rcmail::get_instance();
63 $archive_folder = $rcmail->config->get('archive_mbox');
65 // set localized name for the configured archive folder
66 if ($archive_folder) {
67 if (isset($p['list'][$archive_folder]))
68 $p['list'][$archive_folder]['name'] = $this->gettext('archivefolder');
69 else // search in subfolders
70 $this->_mod_folder_name($p['list'], $archive_folder, $this->gettext('archivefolder'));
76 function _mod_folder_name(&$list, $folder, $new_name)
78 foreach ($list as $idx => $item) {
79 if ($item['id'] == $folder) {
80 $list[$idx]['name'] = $new_name;
82 } else if (!empty($item['folders']))
83 if ($this->_mod_folder_name($list[$idx]['folders'], $folder, $new_name))
89 function prefs_table($args)
93 if ($args['section'] == 'folders') {
94 $this->add_texts('localization');
96 $rcmail = rcmail::get_instance();
98 // load folders list when needed
100 $select = rcmail_mailbox_select(array('noselection' => '---', 'realnames' => true,
101 'maxlength' => 30, 'exceptions' => array('INBOX')));
103 $select = new html_select();
105 $args['blocks']['main']['options']['archive_mbox'] = array(
106 'title' => $this->gettext('archivefolder'),
107 'content' => $select->show($rcmail->config->get('archive_mbox'), array('name' => "_archive_mbox"))
114 function save_prefs($args)
116 if ($args['section'] == 'folders') {
117 $args['prefs']['archive_mbox'] = get_input_value('_archive_mbox', RCUBE_INPUT_POST);