diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index 510e15d7880e9845320badf05167767bbdc93c07..1aca59b766347df61f05de8db223e502f35a1299 100644 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -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 @@ -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")) { @@ -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", @@ -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); diff --git a/configs/samples/voicemail.conf.sample b/configs/samples/voicemail.conf.sample index 30054b59c7503c33f2fe83be8f2bf2f3f4868414..e799cf602be1340147c917908a850469b8264f64 100644 --- a/configs/samples/voicemail.conf.sample +++ b/configs/samples/voicemail.conf.sample @@ -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 diff --git a/doc/CHANGES-staging/app_voicemail_attachext.txt b/doc/CHANGES-staging/app_voicemail_attachext.txt new file mode 100644 index 0000000000000000000000000000000000000000..c56f04a10514b4e044522c65caa7783cb881fad3 --- /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.