Index: apps/app_voicemail.c =================================================================== --- apps/app_voicemail.c (revision 230582) +++ apps/app_voicemail.c (working copy) @@ -7059,6 +7059,7 @@ const char *origtime, *context, *category, *duration, *flag; struct ast_config *msg_cfg; struct ast_flags config_flags = { CONFIG_FLAG_NOCACHE }; + int count_msg = 0; vms->starting = 0; make_file(vms->fn, sizeof(vms->fn), vms->curdir, vms->curmsg); @@ -7068,10 +7069,30 @@ else if (vms->curmsg == vms->lastmsg) res = wait_file2(chan, vms, "vm-last"); /* "last" */ +play_message: snprintf(filename, sizeof(filename), "%s.txt", vms->fn); RETRIEVE(vms->curdir, vms->curmsg, vmu->mailbox, vmu->context); msg_cfg = ast_config_load(filename, config_flags); if (!msg_cfg || msg_cfg == CONFIG_STATUS_FILEINVALID) { + + /* either there's no file or we have filenumber above the maxmsg limit + * for example maxmsg is set to 5 and you already have 4 files in your INBOX, + * caller A and caller B both leaving a message the same time -> you have 6 messages in your Inbox. + * You can't retrieve message number 6 */ + if ((count_msg = count_messages(vmu, vms->curdir)) > 0){ + int message_number = 0; + + /* find the 'queer-message' */ + for (message_number = 1; message_number < MAXMSGLIMIT; message_number++){ + snprintf(filename, sizeof(filename), "%s/msg%04d", vms->curdir, message_number); + if (ast_fileexists(filename, NULL, "txt")){ + ast_log(LOG_NOTICE, "found 'queer' message (%s), renaming it to (%s) and trying to play it again!\n", filename, vms->fn); + RENAME(vms->curdir, message_number, vmu->mailbox, vmu->context, vms->curdir, vms->curmsg, filename, vms->fn); + goto play_message; + } + } + } + ast_log(LOG_WARNING, "No message attribute file?!! (%s)\n", filename); return 0; }