summaryrefslogtreecommitdiff
path: root/plugins/archive
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/archive')
-rw-r--r--plugins/archive/archive.js23
-rw-r--r--plugins/archive/archive.php68
-rw-r--r--plugins/archive/composer.json7
-rw-r--r--plugins/archive/package.xml10
4 files changed, 84 insertions, 24 deletions
diff --git a/plugins/archive/archive.js b/plugins/archive/archive.js
index 3500b9fe4..6ed4f971a 100644
--- a/plugins/archive/archive.js
+++ b/plugins/archive/archive.js
@@ -1,6 +1,6 @@
/*
* Archive plugin script
- * @version 2.0
+ * @version 2.1
*/
function rcmail_archive(prop)
@@ -8,29 +8,38 @@ function rcmail_archive(prop)
if (!rcmail.env.uid && (!rcmail.message_list || !rcmail.message_list.get_selection().length))
return;
- if (rcmail.env.mailbox.indexOf(rcmail.env.archive_folder) != 0) {
+ if (!rcmail_is_archive()) {
if (!rcmail.env.archive_type) {
// simply move to archive folder (if no partition type is set)
rcmail.command('move', rcmail.env.archive_folder);
}
else {
// let the server sort the messages to the according subfolders
- var post_data = { _uid: rcmail.message_list.get_selection().join(','), _mbox: rcmail.env.mailbox };
- rcmail.http_post('plugin.move2archive', post_data);
+ rcmail.http_post('plugin.move2archive', rcmail.selection_post_data());
}
}
}
+function rcmail_is_archive()
+{
+ // check if current folder is an archive folder or one of its children
+ if (rcmail.env.mailbox == rcmail.env.archive_folder
+ || rcmail.env.mailbox.startsWith(rcmail.env.archive_folder + rcmail.env.delimiter)
+ ) {
+ return true;
+ }
+}
+
// callback for app-onload event
if (window.rcmail) {
rcmail.addEventListener('init', function(evt) {
// register command (directly enable in message view mode)
- rcmail.register_command('plugin.archive', rcmail_archive, (rcmail.env.uid && rcmail.env.mailbox != rcmail.env.archive_folder));
+ rcmail.register_command('plugin.archive', rcmail_archive, rcmail.env.uid && !rcmail_is_archive());
// add event-listener to message list
if (rcmail.message_list)
rcmail.message_list.addEventListener('select', function(list) {
- rcmail.enable_command('plugin.archive', (list.get_selection().length > 0 && rcmail.env.mailbox != rcmail.env.archive_folder));
+ rcmail.enable_command('plugin.archive', list.get_selection().length > 0 && !rcmail_is_archive());
});
// set css style for archive folder
@@ -41,7 +50,7 @@ if (window.rcmail) {
// callback for server response
rcmail.addEventListener('plugin.move2archive_response', function(result) {
if (result.update)
- rcmail.command('checkmail'); // refresh list
+ rcmail.command('list'); // refresh list
});
})
}
diff --git a/plugins/archive/archive.php b/plugins/archive/archive.php
index 7a81606ab..4a00d5f58 100644
--- a/plugins/archive/archive.php
+++ b/plugins/archive/archive.php
@@ -6,9 +6,9 @@
* Plugin that adds a new button to the mailbox toolbar
* to move messages to a (user selectable) archive folder.
*
- * @version 2.0
+ * @version 2.1
* @license GNU GPLv3+
- * @author Andre Rodier, Thomas Bruederli
+ * @author Andre Rodier, Thomas Bruederli, Aleksander Machniak
*/
class archive extends rcube_plugin
{
@@ -110,19 +110,29 @@ class archive extends rcube_plugin
*/
function move_messages()
{
- $rcmail = rcmail::get_instance();
$this->add_texts('localization');
- $storage = $rcmail->get_storage();
+ $rcmail = rcmail::get_instance();
+ $storage = $rcmail->get_storage();
+ $delimiter = $storage->get_hierarchy_delimiter();
+ $archive_folder = $rcmail->config->get('archive_mbox');
+ $archive_type = $rcmail->config->get('archive_type', '');
+
$storage->set_folder(($current_mbox = rcube_utils::get_input_value('_mbox', RCUBE_INPUT_POST)));
- $delimiter = $storage->get_hierarchy_delimiter();
- $archive_folder = $rcmail->config->get('archive_mbox');
- $archive_type = $rcmail->config->get('archive_type', '');
+ $result = array('reload' => false, 'update' => false, 'errors' => array());
+ $folders = array();
+ $uids = rcube_utils::get_input_value('_uid', RCUBE_INPUT_POST);
+ $search_request = get_input_value('_search', RCUBE_INPUT_GPC);
- $result = array('reload' => false, 'update' => false, 'errors' => array());
+ if ($uids == '*') {
+ $index = $storage->index(null, rcmail_sort_column(), rcmail_sort_order());
+ $uids = $index->get();
+ }
+ else {
+ $uids = explode(',', $uids);
+ }
- $uids = explode(',', rcube_utils::get_input_value('_uid', RCUBE_INPUT_POST));
foreach ($uids as $uid) {
if (!$archive_folder || !($message = $rcmail->storage->get_message($uid))) {
continue;
@@ -164,12 +174,27 @@ class archive extends rcube_plugin
}
// compose full folder path
- $folder = $archive_folder . ($subfolder ? $delimiter . $subfolder : '');
+ $folder = $archive_folder . ($subfolder ? $delimiter . $subfolder : '');
// create archive subfolder if it doesn't yet exist
- if (!$storage->folder_exists($folder, false)) {
- if ($storage->create_folder($folder, true))
- $result['reload'] = true;
+ // we'll create all folders in the path
+ if (!in_array($folder, $folders)) {
+ if (empty($list)) {
+ $list = $storage->list_folders('', $archive_folder . '*', 'mail', null, true);
+ }
+ $path = explode($delimiter, $folder);
+
+ for ($i=0; $i<count($path); $i++) {
+ $_folder = implode($delimiter, array_slice($path, 0, $i+1));
+ if (!in_array($_folder, $list)) {
+ if ($storage->create_folder($_folder, true)) {
+ $result['reload'] = true;
+ $list[] = $_folder;
+ }
+ }
+ }
+
+ $folders[] = $folder;
}
// move message to target folder
@@ -192,7 +217,22 @@ class archive extends rcube_plugin
$rcmail->output->show_message($this->gettext('archived'), 'confirmation');
}
- $rcmail->output->command('plugin.move2archive_response', $result);
+ // refresh saved search set after moving some messages
+ if ($search_request && $rcmail->storage->get_search_set()) {
+ $_SESSION['search'] = $rcmail->storage->refresh_search();
+ }
+
+ if ($_POST['_from'] == 'show' && !empty($result['update'])) {
+ if ($next = get_input_value('_next_uid', RCUBE_INPUT_GPC)) {
+ $rcmail->output->command('show_message', $next);
+ }
+ else {
+ $rcmail->output->command('command', 'list');
+ }
+ }
+ else {
+ $rcmail->output->command('plugin.move2archive_response', $result);
+ }
}
/**
diff --git a/plugins/archive/composer.json b/plugins/archive/composer.json
index 7826545b8..8a585ad09 100644
--- a/plugins/archive/composer.json
+++ b/plugins/archive/composer.json
@@ -3,12 +3,17 @@
"type": "roundcube-plugin",
"description": "This adds a button to move the selected messages to an archive folder. The folder (and the optional structure of subfolders) can be selected in the settings panel.",
"license": "GNU GPLv3+",
- "version": "2.0",
+ "version": "2.1",
"authors": [
{
"name": "Thomas Bruederli",
"email": "roundcube@gmail.com",
"role": "Lead"
+ },
+ {
+ "name": "Aleksander Machniak",
+ "email": "alec@alec.pl",
+ "role": "Developer"
}
],
"repositories": [
diff --git a/plugins/archive/package.xml b/plugins/archive/package.xml
index 62a009a99..ec3323e4b 100644
--- a/plugins/archive/package.xml
+++ b/plugins/archive/package.xml
@@ -13,9 +13,15 @@
<email>roundcube@gmail.com</email>
<active>yes</active>
</lead>
- <date>2013-01-20</date>
+ <lead>
+ <name>Aleksander Machniak</name>
+ <user>alec</user>
+ <email>alec@alec.pl</email>
+ <active>yes</active>
+ </lead>
+ <date>2013-10-30</date>
<version>
- <release>2.0</release>
+ <release>2.1</release>
<api>2.0</api>
</version>
<stability>