Index: apps/app_voicemail.c =================================================================== --- apps/app_voicemail.c (revision 219015) +++ apps/app_voicemail.c (working copy) @@ -117,6 +117,7 @@ static char imapfolder[64]; static char authuser[32]; static char authpassword[42]; +static int imapversion = 1; static int expungeonhangup = 1; static char delimiter = '\0'; @@ -350,6 +351,7 @@ char imapuser[80]; /* IMAP server login */ char imappassword[80]; /* IMAP server password if authpassword not defined */ char imapvmshareid[80]; /* Shared mailbox ID to use rather than the dialed one */ + int imapversion; /*!< If configuration changes, use the new values */ #endif double volgain; /*!< Volume gain for voicemails sent via email */ AST_LIST_ENTRY(ast_vm_user) list; @@ -385,6 +387,7 @@ MAILSTREAM *mailstream; int vmArrayIndex; char imapuser[80]; /* IMAP server login */ + int imapversion; int interactive; unsigned int quota_limit; unsigned int quota_usage; @@ -625,10 +628,13 @@ #ifdef IMAP_STORAGE } else if (!strcasecmp(var, "imapuser")) { ast_copy_string(vmu->imapuser, value, sizeof(vmu->imapuser)); + vmu->imapversion = imapversion; } else if (!strcasecmp(var, "imappassword") || !strcasecmp(var, "imapsecret")) { ast_copy_string(vmu->imappassword, value, sizeof(vmu->imappassword)); + vmu->imapversion = imapversion; } else if (!strcasecmp(var, "imapvmshareid")) { ast_copy_string(vmu->imapvmshareid, value, sizeof(vmu->imapvmshareid)); + vmu->imapversion = imapversion; #endif } else if (!strcasecmp(var, "delete") || !strcasecmp(var, "deletevoicemail")) { ast_set2_flag(vmu, ast_true(value), VM_DELETE); @@ -730,10 +736,13 @@ #ifdef IMAP_STORAGE } else if (!strcasecmp(tmp->name, "imapuser")) { ast_copy_string(retval->imapuser, tmp->value, sizeof(retval->imapuser)); + retval->imapversion = imapversion; } else if (!strcasecmp(tmp->name, "imappassword") || !strcasecmp(tmp->name, "imapsecret")) { ast_copy_string(retval->imappassword, tmp->value, sizeof(retval->imappassword)); + retval->imapversion = imapversion; } else if (!strcasecmp(tmp->name, "imapvmshareid")) { ast_copy_string(retval->imapvmshareid, tmp->value, sizeof(retval->imapvmshareid)); + retval->imapversion = imapversion; #endif } else apply_option(retval, tmp->name, tmp->value); @@ -780,6 +789,11 @@ context = "default"; AST_LIST_TRAVERSE(&users, cur, list) { +#ifdef IMAP_STORAGE + if (cur->imapversion != imapversion) { + continue; + } +#endif if (ast_test_flag((&globalflags), VM_SEARCH) && !strcasecmp(mailbox, cur->mailbox)) break; if (context && (!strcasecmp(context, cur->context)) && (!strcasecmp(mailbox, cur->mailbox))) @@ -1057,6 +1071,7 @@ * and should have its msgArray properly set up. */ ast_log(LOG_ERROR, "Couldn't find a vm_state for mailbox %s!!! Oh no!\n", vmu->mailbox); + return -1; } make_file(vms->fn, sizeof(vms->fn), dir, msgnum); @@ -1546,6 +1561,8 @@ int ret; ast_copy_string(vms->imapuser,vmu->imapuser, sizeof(vms->imapuser)); + vms->imapversion = vmu->imapversion; + if (option_debug > 2) ast_log(LOG_DEBUG,"Before init_mailstream, user is %s\n",vmu->imapuser); ret = init_mailstream(vms, box); @@ -1915,6 +1932,7 @@ ast_copy_string(vms_p->username, vmu->mailbox, sizeof(vms_p->username)); /* save for access from interactive entry point */ ast_copy_string(vms_p->context, vmu->context, sizeof(vms_p->context)); vms_p->mailstream = NIL; /* save for access from interactive entry point */ + vms_p->imapversion = vmu->imapversion; if (option_debug > 4) ast_log(LOG_DEBUG,"Copied %s to %s\n",vmu->imapuser,vms_p->imapuser); vms_p->updated = 1; @@ -1939,7 +1957,7 @@ ast_mutex_lock(&vmstate_lock); vlist = vmstates; while (vlist) { - if (vlist->vms) { + if (vlist->vms && vlist->vms->imapversion == imapversion) { if (vlist->vms->imapuser) { if (!strcmp(vlist->vms->imapuser,user)) { if (interactive == 2) { @@ -1984,7 +2002,7 @@ ast_log(LOG_DEBUG, "Mailbox set to %s\n",mailbox); while (vlist) { if (vlist->vms) { - if (vlist->vms->username && vlist->vms->context) { + if (vlist->vms->username && vlist->vms->context && vlist->vms->imapversion == imapversion) { if (option_debug > 2) ast_log(LOG_DEBUG, " comparing mailbox %s (i=%d) to vmstate mailbox %s (i=%d)\n",mailbox,interactive,vlist->vms->username,vlist->vms->interactive); if (!strcmp(vlist->vms->username,mailbox) && !(strcmp(vlist->vms->context, local_context))) { @@ -8466,6 +8484,8 @@ mail_parameters(NIL, SET_CLOSETIMEOUT, (void *) DEFAULT_IMAP_TCP_TIMEOUT); } + /* Increment configuration version */ + imapversion++; #endif /* External voicemail notify application */