]> git.donarmstrong.com Git - roundcube.git/blob - plugins/archive/archive.php
Imported Debian patch 0.5.1+dfsg-7
[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 @package_version@
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     $rcmail = rcmail::get_instance();
19
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();
25       
26       $this->include_script('archive.js');
27       $this->add_texts('localization', true);
28       $this->add_button(
29         array(
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,
35         ),
36         'toolbar');
37       
38       // register hook to localize the archive folder
39       $this->add_hook('render_mailboxlist', array($this, 'render_mailboxlist'));
40
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'));
44
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);
49       }  
50     }
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'));
56       }
57     }
58   }
59   
60   function render_mailboxlist($p)
61   {
62     $rcmail = rcmail::get_instance();
63     $archive_folder = $rcmail->config->get('archive_mbox');
64
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'));
71     }
72
73     return $p;
74   }
75
76   function _mod_folder_name(&$list, $folder, $new_name)
77   {
78     foreach ($list as $idx => $item) {
79       if ($item['id'] == $folder) {
80         $list[$idx]['name'] = $new_name;
81         return true;
82       } else if (!empty($item['folders']))
83         if ($this->_mod_folder_name($list[$idx]['folders'], $folder, $new_name))
84         return true;
85     }
86     return false;
87   }
88
89   function prefs_table($args)
90   {
91     global $CURR_SECTION;
92
93     if ($args['section'] == 'folders') {
94       $this->add_texts('localization');
95
96       $rcmail = rcmail::get_instance();
97
98       // load folders list when needed
99       if ($CURR_SECTION)
100         $select = rcmail_mailbox_select(array('noselection' => '---', 'realnames' => true,
101           'maxlength' => 30, 'exceptions' => array('INBOX')));
102       else
103         $select = new html_select();
104
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"))
108       );
109     }
110
111     return $args;
112   }
113
114   function save_prefs($args)
115   {
116     if ($args['section'] == 'folders') {
117       $args['prefs']['archive_mbox'] = get_input_value('_archive_mbox', RCUBE_INPUT_POST);
118       return $args;
119     }
120   }
121
122 }