Index: apps/app_voicemail.c =================================================================== --- apps/app_voicemail.c (revision 295512) +++ apps/app_voicemail.c (working copy) @@ -5742,6 +5742,34 @@ return res; } +#ifndef IMAP_STORAGE +static int resequence_mailbox(struct ast_vm_user *vmu, char *dir) +{ + /* we know max messages, so stop process when number is hit */ + int x, dest; + char sfn[PATH_MAX]; + char dfn[PATH_MAX]; + + if (vm_lock_path(dir)) { + return ERROR_LOCK_PATH; + } + + for (x = 0, dest = 0; x < vmu->maxmsg; x++) { + make_file(sfn, sizeof(sfn), dir, x); + if (EXISTS(dir, x, sfn, NULL)) { + if (x != dest) { + make_file(dfn, sizeof(dfn), dir, dest); + RENAME(dir, x, vmu->mailbox, vmu->context, dir, dest, sfn, dfn); + } + dest++; + } + } + ast_unlock_path(dir); + + return 0; +} +#endif + static int say_and_wait(struct ast_channel *chan, int num, const char *language) { int d; @@ -7420,6 +7448,9 @@ return last_msg; } else if (vms->lastmsg != last_msg) { ast_log(LOG_NOTICE, "Mailbox: %s, expected %d but found %d message(s) in box with max threshold of %d.\n", vms->curdir, last_msg + 1, vms->lastmsg + 1, vmu->maxmsg); + if ((res = resequence_mailbox(vmu, vms->curdir))) { + return res; + } } return 0;