mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-21 20:56:39 +00:00
A few changes, the ultimate goal of which is to keep better track of the number of messages
that a mailbox currently has. A description of the changes: 1. Changed the "updated" field of the vm_state struct to act more as a binary semaphore than a counting semaphore, since its current implementation made the inboxcount function not work properly. This change falls in line with a change made by UPenn with their IMAP setup and helps to sync our changes with theirs. 2. Eliminated some redundant calls to get_vm_state_by_mailbox inside leave_voicemail 3. Use the play_folder variable to keep track of the number of old and new messages in a mailbox as the messages are deleted 4. Added an increment to the number of new messages that was not there previously in the leave_voicemail function git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@71877 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -2542,7 +2542,7 @@ static int inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs)
|
||||
free_user(vmu);
|
||||
return -1;
|
||||
}
|
||||
if (newmsgs && ret==0 && vms_p->updated==1 ) {
|
||||
if (newmsgs && ret==0 && vms_p->updated > 0 ) {
|
||||
pgm = mail_newsearchpgm ();
|
||||
hdr = mail_newsearchheader ("X-Asterisk-VM-Extension", (char *)mailboxnc);
|
||||
pgm->header = hdr;
|
||||
@@ -2558,7 +2558,7 @@ static int inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs)
|
||||
vms_p->newmessages = vms_p->vmArrayIndex;
|
||||
mail_free_searchpgm(&pgm);
|
||||
}
|
||||
if (oldmsgs && ret==0 && vms_p->updated==1 ) {
|
||||
if (oldmsgs && ret==0 && vms_p->updated > 0 ) {
|
||||
pgm = mail_newsearchpgm ();
|
||||
hdr = mail_newsearchheader ("X-Asterisk-VM-Extension", (char *)mailboxnc);
|
||||
pgm->header = hdr;
|
||||
@@ -2574,10 +2574,8 @@ static int inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs)
|
||||
vms_p->oldmessages = vms_p->vmArrayIndex;
|
||||
mail_free_searchpgm(&pgm);
|
||||
}
|
||||
if (vms_p->updated == 1) { /* changes, so we did the searches above */
|
||||
if (vms_p->updated > 1) { /* changes, so we did the searches above */
|
||||
vms_p->updated = 0;
|
||||
} else if (vms_p->updated > 1) { /* decrement delay count */
|
||||
vms_p->updated--;
|
||||
} else { /* no changes, so don't search */
|
||||
mail_ping(vms_p->mailstream);
|
||||
/* Keep the old data */
|
||||
@@ -2991,20 +2989,13 @@ static int leave_voicemail(struct ast_channel *chan, char *ext, struct leave_vm_
|
||||
#ifdef IMAP_STORAGE
|
||||
/* Is ext a mailbox? */
|
||||
/* must open stream for this user to get info! */
|
||||
vms = get_vm_state_by_mailbox(ext,0);
|
||||
if (vms) {
|
||||
if(option_debug > 2)
|
||||
ast_log(LOG_DEBUG, "Using vm_state, interactive set to %d.\n",vms->interactive);
|
||||
newmsgs = vms->newmessages++;
|
||||
oldmsgs = vms->oldmessages;
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
if((vms = get_vm_state_by_mailbox(ext,0)))
|
||||
vms->newmessages++; /*still need to increment new message count*/
|
||||
/* here is a big difference! We add one to it later */
|
||||
msgnum = newmsgs + oldmsgs;
|
||||
if (option_debug > 2)
|
||||
@@ -6375,7 +6366,7 @@ static int vm_execmain(struct ast_channel *chan, void *data)
|
||||
|
||||
#ifdef IMAP_STORAGE
|
||||
vms.interactive = 1;
|
||||
vms.updated = 2;
|
||||
vms.updated = 1;
|
||||
vmstate_insert(&vms);
|
||||
init_vm_state(&vms);
|
||||
#endif
|
||||
@@ -6428,6 +6419,7 @@ static int vm_execmain(struct ast_channel *chan, void *data)
|
||||
if (!vms.newmessages && vms.oldmessages) {
|
||||
/* If we only have old messages start here */
|
||||
res = open_mailbox(&vms, vmu, 1);
|
||||
play_folder = 1;
|
||||
if (res == ERROR_LOCK_PATH)
|
||||
goto out;
|
||||
}
|
||||
@@ -6493,6 +6485,7 @@ static int vm_execmain(struct ast_channel *chan, void *data)
|
||||
res = open_mailbox(&vms, vmu, cmd);
|
||||
if (res == ERROR_LOCK_PATH)
|
||||
goto out;
|
||||
play_folder = cmd;
|
||||
cmd = 0;
|
||||
}
|
||||
if (useadsi)
|
||||
@@ -6629,10 +6622,20 @@ static int vm_execmain(struct ast_channel *chan, void *data)
|
||||
vms.deleted[vms.curmsg] = !vms.deleted[vms.curmsg];
|
||||
if (useadsi)
|
||||
adsi_delete(chan, &vms);
|
||||
if (vms.deleted[vms.curmsg])
|
||||
if (vms.deleted[vms.curmsg]) {
|
||||
if (play_folder == 0)
|
||||
vms.newmessages--;
|
||||
else if (play_folder == 1)
|
||||
vms.oldmessages--;
|
||||
cmd = ast_play_and_wait(chan, "vm-deleted");
|
||||
else
|
||||
}
|
||||
else {
|
||||
if (play_folder == 0)
|
||||
vms.newmessages++;
|
||||
else if (play_folder == 1)
|
||||
vms.oldmessages++;
|
||||
cmd = ast_play_and_wait(chan, "vm-undeleted");
|
||||
}
|
||||
if (ast_test_flag((&globalflags), VM_SKIPAFTERCMD)) {
|
||||
if (vms.curmsg < vms.lastmsg) {
|
||||
vms.curmsg++;
|
||||
@@ -8835,7 +8838,7 @@ static void vmstate_delete(struct vm_state *vms)
|
||||
ast_log(LOG_DEBUG, "Duplicate mailbox %s, copying message info...\n",vms->username);
|
||||
altvms->newmessages = vms->newmessages;
|
||||
altvms->oldmessages = vms->oldmessages;
|
||||
altvms->updated = 2;
|
||||
altvms->updated = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8875,7 +8878,7 @@ static void set_update(MAILSTREAM * stream)
|
||||
if (vms) {
|
||||
if(option_debug > 2)
|
||||
ast_log (LOG_DEBUG, "User %s mailbox set for update.\n",user);
|
||||
vms->updated = 2; /* set updated flag since mailbox changed */
|
||||
vms->updated = 1; /* set updated flag since mailbox changed */
|
||||
} else {
|
||||
if(option_debug > 2)
|
||||
ast_log (LOG_WARNING, "User %s mailbox not found for update.\n",user);
|
||||
|
Reference in New Issue
Block a user