[Asterisk-code-review] app_voicemail: Fix missing email in msg_create_from_file. (asterisk[20])

N A asteriskteam at digium.com
Thu Dec 8 06:38:33 CST 2022


N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/19673 )


Change subject: app_voicemail: Fix missing email in msg_create_from_file.
......................................................................

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
---
M apps/app_voicemail.c
M configs/samples/voicemail.conf.sample
A doc/CHANGES-staging/app_voicemail_attachext.txt
3 files changed, 59 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/73/19673/1

diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index 510e15d..1aca59b 100644
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -570,6 +570,7 @@
 #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
@@ -1258,6 +1259,8 @@
 		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")) {
@@ -6418,6 +6421,12 @@
 	 * 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",
@@ -6437,7 +6446,27 @@
 		}
 
 		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);
diff --git a/configs/samples/voicemail.conf.sample b/configs/samples/voicemail.conf.sample
index 30054b5..e799cf6 100644
--- a/configs/samples/voicemail.conf.sample
+++ b/configs/samples/voicemail.conf.sample
@@ -262,6 +262,8 @@
 			; 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
diff --git a/doc/CHANGES-staging/app_voicemail_attachext.txt b/doc/CHANGES-staging/app_voicemail_attachext.txt
new file mode 100644
index 0000000..c56f04a
--- /dev/null
+++ b/doc/CHANGES-staging/app_voicemail_attachext.txt
@@ -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.

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/19673
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 20
Gerrit-Change-Id: I597cbb9cf971a18d8776172b26ab187dc096a5c7
Gerrit-Change-Number: 19673
Gerrit-PatchSet: 1
Gerrit-Owner: N A <asterisk at phreaknet.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20221208/c0891f73/attachment-0001.html>


More information about the asterisk-code-review mailing list