annotate plugins/archive/archive.php @ 38:ac106d4c8961 default tip

flip /etc/roundcube to point here
author Charlie Root
date Sat, 29 Dec 2018 05:39:53 -0500
parents 1e000243b222
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1 <?php
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4 * Archive
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6 * Plugin that adds a new button to the mailbox toolbar
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7 * to move messages to a (user selectable) archive folder.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9 * @version 3.0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
10 * @license GNU GPLv3+
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
11 * @author Andre Rodier, Thomas Bruederli, Aleksander Machniak
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
12 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
13 class archive extends rcube_plugin
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
14 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
15 public $task = 'settings|mail';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
16
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
17
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
18 function init()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
19 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
20 $rcmail = rcmail::get_instance();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
21
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
22 // register special folder type
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
23 rcube_storage::$folder_types[] = 'archive';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
24
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
25 if ($rcmail->task == 'mail' && ($rcmail->action == '' || $rcmail->action == 'show')
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
26 && ($archive_folder = $rcmail->config->get('archive_mbox'))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
27 ) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
28 $skin_path = $this->local_skin_path();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
29 if (is_file($this->home . "/$skin_path/archive.css")) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
30 $this->include_stylesheet("$skin_path/archive.css");
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
31 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
32
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
33 $this->include_script('archive.js');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
34 $this->add_texts('localization', true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
35 $this->add_button(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
36 array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
37 'type' => 'link',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
38 'label' => 'buttontext',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
39 'command' => 'plugin.archive',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
40 'class' => 'button buttonPas archive disabled',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
41 'classact' => 'button archive',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
42 'width' => 32,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
43 'height' => 32,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
44 'title' => 'buttontitle',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
45 'domain' => $this->ID,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
46 ),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
47 'toolbar');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
48
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
49 // register hook to localize the archive folder
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
50 $this->add_hook('render_mailboxlist', array($this, 'render_mailboxlist'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
51
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
52 // set env variables for client
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
53 $rcmail->output->set_env('archive_folder', $archive_folder);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
54 $rcmail->output->set_env('archive_type', $rcmail->config->get('archive_type',''));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
55 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
56 else if ($rcmail->task == 'mail') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
57 // handler for ajax request
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
58 $this->register_action('plugin.move2archive', array($this, 'move_messages'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
59 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
60 else if ($rcmail->task == 'settings') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
61 $this->add_hook('preferences_list', array($this, 'prefs_table'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
62 $this->add_hook('preferences_save', array($this, 'save_prefs'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
63 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
64 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
65
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
66 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
67 * Hook to give the archive folder a localized name in the mailbox list
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
68 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
69 function render_mailboxlist($p)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
70 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
71 $rcmail = rcmail::get_instance();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
72 $archive_folder = $rcmail->config->get('archive_mbox');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
73 $show_real_name = $rcmail->config->get('show_real_foldernames');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
74
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
75 // set localized name for the configured archive folder
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
76 if ($archive_folder && !$show_real_name) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
77 if (isset($p['list'][$archive_folder])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
78 $p['list'][$archive_folder]['name'] = $this->gettext('archivefolder');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
79 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
80 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
81 // search in subfolders
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
82 $this->_mod_folder_name($p['list'], $archive_folder, $this->gettext('archivefolder'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
83 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
84 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
85
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
86 return $p;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
87 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
88
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
89 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
90 * Helper method to find the archive folder in the mailbox tree
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
91 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
92 private function _mod_folder_name(&$list, $folder, $new_name)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
93 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
94 foreach ($list as $idx => $item) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
95 if ($item['id'] == $folder) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
96 $list[$idx]['name'] = $new_name;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
97 return true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
98 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
99 else if (!empty($item['folders'])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
100 if ($this->_mod_folder_name($list[$idx]['folders'], $folder, $new_name)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
101 return true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
102 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
103 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
104 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
105
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
106 return false;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
107 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
108
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
109 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
110 * Plugin action to move the submitted list of messages to the archive subfolders
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
111 * according to the user settings and their headers.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
112 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
113 function move_messages()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
114 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
115 $rcmail = rcmail::get_instance();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
116
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
117 // only process ajax requests
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
118 if (!$rcmail->output->ajax_call) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
119 return;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
120 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
121
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
122 $this->add_texts('localization');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
123
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
124 $storage = $rcmail->get_storage();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
125 $delimiter = $storage->get_hierarchy_delimiter();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
126 $read_on_move = (bool) $rcmail->config->get('read_on_archive');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
127 $archive_type = $rcmail->config->get('archive_type', '');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
128 $archive_folder = $rcmail->config->get('archive_mbox');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
129 $archive_prefix = $archive_folder . $delimiter;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
130 $current_mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
131 $search_request = rcube_utils::get_input_value('_search', rcube_utils::INPUT_GPC);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
132 $uids = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
133
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
134 // count messages before changing anything
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
135 if ($_POST['_from'] != 'show') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
136 $threading = (bool) $storage->get_threading();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
137 $old_count = $storage->count(null, $threading ? 'THREADS' : 'ALL');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
138 $old_pages = ceil($old_count / $storage->get_pagesize());
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
139 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
140
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
141 $count = 0;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
142
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
143 // this way response handler for 'move' action will be executed
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
144 $rcmail->action = 'move';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
145 $this->result = array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
146 'reload' => false,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
147 'error' => false,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
148 'sources' => array(),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
149 'destinations' => array(),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
150 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
151
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
152 foreach (rcmail::get_uids(null, null, $multifolder) as $mbox => $uids) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
153 if (!$archive_folder || strpos($mbox, $archive_prefix) === 0) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
154 $count = count($uids);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
155 continue;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
156 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
157 else if (!$archive_type || $archive_type == 'folder') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
158 $folder = $archive_folder;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
159
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
160 if ($archive_type == 'folder') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
161 // compose full folder path
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
162 $folder .= $delimiter . $mbox;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
163
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
164 // create archive subfolder if it doesn't yet exist
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
165 $this->subfolder_worker($folder);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
166 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
167
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
168 $count += $this->move_messages_worker($uids, $mbox, $folder, $read_on_move);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
169 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
170 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
171 if ($uids == '*') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
172 $index = $storage->index(null, rcmail_sort_column(), rcmail_sort_order());
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
173 $uids = $index->get();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
174 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
175
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
176 $messages = $storage->fetch_headers($mbox, $uids);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
177 $execute = array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
178
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
179 foreach ($messages as $message) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
180 $subfolder = null;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
181 switch ($archive_type) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
182 case 'year':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
183 $subfolder = $rcmail->format_date($message->timestamp, 'Y');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
184 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
185
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
186 case 'month':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
187 $subfolder = $rcmail->format_date($message->timestamp, 'Y')
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
188 . $delimiter . $rcmail->format_date($message->timestamp, 'm');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
189 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
190
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
191 case 'sender':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
192 $from = $message->get('from');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
193 preg_match('/[\b<](.+@.+)[\b>]/i', $from, $m);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
194 $subfolder = $m[1] ?: $this->gettext('unkownsender');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
195
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
196 // replace reserved characters in folder name
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
197 $repl = $delimiter == '-' ? '_' : '-';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
198 $replacements[$delimiter] = $repl;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
199 $replacements['.'] = $repl; // some IMAP server do not allow . characters
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
200 $subfolder = strtr($subfolder, $replacements);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
201 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
202 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
203
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
204 // compose full folder path
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
205 $folder = $archive_folder . ($subfolder ? $delimiter . $subfolder : '');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
206
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
207 $execute[$folder][] = $message->uid;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
208 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
209
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
210 foreach ($execute as $folder => $uids) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
211 // create archive subfolder if it doesn't yet exist
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
212 $this->subfolder_worker($folder);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
213
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
214 $count += $this->move_messages_worker($uids, $mbox, $folder, $read_on_move);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
215 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
216 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
217 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
218
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
219 if ($this->result['error']) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
220 if ($_POST['_from'] != 'show') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
221 $rcmail->output->command('list_mailbox');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
222 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
223
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
224 $rcmail->output->show_message($this->gettext('archiveerror'), 'warning');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
225 $rcmail->output->send();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
226 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
227
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
228 if (!empty($_POST['_refresh'])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
229 // FIXME: send updated message rows instead of reloading the entire list
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
230 $rcmail->output->command('refresh_list');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
231 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
232 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
233 $addrows = true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
234 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
235
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
236 // refresh saved search set after moving some messages
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
237 if ($search_request && $rcmail->storage->get_search_set()) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
238 $_SESSION['search'] = $rcmail->storage->refresh_search();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
239 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
240
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
241 if ($_POST['_from'] == 'show') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
242 if ($next = rcube_utils::get_input_value('_next_uid', rcube_utils::INPUT_GPC)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
243 $rcmail->output->command('show_message', $next);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
244 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
245 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
246 $rcmail->output->command('command', 'list');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
247 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
248
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
249 $rcmail->output->send();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
250 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
251
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
252 $mbox = $storage->get_folder();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
253 $msg_count = $storage->count(null, $threading ? 'THREADS' : 'ALL');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
254 $exists = $storage->count($mbox, 'EXISTS', true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
255 $page_size = $storage->get_pagesize();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
256 $page = $storage->get_page();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
257 $pages = ceil($msg_count / $page_size);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
258 $nextpage_count = $old_count - $page_size * $page;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
259 $remaining = $msg_count - $page_size * ($page - 1);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
260
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
261 // jump back one page (user removed the whole last page)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
262 if ($page > 1 && $remaining == 0) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
263 $page -= 1;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
264 $storage->set_page($page);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
265 $_SESSION['page'] = $page;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
266 $jump_back = true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
267 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
268
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
269 // update message count display
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
270 $rcmail->output->set_env('messagecount', $msg_count);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
271 $rcmail->output->set_env('current_page', $page);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
272 $rcmail->output->set_env('pagecount', $pages);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
273 $rcmail->output->set_env('exists', $exists);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
274
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
275 // update mailboxlist
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
276 $unseen_count = $msg_count ? $storage->count($mbox, 'UNSEEN') : 0;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
277 $old_unseen = rcmail_get_unseen_count($mbox);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
278 $quota_root = $multifolder ? $this->result['sources'][0] : 'INBOX';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
279
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
280 if ($old_unseen != $unseen_count) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
281 $rcmail->output->command('set_unread_count', $mbox, $unseen_count, ($mbox == 'INBOX'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
282 rcmail_set_unseen_count($mbox, $unseen_count);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
283 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
284
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
285 $rcmail->output->command('set_quota', $rcmail->quota_content(null, $quota_root));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
286 $rcmail->output->command('set_rowcount', rcmail_get_messagecount_text($msg_count), $mbox);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
287
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
288 if ($threading) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
289 $count = rcube_utils::get_input_value('_count', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
290 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
291
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
292 // add new rows from next page (if any)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
293 if ($addrows && $count && $uids != '*' && ($jump_back || $nextpage_count > 0)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
294 // #5862: Don't add more rows than it was on the next page
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
295 $count = $jump_back ? null : min($nextpage_count, $count);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
296
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
297 $a_headers = $storage->list_messages($mbox, null,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
298 rcmail_sort_column(), rcmail_sort_order(), $count);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
299
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
300 rcmail_js_message_list($a_headers, false);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
301 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
302
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
303 if ($this->result['reload']) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
304 $rcmail->output->show_message($this->gettext('archivedreload'), 'confirmation');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
305 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
306 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
307 $rcmail->output->show_message($this->gettext('archived'), 'confirmation');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
308
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
309 if (!$read_on_move) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
310 foreach ($this->result['destinations'] as $folder) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
311 rcmail_send_unread_count($folder, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
312 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
313 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
314 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
315
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
316 // send response
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
317 $rcmail->output->send();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
318 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
319
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
320 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
321 * Move messages from one folder to another and mark as read if needed
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
322 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
323 private function move_messages_worker($uids, $from_mbox, $to_mbox, $read_on_move)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
324 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
325 $storage = rcmail::get_instance()->get_storage();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
326
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
327 if ($read_on_move) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
328 // don't flush cache (4th argument)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
329 $storage->set_flag($uids, 'SEEN', $from_mbox, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
330 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
331
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
332 // move message to target folder
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
333 if ($storage->move_message($uids, $to_mbox, $from_mbox)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
334 if (!in_array($from_mbox, $this->result['sources'])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
335 $this->result['sources'][] = $from_mbox;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
336 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
337 if (!in_array($to_mbox, $this->result['destinations'])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
338 $this->result['destinations'][] = $to_mbox;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
339 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
340
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
341 return count($uids);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
342 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
343
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
344 $this->result['error'] = true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
345 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
346
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
347 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
348 * Create archive subfolder if it doesn't yet exist
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
349 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
350 private function subfolder_worker($folder)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
351 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
352 $storage = rcmail::get_instance()->get_storage();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
353 $delimiter = $storage->get_hierarchy_delimiter();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
354
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
355 if ($this->folders === null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
356 $this->folders = $storage->list_folders('', $archive_folder . '*', 'mail', null, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
357 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
358
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
359 if (!in_array($folder, $this->folders)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
360 $path = explode($delimiter, $folder);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
361
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
362 // we'll create all folders in the path
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
363 for ($i=0; $i<count($path); $i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
364 $_folder = implode($delimiter, array_slice($path, 0, $i+1));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
365 if (!in_array($_folder, $this->folders)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
366 if ($storage->create_folder($_folder, true)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
367 $this->result['reload'] = true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
368 $this->folders[] = $_folder;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
369 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
370 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
371 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
372 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
373 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
374
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
375 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
376 * Hook to inject plugin-specific user settings
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
377 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
378 function prefs_table($args)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
379 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
380 global $CURR_SECTION;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
381
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
382 $this->add_texts('localization');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
383
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
384 $rcmail = rcmail::get_instance();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
385 $dont_override = $rcmail->config->get('dont_override', array());
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
386
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
387 if ($args['section'] == 'folders' && !in_array('archive_mbox', $dont_override)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
388 $mbox = $rcmail->config->get('archive_mbox');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
389 $type = $rcmail->config->get('archive_type');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
390
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
391 // load folders list when needed
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
392 if ($CURR_SECTION) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
393 $select = $rcmail->folder_selector(array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
394 'noselection' => '---',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
395 'realnames' => true,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
396 'maxlength' => 30,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
397 'folder_filter' => 'mail',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
398 'folder_rights' => 'w',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
399 'onchange' => "if ($(this).val() == 'INBOX') $(this).val('')",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
400 ));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
401 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
402 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
403 $select = new html_select();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
404 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
405
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
406 $args['blocks']['main']['options']['archive_mbox'] = array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
407 'title' => $this->gettext('archivefolder'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
408 'content' => $select->show($mbox, array('name' => "_archive_mbox"))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
409 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
410
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
411 // add option for structuring the archive folder
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
412 $archive_type = new html_select(array('name' => '_archive_type', 'id' => 'ff_archive_type'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
413 $archive_type->add($this->gettext('none'), '');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
414 $archive_type->add($this->gettext('archivetypeyear'), 'year');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
415 $archive_type->add($this->gettext('archivetypemonth'), 'month');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
416 $archive_type->add($this->gettext('archivetypesender'), 'sender');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
417 $archive_type->add($this->gettext('archivetypefolder'), 'folder');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
418
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
419 $args['blocks']['archive'] = array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
420 'name' => rcube::Q($this->gettext('settingstitle')),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
421 'options' => array('archive_type' => array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
422 'title' => $this->gettext('archivetype'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
423 'content' => $archive_type->show($type)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
424 )
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
425 )
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
426 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
427 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
428 else if ($args['section'] == 'server' && !in_array('read_on_archive', $dont_override)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
429 $chbox = new html_checkbox(array('name' => '_read_on_archive', 'id' => 'ff_read_on_archive', 'value' => 1));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
430 $args['blocks']['main']['options']['read_on_archive'] = array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
431 'title' => $this->gettext('readonarchive'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
432 'content' => $chbox->show($rcmail->config->get('read_on_archive') ? 1 : 0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
433 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
434 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
435
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
436 return $args;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
437 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
438
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
439 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
440 * Hook to save plugin-specific user settings
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
441 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
442 function save_prefs($args)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
443 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
444 $rcmail = rcmail::get_instance();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
445 $dont_override = $rcmail->config->get('dont_override', array());
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
446
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
447 if ($args['section'] == 'folders' && !in_array('archive_mbox', $dont_override)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
448 $args['prefs']['archive_type'] = rcube_utils::get_input_value('_archive_type', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
449 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
450 else if ($args['section'] == 'server' && !in_array('read_on_archive', $dont_override)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
451 $args['prefs']['read_on_archive'] = (bool) rcube_utils::get_input_value('_read_on_archive', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
452 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
453
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
454 return $args;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
455 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
456 }