Index: apps/app_voicemail.c =================================================================== --- apps/app_voicemail.c (revision 300158) +++ apps/app_voicemail.c (working copy) @@ -2910,7 +2910,7 @@ * A negative return value indicates an error. */ #if (!defined(IMAP_STORAGE) && !defined(ODBC_STORAGE)) -static int last_message_index(struct ast_vm_user *vmu, char *dir) +static int last_message_index(struct ast_vm_user *vmu, char *dir, int stopcount) { int x; char fn[PATH_MAX]; @@ -2920,8 +2920,13 @@ for (x = 0; x < vmu->maxmsg; x++) { make_file(fn, sizeof(fn), dir, x); - if (ast_fileexists(fn, NULL, NULL) < 1) - break; + if (ast_fileexists(fn, NULL, NULL) < 1) { + if (stopcount <= 0) { + break; + } + } else { + stopcount--; + } } ast_unlock_path(dir); @@ -4527,9 +4532,9 @@ } #ifndef IMAP_STORAGE -static int resequence_mailbox(struct ast_vm_user *vmu, char *dir, int count_msg) +static int resequence_mailbox(struct ast_vm_user *vmu, char *dir, int stopcount) { - /* we know max messages, so stop process when number is hit */ + /* we know the actual number of messages, so stop process when number is hit */ int x,dest; char sfn[PATH_MAX]; @@ -4538,7 +4543,7 @@ if (vm_lock_path(dir)) return ERROR_LOCK_PATH; - for (x = 0, dest = 0; x < count_msg + 1; x++) { + for (x = 0, dest = 0; dest != stopcount && x < vmu->maxmsg + 10; x++) { make_file(sfn, sizeof(sfn), dir, x); if (EXISTS(dir, x, sfn, NULL)) { @@ -5996,7 +6001,11 @@ */ /* for local storage, checks directory for messages up to maxmsg limit */ +#ifndef ODBC_STORAGE /* file storage */ + last_msg = last_message_index(vmu, vms->curdir, count_msg); +#else last_msg = last_message_index(vmu, vms->curdir); +#endif if (last_msg < -1) return last_msg; else if (vms->lastmsg != last_msg)