[svn-commits] jpeeler: branch 1.6.0 r258434 - in /branches/1.6.0: ./ apps/app_voicemail.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Apr 21 17:09:32 CDT 2010


Author: jpeeler
Date: Wed Apr 21 17:09:31 2010
New Revision: 258434

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=258434
Log:
Merged revisions 258433 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

................
  r258433 | jpeeler | 2010-04-21 16:56:09 -0500 (Wed, 21 Apr 2010) | 15 lines
  
  Merged revisions 258432 via svnmerge from 
  https://origsvn.digium.com/svn/asterisk/branches/1.4
  
  ........
    r258432 | jpeeler | 2010-04-21 16:45:36 -0500 (Wed, 21 Apr 2010) | 8 lines
    
    Fix looping forever when no input received in certain voicemail menu scenarios.
    
    Specifically, prompting for an extension (when leaving or forwarding a message)
    or when prompting for a digit (when saving a message or changing folders).
    
    ABE-2122
    SWP-1268
  ........
................

Modified:
    branches/1.6.0/   (props changed)
    branches/1.6.0/apps/app_voicemail.c

Propchange: branches/1.6.0/
------------------------------------------------------------------------------
Binary property 'trunk-merged' - no diff available.

Modified: branches/1.6.0/apps/app_voicemail.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.6.0/apps/app_voicemail.c?view=diff&rev=258434&r1=258433&r2=258434
==============================================================================
--- branches/1.6.0/apps/app_voicemail.c (original)
+++ branches/1.6.0/apps/app_voicemail.c Wed Apr 21 17:09:31 2010
@@ -1494,6 +1494,108 @@
 	return 0;
 }
 
+static int messagecount(const char *context, const char *mailbox, const char *folder)
+{
+	SEARCHPGM *pgm;
+	SEARCHHEADER *hdr;
+
+	struct ast_vm_user *vmu, vmus;
+	struct vm_state *vms_p;
+	int ret = 0;
+	int fold = folder_int(folder);
+	
+	if (ast_strlen_zero(mailbox))
+		return 0;
+
+	/* We have to get the user before we can open the stream! */
+	/* ast_log(LOG_DEBUG, "Before find_user, context is %s and mailbox is %s\n", context, mailbox); */
+	vmu = find_user(&vmus, context, mailbox);
+	if (!vmu) {
+		ast_log(LOG_ERROR, "Couldn't find mailbox %s in context %s\n", mailbox, context);
+		return -1;
+	} else {
+		/* No IMAP account available */
+		if (vmu->imapuser[0] == '\0') {
+			ast_log(LOG_WARNING, "IMAP user not set for mailbox %s\n", vmu->mailbox);
+			return -1;
+		}
+	}
+	
+	/* No IMAP account available */
+	if (vmu->imapuser[0] == '\0') {
+		ast_log(LOG_WARNING, "IMAP user not set for mailbox %s\n", vmu->mailbox);
+		free_user(vmu);
+		return -1;
+	}
+
+	/* check if someone is accessing this box right now... */
+	vms_p = get_vm_state_by_imapuser(vmu->imapuser, 1);
+	if (!vms_p) {
+		vms_p = get_vm_state_by_mailbox(mailbox, 1);
+	}
+	if (vms_p) {
+		ast_debug(3, "Returning before search - user is logged in\n");
+		if (fold == 0) { /* INBOX */
+			return vms_p->newmessages;
+		}
+		if (fold == 1) { /* Old messages */
+			return vms_p->oldmessages;
+		}
+	}
+
+	/* add one if not there... */
+	vms_p = get_vm_state_by_imapuser(vmu->imapuser, 0);
+	if (!vms_p) {
+		vms_p = get_vm_state_by_mailbox(mailbox, 0);
+	}
+
+	if (!vms_p) {
+		vms_p = create_vm_state_from_user(vmu);
+	}
+	ret = init_mailstream(vms_p, fold);
+	if (!vms_p->mailstream) {
+		ast_log(LOG_ERROR, "Houston we have a problem - IMAP mailstream is NULL\n");
+		return -1;
+	}
+	if (ret == 0) {
+		ast_mutex_lock(&vms_p->lock);
+		pgm = mail_newsearchpgm ();
+		hdr = mail_newsearchheader ("X-Asterisk-VM-Extension", (char *)(!ast_strlen_zero(vmu->imapvmshareid) ? vmu->imapvmshareid : mailbox));
+		hdr->next = mail_newsearchheader("X-Asterisk-VM-Context", (char *) S_OR(context, "default"));
+		pgm->header = hdr;
+		if (fold != 1) {
+			pgm->unseen = 1;
+			pgm->seen = 0;
+		}
+		/* In the special case where fold is 1 (old messages) we have to do things a bit
+		* differently. Old messages are stored in the INBOX but are marked as "seen"
+		*/
+		else {
+			pgm->unseen = 0;
+			pgm->seen = 1;
+		}
+		pgm->undeleted = 1;
+		pgm->deleted = 0;
+
+		vms_p->vmArrayIndex = 0;
+		mail_search_full (vms_p->mailstream, NULL, pgm, NIL);
+		if (fold == 0)
+			vms_p->newmessages = vms_p->vmArrayIndex;
+		if (fold == 1)
+			vms_p->oldmessages = vms_p->vmArrayIndex;
+		/* Freeing the searchpgm also frees the searchhdr */
+		mail_free_searchpgm(&pgm);
+		ast_mutex_unlock(&vms_p->lock);
+		vms_p->updated = 0;
+		return vms_p->vmArrayIndex;
+	} else {
+		ast_mutex_lock(&vms_p->lock);
+		mail_ping(vms_p->mailstream);
+		ast_mutex_unlock(&vms_p->lock);
+	}
+	return 0;
+}
+
 static int imap_store_file(char *dir, char *mailboxuser, char *mailboxcontext, int msgnum, struct ast_channel *chan, struct ast_vm_user *vmu, char *fmt, int duration, struct vm_state *vms)
 {
 	char *myserveremail = serveremail;
@@ -1592,107 +1694,6 @@
 
 }
 
-static int messagecount(const char *context, const char *mailbox, const char *folder)
-{
-	SEARCHPGM *pgm;
-	SEARCHHEADER *hdr;
-
-	struct ast_vm_user *vmu, vmus;
-	struct vm_state *vms_p;
-	int ret = 0;
-	int fold = folder_int(folder);
-	
-	if (ast_strlen_zero(mailbox))
-		return 0;
-
-	/* We have to get the user before we can open the stream! */
-	/* ast_log(LOG_DEBUG, "Before find_user, context is %s and mailbox is %s\n", context, mailbox); */
-	vmu = find_user(&vmus, context, mailbox);
-	if (!vmu) {
-		ast_log(LOG_ERROR, "Couldn't find mailbox %s in context %s\n", mailbox, context);
-		return -1;
-	} else {
-		/* No IMAP account available */
-		if (vmu->imapuser[0] == '\0') {
-			ast_log(LOG_WARNING, "IMAP user not set for mailbox %s\n", vmu->mailbox);
-			return -1;
-		}
-	}
-	
-	/* No IMAP account available */
-	if (vmu->imapuser[0] == '\0') {
-		ast_log(LOG_WARNING, "IMAP user not set for mailbox %s\n", vmu->mailbox);
-		free_user(vmu);
-		return -1;
-	}
-
-	/* check if someone is accessing this box right now... */
-	vms_p = get_vm_state_by_imapuser(vmu->imapuser, 1);
-	if (!vms_p) {
-		vms_p = get_vm_state_by_mailbox(mailbox, 1);
-	}
-	if (vms_p) {
-		ast_debug(3, "Returning before search - user is logged in\n");
-		if (fold == 0) { /* INBOX */
-			return vms_p->newmessages;
-		}
-		if (fold == 1) { /* Old messages */
-			return vms_p->oldmessages;
-		}
-	}
-
-	/* add one if not there... */
-	vms_p = get_vm_state_by_imapuser(vmu->imapuser, 0);
-	if (!vms_p) {
-		vms_p = get_vm_state_by_mailbox(mailbox, 0);
-	}
-
-	if (!vms_p) {
-		vms_p = create_vm_state_from_user(vmu);
-	}
-	ret = init_mailstream(vms_p, fold);
-	if (!vms_p->mailstream) {
-		ast_log(LOG_ERROR, "Houston we have a problem - IMAP mailstream is NULL\n");
-		return -1;
-	}
-	if (ret == 0) {
-		ast_mutex_lock(&vms_p->lock);
-		pgm = mail_newsearchpgm ();
-		hdr = mail_newsearchheader ("X-Asterisk-VM-Extension", (char *)(!ast_strlen_zero(vmu->imapvmshareid) ? vmu->imapvmshareid : mailbox));
-		hdr->next = mail_newsearchheader("X-Asterisk-VM-Context", (char *) S_OR(context, "default"));
-		pgm->header = hdr;
-		if (fold != 1) {
-			pgm->unseen = 1;
-			pgm->seen = 0;
-		}
-		/* In the special case where fold is 1 (old messages) we have to do things a bit
-		* differently. Old messages are stored in the INBOX but are marked as "seen"
-		*/
-		else {
-			pgm->unseen = 0;
-			pgm->seen = 1;
-		}
-		pgm->undeleted = 1;
-		pgm->deleted = 0;
-
-		vms_p->vmArrayIndex = 0;
-		mail_search_full (vms_p->mailstream, NULL, pgm, NIL);
-		if (fold == 0)
-			vms_p->newmessages = vms_p->vmArrayIndex;
-		if (fold == 1)
-			vms_p->oldmessages = vms_p->vmArrayIndex;
-		/* Freeing the searchpgm also frees the searchhdr */
-		mail_free_searchpgm(&pgm);
-		ast_mutex_unlock(&vms_p->lock);
-		vms_p->updated = 0;
-		return vms_p->vmArrayIndex;
-	} else {
-		ast_mutex_lock(&vms_p->lock);
-		mail_ping(vms_p->mailstream);
-		ast_mutex_unlock(&vms_p->lock);
-	}
-	return 0;
-}
 static int inboxcount(const char *mailbox_context, int *newmsgs, int *oldmsgs)
 {
 	char tmp[PATH_MAX] = "";
@@ -5520,10 +5521,16 @@
 	static int get_folder2(struct ast_channel *chan, char *fn, int start)
 	{
 		int res = 0;
+		int loops = 0;
 		res = ast_play_and_wait(chan, fn);	/* Folder name */
 		while (((res < '0') || (res > '9')) &&
-				(res != '#') && (res >= 0)) {
+				(res != '#') && (res >= 0) &&
+				loops < 4) {
 			res = get_folder(chan, 0);
+			loops++;
+		}
+		if (loops == 4) { /* give up */
+			return '#';
 		}
 		return res;
 	}
@@ -5740,6 +5747,7 @@
 		int valid_extensions = 0;
 		char *dir;
 		int curmsg;
+		int prompt_played = 0;
 
 		if (vms == NULL) return -1;
 		dir = vms->curdir;
@@ -5819,7 +5827,8 @@
 			} else {
 				/* Ask for an extension */
 				res = ast_streamfile(chan, "vm-extension", chan->language);	/* "extension" */
-				if (res)
+				prompt_played++;
+				if (res || prompt_played > 4)
 					break;
 				if ((res = ast_readstring(chan, username, sizeof(username) - 1, 2000, 10000, "#") < 0))
 					break;




More information about the svn-commits mailing list