Index: apps/app_voicemail.c =================================================================== --- apps/app_voicemail.c (revision 123826) +++ apps/app_voicemail.c (working copy) @@ -144,6 +144,7 @@ static char *get_user_by_mailbox(char *mailbox, char *buf, size_t len); static struct vm_state *get_vm_state_by_imapuser(char *user, int interactive); static struct vm_state *get_vm_state_by_mailbox(const char *mailbox, int interactive); +static struct vm_state *get_vm_state_by_user(struct ast_vm_user *vmu, char *mailbox); static void vmstate_insert(struct vm_state *vms); static void vmstate_delete(struct vm_state *vms); static void set_update(MAILSTREAM * stream); @@ -5328,12 +5328,16 @@ } /* by now vms->fn should have merged audio */ /* get destination mailbox */ - if ((dstvms = get_vm_state_by_mailbox(vmtmp->mailbox, 0))) { + dstvms = get_vm_state_by_mailbox(vmtmp->mailbox, 0); + if (!dstvms) { + dstvms = get_vm_state_by_user(vmtmp, vmtmp->mailbox); + } + if (dstvms) { init_mailstream(dstvms, 0); if (!dstvms->mailstream) { ast_log(AST_LOG_ERROR, "IMAP mailstream for %s is NULL\n", vmtmp->mailbox); } else { - STORE(todir, vmtmp->mailbox, vmtmp->context, dstvms->curmsg, chan, vmtmp, fmt, duration, dstvms, tmptxtfile, urgent_str); + STORE(todir, vmtmp->mailbox, vmtmp->context, vms->curmsg, chan, vmtmp, fmt, duration, dstvms, tmptxtfile, urgent_str); run_externnotify(vmtmp->context, vmtmp->mailbox, urgent_str); } } else { @@ -10924,6 +10936,25 @@ } } +static struct vm_state *get_vm_state_by_user(struct ast_vm_user *vmu, char *mailbox) +{ + struct vm_state *vms_p; + + ast_debug(5,"Adding new vmstate for %s\n",vmu->imapuser); + if (!(vms_p = ast_calloc(1, sizeof(*vms_p)))) + return NULL; + ast_copy_string(vms_p->imapuser,vmu->imapuser, sizeof(vms_p->imapuser)); + ast_copy_string(vms_p->username, mailbox, sizeof(vms_p->username)); /* save for access from interactive entry point */ + vms_p->mailstream = NIL; /* save for access from interactive entry point */ + ast_debug(5,"Copied %s to %s\n",vmu->imapuser,vms_p->imapuser); + vms_p->updated = 1; + /* set mailbox to INBOX! */ + ast_copy_string(vms_p->curbox, mbox(0), sizeof(vms_p->curbox)); + init_vm_state(vms_p); + vmstate_insert(vms_p); + return vms_p; +} + static struct vm_state *get_vm_state_by_imapuser(char *user, int interactive) { struct vmstate *vlist = NULL;