Status > Emails: Added ability to view, download, resend and/or delete failed emails.

This commit is contained in:
Nate Jones 2015-03-14 06:43:19 +00:00
parent 37bf2da79b
commit 3dd924775a
5 changed files with 373 additions and 18 deletions

View File

@ -65,6 +65,21 @@ $text['label-status_failed']['es-cl'] = "Fracasado";
$text['label-status_failed']['pt-pt'] = "Fracassado";
$text['label-status_failed']['fr-fr'] = "Manqué";
$text['label-from']['en-us'] = "From";
$text['label-from']['es-cl'] = "Desde";
$text['label-from']['pt-pt'] = "A Partir De";
$text['label-from']['fr-fr'] = "A Partir De";
$text['label-to']['en-us'] = "To";
$text['label-to']['es-cl'] = "Final";
$text['label-to']['pt-pt'] = "Final";
$text['label-to']['fr-fr'] = "Fin";
$text['label-subject']['en-us'] = "Subject";
$text['label-subject']['es-cl'] = "Sujeto";
$text['label-subject']['pt-pt'] = "Assunto";
$text['label-subject']['fr-fr'] = "Sujet";
$text['label-message']['en-us'] = "Message";
$text['label-message']['es-cl'] = "Mensaje";
$text['label-message']['pt-pt'] = "Mensagem";
@ -80,9 +95,59 @@ $text['label-attachment']['es-cl'] = "Accesorio";
$text['label-attachment']['pt-pt'] = "Acessório";
$text['label-attachment']['fr-fr'] = "Attachement";
$text['label-attachment_download']['en-us'] = "Download";
$text['label-attachment_download']['es-cl'] = "Descargar";
$text['label-attachment_download']['pt-pt'] = "Descarregar";
$text['label-attachment_download']['fr-fr'] = "Télécharger";
$text['label-download']['en-us'] = "Download";
$text['label-download']['es-cl'] = "Descargar";
$text['label-download']['pt-pt'] = "Descarregar";
$text['label-download']['fr-fr'] = "Télécharger";
$text['label-resend']['en-us'] = "Resend";
$text['label-resend']['es-cl'] = "Vuelva a Enviar";
$text['label-resend']['pt-pt'] = "Reenviar";
$text['label-resend']['fr-fr'] = "Renvoyer";
$text['message-invalid_email']['en-us'] = "Invalid Email";
$text['message-invalid_email']['es-cl'] = "No Válida de Correo Electrónico";
$text['message-invalid_email']['pt-pt'] = "E-mail Inválido";
$text['message-invalid_email']['fr-fr'] = "Email Valide";
$text['message-decoding_error']['en-us'] = "MIME Message Decoding Error";
$text['message-decoding_error']['es-cl'] = "MIME Mensaje Decodificación de error";
$text['message-decoding_error']['pt-pt'] = "MIME Mensagem Decoding erro";
$text['message-decoding_error']['fr-fr'] = "MIME message Décodage Erreur";
$text['title-view_email']['en-us'] = "View Email";
$text['title-view_email']['es-cl'] = "Ver Email";
$text['title-view_email']['pt-pt'] = "Ver Email";
$text['title-view_email']['fr-fr'] = "Visualiser Courriel";
$text['header-view_email']['en-us'] = "View Email";
$text['header-view_email']['es-cl'] = "Ver Email";
$text['header-view_email']['pt-pt'] = "Ver Email";
$text['header-view_email']['fr-fr'] = "Visualiser Courriel";
$text['button-back']['en-us'] = "Back";
$text['button-back']['es-cl'] = "Volver";
$text['button-back']['pt-pt'] = "Voltar";
$text['button-back']['fr-fr'] = "Retour";
$text['button-download']['en-us'] = "Download";
$text['button-download']['es-cl'] = "Descargar";
$text['button-download']['pt-pt'] = "Descarregar";
$text['button-download']['fr-fr'] = "Télécharger";
$text['button-resend']['en-us'] = "Resend";
$text['button-resend']['es-cl'] = "Vuelva a Enviar";
$text['button-resend']['pt-pt'] = "Reenviar";
$text['button-resend']['fr-fr'] = "Renvoyer";
$text['message-message_resent']['en-us'] = "Message Resent";
$text['message-message_resent']['es-cl'] = "Mensaje Resent";
$text['message-message_resent']['pt-pt'] = "Mensagem Reenviada";
$text['message-message_resent']['fr-fr'] = "Renvoyer un Message";
$text['message-resend_failed']['en-us'] = "Resend Failed";
$text['message-resend_failed']['es-cl'] = "Vuelva a enviar Error";
$text['message-resend_failed']['pt-pt'] = "Reenviar Falha";
$text['message-resend_failed']['fr-fr'] = "Renvoyer Échec";
?>

View File

@ -17,7 +17,7 @@
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Copyright (C) 2008-2012
Copyright (C) 2008-2015
All Rights Reserved.
Contributor(s):
@ -50,7 +50,9 @@ else {
unset($sql, $prep_statement);
//set message
$_SESSION["message"] = $text['message-delete'];
if ($_SESSION["message"] == '') {
$_SESSION["message"] = $text['message-delete'];
}
}
//redirect user

207
app/emails/email_view.php Normal file
View File

@ -0,0 +1,207 @@
<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Copyright (C) 2008-2015
All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
include "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
if (permission_exists('email_view')) {
//access granted
}
else {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//get email
$email_uuid = check_str($_REQUEST["id"]);
$msg_found = false;
if ($email_uuid != '') {
$sql = "select * from v_emails ";
$sql .= "where email_uuid = '".$email_uuid."' ";
$sql .= "and domain_uuid = '".$domain_uuid."' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
$result_count = count($result);
unset ($prep_statement, $sql);
if ($result_count > 0) {
foreach($result as $row) {
$sent = $row['sent_date'];
$type = $row['type'];
$status = $row['status'];
$email = $row['email'];
$msg_found = true;
break;
}
}
}
if (!$msg_found) {
$_SESSION["message"] = $text['message-invalid_email'];
header("Location: emails.php");
exit;
}
//includes
require('resources/pop3/mime_parser.php');
require('resources/pop3/rfc822_addresses.php');
//parse the email message
$mime = new mime_parser_class;
$mime->decode_bodies = 1;
$parameters = array('Data' => $email);
$success = $mime->Decode($parameters, $decoded);
if ($success) {
//get the headers
$headers = json_decode($decoded[0]["Headers"]["x-headers:"], true);
$subject = $decoded[0]["Headers"]["subject:"];
$from = $decoded[0]["Headers"]["from:"];
$reply_to = $decoded[0]["Headers"]["reply-to:"];
$to = $decoded[0]["Headers"]["to:"];
$subject = $decoded[0]["Headers"]["subject:"];
if (substr_count($subject, '=?utf-8?B?') > 0) {
$subject = str_replace('=?utf-8?B?', '', $subject);
$subject = str_replace('?=', '', $subject);
$subject = base64_decode($subject);
}
//get the body
$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"]; $body = $body_plain; }
}
}
else {
$content_type_array = explode(";", $content_type);
$body = $decoded[0]["Body"];
}
//get the attachments (if any)
foreach ($decoded[0]['Parts'] as &$parts_array) {
$content_type = $parts_array["Parts"][0]["Headers"]["content-type:"]; //audio/wav; name="msg_b64f97e0-8570-11e4-8400-35da04cdaa74.wav"
$content_transfer_encoding = $parts_array["Parts"][0]["Headers"]["content-transfer-encoding:"]; //base64
$content_disposition = $parts_array["Parts"][0]["Headers"]["content-disposition"]; //attachment; filename="msg_b64f97e0-8570-11e4-8400-35da04cdaa74.wav"
$file_name = $parts_array["FileName"];
$file_size = $parts_array["BodyLength"];
}
}
else {
$_SESSION["message"] = $text['message-decoding_error'].(($mime->error != '') ? ': '.htmlspecialchars($mime->error) : null);
header("Location: emails.php");
exit;
}
//show the header
$document['title'] = $text['title-view_email'];
require_once "resources/header.php";
//show content
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo " <tr>";
echo " <td valign='top' align='left' nowrap>";
echo " <b>".$text['header-view_email']."</b>\n";
echo " </td>";
echo " <td valign='top' align='right' nowrap>";
echo " <input type='button' class='btn' alt='".$text['button-back']."' onclick=\"document.location.href='emails.php';\" value='".$text['button-back']."'>";
if (permission_exists('email_download')) {
echo " <input type='button' class='btn' alt='".$text['button-download']."' onclick=\"document.location.href='emails.php?id=".$email_uuid."&a=download';\" value='".$text['button-download']."'>";
}
if (permission_exists('email_resend')) {
echo " <input type='button' class='btn' alt='".$text['button-resend']."' onclick=\"document.location.href='emails.php?id=".$email_uuid."&a=resend';\" value='".$text['button-resend']."'>";
}
echo " </td>";
echo " </tr>";
echo "</table>";
echo "<br>\n";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo "<td width='30%' class='vncell' valign='top' align='left' nowrap>".$text['label-sent']."</td>\n";
echo "<td width='70%' class='vtable' align='left'>".$sent."</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap>".$text['label-type']."</td>\n";
echo "<td class='vtable' align='left'>".$text['label-type_'.$type]."</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap>".$text['label-status']."</td>\n";
echo "<td class='vtable' align='left'>".$text['label-status_'.$status]."</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap>".$text['label-from']."</td>\n";
echo "<td class='vtable' align='left'>".$from."</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap>".$text['label-to']."</td>\n";
echo "<td class='vtable' align='left'>".$to."</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap>".$text['label-subject']."</td>\n";
echo "<td class='vtable' align='left'>".$subject."</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap>".$text['label-message']."</td>\n";
echo "<td class='vtable' align='left'>";
echo " <iframe id='msg_display' width='100%' height='250' scrolling='auto' cellspacing='0' style='border: 1px solid #c5d1e5; overflow: scroll;'></iframe>\n";
echo " <textarea id='msg' width='1' height='1' style='width: 1px; height: 1px; display: none;'>".$body."</textarea>\n";
echo " <script>";
echo " var iframe = document.getElementById('msg_display');";
echo " iframe.contentDocument.write(document.getElementById('msg').value);";
echo " iframe.contentDocument.close();";
echo " </script>\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap>".$text['label-attachment']."</td>\n";
echo "<td class='vtable' align='left'>".$file_name." (".round($file_size/1024,2)." KB)</td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "<br><br>";
//include the footer
require_once "resources/footer.php";
?>

View File

@ -18,9 +18,82 @@ else {
$order_by = ($_GET["order_by"] != '') ? $_GET["order_by"] : 'sent_date';
$order = ($_GET["order"] != '') ? $_GET["order"] : 'desc';
//get the fax_uuid
if (count($_GET) > 0) {
$email_uuid = check_str($_GET["id"]);
//download email
if ($_REQUEST['a'] == 'download' && permission_exists('email_download')) {
$email_uuid = check_str($_REQUEST["id"]);
$msg_found = false;
if ($email_uuid != '') {
$sql = "select call_uuid, email from v_emails ";
$sql .= "where email_uuid = '".$email_uuid."' ";
$sql .= "and domain_uuid = '".$domain_uuid."' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
$result_count = count($result);
if ($result_count > 0) {
foreach($result as $row) {
$call_uuid = $row['call_uuid'];
$email = $row['email'];
$msg_found = true;
break;
}
}
unset ($prep_statement, $sql, $result, $result_count);
}
if ($msg_found) {
header("Content-Type: message/rfc822");
header('Content-Disposition: attachment; filename="'.$call_uuid.'.eml"');
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Content-Length: ".strlen($email));
echo $email;
exit;
}
}
//resend email
if ($_REQUEST['a'] == 'resend' && permission_exists('email_resend')) {
$email_uuid = check_str($_REQUEST["id"]);
$msg_found = false;
if ($email_uuid != '') {
$sql = "select email from v_emails ";
$sql .= "where email_uuid = '".$email_uuid."' ";
$sql .= "and domain_uuid = '".$domain_uuid."' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
$result_count = count($result);
if ($result_count > 0) {
foreach($result as $row) {
$email = $row['email'];
$msg_found = true;
break;
}
}
unset ($prep_statement, $sql, $result, $result_count);
}
if ($msg_found) {
$msg = $email;
require_once "secure/v_mailto.php";
if ($mailer_error == '') {
$_SESSION["message"] = $text['message-message_resent'];
header("Location: email_delete.php?id=".$email_uuid);
}
else {
$_SESSION["message_mood"] = 'negative';
$_SESSION["message_delay"] = '4'; //sec
$_SESSION["message"] = $text['message-resend_failed'].": ".$mailer_error;
header("Location: emails.php");
}
}
exit;
}
//additional includes
@ -83,7 +156,6 @@ else {
echo th_order_by('type', $text['label-type'], $order_by, $order);
echo th_order_by('status', $text['label-status'], $order_by, $order);
echo "<th>".$text['label-message']."</th>\n";
echo "<th>".$text['label-attachment']."</th>\n";
echo "<th>".$text['label-reference']."</th>\n";
echo "<td class='list_control_icons'>&nbsp;</td>\n";
echo "</tr>\n";
@ -114,17 +186,24 @@ else {
echo " </td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".$text['label-type_'.$row['type']]."</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".$text['label-status_'.$row['status']]."</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'><a href=''>".$text['label-message_view']."</a></td>\n";
echo " <td valign='top' class='".$row_style[$c]." tr_link_void'><a href=''>".$text['label-attachment_download']."</a></td>\n";
echo " <td valign='top' class='".$row_style[$c]." tr_link_void'>";
echo " <a href='email_view.php?id=".$row['email_uuid']."'>".$text['label-message_view']."</a>&nbsp;&nbsp;";
if (permission_exists('email_download')) {
echo " <a href='?id=".$row['email_uuid']."&a=download'>".$text['label-download']."</a>&nbsp;&nbsp;";
}
if (permission_exists('email_resend')) {
echo " <a href='?id=".$row['email_uuid']."&a=resend'>".$text['label-resend']."</a>";
}
echo " </td>\n";
echo " <td valign='top' class='row_stylebg tr_link_void' style='white-space: nowrap; vertical-align: top;'>";
echo " <a href='".PROJECT_PATH."/app/xml_cdr/xml_cdr_details.php?uuid=".$row['call_uuid']."'>".$text['label-reference_cdr']."</a>";
echo " ".($caller_id_name != '') ? "&nbsp;&nbsp;".$caller_id_name." (".format_phone($caller_id_number).")" : $caller_id_number;
echo "&nbsp;&nbsp;<span style='font-size: 150%; line-height: 10px;'>&#8674;</span>&nbsp;&nbsp;".$destination_number;
echo " </td>\n";
echo " <td class='list_control_icons'>";
echo "<a href='email_view.php?id=".$row['email_uuid']."' alt='".$text['label-message_view']."'>$v_link_label_view</a>";
echo "<a href='email_view.php?id=".$row['email_uuid']."' alt='".$text['label-message_view']."'>$v_link_label_view</a>";
if (permission_exists('email_delete')) {
echo "<a href='email_delete.php?id=".$row['email_uuid']."' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">$v_link_label_delete</a>";
echo "<a href='email_delete.php?id=".$row['email_uuid']."' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">$v_link_label_delete</a>";
}
echo " </td>\n";
echo "</tr>\n";

View File

@ -45,7 +45,7 @@
$string = preg_replace ('/<[^>]*>/', ' ', $string);
// ----- remove control characters -----
$string = str_replace("\r", '', $string); // --- replace with empty space
$string = str_replace("\n", ' ', $string); // --- replace with space
$string = str_replace("\t", ' ', $string); // --- replace with space
@ -60,9 +60,11 @@
ini_set('memory_limit', '128M');
//listen for standard input
$fd = fopen("php://stdin", "r");
$msg = file_get_contents ("php://stdin");
fclose($fd);
if ($msg == '') {
$fd = fopen("php://stdin", "r");
$msg = file_get_contents ("php://stdin");
fclose($fd);
}
//save output to
$fp = fopen(sys_get_temp_dir()."/mailer-app.log", "w");