diff --git a/app/fax/app_config.php b/app/fax/app_config.php index fe63326d1d..83fe88019d 100644 --- a/app/fax/app_config.php +++ b/app/fax/app_config.php @@ -554,6 +554,10 @@ $apps[$x]['db'][$y]['fields'][$z]['type'] = 'text'; $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ''; $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = 'task_reply_address'; + $apps[$x]['db'][$y]['fields'][$z]['type'] = 'text'; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ''; + $z++; $apps[$x]['db'][$y]['fields'][$z]['name'] = 'task_interrupted'; $apps[$x]['db'][$y]['fields'][$z]['type'] = 'text'; $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ''; diff --git a/app/fax/fax_send.php b/app/fax/fax_send.php index 362dbaf46c..b5491287a0 100644 --- a/app/fax/fax_send.php +++ b/app/fax/fax_send.php @@ -131,7 +131,7 @@ if(!function_exists('gs_cmd')) { } if(!function_exists('fax_enqueue')) { - function fax_enqueue($fax_uuid, $fax_file, $wav_file, $fax_uri, $fax_dtmf, $dial_string){ + function fax_enqueue($fax_uuid, $fax_file, $wav_file, $reply_address, $fax_uri, $fax_dtmf, $dial_string){ global $db, $db_type; $fax_task_uuid = uuid(); @@ -151,12 +151,12 @@ INSERT INTO v_fax_tasks( fax_task_uuid, fax_uuid, task_next_time, task_lock_time, task_fax_file, task_wav_file, task_uri, task_dial_string, task_dtmf, task_interrupted, task_status, task_no_answer_counter, task_no_answer_retry_counter, task_retry_counter, - task_description) + task_reply_address, task_description) VALUES (?, ?, $date_utc_now_sql, NULL, ?, ?, ?, ?, ?, 'false', 0, 0, 0, 0, - ?); + ?, ?); HERE; $stmt = $db->prepare($sql); $i = 0; @@ -167,6 +167,7 @@ HERE; $stmt->bindValue(++$i, $fax_uri); $stmt->bindValue(++$i, $dial_string); $stmt->bindValue(++$i, $fax_dtmf); + $stmt->bindValue(++$i, $reply_address); $stmt->bindValue(++$i, $description); if ($stmt->execute()) { $response = 'Enqueued'; @@ -694,8 +695,6 @@ function fax_split_dtmf(&$fax_number, &$fax_dtmf){ $common_dial_string .= "sip_h_X-accountcode='" . $fax_accountcode . "',"; $common_dial_string .= "domain_uuid=" . $_SESSION["domain_uuid"] . ","; $common_dial_string .= "domain_name=" . $_SESSION["domain_name"] . ","; - $common_dial_string .= "mailto_address='" . $mailto_address . "',"; - $common_dial_string .= "mailfrom_address='" . $mailfrom_address . "',"; $common_dial_string .= "origination_caller_id_name='" . $fax_caller_id_name . "',"; $common_dial_string .= "origination_caller_id_number='" . $fax_caller_id_number . "',"; $common_dial_string .= "fax_ident='" . $fax_caller_id_number . "',"; @@ -722,6 +721,8 @@ function fax_split_dtmf(&$fax_number, &$fax_dtmf){ if ($fax_send_mode != 'queue') { $dial_string .= $t38; + $dial_string .= "mailto_address='" . $mailto_address . "',"; + $dial_string .= "mailfrom_address='" . $mailfrom_address . "',"; $dial_string .= "fax_uri=" . $fax_uri . ","; $dial_string .= "fax_retry_attempts=1" . ","; $dial_string .= "fax_retry_limit=20" . ","; @@ -744,7 +745,7 @@ function fax_split_dtmf(&$fax_number, &$fax_dtmf){ } else{ // enqueue $wav_file = ''; //! @todo add custom message - $response = fax_enqueue($fax_uuid, $fax_file, $wav_file, $fax_uri, $fax_dtmf, $dial_string); + $response = fax_enqueue($fax_uuid, $fax_file, $wav_file, $mailto_address, $fax_uri, $fax_dtmf, $dial_string); } } diff --git a/resources/install/scripts/app/fax/resources/scripts/queue/retry.lua b/resources/install/scripts/app/fax/resources/scripts/queue/retry.lua index feb8f6ef4f..32ef3fac07 100644 --- a/resources/install/scripts/app/fax/resources/scripts/queue/retry.lua +++ b/resources/install/scripts/app/fax/resources/scripts/queue/retry.lua @@ -4,10 +4,11 @@ require "resources.functions.split"; require "resources.functions.count"; - local log = require "resources.functions.log".fax_retry - local Database = require "resources.functions.database" - local Settings = require "resources.functions.lazy_settings" - local Tasks = require "app.fax.resources.scripts.queue.tasks" + local log = require "resources.functions.log".fax_retry + local Database = require "resources.functions.database" + local Settings = require "resources.functions.lazy_settings" + local Tasks = require "app.fax.resources.scripts.queue.tasks" + local send_mail = require "resources.functions.send_mail" local fax_task_uuid = env:getHeader('fax_task_uuid') local task = Tasks.select_task(fax_task_uuid) @@ -69,11 +70,7 @@ local fax_uuid = task.fax_uuid -- Email variables - local email_address = env:getHeader("mailto_address") - local from_address = env:getHeader("mailfrom_address") or email_address local number_dialed = fax_uri:match("/([^/]-)%s*$") - local email_message_fail = "We are sorry the fax failed to go through. It has been attached. Please check the number "..number_dialed..", and if it was correct you might consider emailing it instead." - local email_message_success = "We are happy to report the fax was sent successfully. It has been attached for your records." log.noticef([[<<< CALL RESULT >>> uuid: = '%s' @@ -86,7 +83,6 @@ accountcode: = '%s' origination_caller_id_name: = '%s' origination_caller_id_number: = '%s' - mailfrom_address: = '%s' mailto_address: = '%s' hangup_cause_q850: = '%s' fax_options = '%s' @@ -101,8 +97,7 @@ tostring(accountcode) , tostring(origination_caller_id_name) , tostring(origination_caller_id_number) , - tostring(from_address) , - tostring(email_address) , + tostring(task.reply_address) , tostring(hangup_cause_q850) , fax_options ) @@ -249,6 +244,14 @@ dbh:query(sql); end +--prepare the headers + local mail_x_headers = { + ["X-FusionPBX-Domain-UUID"] = domain_uuid; + ["X-FusionPBX-Domain-Name"] = domain_name; + ["X-FusionPBX-Call-UUID"] = uuid; + ["X-FusionPBX-Email-Type"] = 'email2fax'; + } + -- add the fax files if fax_success == "1" then @@ -328,6 +331,16 @@ end Tasks.remove_task(task) + + if task.reply_address and #task.reply_address > 0 then + send_mail(mail_x_headers, task.reply_address, { + "Fax to: " .. number_dialed .. " SENT", + table.concat{ + "We are happy to report the fax was sent successfully.", + "It has been attached for your records.", + } + }) + end end if fax_success ~= "1" then @@ -349,6 +362,16 @@ Tasks.wait_task(task, answered, hangup_cause_q850) if task.status ~= 0 then Tasks.remove_task(task) + if task.reply_address and #task.reply_address > 0 then + send_mail(mail_x_headers, task.reply_address, { + "Fax to: " .. number_dialed .. " FAILED", + table.concat{ + "We are sorry the fax failed to go through. ", + "It has been attached. Please check the number "..number_dialed..", ", + "and if it was correct you might consider emailing it instead.", + } + }) + end end end end diff --git a/resources/install/scripts/app/fax/resources/scripts/queue/tasks.lua b/resources/install/scripts/app/fax/resources/scripts/queue/tasks.lua index 96f6d612bf..dd049fd8ef 100644 --- a/resources/install/scripts/app/fax/resources/scripts/queue/tasks.lua +++ b/resources/install/scripts/app/fax/resources/scripts/queue/tasks.lua @@ -43,6 +43,7 @@ select t1.task_dtmf as dtmf, t1.task_fax_file as fax_file, t1.task_wav_file as wav_file, + t1.task_reply_address as reply_address, t1.task_no_answer_counter as no_answer_counter, t1.task_no_answer_retry_counter as no_answer_retry_counter, t1.task_retry_counter as retry_counter, diff --git a/secure/fax_to_email.php b/secure/fax_to_email.php index a0576756c0..3005595d6b 100644 --- a/secure/fax_to_email.php +++ b/secure/fax_to_email.php @@ -236,7 +236,7 @@ if(!function_exists('tiff2pdf')) { } if(!function_exists('fax_enqueue')) { - function fax_enqueue($fax_uuid, $fax_file, $wav_file, $fax_uri, $fax_dtmf, $dial_string){ + function fax_enqueue($fax_uuid, $fax_file, $wav_file, $reply_address, $fax_uri, $fax_dtmf, $dial_string){ global $db, $db_type; $fax_task_uuid = uuid(); @@ -256,12 +256,12 @@ INSERT INTO v_fax_tasks( fax_task_uuid, fax_uuid, task_next_time, task_lock_time, task_fax_file, task_wav_file, task_uri, task_dial_string, task_dtmf, task_interrupted, task_status, task_no_answer_counter, task_no_answer_retry_counter, task_retry_counter, - task_description) + task_reply_address, task_description) VALUES (?, ?, $date_utc_now_sql, NULL, ?, ?, ?, ?, ?, 'false', 0, 0, 0, 0, - ?); + ?, ?); HERE; $stmt = $db->prepare($sql); $i = 0; @@ -272,6 +272,7 @@ HERE; $stmt->bindValue(++$i, $fax_uri); $stmt->bindValue(++$i, $dial_string); $stmt->bindValue(++$i, $fax_dtmf); + $stmt->bindValue(++$i, $reply_address); $stmt->bindValue(++$i, $description); if ($stmt->execute()) { $response = 'Enqueued'; @@ -479,8 +480,6 @@ if(!function_exists('fax_split_dtmf')) { $common_dial_string .= "sip_h_X-accountcode='" . $fax_accountcode . "',"; $common_dial_string .= "domain_uuid=" . $_SESSION["domain_uuid"] . ","; $common_dial_string .= "domain_name=" . $_SESSION["domain_name"] . ","; - $common_dial_string .= "mailto_address='" . $mailto_address . "',"; - $common_dial_string .= "mailfrom_address='" . $mailfrom_address . "',"; $common_dial_string .= "origination_caller_id_name='" . $fax_caller_id_name . "',"; $common_dial_string .= "origination_caller_id_number='" . $fax_caller_id_number . "',"; $common_dial_string .= "fax_ident='" . $fax_caller_id_number . "',"; @@ -489,6 +488,8 @@ if(!function_exists('fax_split_dtmf')) { if ($fax_send_mode != 'queue') { $dial_string .= $t38; + $dial_string .= "mailto_address='" . $mailto_address . "',"; + $dial_string .= "mailfrom_address='" . $mailfrom_address . "',"; $dial_string .= "fax_uri=" . $fax_uri . ","; $dial_string .= "fax_retry_attempts=1" . ","; $dial_string .= "fax_retry_limit=20" . ","; @@ -533,7 +534,7 @@ if(!function_exists('fax_split_dtmf')) { } else{ $wav_file = ''; - $response = fax_enqueue($fax_uuid, $fax_file, $wav_file, $fax_uri, $fax_dtmf, $dial_string); + $response = fax_enqueue($fax_uuid, $fax_file, $wav_file, $mailto_address, $fax_uri, $fax_dtmf, $dial_string); } } }