4444/*** DOCUMENTATION
4545 <function name="VMCOUNT" language="en_US">
4646 <synopsis>
47- Count the voicemails in a specified mailbox.
47+ Count the voicemails in a specified mailbox or mailboxes .
4848 </synopsis>
4949 <syntax>
50- <parameter name="vmbox" required="true" />
50+ <parameter name="vmbox" required="true" argsep="&">
51+ <para>A mailbox or list of mailboxes</para>
52+ </parameter>
5153 <parameter name="folder" required="false">
5254 <para>If not specified, defaults to <literal>INBOX</literal></para>
5355 </parameter>
5658 <para>Count the number of voicemails in a specified mailbox, you could also specify
5759 the mailbox <replaceable>folder</replaceable>.</para>
5860 <para>Example: <literal>exten => s,1,Set(foo=${VMCOUNT(125@default)})</literal></para>
61+ <para>An ampersand-separated list of mailboxes may be specified to count voicemails in
62+ multiple mailboxes. If a folder is specified, this will apply to all mailboxes specified.</para>
63+ <example title="Multiple mailbox inbox count">
64+ same => n,NoOp(${VMCOUNT(1234@default&1235@default&1236@default,INBOX)})
65+ </example>
5966 </description>
6067 </function>
6168 ***/
6269
6370static int acf_vmcount_exec (struct ast_channel * chan , const char * cmd , char * argsstr , char * buf , size_t len )
6471{
72+ int total = 0 ;
73+ char * mailbox = NULL ;
6574 AST_DECLARE_APP_ARGS (args ,
6675 AST_APP_ARG (vmbox );
6776 AST_APP_ARG (folder );
@@ -82,7 +91,15 @@ static int acf_vmcount_exec(struct ast_channel *chan, const char *cmd, char *arg
8291 args .folder = "INBOX" ;
8392 }
8493
85- snprintf (buf , len , "%d" , ast_app_messagecount (args .vmbox , args .folder ));
94+ while ((mailbox = strsep (& args .vmbox , "&" ))) {
95+ int c ;
96+ if (ast_strlen_zero (mailbox )) {
97+ continue ;
98+ }
99+ c = ast_app_messagecount (mailbox , args .folder );
100+ total += (c > 0 ? c : 0 );
101+ }
102+ snprintf (buf , len , "%d" , total );
86103
87104 return 0 ;
88105}
0 commit comments