Skip to content

Commit

Permalink
app_voicemail: Fix missing email in msg_create_from_file.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
InterLinked1 authored and Friendly Automation committed Dec 8, 2022
1 parent 52ed64e commit 9e14523
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
31 changes: 30 additions & 1 deletion apps/app_voicemail.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ static AST_LIST_HEAD_STATIC(vmstates, vmstate);
#define VM_MOVEHEARD (1 << 16) /*!< Move a "heard" message to Old after listening to it */
#define VM_MESSAGEWRAP (1 << 17) /*!< Wrap around from the last message to the first, and vice-versa */
#define VM_FWDURGAUTO (1 << 18) /*!< Autoset of Urgent flag on forwarded Urgent messages set globally */
#define VM_EMAIL_EXT_RECS (1 << 19) /*!< Send voicemail emails when an external recording is added to a mailbox */
#define ERROR_LOCK_PATH -100
#define ERROR_MAX_MSGS -101
#define OPERATOR_EXIT 300
Expand Down Expand Up @@ -1258,6 +1259,8 @@ static void apply_option(struct ast_vm_user *vmu, const char *var, const char *v
ast_set2_flag(vmu, ast_true(value), VM_ATTACH);
} else if (!strcasecmp(var, "attachfmt")) {
ast_copy_string(vmu->attachfmt, value, sizeof(vmu->attachfmt));
} else if (!strcasecmp(var, "attachextrecs")) {
ast_set2_flag(vmu, ast_true(value), VM_EMAIL_EXT_RECS);
} else if (!strcasecmp(var, "serveremail")) {
ast_copy_string(vmu->serveremail, value, sizeof(vmu->serveremail));
} else if (!strcasecmp(var, "fromstring")) {
Expand Down Expand Up @@ -6418,6 +6421,12 @@ static int msg_create_from_file(struct ast_vm_recording_data *recdata)
* 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
* time to create the voicemail database entry. */
if (ast_fileexists(destination, NULL, NULL) > 0) {
struct ast_channel *chan = NULL;
char fmt[80];
char clid[80];
char cidnum[80], cidname[80];
int send_email;

if (ast_check_realtime("voicemail_data")) {
get_date(date, sizeof(date));
ast_store_realtime("voicemail_data",
Expand All @@ -6437,7 +6446,27 @@ static int msg_create_from_file(struct ast_vm_recording_data *recdata)
}

STORE(dir, recipient->mailbox, recipient->context, msgnum, NULL, recipient, fmt, 0, vms, "", msg_id);
notify_new_state(recipient);

send_email = ast_test_flag(recipient, VM_EMAIL_EXT_RECS);

if (send_email) {
/* Send an email if possible, fall back to just notifications if not. */
ast_copy_string(fmt, recdata->recording_ext, sizeof(fmt));
ast_copy_string(clid, recdata->call_callerid, sizeof(clid));
ast_callerid_split(clid, cidname, sizeof(cidname), cidnum, sizeof(cidnum));

/* recdata->call_callerchan itself no longer exists, so we can't use the real channel. Use a dummy one. */
chan = ast_dummy_channel_alloc();
}
if (chan) {
notify_new_message(chan, recipient, NULL, msgnum, duration, fmt, cidnum, cidname, "");
ast_channel_unref(chan);
} else {
if (send_email) { /* We tried and failed. */
ast_log(LOG_WARNING, "Failed to allocate dummy channel, email will not be sent\n");
}
notify_new_state(recipient);
}
}

free_user(recipient);
Expand Down
2 changes: 2 additions & 0 deletions configs/samples/voicemail.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ pagerdateformat=%A, %B %d, %Y at %r
; option lets you customize the format sent to particular mailboxes.
; Useful if Windows users want wav49, but Linux users want gsm.
; [per-mailbox only]
; attachextrecs=no ; Whether to attach recordings that are externally added to mailboxes,
; such as through MixMonitor. Default is no.
; saycid=yes ; Say the caller id information before the message. If not described,
; or set to no, it will be in the envelope. When enabled, if a recorded file
; with the same name as the caller id exists in
Expand Down
5 changes: 5 additions & 0 deletions doc/CHANGES-staging/app_voicemail_attachext.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Subject: app_voicemail

The voicemail user option attachextrecs can
now be set to control whether external recordings
trigger voicemail email notifications.

0 comments on commit 9e14523

Please sign in to comment.