Skip to content

Commit d900130

Browse files
InterLinked1gtjoseph
authored andcommitted
func_vmcount: Add support for multiple mailboxes
Allows multiple mailboxes to be specified for VMCOUNT instead of just one. ASTERISK-29661 #close Change-Id: I9108528300795fd5b607efa9d4dd7b74be031813
1 parent 5ca9898 commit d900130

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Subject: func_vmcount
2+
3+
Multiple mailboxes may now be specified instead of just one.

‎funcs/func_vmcount.c‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@
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="&amp;">
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>
@@ -56,12 +58,19 @@
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&amp;1235@default&amp;1236@default,INBOX)})
65+
</example>
5966
</description>
6067
</function>
6168
***/
6269

6370
static 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

Comments
 (0)