summaryrefslogtreecommitdiff
path: root/roundcubemail/program
diff options
context:
space:
mode:
authorNathan Kinkade <nkinkade@nkinka.de>2009-03-05 21:11:55 +0000
committerNathan Kinkade <nkinkade@nkinka.de>2009-03-11 12:51:51 +0000
commit8fd923e70c08c103a3b9aa644431e4ee8cd0b330 (patch)
treec69344a978609e5b7a92d8de4d30380bfb878bd3 /roundcubemail/program
parentbc3c5f3f9922ae33c3f0077b71650ec5749d72dc (diff)
Added functionality to copy messages from one mailbox to another.
Diffstat (limited to 'roundcubemail/program')
-rw-r--r--roundcubemail/program/include/rcube_imap.php39
-rw-r--r--roundcubemail/program/js/app.js30
-rw-r--r--roundcubemail/program/steps/mail/copy.inc96
3 files changed, 164 insertions, 1 deletions
diff --git a/roundcubemail/program/include/rcube_imap.php b/roundcubemail/program/include/rcube_imap.php
index 788b0ff58..2f3a49cb1 100644
--- a/roundcubemail/program/include/rcube_imap.php
+++ b/roundcubemail/program/include/rcube_imap.php
@@ -1758,6 +1758,45 @@ class rcube_imap
return $moved;
}
+ /**
+ * Copy a message from one mailbox to another
+ *
+ * @param string List of UIDs to move, separated by comma
+ * @param string Target mailbox
+ * @param string Source mailbox
+ * @return boolean True on success, False on error
+ */
+ function copy_message($uids, $to_mbox, $from_mbox='')
+ {
+ $to_mbox = $this->_mod_mailbox($to_mbox);
+ $from_mbox = $from_mbox ? $this->_mod_mailbox($from_mbox) : $this->mailbox;
+
+ // make sure mailbox exists
+ if ($to_mbox != 'INBOX' && !in_array($to_mbox, $this->_list_mailboxes()))
+ {
+ if (in_array($to_mbox_in, $this->default_folders))
+ $this->create_mailbox($to_mbox_in, TRUE);
+ else
+ return FALSE;
+ }
+
+ // convert the list of uids to array
+ $a_uids = is_string($uids) ? explode(',', $uids) : (is_array($uids) ? $uids : NULL);
+
+ // exit if no message uids are specified
+ if (!is_array($a_uids))
+ return false;
+
+ // convert uids to message ids
+ $a_mids = array();
+ foreach ($a_uids as $uid)
+ $a_mids[] = $this->_uid2id($uid, $from_mbox);
+
+ $iil_copy = iil_C_Copy($this->conn, join(',', $a_mids), $from_mbox, $to_mbox);
+ $copied = !($iil_copy === false || $iil_copy < 0);
+
+ return $copied;
+ }
/**
* Mark messages as deleted and expunge mailbox
diff --git a/roundcubemail/program/js/app.js b/roundcubemail/program/js/app.js
index 03984427d..fbe1dcd75 100644
--- a/roundcubemail/program/js/app.js
+++ b/roundcubemail/program/js/app.js
@@ -160,7 +160,7 @@ function rcube_webmail()
if (this.env.action=='show' || this.env.action=='preview')
{
- this.enable_command('show', 'reply', 'reply-all', 'forward', 'moveto', 'delete', 'mark', 'viewsource', 'print', 'load-attachment', 'load-headers', true);
+ this.enable_command('show', 'reply', 'reply-all', 'forward', 'moveto', 'copyto', 'delete', 'mark', 'viewsource', 'print', 'load-attachment', 'load-headers', true);
if (this.env.next_uid)
{
this.enable_command('nextmessage', true);
@@ -725,6 +725,11 @@ function rcube_webmail()
this.copy_contact(null, props);
break;
+ case 'copyto':
+ if (this.task == 'mail')
+ this.copy_messages(props);
+ break;
+
case 'mark':
if (props)
this.mark_message(props);
@@ -1752,6 +1757,29 @@ function rcube_webmail()
this._with_selected_messages('moveto', lock, add_url, (this.env.flag_for_deletion ? false : true));
};
+ // copy selected messages to the specified mailbox
+ this.copy_messages = function(mbox)
+ {
+ // exit if current or no mailbox specified or if selection is empty
+ if (!mbox || mbox == this.env.mailbox || (!this.env.uid && (!this.message_list || !this.message_list.get_selection().length)))
+ return;
+
+ var lock = false;
+ var add_url = '&_target_mbox='+urlencode(mbox)+'&_from='+(this.env.action ? this.env.action : '');
+
+ // show wait message
+ if (this.env.action=='show')
+ {
+ lock = true;
+ this.set_busy(true, 'copyingmessage');
+ }
+
+ // Hide message command buttons until a message is selected
+ this.enable_command('reply', 'reply-all', 'forward', 'delete', 'mark', 'print', false);
+
+ this._with_selected_messages('copyto', lock, add_url, false);
+ };
+
// delete selected messages from the current mailbox
this.delete_messages = function()
{
diff --git a/roundcubemail/program/steps/mail/copy.inc b/roundcubemail/program/steps/mail/copy.inc
new file mode 100644
index 000000000..247f6d96c
--- /dev/null
+++ b/roundcubemail/program/steps/mail/copy.inc
@@ -0,0 +1,96 @@
+<?php
+
+/*
+ +-----------------------------------------------------------------------+
+ | program/steps/mail/move_del.inc |
+ | |
+ | This file is part of the RoundCube Webmail client |
+ | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland |
+ | Licensed under the GNU GPL |
+ | |
+ | PURPOSE: |
+ | Move the submitted messages to a specific mailbox or delete them |
+ | |
+ +-----------------------------------------------------------------------+
+ | Author: Thomas Bruederli <roundcube@gmail.com> |
+ +-----------------------------------------------------------------------+
+
+ $Id: move_del.inc 2018 2008-10-27 10:53:56Z alec $
+
+*/
+
+// count messages before changing anything
+$old_count = $IMAP->messagecount(NULL, rcmail::get_instance()->imap->threading?'THREADS':'ALL');
+$old_pages = ceil($old_count / $IMAP->page_size);
+
+// copy messages
+if ($RCMAIL->action=='copyto' && !empty($_POST['_uid']) && !empty($_POST['_target_mbox'])) {
+ $count = sizeof(explode(',', ($uids = get_input_value('_uid', RCUBE_INPUT_POST))));
+ $target = get_input_value('_target_mbox', RCUBE_INPUT_POST);
+ $mbox = get_input_value('_mbox', RCUBE_INPUT_POST);
+
+ $moved = $IMAP->copy_message($uids, $target, $mbox);
+
+ if (!$moved) {
+ // send error message
+ $OUTPUT->command('list_mailbox');
+ $OUTPUT->show_message('errormoving', 'error');
+ $OUTPUT->send();
+ exit;
+ }
+
+}
+// unknown action or missing query param
+else {
+ exit;
+}
+// refresh saved search set after moving some messages
+if (($search_request = get_input_value('_search', RCUBE_INPUT_GPC)) && $IMAP->search_set) {
+ $_SESSION['search'][$search_request] = $IMAP->refresh_search();
+}
+
+$msg_count = $IMAP->messagecount(NULL, rcmail::get_instance()->imap->threading?'THREADS':'ALL');
+$pages = ceil($msg_count / $IMAP->page_size);
+$nextpage_count = $old_count - $IMAP->page_size * $IMAP->list_page;
+$remaining = $msg_count - $IMAP->page_size * ($IMAP->list_page - 1);
+
+// jump back one page (user removed the whole last page)
+if ($IMAP->list_page > 1 && $nextpage_count <= 0 && $remaining == 0) {
+ $IMAP->set_page($IMAP->list_page-1);
+ $_SESSION['page'] = $IMAP->list_page;
+ $jump_back = true;
+}
+
+// update message count display
+$OUTPUT->set_env('pagecount', $pages);
+$OUTPUT->set_env('messagecount', $msg_count);
+$OUTPUT->set_env('current_page', $IMAP->list_page);
+$OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($msg_count));
+
+// update mailboxlist
+$OUTPUT->command('set_unread_count', $mbox, $IMAP->messagecount($mbox, 'UNSEEN'), ($mbox == 'INBOX'));
+
+if ($RCMAIL->action=='moveto' && $target) {
+ $OUTPUT->command('set_unread_count', $target, $IMAP->messagecount($target, 'UNSEEN'));
+}
+
+$OUTPUT->command('set_quota', rcmail_quota_content($IMAP->get_quota()));
+
+// add new rows from next page (if any)
+if ($addrows && $_POST['_from']!='show' && ($jump_back || $nextpage_count > 0)) {
+ $sort_col = isset($_SESSION['sort_col']) ? $_SESSION['sort_col'] : $CONFIG['message_sort_col'];
+ $sort_order = isset($_SESSION['sort_order']) ? $_SESSION['sort_order'] : $CONFIG['message_sort_order'];
+
+ $a_headers = $IMAP->list_headers($mbox, NULL, $sort_col, $sort_order);
+ if (!$jump_back) {
+ if ($_SESSION['threads'])
+ // TODO: count number of roots deleted and slice that many roots from the end of $a_headers
+ $OUTPUT->command('message_list.clear');
+ else
+ $a_headers = array_slice($a_headers, -$count, $count);
+ }
+ rcmail_js_message_list($a_headers);
+}
+
+// send response
+$OUTPUT->send();