From 578dcc6256e8f6f74d852d1955a692448b4c7f43 Mon Sep 17 00:00:00 2001 From: fusionate Date: Fri, 4 Aug 2023 03:49:29 +0000 Subject: [PATCH] Voicemail - Email [Function]: Send basic email even if email template is disabled. --- .../scripts/app/voicemail/app_languages.lua | 9 ++ .../resources/functions/send_email.lua | 103 +++++++++++------- 2 files changed, 71 insertions(+), 41 deletions(-) diff --git a/app/switch/resources/scripts/app/voicemail/app_languages.lua b/app/switch/resources/scripts/app/voicemail/app_languages.lua index 426e1d1414..b831e2e273 100644 --- a/app/switch/resources/scripts/app/voicemail/app_languages.lua +++ b/app/switch/resources/scripts/app/voicemail/app_languages.lua @@ -27,4 +27,13 @@ text['label-attached']['fr-fr'] = "Attaché"; text['label-attached']['de-de'] = "im Anhang"; text['label-attached']['de-at'] = "im Anhang"; +text['label-voicemail'] = {}; +text['label-voicemail']['en-us'] = "Voicemail"; +text['label-voicemail']['es-cl'] = "Correo de Voz"; +text['label-voicemail']['pt-pt'] = "Correio de Voz"; +text['label-voicemail']['ru-ru'] = "Голосовая почта"; +text['label-voicemail']['fr-fr'] = "Messagerie Vocale"; +text['label-voicemail']['de-de'] = "Mailbox"; +text['label-voicemail']['de-at'] = "Mailbox"; + return text \ No newline at end of file diff --git a/app/switch/resources/scripts/app/voicemail/resources/functions/send_email.lua b/app/switch/resources/scripts/app/voicemail/resources/functions/send_email.lua index 6a3a3790f3..0779535f69 100644 --- a/app/switch/resources/scripts/app/voicemail/resources/functions/send_email.lua +++ b/app/switch/resources/scripts/app/voicemail/resources/functions/send_email.lua @@ -214,53 +214,74 @@ voicemail_name_formatted = voicemail_name_formatted.." ("..voicemail_description..")"; end + --prepare file + file = voicemail_dir.."/"..id.."/msg_"..uuid.."."..vm_message_ext; + --prepare the subject - subject = subject:gsub("${caller_id_name}", caller_id_name); - subject = subject:gsub("${caller_id_number}", caller_id_number); - subject = subject:gsub("${message_date}", message_date); - subject = subject:gsub("${message_duration}", message_length_formatted); - subject = subject:gsub("${account}", voicemail_name_formatted); - subject = subject:gsub("${voicemail_id}", id); - subject = subject:gsub("${voicemail_description}", voicemail_description); - subject = subject:gsub("${voicemail_name_formatted}", voicemail_name_formatted); - subject = subject:gsub("${domain_name}", domain_name); - subject = subject:gsub("${new_messages}", new_messages); - subject = trim(subject); + if (subject ~= nil) then + subject = subject:gsub("${caller_id_name}", caller_id_name); + subject = subject:gsub("${caller_id_number}", caller_id_number); + subject = subject:gsub("${message_date}", message_date); + subject = subject:gsub("${message_duration}", message_length_formatted); + subject = subject:gsub("${account}", voicemail_name_formatted); + subject = subject:gsub("${voicemail_id}", id); + subject = subject:gsub("${voicemail_description}", voicemail_description); + subject = subject:gsub("${voicemail_name_formatted}", voicemail_name_formatted); + subject = subject:gsub("${domain_name}", domain_name); + subject = subject:gsub("${new_messages}", new_messages); + subject = trim(subject); + else + subject = text['label-voicemail'] .. ' ' .. caller_id_name .. ' <' .. caller_id_number .. '> ' .. message_length_formatted; + end subject = '=?utf-8?B?'..base64.encode(subject)..'?='; --prepare the body - body = body:gsub("${caller_id_name}", caller_id_name); - body = body:gsub("${caller_id_number}", caller_id_number); - body = body:gsub("${message_date}", message_date); - if (transcription ~= nil) then - transcription = transcription:gsub("%%", "*"); - body = body:gsub("${message_text}", transcription); - end - body = body:gsub("${message_duration}", message_length_formatted); - body = body:gsub("${account}", voicemail_name_formatted); - body = body:gsub("${voicemail_id}", id); - body = body:gsub("${voicemail_description}", voicemail_description); - body = body:gsub("${voicemail_name_formatted}", voicemail_name_formatted); - body = body:gsub("${domain_name}", domain_name); - body = body:gsub("${sip_to_user}", id); - if (origination_callee_id_name ~= nil) then - body = body:gsub("${origination_callee_id_name}", origination_callee_id_name); - end - body = body:gsub("${dialed_user}", id); - if (voicemail_file == "attach") then - body = body:gsub("${message}", text['label-attached']); - elseif (voicemail_file == "link") then - body = body:gsub("${message}", ""..text['label-download']..""); + if (body ~= nil) then + body = body:gsub("${caller_id_name}", caller_id_name); + body = body:gsub("${caller_id_number}", caller_id_number); + body = body:gsub("${message_date}", message_date); + if (transcription ~= nil) then + transcription = transcription:gsub("%%", "*"); + body = body:gsub("${message_text}", transcription); + end + body = body:gsub("${message_duration}", message_length_formatted); + body = body:gsub("${account}", voicemail_name_formatted); + body = body:gsub("${voicemail_id}", id); + body = body:gsub("${voicemail_description}", voicemail_description); + body = body:gsub("${voicemail_name_formatted}", voicemail_name_formatted); + body = body:gsub("${domain_name}", domain_name); + body = body:gsub("${sip_to_user}", id); + if (origination_callee_id_name ~= nil) then + body = body:gsub("${origination_callee_id_name}", origination_callee_id_name); + end + body = body:gsub("${dialed_user}", id); + if (voicemail_file == "attach" and file) then + body = body:gsub("${message}", text['label-attached']); + elseif (voicemail_file == "link") then + body = body:gsub("${message}", ""..text['label-download']..""); + else + body = body:gsub("${message}", ""..text['label-listen']..""); + end + --body = body:gsub(" ", " "); + --body = body:gsub("%s+", ""); + --body = body:gsub(" ", " "); + body = trim(body); else - body = body:gsub("${message}", ""..text['label-listen']..""); + body = ''; + if (caller_id_name ~= nil and caller_id_name ~= caller_id_number) then + body = body .. caller_id_name .. '
'; + end + body = body .. caller_id_number .. '
'; + body = body .. message_date .. '
'; + if (voicemail_file == "attach" and file) then + body = body .. '
' .. text['label-attached']; + elseif (voicemail_file == "link") then + body = body .. "
"..text['label-download']..""; + else + body = body .. "
"..text['label-listen']..""; + end + body = body .. ''; end - --body = body:gsub(" ", " "); - --body = body:gsub("%s+", ""); - --body = body:gsub(" ", " "); - body = trim(body); - - --prepare file - file = voicemail_dir.."/"..id.."/msg_"..uuid.."."..vm_message_ext; --send the email send_mail(headers,