int i;
int this_index_only = -1;
int open = 0;
- int inbox_index = 0;
- int old_index = 1;
+ int inbox_index = get_folder_by_name("INBOX");
+ int old_index = get_folder_by_name("Old");
+ int urgent_index = get_folder_by_name("Urgent");
if (ast_strlen_zero(mailbox)) {
ast_log(LOG_WARNING, "Cannot create a mailbox snapshot since no mailbox was specified\n");
for (i = 0; i < mailbox_snapshot->folders; i++) {
int combining_old = 0;
- if ((i == old_index) && (combine_INBOX_and_OLD)) {
+ /* 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;
}