Skip to content

Commit 9e14523

Browse files
InterLinked1Friendly Automation
authored andcommitted
app_voicemail: Fix missing email in msg_create_from_file.
msg_create_from_file currently does not dispatch emails, which means that applications using this function, such as MixMonitor, will not trigger notifications to users (only AMI events are sent our currently). This is inconsistent with other ways users can receive voicemail. This is fixed by adding an option that attempts to send an email and falling back to just the notifications as done now if that fails. The existing behavior remains the default. ASTERISK-30283 #close Change-Id: I597cbb9cf971a18d8776172b26ab187dc096a5c7
1 parent 52ed64e commit 9e14523

3 files changed

Lines changed: 37 additions & 1 deletion

File tree

apps/app_voicemail.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ static AST_LIST_HEAD_STATIC(vmstates, vmstate);
570570
#define VM_MOVEHEARD (1 << 16) /*!< Move a "heard" message to Old after listening to it */
571571
#define VM_MESSAGEWRAP (1 << 17) /*!< Wrap around from the last message to the first, and vice-versa */
572572
#define VM_FWDURGAUTO (1 << 18) /*!< Autoset of Urgent flag on forwarded Urgent messages set globally */
573+
#define VM_EMAIL_EXT_RECS (1 << 19) /*!< Send voicemail emails when an external recording is added to a mailbox */
573574
#define ERROR_LOCK_PATH -100
574575
#define ERROR_MAX_MSGS -101
575576
#define OPERATOR_EXIT 300
@@ -1258,6 +1259,8 @@ static void apply_option(struct ast_vm_user *vmu, const char *var, const char *v
12581259
ast_set2_flag(vmu, ast_true(value), VM_ATTACH);
12591260
} else if (!strcasecmp(var, "attachfmt")) {
12601261
ast_copy_string(vmu->attachfmt, value, sizeof(vmu->attachfmt));
1262+
} else if (!strcasecmp(var, "attachextrecs")) {
1263+
ast_set2_flag(vmu, ast_true(value), VM_EMAIL_EXT_RECS);
12611264
} else if (!strcasecmp(var, "serveremail")) {
12621265
ast_copy_string(vmu->serveremail, value, sizeof(vmu->serveremail));
12631266
} else if (!strcasecmp(var, "fromstring")) {
@@ -6418,6 +6421,12 @@ static int msg_create_from_file(struct ast_vm_recording_data *recdata)
64186421
* to do both with one line and is also safe to use with file storage mode. Also, if we are using ODBC, now is a good
64196422
* time to create the voicemail database entry. */
64206423
if (ast_fileexists(destination, NULL, NULL) > 0) {
6424+
struct ast_channel *chan = NULL;
6425+
char fmt[80];
6426+
char clid[80];
6427+
char cidnum[80], cidname[80];
6428+
int send_email;
6429+
64216430
if (ast_check_realtime("voicemail_data")) {
64226431
get_date(date, sizeof(date));
64236432
ast_store_realtime("voicemail_data",
@@ -6437,7 +6446,27 @@ static int msg_create_from_file(struct ast_vm_recording_data *recdata)
64376446
}
64386447

64396448
STORE(dir, recipient->mailbox, recipient->context, msgnum, NULL, recipient, fmt, 0, vms, "", msg_id);
6440-
notify_new_state(recipient);
6449+
6450+
send_email = ast_test_flag(recipient, VM_EMAIL_EXT_RECS);
6451+
6452+
if (send_email) {
6453+
/* Send an email if possible, fall back to just notifications if not. */
6454+
ast_copy_string(fmt, recdata->recording_ext, sizeof(fmt));
6455+
ast_copy_string(clid, recdata->call_callerid, sizeof(clid));
6456+
ast_callerid_split(clid, cidname, sizeof(cidname), cidnum, sizeof(cidnum));
6457+
6458+
/* recdata->call_callerchan itself no longer exists, so we can't use the real channel. Use a dummy one. */
6459+
chan = ast_dummy_channel_alloc();
6460+
}
6461+
if (chan) {
6462+
notify_new_message(chan, recipient, NULL, msgnum, duration, fmt, cidnum, cidname, "");
6463+
ast_channel_unref(chan);
6464+
} else {
6465+
if (send_email) { /* We tried and failed. */
6466+
ast_log(LOG_WARNING, "Failed to allocate dummy channel, email will not be sent\n");
6467+
}
6468+
notify_new_state(recipient);
6469+
}
64416470
}
64426471

64436472
free_user(recipient);

configs/samples/voicemail.conf.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ pagerdateformat=%A, %B %d, %Y at %r
262262
; option lets you customize the format sent to particular mailboxes.
263263
; Useful if Windows users want wav49, but Linux users want gsm.
264264
; [per-mailbox only]
265+
; attachextrecs=no ; Whether to attach recordings that are externally added to mailboxes,
266+
; such as through MixMonitor. Default is no.
265267
; saycid=yes ; Say the caller id information before the message. If not described,
266268
; or set to no, it will be in the envelope. When enabled, if a recorded file
267269
; with the same name as the caller id exists in
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Subject: app_voicemail
2+
3+
The voicemail user option attachextrecs can
4+
now be set to control whether external recordings
5+
trigger voicemail email notifications.

0 commit comments

Comments
 (0)