diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index 3361aba1d80ea103561257e052426765d0868f7a..667ba8f95c9aacd697c1372ee1b3c667db68326e 100644
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -5032,11 +5032,13 @@ static int close_mailbox(struct vm_state *vms, struct ast_vm_user *vmu)
 	}
 	ast_unlock_path(vms->curdir);
 #else
-	for (x=0;x < vmu->maxmsg;x++) { 
-		if (vms->deleted[x]) { 
-			if(option_debug > 2)
-				ast_log(LOG_DEBUG,"IMAP delete of %d\n",x);
-			IMAP_DELETE(vms->curdir, x, vms->fn, vms);
+	if (vms->deleted) {
+		for (x=0;x < vmu->maxmsg;x++) { 
+			if (vms->deleted[x]) { 
+				if(option_debug > 2)
+					ast_log(LOG_DEBUG,"IMAP delete of %d\n",x);
+				IMAP_DELETE(vms->curdir, x, vms->fn, vms);
+			}
 		}
 	}
 #endif