]> git.donarmstrong.com Git - roundcube.git/blob - plugins/archive/archive.php
Imported Upstream version 0.3
[roundcube.git] / plugins / archive / archive.php
1 <?php
2
3 /**
4  * Archive
5  *
6  * Plugin that adds a new button to the mailbox toolbar
7  * to move messages to a (user selectable) archive folder.
8  *
9  * @version 1.4
10  * @author Andre Rodier, Thomas Bruederli
11  */
12 class archive extends rcube_plugin
13 {
14   public $task = 'mail|settings';
15
16   function init()
17   {
18     $this->register_action('plugin.archive', array($this, 'request_action'));
19
20     # There is no "Archived flags"
21     # $GLOBALS['IMAP_FLAGS']['ARCHIVED'] = 'Archive';
22     
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);
27       $this->add_button(
28         array(
29             'command' => 'plugin.archive',
30             'imagepas' => 'archive_pas.png',
31             'imageact' => 'archive_act.png',
32             'title' => 'buttontitle',
33             'domain' => $this->ID,
34         ),
35         'toolbar');
36       
37       // register hook to localize the archive folder
38       $this->add_hook('render_mailboxlist', array($this, 'render_mailboxlist'));
39
40       // set env variable for client
41       $rcmail->output->set_env('archive_folder', $archive_folder);
42
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);
47       }
48       
49     }
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'));
55       }
56     }
57   }
58   
59   function render_mailboxlist($p)
60   {
61     $rcmail = rcmail::get_instance();
62     $archive_folder = $rcmail->config->get('archive_mbox');
63
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'));
70     }
71
72     return $p;
73   }
74
75   function _mod_folder_name(&$list, $folder, $new_name)
76   {
77     foreach ($list as $idx => $item) {
78       if ($item['id'] == $folder) {
79         $list[$idx]['name'] = $new_name;
80         return true;
81       } else if (!empty($item['folders']))
82         if ($this->_mod_folder_name($list[$idx]['folders'], $folder, $new_name))
83           return true;
84     }
85     return false;
86   }
87
88   function request_action()
89   {
90     $this->add_texts('localization');
91     
92     $uids = get_input_value('_uid', RCUBE_INPUT_POST);
93     $mbox = get_input_value('_mbox', RCUBE_INPUT_POST);
94     
95     $rcmail = rcmail::get_instance();
96     
97     // There is no "Archive flags", but I left this line in case it may be useful
98     // $rcmail->imap->set_flag($uids, 'ARCHIVE');
99     
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');
103     }
104     
105     $rcmail->output->send();
106   }
107
108   function prefs_table($args)
109   {
110     if ($args['section'] == 'folders') {
111       $this->add_texts('localization');
112       
113       $rcmail = rcmail::get_instance();
114       $select = rcmail_mailbox_select(array('noselection' => '---', 'realnames' => true, 'maxlength' => 30));
115
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"))
119       );
120     }
121
122     return $args;
123   }
124
125   function save_prefs($args)
126   {
127     if ($args['section'] == 'folders') {
128       $args['prefs']['archive_mbox'] = get_input_value('_archive_mbox', RCUBE_INPUT_POST);
129       return $args;
130     }
131   }
132
133 }