Skip to content

Commit

Permalink
Fix so message flags modified by another client are applied on the li…
Browse files Browse the repository at this point in the history
…st on refresh (#1485186)
  • Loading branch information
alecpl committed Dec 23, 2013
1 parent 6b2b2ec commit ac0fc38
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CHANGELOG Roundcube Webmail
===========================

- Fix so message flags modified by another client are applied on the list on refresh (#1485186)
- Fix broken text/* attachments when forwarding/editing a message (#1489426)
- Improved minified files handling, added css minification (#1486988)
- Fix handling of X-Forwarded-For header with multiple addresses (#1489481)
Expand Down
19 changes: 17 additions & 2 deletions program/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6923,6 +6923,16 @@ function rcube_webmail()

case 'refresh':
case 'check-recent':
// update message flags
$.each(this.env.recent_flags || {}, function(uid, flags) {
ref.set_message(uid, 'deleted', flags.deleted);
ref.set_message(uid, 'replied', flags.answered);
ref.set_message(uid, 'unread', !flags.seen);
ref.set_message(uid, 'forwarded', flags.forwarded);
ref.set_message(uid, 'flagged', flags.flagged);
});
delete this.env.recent_flags;

case 'getunread':
case 'search':
this.env.qsearch = null;
Expand Down Expand Up @@ -7246,13 +7256,18 @@ function rcube_webmail()

if (this.gui_objects.mailboxlist)
params._folderlist = 1;
if (this.gui_objects.messagelist)
params._list = 1;
if (this.gui_objects.quotadisplay)
params._quota = 1;
if (this.env.search_request)
params._search = this.env.search_request;

if (this.gui_objects.messagelist) {
params._list = 1;

// message uids for flag updates check
params._uids = $.map(this.message_list.rows, function(row, uid) { return uid; }).join(',');
}

return params;
};

Expand Down
35 changes: 35 additions & 0 deletions program/lib/Roundcube/rcube_imap.php
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,41 @@ protected function countmessages($folder, $mode='ALL', $force=false, $status=tru
}


/**
* Public method for listing message flags
*
* @param string $folder Folder name
* @param array $uids Message UIDs
* @param int $mod_seq Optional MODSEQ value (of last flag update)
*
* @return array Indexed array with message flags
*/
public function list_flags($folder, $uids, $mod_seq = null)
{
if (!strlen($folder)) {
$folder = $this->folder;
}

if (!$this->check_connection()) {
return array();
}

// @TODO: when cache was synchronized in this request
// we might already have asked for flag updates, use it.

$flags = $this->conn->fetch($folder, $uids, true, array('FLAGS'), $mod_seq);
$result = array();

if (!empty($flags)) {
foreach ($flags as $message) {
$result[$message->uid] = $message->flags;
}
}

return $result;
}


/**
* Public method for listing headers
*
Expand Down
12 changes: 12 additions & 0 deletions program/lib/Roundcube/rcube_storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,18 @@ abstract function get_namespace($name = null);
abstract function count($folder = null, $mode = 'ALL', $force = false, $status = true);


/**
* Public method for listing message flags
*
* @param string $folder Folder name
* @param array $uids Message UIDs
* @param int $mod_seq Optional MODSEQ value
*
* @return array Indexed array with message flags
*/
abstract function list_flags($folder, $uids, $mod_seq = null);


/**
* Public method for listing headers.
*
Expand Down
18 changes: 18 additions & 0 deletions program/steps/mail/check_recent.inc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,24 @@ foreach ($a_mailboxes as $mbox_name) {
$OUTPUT->command('update_selection');
}
}
// handle flag updates
else if ($is_current && ($uids = rcube_utils::get_input_value('_uids', rcube_utils::INPUT_GPC))) {
$data = $RCMAIL->storage->folder_data($mbox_name);

if (empty($_SESSION['list_mod_seq']) || $_SESSION['list_mod_seq'] != $data['HIGHESTMODSEQ']) {
$flags = $RCMAIL->storage->list_flags($mbox_name, explode(',', $uids), $_SESSION['list_mod_seq']);
foreach ($flags as $idx => $row) {
$flags[$idx] = array_change_key_case(array_map('intval', $row));
}

// remember last HIGHESTMODSEQ value (if supported)
if (!empty($data['HIGHESTMODSEQ'])) {
$_SESSION['list_mod_seq'] = $data['HIGHESTMODSEQ'];
}

$RCMAIL->output->set_env('recent_flags', $flags);
}
}
}

// trigger refresh hook
Expand Down
11 changes: 9 additions & 2 deletions program/steps/mail/list.inc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ if (!$OUTPUT->ajax_call) {
return;
}

$save_arr = array();
$dont_override = (array) $RCMAIL->config->get('dont_override');
$save_arr = array();
$dont_override = (array) $RCMAIL->config->get('dont_override');

// is there a sort type for this request?
if ($sort = rcube_utils::get_input_value('_sort', rcube_utils::INPUT_GET)) {
Expand Down Expand Up @@ -104,6 +104,13 @@ if (isset($a_headers) && count($a_headers)) {
if ($search_request) {
$OUTPUT->show_message('searchsuccessful', 'confirmation', array('nr' => $count));
}

// remember last HIGHESTMODSEQ value (if supported)
// we need it for flag updates in check-recent
$data = $RCMAIL->storage->folder_data($mbox_name);
if (!empty($data['HIGHESTMODSEQ'])) {
$_SESSION['list_mod_seq'] = $data['HIGHESTMODSEQ'];
}
}
else {
// handle IMAP errors (e.g. #1486905)
Expand Down
7 changes: 7 additions & 0 deletions program/steps/mail/search.inc
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ if (!empty($result_h)) {
rcmail_js_message_list($result_h);
if ($search_str)
$OUTPUT->show_message('searchsuccessful', 'confirmation', array('nr' => $RCMAIL->storage->count(NULL, 'ALL')));

// remember last HIGHESTMODSEQ value (if supported)
// we need it for flag updates in check-recent
$data = $RCMAIL->storage->folder_data($mbox_name);
if (!empty($data['HIGHESTMODSEQ'])) {
$_SESSION['list_mod_seq'] = $data['HIGHESTMODSEQ'];
}
}
// handle IMAP errors (e.g. #1486905)
else if ($err_code = $RCMAIL->storage->get_error_code()) {
Expand Down

0 comments on commit ac0fc38

Please sign in to comment.