Index: apps/app_voicemail.c =================================================================== --- apps/app_voicemail.c (revision 71721) +++ apps/app_voicemail.c (working copy) @@ -3117,13 +3117,25 @@ newmsgs = vms->newmessages++; oldmsgs = vms->oldmessages; } else { + if (!(vms = ast_calloc(1, sizeof(*vms)))) { + ast_log (LOG_ERROR, "Couldn't allocate necessary space\n"); + return -1; + } + ast_copy_string(vms->imapuser,vmu->imapuser, sizeof(vms->imapuser)); + ast_copy_string(vms->username, ext, sizeof(vms->username)); + vms->mailstream = NIL; + ast_debug(3,"Copied %s to %s\n",vmu->imapuser,vms->imapuser); + vms->updated = 1; + ast_copy_string(vms->curbox, mbox(0), sizeof(vms->curbox)); + init_vm_state(vms); + vmstate_insert(vms); res = inboxcount(ext_context, &newmsgs, &oldmsgs); if(res < 0) { ast_log(LOG_NOTICE,"Can not leave voicemail, unable to count messages\n"); return -1; } - vms = get_vm_state_by_mailbox(ext,0); } + /* here is a big difference! We add one to it later */ msgnum = newmsgs + oldmsgs; ast_debug(3, "Messagecount set to %d\n",msgnum);