diff --git a/core/upgrade/app_config.php b/core/upgrade/app_config.php
index 79c8a5b0ea..fa6f3416df 100644
--- a/core/upgrade/app_config.php
+++ b/core/upgrade/app_config.php
@@ -74,6 +74,53 @@
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
+ //schema details
+ $y = 1; //table array index
+ $z = 0; //field array index
+ $apps[$x]['db'][$y]['table'] = "v_emails";
+ $apps[$x]['db'][$y]['fields'][$z]['name'] = "email_uuid";
+ $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = "uuid";
+ $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = "text";
+ $apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = "char(36)";
+ $apps[$x]['db'][$y]['fields'][$z]['key']['type'] = "primary";
+ $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
+ $z++;
+ $apps[$x]['db'][$y]['fields'][$z]['name'] = "call_uuid";
+ $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = "uuid";
+ $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = "text";
+ $apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = "char(36)";
+ $apps[$x]['db'][$y]['fields'][$z]['key']['type'] = "foreign";
+ $apps[$x]['db'][$y]['fields'][$z]['key']['reference']['table'] = "v_xml_cdr";
+ $apps[$x]['db'][$y]['fields'][$z]['key']['reference']['field'] = "uuid";
+ $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
+ $z++;
+ $apps[$x]['db'][$y]['fields'][$z]['name'] = "domain_uuid";
+ $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = "uuid";
+ $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = "text";
+ $apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = "char(36)";
+ $apps[$x]['db'][$y]['fields'][$z]['key']['type'] = "foreign";
+ $apps[$x]['db'][$y]['fields'][$z]['key']['reference']['table'] = "v_domains";
+ $apps[$x]['db'][$y]['fields'][$z]['key']['reference']['field'] = "domain_uuid";
+ $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
+ $z++;
+ $apps[$x]['db'][$y]['fields'][$z]['name'] = "sent_date";
+ $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = "timestamp";
+ $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = "date";
+ $apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = "timestamp";
+ $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
+ $z++;
+ $apps[$x]['db'][$y]['fields'][$z]['name'] = "type";
+ $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'] = "status";
+ $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'] = "email";
+ $apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
+ $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
+
/*
$y = 0; //table array index
$z = 0; //field array index
diff --git a/resources/install/scripts/app/voicemail/resources/templates/en/gb/email_body.tpl b/resources/install/scripts/app/voicemail/resources/templates/en/gb/email_body.tpl
index c4fc58960c..d18866fa7d 100644
--- a/resources/install/scripts/app/voicemail/resources/templates/en/gb/email_body.tpl
+++ b/resources/install/scripts/app/voicemail/resources/templates/en/gb/email_body.tpl
@@ -1,7 +1,9 @@
+
Message From "${caller_id_name}" ${caller_id_number}
Created: ${message_date}
Duration: ${message_duration}
Account: ${account}@${domain_name}
-
\ No newline at end of file
+
+
\ No newline at end of file
diff --git a/resources/install/scripts/app/voicemail/resources/templates/en/us/email_body.tpl b/resources/install/scripts/app/voicemail/resources/templates/en/us/email_body.tpl
index c4fc58960c..d18866fa7d 100644
--- a/resources/install/scripts/app/voicemail/resources/templates/en/us/email_body.tpl
+++ b/resources/install/scripts/app/voicemail/resources/templates/en/us/email_body.tpl
@@ -1,7 +1,9 @@
+
Message From "${caller_id_name}" ${caller_id_number}
Created: ${message_date}
Duration: ${message_duration}
Account: ${account}@${domain_name}
-
\ No newline at end of file
+
+
\ No newline at end of file
diff --git a/resources/install/scripts/email.lua b/resources/install/scripts/email.lua
index 3b5e06bc9e..9670d51dd7 100644
--- a/resources/install/scripts/email.lua
+++ b/resources/install/scripts/email.lua
@@ -36,7 +36,7 @@
--convert_ext (optional) to replace the file's extension
--Example
- --luarun email.lua to@domain.com from@domain.com 'subject' 'body'
+ --luarun email.lua to@domain.com from@domain.com 'headers' 'subject' 'body'
--get the argv values
script_name = argv[0];
diff --git a/secure/v_mailto.php b/secure/v_mailto.php
index 60c7e579a9..80577cc9b6 100644
--- a/secure/v_mailto.php
+++ b/secure/v_mailto.php
@@ -95,21 +95,18 @@
//get the body
$body = '';
- foreach($decoded[0]["Parts"] as $row) {
- $content_type = $row['Headers']['content-type:'];
- if (substr($content_type, 0, 21) == "multipart/alternative") {
- $content_type = $row["Parts"][0]["Headers"]["content-type:"];
- if (substr($content_type, 0, 9) == "text/html") { $body = $row["Parts"][0]["Body"]; }
- if (substr($content_type, 0, 10) == "text/plain") { $body_plain = $row["Parts"][0]["Body"]; }
- $content_type = $row["Parts"][1]["Headers"]["content-type:"];
- if (substr($content_type, 0, 9) == "text/html") { $body = $row["Parts"][1]["Body"]; }
- if (substr($content_type, 0, 10) == "text/plain") { $body_plain = $row["Parts"][1]["Body"]; }
+ $content_type = $decoded[0]['Headers']['content-type:'];
+ if (substr($content_type, 0, 15) == "multipart/mixed" || substr($content_type, 0, 21) == "multipart/alternative") {
+ foreach($decoded[0]["Parts"] as $row) {
+ $body_content_type = $row["Headers"]["content-type:"];
+ if (substr($body_content_type, 0, 9) == "text/html") { $body = $row["Body"]; }
+ if (substr($body_content_type, 0, 10) == "text/plain") { $body_plain = $row["Body"]; }
}
- else {
- $content_type_array = explode(";", $content_type);
- if ($content_type_array[0] == "text/plain") {
- $body = $row["Body"];
- }
+ }
+ else {
+ $content_type_array = explode(";", $content_type);
+ if ($content_type_array[0] == "text/html" || $content_type_array[0] == "text/plain") {
+ $body = $row["Body"];
}
}
}
@@ -256,12 +253,44 @@
}
//add the body to the email
- $mail->AltBody = $body_plain; // optional, comment out and test
- $mail->MsgHTML($body);
+ if (substr($body, 0, 5) == "ContentType = "text/html";
+ $mail->Body = $body;
+ }
+ else {
+ $mail->Body = ($body != '') ? $body : $body_plain;
+ $mail->AltBody = $body_plain;
+ }
//send the email
if(!$mail->Send()) {
- echo "Mailer Error: " . $mail->ErrorInfo;
+ $mailer_error = $mail->ErrorInfo;
+ echo "Mailer Error: ".$mailer_error."\n\n";
+
+ // log/store message in database for review
+ $email_uuid = uuid();
+ $sql = "insert into v_emails ( ";
+ $sql .= "email_uuid, ";
+ $sql .= "call_uuid, ";
+ $sql .= "domain_uuid, ";
+ $sql .= "sent_date, ";
+ $sql .= "type, ";
+ $sql .= "status, ";
+ $sql .= "email ";
+ $sql .= ") values ( ";
+ $sql .= "'".$email_uuid."', ";
+ $sql .= "'".$headers["X-FusionPBX-Call-UUID"]."', ";
+ $sql .= "'".$headers["X-FusionPBX-Domain-UUID"]."', ";
+ $sql .= "now(),";
+ $sql .= "'".$headers["X-FusionPBX-Email-Type"]."', ";
+ $sql .= "'failed', ";
+ $sql .= "'".str_replace("'", "''", $msg)."' ";
+ $sql .= ") ";
+ $db->exec(check_sql($sql));
+ unset($sql);
+
+ echo "Retained in v_emails as email_uuid = ".$email_uuid."\n";
+
}
else {
echo "Message sent!";
@@ -276,4 +305,35 @@
fwrite($fp, $content);
fclose($fp);
+
+/********************************************************************************************
+
+// save in /tmp as eml file
+
+$fp = fopen(sys_get_temp_dir()."/email.eml", "w");
+
+ob_end_clean();
+ob_start();
+
+$sql = "select email from v_emails where email_uuid = '".$email_uuid."'";
+$prep_statement = $db->prepare($sql);
+if ($prep_statement) {
+ $prep_statement->execute();
+ $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+ foreach ($result as &$row) {
+ echo $row["email"];
+ break;
+ }
+}
+unset($sql, $prep_statement, $result);
+
+$content = ob_get_contents(); //get the output from the buffer
+$content = str_replace("
", "", $content);
+
+ob_end_clean(); //clean the buffer
+
+fwrite($fp, $content);
+fclose($fp);
+
+*/
?>
\ No newline at end of file