Fix. Decode email message from quoted-printable/base64.

Fix. Allow set custom fonts to support non latin alphabet.
This commit is contained in:
Alexey Melnichuk 2015-11-20 14:45:06 +03:00
parent b95410387e
commit 2f88d1d985
4 changed files with 75 additions and 15 deletions

View File

@ -12,6 +12,13 @@ if ($domains_processed == 1) {
$array[$x]['default_setting_description'] = 'Path to image/logo file displayed in the header of the cover sheet.';
$x++;
$array[$x]['default_setting_category'] = 'fax';
$array[$x]['default_setting_subcategory'] = 'cover_font';
$array[$x]['default_setting_name'] = 'text';
$array[$x]['default_setting_value'] = 'times';
$array[$x]['default_setting_enabled'] = 'false';
$array[$x]['default_setting_description'] = 'Font used to generate cover page. Can be full path to .ttf file or font name alredy installed.';
$x++;
$array[$x]['default_setting_category'] = 'fax';
$array[$x]['default_setting_subcategory'] = 'cover_footer';
$array[$x]['default_setting_name'] = 'text';
$array[$x]['default_setting_value'] = "The information contained in this facsimile is intended for the sole confidential use of the recipient(s) designated above, and may contain confidential and legally privileged information. If you are not the intended recipient, you are hereby notified that the review, disclosure, dissemination, distribution, copying, duplication in any form, and taking of any action in regards to the contents of this document - except with respect to its direct delivery to the intended recipient - is strictly prohibited. Please notify the sender immediately and destroy this cover sheet and all attachments. If stored or viewed electronically, please permanently delete it from your system.";

View File

@ -29,6 +29,7 @@ include "root.php";
require_once "resources/require.php";
require_once "resources/functions/object_to_array.php";
require_once "resources/functions/parse_attachments.php";
require_once "resources/functions/parse_message.php";
require_once "resources/classes/text.php";
//get accounts to monitor
@ -59,6 +60,7 @@ if (sizeof($result) != 0) {
if(strlen($fax_send_mode_default) == 0){
$fax_send_mode_default = 'direct';
}
$fax_cover_font_default = $_SESSION['fax']['cover_font']['text'];
foreach ($result as $row) {
//get fax server and account connection details
@ -91,6 +93,11 @@ if (sizeof($result) != 0) {
$fax_send_mode = $fax_send_mode_default;
}
$fax_cover_font = $_SESSION['fax']['cover_font']['text'];
if(strlen($fax_cover_font) == 0){
$fax_cover_font = $fax_cover_font_default;
}
//load event socket connection parameters
$_SESSION['event_socket_ip_address'] = $event_socket['ip_address'];
$_SESSION['event_socket_port'] = $event_socket['port'];
@ -173,15 +180,11 @@ if (sizeof($result) != 0) {
unset($fax_subject); //clear so not on cover page
//get email body (if any) for cover page
$fax_message = imap_fetchbody($connection, $email_id, '1.1', FT_UID);
$fax_message = strip_tags($fax_message);
$fax_message = trim($fax_message);
$fax_message = parse_message($connection, $email_id, FT_UID);
if ($fax_message == '') {
$fax_message = imap_fetchbody($connection, $email_id, '1', FT_UID);
$fax_message = strip_tags($fax_message);
$fax_message = trim($fax_message);
$fax_message = str_replace("\r\n\r\n","\r\n", $fax_message);
}
$fax_message = str_replace("\r\n\r\n","\r\n", $fax_message);
// set fax directory (used for pdf creation - cover and/or attachments)
$fax_dir = $_SESSION['switch']['storage']['dir'].'/fax'.(($domain_name != '') ? '/'.$domain_name : null);

View File

@ -103,6 +103,8 @@ if (!$included) {
//set the fax directory
$fax_dir = $_SESSION['switch']['storage']['dir'].'/fax'.((count($_SESSION["domains"]) > 1) ? '/'.$_SESSION['domain_name'] : null);
// set fax cover font to generate pdf
$fax_cover_font = $_SESSION['fax']['cover_font']['text'];
}
else{
require_once "resources/classes/EventSocket.php";
@ -342,6 +344,19 @@ if(!function_exists('gs_cmd')) {
$pdf -> setPrintFooter(false);
$pdf -> SetMargins(0, 0, 0, true);
if(strlen($fax_cover_font) > 0){
if(substr($fax_cover_font, -4) == '.ttf'){
$pdf_font = TCPDF_FONTS::addTTFfont($fax_cover_font);
}
else{
$pdf_font = $fax_cover_font;
}
}
if(!$pdf_font){
$pdf_font = 'times';
}
//add blank page
$pdf -> AddPage('P', array($page_width, $page_height));
@ -349,9 +364,6 @@ if(!function_exists('gs_cmd')) {
$x = 0;
$y = 0;
// output grid
//showgrid($pdf);
//logo
$display_logo = false;
if (!isset($_SESSION['fax']['cover_logo']['text'])) {
@ -395,23 +407,23 @@ if(!function_exists('gs_cmd')) {
//header
if ($fax_header != '') {
$pdf -> SetLeftMargin(0.5);
$pdf -> SetFont("times", "", 10);
$pdf -> SetFont($pdf_font, "", 10);
$pdf -> Write(0.3, $fax_header);
}
//fax, cover sheet
$pdf -> SetTextColor(0,0,0);
$pdf -> SetFont("times", "B", 55);
$pdf -> SetFont($pdf_font, "B", 55);
$pdf -> SetXY($x + 4.55, $y + 0.25);
$pdf -> Cell($x + 3.50, $y + 0.4, $text['label-fax-fax'], 0, 0, 'R', false, null, 0, false, 'T', 'T');
$pdf -> SetFont("times", "", 12);
$pdf -> SetFont($pdf_font, "", 12);
$pdf -> SetFontSpacing(0.0425);
$pdf -> SetXY($x + 4.55, $y + 1.0);
$pdf -> Cell($x + 3.50, $y + 0.4, $text['label-fax-cover-sheet'], 0, 0, 'R', false, null, 0, false, 'T', 'T');
$pdf -> SetFontSpacing(0);
//field labels
$pdf -> SetFont("times", "B", 12);
$pdf -> SetFont($pdf_font, "B", 12);
if ($fax_recipient != '' || sizeof($fax_numbers) > 0) {
$pdf -> Text($x + 0.5, $y + 2.0, strtoupper($text['label-fax-recipient']).":");
}
@ -426,7 +438,7 @@ if(!function_exists('gs_cmd')) {
}
//field values
$pdf -> SetFont("times", "", 12);
$pdf -> SetFont($pdf_font, "", 12);
$pdf -> SetXY($x + 2.0, $y + 1.95);
if ($fax_recipient != '') {
$pdf -> Write(0.3, $fax_recipient);
@ -466,7 +478,7 @@ if(!function_exists('gs_cmd')) {
//message
$pdf -> Rect($x + 0.5, $y + 3.4, 7.5, 6.25, 'D');
if ($fax_message != '') {
$pdf -> SetFont("times", "", 12);
$pdf -> SetFont($pdf_font, "", 12);
$pdf -> SetXY($x + 0.75, $y + 3.65);
$pdf -> MultiCell(7, 5.75, $fax_message, 0, 'L', false);
}

View File

@ -0,0 +1,38 @@
<?php
function parse_message($connection, $message_number, $option = '', $to_charset = 'UTF-8') {
$structure = imap_fetchstructure($connection, $message_number, $option);
if(isset($structure->parts) && count($structure->parts)) {
for($i = 0; $i < count($structure->parts); $i++) {
$msg = '';
$part = $structure->parts[$i];
if($part->type == TYPETEXT){
$msg = imap_fetchbody($connection, $message_number, $i+1, $option);
if($part->encoding == ENCBASE64){
$msg = base64_decode($msg);
}
else if($part->encoding == ENCQUOTEDPRINTABLE){
$msg = quoted_printable_decode($msg);
}
if($msg && $to_charset){
$charset = '';
if(isset($part->parameters) && count($part->parameters)) {
foreach($part->parameters as &$parameter){
if($parameter->attribute == 'CHARSET') {
$charset = $parameter->value;
break;
}
}
}
if($charset){
$msg = mb_convert_encoding($msg, $to_charset, $charset);
}
}
if($msg){
return $msg;
}
}
}
}
}