alecpl
2009-10-06 ffeab7fe7e0ccf1d458d6a863600359c38769950
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   {
18     $this->register_action('plugin.archive', array($this, 'request_action'));
19
34aec7 20     // There is no "Archived flags"
A 21     // $GLOBALS['IMAP_FLAGS']['ARCHIVED'] = 'Archive';
85c812 22     
T 23     $rcmail = rcmail::get_instance();
34aec7 24     if ($rcmail->task == 'mail' && ($rcmail->action == '' || $rcmail->action == 'show')
A 25       && ($archive_folder = $rcmail->config->get('archive_mbox'))) {
26
27       $skin_path = 'skins/'.$rcmail->output->config['skin'];
28
85c812 29       $this->include_script('archive.js');
T 30       $this->add_texts('localization', true);
31       $this->add_button(
32         array(
33             'command' => 'plugin.archive',
34aec7 34             'imagepas' => $skin_path.'/archive_pas.png',
A 35             'imageact' => $skin_path.'/archive_act.png',
85c812 36             'title' => 'buttontitle',
T 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);
34aec7 46       $rcmail->output->set_env('archive_folder_icon', $this->url($skin_path.'/foldericon.png'));
85c812 47
516cc4 48       // add archive folder to the list of default mailboxes
85c812 49       if (($default_folders = $rcmail->config->get('default_imap_folders')) && !in_array($archive_folder, $default_folders)) {
T 50         $default_folders[] = $archive_folder;
51         $rcmail->config->set('default_imap_folders', $default_folders);
34aec7 52       }  
85c812 53     }
T 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');
516cc4 67
A 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
85c812 76     return $p;
516cc4 77   }
A 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;
85c812 90   }
T 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     
516cc4 101     // There is no "Archive flags", but I left this line in case it may be useful
A 102     // $rcmail->imap->set_flag($uids, 'ARCHIVE');
85c812 103     
T 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();
93a88c 118       $select = rcmail_mailbox_select(array('noselection' => '---', 'realnames' => true,
A 119         'maxlength' => 30, 'exceptions' => array('INBOX')));
85c812 120
T 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   {
16506f 132     if ($args['section'] == 'folders') {
T 133       $args['prefs']['archive_mbox'] = get_input_value('_archive_mbox', RCUBE_INPUT_POST);
134       return $args;
135     }
85c812 136   }
T 137
138 }