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