gui: Fix journal handling

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO
2018-12-23 20:00:22 +00:00
parent 0bf20b1f66
commit 8bd4531b04
5 changed files with 62 additions and 86 deletions

View File

@ -1,5 +1,7 @@
<?php
require DIR_SYSTEM . 'helper/mime.php';
class ModelMessageRestore extends Model {
@ -26,7 +28,7 @@ class ModelMessageRestore extends Model {
$rawemail = $this->model_search_message->get_raw_message($piler_id);
$this->model_search_message->remove_journal($rawemail);
Piler_Mime_Decode::removeJournal($rawemail);
$zip->addFromString($filename . ".eml", $rawemail);

View File

@ -105,12 +105,13 @@ class ModelSearchMessage extends Model {
public function get_message_headers($id = '') {
$headers = '';
$has_journal = 0;
$msg = $this->get_raw_message($id);
Piler_Mime_Decode::splitMessageRaw($msg, $headers, $body);
Piler_Mime_Decode::splitMessageRaw($msg, $headers, $journal, $body);
$has_journal = $this->remove_journal($headers);
if($journal) { $has_journal = 1; }
$headers = Piler_Mime_Decode::escape_lt_gt_symbols($headers);
@ -119,87 +120,11 @@ class ModelSearchMessage extends Model {
public function get_message_journal($id = '') {
$data = '&lt; &gt;';
$boundary = '';
$msg = $this->get_raw_message($id);
$hdr = substr($msg, 0, 8192);
Piler_Mime_Decode::splitMessageRaw($msg, $headers, $journal, $body);
$s = preg_split("/\n/", $hdr);
while(list($k, $v) = each($s)) {
if(preg_match("/boundary\s{0,}=\s{0,}\"{0,}([\w\_\-\@\.]+)\"{0,}/i", $v, $m)) {
if(isset($m[1])) { $boundary = $m[1]; break; }
}
}
$p = strstr($msg, "\nX-MS-Journal-Report:");
$msg = '';
if($p) {
$s = preg_split("/\n/", $p);
$i=0; $j=0; $data = '';
while(list($k, $v) = each($s)) {
if(strstr($v, $boundary)) { $i++; }
if($i > 0 && preg_match("/^\s{1,}$/", $v)) { $j++; }
if($j == 1) {
$data .= "$v\n";
}
if($i >= 2) { break; }
}
$p = '';
$data = Piler_Mime_Decode::escape_lt_gt_symbols($data);
}
return $data;
}
public function remove_journal(&$msg = '') {
$p = $q = '';
$boundary = '';
$has_journal = 0;
$hdr = substr($msg, 0, 4096);
$s = preg_split("/\n/", $hdr);
while(list($k, $v) = each($s)) {
if(preg_match("/boundary\s{0,}=\s{0,}\"{0,}([\w\_\-\@\.]+)\"{0,}/i", $v, $m)) {
if(isset($m[1])) { $boundary = $m[1]; break; }
}
}
$p = strstr($msg, "\nX-MS-Journal-Report:");
if($p) {
$has_journal = 1;
$msg = '';
$q = strstr($p, "Received: from");
if($q) {
$p = '';
$msg = $q;
$q = '';
}
else {
$msg = $p;
$p = '';
}
if($boundary) {
$msg = substr($msg, 0, strlen($msg) - strlen($boundary) - 6);
}
}
return $has_journal;
return Piler_Mime_Decode::escape_lt_gt_symbols($journal);
}
@ -212,7 +137,7 @@ class ModelSearchMessage extends Model {
$msg = $this->get_raw_message($id);
$has_journal = $this->remove_journal($msg);
$has_journal = Piler_Mime_Decode::removeJournal($msg);
Piler_Mime_Decode::splitMessage($msg, $headers, $body);