From 67729f624971bc1e6c1d0547e4f11c8cb83a8ccb Mon Sep 17 00:00:00 2001 From: Jason Parker <jparker@digium.com> Date: Wed, 15 May 2013 14:25:35 +0000 Subject: [PATCH] Fix VM snapshot handling for combined INBOX. The snapshot API contains an option that allow for combining of new and old messages within a single snapshot. New messages, however, include options beyond just 'INBOX' - it also includes the Urgent folder. A previous patch that combined INBOX and Urgent accidentally impacted snapshots that attempted to gain messages from just the Old folder. This patch fixes the snapshot gathering such that the API returns the appropriate messages for the folder selected, with and without the combine option. This should make it more clear about what's happening. Review: https://reviewboard.asterisk.org/r/2539/ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/11@388816 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- apps/app_voicemail.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index af6f66c28b..5dce9f8151 100644 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -15034,27 +15034,22 @@ static struct ast_vm_mailbox_snapshot *vm_mailbox_snapshot_create(const char *ma mailbox_snapshot->folders = ARRAY_LEN(mailbox_folders); for (i = 0; i < mailbox_snapshot->folders; i++) { - int combining_old = 0; - /* Assume we are combining folders if: - * - The current index is the old folder index OR - * - The current index is urgent and we were looking for INBOX or all folders OR - * - The current index is INBOX and we were looking for Urgent or all folders - */ - if ((i == old_index || - (i == urgent_index && (this_index_only == inbox_index || this_index_only == -1)) || - (i == inbox_index && (this_index_only == urgent_index || this_index_only == -1))) && (combine_INBOX_and_OLD)) { - combining_old = 1; - } + int msg_folder_index = i; - /* This if statement is confusing looking. Here is what it means in english. - * - If a folder is given to the function and that folder's index is not the one we are iterating over, skip it... - * - Unless we are combining old and new messages and the current index is one of old, new, or urgent folders + /* We want this message in the snapshot if any of the following: + * No folder was specified. + * The specified folder matches the current folder. + * The specified folder is INBOX AND we were asked to combine messages AND the current folder is either Old or Urgent. */ - if ((this_index_only != -1 && this_index_only != i) && - !(combining_old && (i == old_index || i == urgent_index || i == inbox_index))) { + if (!(this_index_only == -1 || this_index_only == i || (this_index_only == inbox_index && combine_INBOX_and_OLD && (i == old_index || i == urgent_index)))) { continue; } + /* Make sure that Old or Urgent messages are marked as being in INBOX. */ + if (combine_INBOX_and_OLD && (i == old_index || i == urgent_index)) { + msg_folder_index = inbox_index; + } + memset(&vms, 0, sizeof(vms)); ast_copy_string(vms.username, mailbox, sizeof(vms.username)); vms.lastmsg = -1; @@ -15069,7 +15064,7 @@ static struct ast_vm_mailbox_snapshot *vm_mailbox_snapshot_create(const char *ma /* Iterate through each msg, storing off info */ if (vms.lastmsg != -1) { - if ((vm_msg_snapshot_create(vmu, &vms, mailbox_snapshot, combining_old ? inbox_index : i, i, descending, sort_val))) { + if ((vm_msg_snapshot_create(vmu, &vms, mailbox_snapshot, msg_folder_index, i, descending, sort_val))) { ast_log(LOG_WARNING, "Failed to create msg snapshots for %s@%s\n", mailbox, context); goto snapshot_cleanup; } -- GitLab