[asterisk-commits] seanbright: trunk r221090 - /trunk/apps/app_voicemail.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Sep 30 10:11:26 CDT 2009


Author: seanbright
Date: Wed Sep 30 10:11:21 2009
New Revision: 221090

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=221090
Log:
Modify VoiceMailMain()'s a() argument to allow mailboxes to be specified by name.

(closes issue #14740)
Reported by: pj
Patches:
      issue14740_09022009.diff uploaded by seanbright (license 71)
Tested by: seanbright, lmadsen

Modified:
    trunk/apps/app_voicemail.c

Modified: trunk/apps/app_voicemail.c
URL: http://svnview.digium.com/svn/asterisk/trunk/apps/app_voicemail.c?view=diff&rev=221090&r1=221089&r2=221090
==============================================================================
--- trunk/apps/app_voicemail.c (original)
+++ trunk/apps/app_voicemail.c Wed Sep 30 10:11:21 2009
@@ -222,7 +222,7 @@
 					<option name="a">
 						<argument name="folder" required="true" />
 						<para>Skip folder prompt and go directly to <replaceable>folder</replaceable> specified.
-						Defaults to <literal>0</literal> (INBOX).</para>
+						Defaults to <literal>INBOX</literal> (or <literal>0</literal>).</para>
 						<enumlist>
 							<enum name="0"><para>INBOX</para></enum>
 							<enum name="1"><para>Old</para></enum>
@@ -1456,27 +1456,41 @@
 	return 0;
 }
 
+static const char * const mailbox_folders[] = {
+#ifdef IMAP_STORAGE
+	imapfolder,
+#else
+	"INBOX",
+#endif
+	"Old",
+	"Work",
+	"Family",
+	"Friends",
+	"Cust1",
+	"Cust2",
+	"Cust3",
+	"Cust4",
+	"Cust5",
+	"Deleted",
+	"Urgent",
+};
+
 static const char *mbox(int id)
 {
-	static const char * const msgs[] = {
-#ifdef IMAP_STORAGE
-		imapfolder,
-#else
-		"INBOX",
-#endif
-		"Old",
-		"Work",
-		"Family",
-		"Friends",
-		"Cust1",
-		"Cust2",
-		"Cust3",
-		"Cust4",
-		"Cust5",
-		"Deleted",
-		"Urgent"
-	};
-	return (id >= 0 && id < ARRAY_LEN(msgs)) ? msgs[id] : "Unknown";
+	return (id >= 0 && id < ARRAY_LEN(mailbox_folders)) ? mailbox_folders[id] : "Unknown";
+}
+
+static int get_folder_by_name(const char *name)
+{
+	size_t i;
+
+	for (i = 0; i < ARRAY_LEN(mailbox_folders); i++) {
+		if (strcasecmp(name, mailbox_folders[i]) == 0) {
+			return i;
+		}
+	}
+
+	return -1;
 }
 
 static void free_user(struct ast_vm_user *vmu)
@@ -9090,15 +9104,22 @@
 			}
 			if (ast_test_flag(&flags, OPT_AUTOPLAY) ) {
 				play_auto = 1;
-				if (opts[OPT_ARG_PLAYFOLDER]) {
-					if (sscanf(opts[OPT_ARG_PLAYFOLDER], "%30d", &play_folder) != 1) {
-						ast_log(AST_LOG_WARNING, "Invalid value '%s' provided for folder autoplay option\n", opts[OPT_ARG_PLAYFOLDER]);
+				if (!ast_strlen_zero(opts[OPT_ARG_PLAYFOLDER])) {
+					/* See if it is a folder name first */
+					if (isdigit(opts[OPT_ARG_PLAYFOLDER][0])) {
+						if (sscanf(opts[OPT_ARG_PLAYFOLDER], "%30d", &play_folder) != 1) {
+							play_folder = -1;
+						}
+					} else {
+						play_folder = get_folder_by_name(opts[OPT_ARG_PLAYFOLDER]);
 					}
 				} else {
 					ast_log(AST_LOG_WARNING, "Invalid folder set with option a\n");
-				}	
-				if ( play_folder > 9 || play_folder < 0) {
-					ast_log(AST_LOG_WARNING, "Invalid value '%d' provided for folder autoplay option\n", play_folder);
+				}
+				if (play_folder > 9 || play_folder < 0) {
+					ast_log(AST_LOG_WARNING,
+						"Invalid value '%s' provided for folder autoplay option. Defaulting to 'INBOX'\n",
+						opts[OPT_ARG_PLAYFOLDER]);
 					play_folder = 0;
 				}
 			}




More information about the asterisk-commits mailing list