]> git.donarmstrong.com Git - roundcube.git/blob - plugins/archive/archive.php
Imported Upstream version 0.3.1
[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')
25       && ($archive_folder = $rcmail->config->get('archive_mbox'))) {
26
27       $skin_path = $this->local_skin_path();
28       
29       $this->include_script('archive.js');
30       $this->add_texts('localization', true);
31       $this->add_button(
32         array(
33             'command' => 'plugin.archive',
34             'imagepas' => $skin_path.'/archive_pas.png',
35             'imageact' => $skin_path.'/archive_act.png',
36             'title' => 'buttontitle',
37             'domain' => $this->ID,
38         ),
39         'toolbar');
40       
41       // register hook to localize the archive folder
42       $this->add_hook('render_mailboxlist', array($this, 'render_mailboxlist'));
43
44       // set env variable for client
45       $rcmail->output->set_env('archive_folder', $archive_folder);
46       $rcmail->output->set_env('archive_folder_icon', $this->url($skin_path.'/foldericon.png'));
47
48       // add archive folder to the list of default mailboxes
49       if (($default_folders = $rcmail->config->get('default_imap_folders')) && !in_array($archive_folder, $default_folders)) {
50         $default_folders[] = $archive_folder;
51         $rcmail->config->set('default_imap_folders', $default_folders);
52       }  
53     }
54     else if ($rcmail->task == 'settings') {
55       $dont_override = $rcmail->config->get('dont_override', array());
56       if (!in_array('archive_mbox', $dont_override)) {
57         $this->add_hook('user_preferences', array($this, 'prefs_table'));
58         $this->add_hook('save_preferences', array($this, 'save_prefs'));
59       }
60     }
61   }
62   
63   function render_mailboxlist($p)
64   {
65     $rcmail = rcmail::get_instance();
66     $archive_folder = $rcmail->config->get('archive_mbox');
67
68     // set localized name for the configured archive folder
69     if ($archive_folder) {
70       if (isset($p['list'][$archive_folder]))
71         $p['list'][$archive_folder]['name'] = $this->gettext('archivefolder');
72       else // search in subfolders
73         $this->_mod_folder_name($p['list'], $archive_folder, $this->gettext('archivefolder'));
74     }
75
76     return $p;
77   }
78
79   function _mod_folder_name(&$list, $folder, $new_name)
80   {
81     foreach ($list as $idx => $item) {
82       if ($item['id'] == $folder) {
83         $list[$idx]['name'] = $new_name;
84         return true;
85       } else if (!empty($item['folders']))
86         if ($this->_mod_folder_name($list[$idx]['folders'], $folder, $new_name))
87           return true;
88     }
89     return false;
90   }
91
92   function request_action()
93   {
94     $this->add_texts('localization');
95     
96     $uids = get_input_value('_uid', RCUBE_INPUT_POST);
97     $mbox = get_input_value('_mbox', RCUBE_INPUT_POST);
98     
99     $rcmail = rcmail::get_instance();
100     
101     // There is no "Archive flags", but I left this line in case it may be useful
102     // $rcmail->imap->set_flag($uids, 'ARCHIVE');
103     
104     if (($archive_mbox = $rcmail->config->get('archive_mbox')) && $mbox != $archive_mbox) {
105       $rcmail->output->command('move_messages', $archive_mbox);
106       $rcmail->output->command('display_message', $this->gettext('archived'), 'confirmation');
107     }
108     
109     $rcmail->output->send();
110   }
111
112   function prefs_table($args)
113   {
114     if ($args['section'] == 'folders') {
115       $this->add_texts('localization');
116       
117       $rcmail = rcmail::get_instance();
118       $select = rcmail_mailbox_select(array('noselection' => '---', 'realnames' => true,
119         'maxlength' => 30, 'exceptions' => array('INBOX')));
120
121       $args['blocks']['main']['options']['archive_mbox'] = array(
122           'title' => $this->gettext('archivefolder'),
123           'content' => $select->show($rcmail->config->get('archive_mbox'), array('name' => "_archive_mbox"))
124       );
125     }
126
127     return $args;
128   }
129
130   function save_prefs($args)
131   {
132     if ($args['section'] == 'folders') {
133       $args['prefs']['archive_mbox'] = get_input_value('_archive_mbox', RCUBE_INPUT_POST);
134       return $args;
135     }
136   }
137
138 }