Change. parse_message do full parse test and attachments.

Change. use only `text/plain` part to build front page.
Change. use only `attachment` but not `inline` files to build fax file.
This commit is contained in:
Alexey Melnichuk
2016-04-08 12:31:13 +03:00
parent 8863db89fd
commit 889b8f9998
3 changed files with 158 additions and 102 deletions
+35 -12
View File
@@ -28,7 +28,6 @@
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";
@@ -179,33 +178,57 @@ if (sizeof($result) != 0) {
}
unset($fax_subject); //clear so not on cover page
$message = parse_message($connection, $email_id, FT_UID);
//get email body (if any) for cover page
$fax_message = parse_message($connection, $email_id, FT_UID);
$fax_message = '';
//Debug print
print('attachments:' . "\n");
foreach($message['attachments'] as &$attachment){
print(' - ' . $attachment['type'] . ' - ' . $attachment['name'] . ': ' . $attachment['size'] . ' disposition: ' . $attachment['disposition'] . "\n");
}
print('messages:' . "\n");
foreach($message['messages'] as &$msg){
print(' - ' . $msg['type'] . ' - ' . $msg['size'] . "\n");
// print($msg['data']);
// print("\n--------------------------------------------------------\n");
}
foreach($message['messages'] as &$msg){
if(($msg['size'] > 0) && ($msg['type'] == 'text/plain')) {
$fax_message = $msg['data'];
break;
}
}
if ($fax_message != '') {
$fax_message = strip_tags($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);
//handle attachments (if any)
$attachments = parse_attachments($connection, $email_id, FT_UID);
$attachments = $message['attachments'];
if (sizeof($attachments) > 0) {
$disallowed_file_extensions = explode(',','sh,ssh,so,dll,exe,bat,vbs,zip,rar,z,tar,tbz,tgz,gz');
foreach ($attachments as $attachment['num'] => $attachment) {
$fax_file_extension = pathinfo($attachment['filename'], PATHINFO_EXTENSION);
foreach ($attachments as &$attachment) {
$fax_file_extension = pathinfo($attachment['name'], PATHINFO_EXTENSION);
if (in_array($fax_file_extension, $disallowed_file_extensions) || $fax_file_extension == '') { continue; } //block unauthorized files
if($attachment['disposition'] != 'attachment'){ continue; } //support only attachments
//store attachment in local fax temp folder
$local_filepath = $fax_dir.'/'.$fax_extension.'/temp/'.$attachment['filename'];
file_put_contents($local_filepath, $attachment['attachment']);
$local_filepath = $fax_dir.'/'.$fax_extension.'/temp/'.$attachment['name'];
file_put_contents($local_filepath, $attachment['data']);
//load files array with attachments
$emailed_files['error'][$attachment['num']] = 0;
$emailed_files['size'][$attachment['num']] = $attachment['size'];
$emailed_files['tmp_name'][$attachment['num']] = $attachment['filename'];
$emailed_files['name'][$attachment['num']] = $attachment['filename'];
$emailed_files['error'][] = 0;
$emailed_files['size'][] = $attachment['size'];
$emailed_files['tmp_name'][] = $attachment['name'];
$emailed_files['name'][] = $attachment['name'];
}
}