commit | author | age
|
48e9c1
|
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 @package_version@ |
|
10 |
* @license GNU GPLv3+ |
|
11 |
* @author Andre Rodier, Thomas Bruederli |
|
12 |
*/ |
|
13 |
class archive extends rcube_plugin |
|
14 |
{ |
|
15 |
public $task = 'mail|settings'; |
|
16 |
|
|
17 |
function init() |
|
18 |
{ |
|
19 |
$rcmail = rcmail::get_instance(); |
|
20 |
|
|
21 |
// There is no "Archived flags" |
|
22 |
// $GLOBALS['IMAP_FLAGS']['ARCHIVED'] = 'Archive'; |
|
23 |
if ($rcmail->task == 'mail' && ($rcmail->action == '' || $rcmail->action == 'show') |
|
24 |
&& ($archive_folder = $rcmail->config->get('archive_mbox'))) { |
|
25 |
$skin_path = $this->local_skin_path(); |
|
26 |
if (is_file($this->home . "/$skin_path/archive.css")) |
|
27 |
$this->include_stylesheet("$skin_path/archive.css"); |
|
28 |
|
|
29 |
$this->include_script('archive.js'); |
|
30 |
$this->add_texts('localization', true); |
|
31 |
$this->add_button( |
|
32 |
array( |
|
33 |
'type' => 'link', |
|
34 |
'label' => 'buttontext', |
|
35 |
'command' => 'plugin.archive', |
|
36 |
'class' => 'button buttonPas archive disabled', |
|
37 |
'classact' => 'button archive', |
|
38 |
'width' => 32, |
|
39 |
'height' => 32, |
|
40 |
'title' => 'buttontitle', |
|
41 |
'domain' => $this->ID, |
|
42 |
), |
|
43 |
'toolbar'); |
|
44 |
|
|
45 |
// register hook to localize the archive folder |
|
46 |
$this->add_hook('render_mailboxlist', array($this, 'render_mailboxlist')); |
|
47 |
|
|
48 |
// set env variable for client |
|
49 |
$rcmail->output->set_env('archive_folder', $archive_folder); |
|
50 |
|
|
51 |
// add archive folder to the list of default mailboxes |
|
52 |
if (($default_folders = $rcmail->config->get('default_folders')) && !in_array($archive_folder, $default_folders)) { |
|
53 |
$default_folders[] = $archive_folder; |
|
54 |
$rcmail->config->set('default_folders', $default_folders); |
|
55 |
} |
|
56 |
} |
|
57 |
else if ($rcmail->task == 'settings') { |
|
58 |
$dont_override = $rcmail->config->get('dont_override', array()); |
|
59 |
if (!in_array('archive_mbox', $dont_override)) { |
|
60 |
$this->add_hook('preferences_list', array($this, 'prefs_table')); |
|
61 |
$this->add_hook('preferences_save', array($this, 'save_prefs')); |
|
62 |
} |
|
63 |
} |
|
64 |
} |
|
65 |
|
|
66 |
function render_mailboxlist($p) |
|
67 |
{ |
|
68 |
$rcmail = rcmail::get_instance(); |
|
69 |
$archive_folder = $rcmail->config->get('archive_mbox'); |
|
70 |
|
|
71 |
// set localized name for the configured archive folder |
|
72 |
if ($archive_folder) { |
|
73 |
if (isset($p['list'][$archive_folder])) |
|
74 |
$p['list'][$archive_folder]['name'] = $this->gettext('archivefolder'); |
|
75 |
else // search in subfolders |
|
76 |
$this->_mod_folder_name($p['list'], $archive_folder, $this->gettext('archivefolder')); |
|
77 |
} |
|
78 |
|
|
79 |
return $p; |
|
80 |
} |
|
81 |
|
|
82 |
function _mod_folder_name(&$list, $folder, $new_name) |
|
83 |
{ |
|
84 |
foreach ($list as $idx => $item) { |
|
85 |
if ($item['id'] == $folder) { |
|
86 |
$list[$idx]['name'] = $new_name; |
|
87 |
return true; |
|
88 |
} else if (!empty($item['folders'])) |
|
89 |
if ($this->_mod_folder_name($list[$idx]['folders'], $folder, $new_name)) |
|
90 |
return true; |
|
91 |
} |
|
92 |
return false; |
|
93 |
} |
|
94 |
|
|
95 |
function prefs_table($args) |
|
96 |
{ |
|
97 |
global $CURR_SECTION; |
|
98 |
|
|
99 |
if ($args['section'] == 'folders') { |
|
100 |
$this->add_texts('localization'); |
|
101 |
|
|
102 |
$rcmail = rcmail::get_instance(); |
|
103 |
|
|
104 |
// load folders list when needed |
|
105 |
if ($CURR_SECTION) |
|
106 |
$select = rcmail_mailbox_select(array('noselection' => '---', 'realnames' => true, |
|
107 |
'maxlength' => 30, 'exceptions' => array('INBOX'), 'folder_filter' => 'mail', 'folder_rights' => 'w')); |
|
108 |
else |
|
109 |
$select = new html_select(); |
|
110 |
|
|
111 |
$args['blocks']['main']['options']['archive_mbox'] = array( |
|
112 |
'title' => $this->gettext('archivefolder'), |
|
113 |
'content' => $select->show($rcmail->config->get('archive_mbox'), array('name' => "_archive_mbox")) |
|
114 |
); |
|
115 |
} |
|
116 |
|
|
117 |
return $args; |
|
118 |
} |
|
119 |
|
|
120 |
function save_prefs($args) |
|
121 |
{ |
|
122 |
if ($args['section'] == 'folders') { |
|
123 |
$args['prefs']['archive_mbox'] = get_input_value('_archive_mbox', RCUBE_INPUT_POST); |
|
124 |
return $args; |
|
125 |
} |
|
126 |
} |
|
127 |
|
|
128 |
} |