Update send_email.lua

This commit is contained in:
FusionPBX
2017-12-17 01:51:39 -07:00
committed by GitHub
parent d06b99e01e
commit fc7ab309a4
@@ -114,20 +114,31 @@
if (debug["info"]) then if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail] message length: " .. message_length .. "\n"); freeswitch.consoleLog("notice", "[voicemail] message length: " .. message_length .. "\n");
end end
local message_date = os.date("%A, %d %b %Y %I:%M %p", created_epoch) local message_date = os.date("%A, %d %b %Y %I:%M %p", created_epoch);
--prepare the files --connect to the database
if (transcription ~= nil) then local dbh = Database.new('system');
file_subject = scripts_dir.."/app/voicemail/resources/templates/"..default_language.."/"..default_dialect.."/email_subject.tpl";
file_body = scripts_dir.."/app/voicemail/resources/templates/"..default_language.."/"..default_dialect.."/email_body_transcription.tpl"; --get the templates
local sql = "SELECT * FROM v_email_templates ";
sql = sql .. "WHERE (domain_uuid = :domain_uuid or domain_uuid is null) ";
sql = sql .. "AND template_language = :template_language ";
sql = sql .. "AND template_category = 'email' "
if (transcription == nil) then
sql = sql .. "AND template_subcategory = 'default' "
else else
file_subject = scripts_dir.."/app/voicemail/resources/templates/"..default_language.."/"..default_dialect.."/email_subject.tpl"; sql = sql .. "AND template_subcategory = 'transcription' "
file_body = scripts_dir.."/app/voicemail/resources/templates/"..default_language.."/"..default_dialect.."/email_body.tpl";
end end
if (not file_exists(file_subject)) then sql = sql .. "AND template_enabled = 'true' "
file_subject = scripts_dir.."/app/voicemail/resources/templates/en/us/email_subject.tpl"; sql = sql .. "ORDER BY domain_uuid DESC "
file_body = scripts_dir.."/app/voicemail/resources/templates/en/us/email_body.tpl"; local params = {domain_uuid = domain_uuid, template_language = default_language.."-"..default_dialect};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end end
dbh:query(sql, params, function(row)
subject = row["template_subject"];
body = row["template_body"];
end);
--get the link_address --get the link_address
link_address = http_protocol.."://"..domain_name..project_path; link_address = http_protocol.."://"..domain_name..project_path;
@@ -150,10 +161,11 @@
if (voicemail_description ~= nil and voicemail_description ~= "" and voicemail_description ~= id) then if (voicemail_description ~= nil and voicemail_description ~= "" and voicemail_description ~= id) then
voicemail_name_formatted = voicemail_name_formatted.." ("..voicemail_description..")"; voicemail_name_formatted = voicemail_name_formatted.." ("..voicemail_description..")";
end end
--prepare the subject --prepare the subject
local f = io.open(file_subject, "r"); --local f = io.open(file_subject, "r");
local subject = f:read("*all"); --local subject = f:read("*all");
f:close(); --f:close();
subject = subject:gsub("${caller_id_name}", caller_id_name); subject = subject:gsub("${caller_id_name}", caller_id_name);
subject = subject:gsub("${caller_id_number}", caller_id_number); subject = subject:gsub("${caller_id_number}", caller_id_number);
subject = subject:gsub("${message_date}", message_date); subject = subject:gsub("${message_date}", message_date);
@@ -167,9 +179,9 @@
subject = '=?utf-8?B?'..base64.encode(subject)..'?='; subject = '=?utf-8?B?'..base64.encode(subject)..'?=';
--prepare the body --prepare the body
local f = io.open(file_body, "r"); --local f = io.open(file_body, "r");
body = f:read("*all"); --body = f:read("*all");
f:close(); --f:close();
body = body:gsub("${caller_id_name}", caller_id_name); body = body:gsub("${caller_id_name}", caller_id_name);
body = body:gsub("${caller_id_number}", caller_id_number); body = body:gsub("${caller_id_number}", caller_id_number);
body = body:gsub("${message_date}", message_date); body = body:gsub("${message_date}", message_date);
@@ -191,11 +203,13 @@
else else
body = body:gsub("${message}", "<a href='"..link_address.."/app/voicemails/voicemail_messages.php?action=autoplay&id="..db_voicemail_uuid.."&uuid="..uuid.."'>"..text['label-listen'].."</a>"); body = body:gsub("${message}", "<a href='"..link_address.."/app/voicemails/voicemail_messages.php?action=autoplay&id="..db_voicemail_uuid.."&uuid="..uuid.."'>"..text['label-listen'].."</a>");
end end
body = body:gsub(" ", "&nbsp;"); --body = body:gsub("<", "");
body = body:gsub("%s+", ""); --body = body:gsub(">", "");
body = body:gsub("&nbsp;", " "); --body = body:gsub(" ", "&nbsp;");
body = body:gsub("\n", ""); --body = body:gsub("%s+", "");
body = body:gsub("\n", ""); --body = body:gsub("&nbsp;", " ");
--body = body:gsub("\n", "");
--body = body:gsub("\n", "");
body = trim(body); body = trim(body);
--prepare file --prepare file