gui: fixing journal handling

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO 2018-12-15 22:11:14 +00:00
parent 5f391ef9ef
commit 1b7026dce6
7 changed files with 44 additions and 56 deletions

View File

@ -84,7 +84,8 @@ class ControllerMessageBulkrestore extends Controller {
$piler_id = $this->model_search_message->get_piler_id_by_id($id);
$msg = $this->model_search_message->get_raw_message($piler_id);
$this->model_search_message->remove_journal($msg);
Piler_Mime_Decode::splitMessage($msg, $headers, $journal, $body);
$msg = $headers . $body;
if(RESTORE_OVER_IMAP == 1 && Registry::get('auditor_user') == 0) {
if($imap_ok) {

View File

@ -51,7 +51,9 @@ class ControllerMessageDownload extends Controller {
$msg = $this->model_search_message->get_raw_message($this->data['piler_id']);
$this->model_search_message->remove_journal($msg);
Piler_Mime_Decode::splitMessage($msg, $headers, $journal, $body);
$msg = $headers . $body;
print $msg;
}

View File

@ -14,7 +14,7 @@ class ControllerMessageJournal extends Controller {
$this->load->model('search/search');
$this->load->model('search/message');
$this->load->model('audit/audit');
$this->load->model('user/user');
$this->document->title = $this->data['text_message'];
@ -47,5 +47,3 @@ class ControllerMessageJournal extends Controller {
}
?>

View File

@ -72,7 +72,8 @@ class ControllerMessageRestore extends Controller {
$msg = $this->model_search_message->get_raw_message($this->data['piler_id']);
$this->model_search_message->remove_journal($msg);
Piler_Mime_Decode::splitMessage($msg, $headers, $journal, $body);
$msg = $headers . $body;
if(RESTORE_OVER_IMAP == 1) {
if($this->model_mail_mail->connect_imap()) {

View File

@ -26,7 +26,8 @@ class ModelMessageRestore extends Model {
$rawemail = $this->model_search_message->get_raw_message($piler_id);
$this->model_search_message->remove_journal($rawemail);
Piler_Mime_Decode::splitMessage($rawemail, $headers, $journal, $body);
$rawemail = $headers . $body;
$zip->addFromString($filename . ".eml", $rawemail);

View File

@ -105,12 +105,12 @@ 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);
$has_journal = $this->remove_journal($headers);
Piler_Mime_Decode::splitMessage($msg, $headers, $journal, $body);
if($journal) { $has_journal = 1; }
$headers = Piler_Mime_Decode::escape_lt_gt_symbols($headers);
@ -123,6 +123,8 @@ class ModelSearchMessage extends Model {
$boundary = '';
$msg = $this->get_raw_message($id);
Piler_Mime_Decode::splitMessage($msg, $headers, $journal, $body);
return $journal;
$hdr = substr($msg, 0, 8192);
@ -163,58 +165,21 @@ class ModelSearchMessage extends Model {
}
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;
}
public function extract_message($id = '', $terms = '') {
$from = "From: ";
$to = "To: ";
$cc = "Cc: ";
$subject = "Subject: ";
$date = "Date: ";
$has_journal = 0;
$msg = $this->get_raw_message($id);
$has_journal = $this->remove_journal($msg);
Piler_Mime_Decode::splitMessage($msg, $headers, $journal, $body);
Piler_Mime_Decode::splitMessage($msg, $headers, $body);
if($journal) { $has_journal = 1; }
$headers = Piler_Mime_Decode::splitHeaders($headers);
for($i=0; $i<count(Piler_Mime_Decode::HEADER_FIELDS); $i++) {
if(isset($headers[Piler_Mime_Decode::HEADER_FIELDS[$i]]) && is_array($headers[Piler_Mime_Decode::HEADER_FIELDS[$i]])) {
@ -253,7 +218,7 @@ class ModelSearchMessage extends Model {
$this->message['text/html'] = $purifier->purify($body);
}
else {
$this->message['text/plain'] = $body;
$this->message['text/plain'] = str_replace("\n", "<br />\n", $body);
}
}

View File

@ -7,7 +7,7 @@ class Piler_Mime_Decode {
public static function parseMessage($message, &$result) {
self::splitMessage($message, $headers, $body);
self::splitMessage($message, $headers, $journal, $body);
$boundary = self::getBoundary($headers);
@ -31,7 +31,7 @@ class Piler_Mime_Decode {
for($i=0; $i<count($parts); $i++) {
self::splitMessage($parts[$i], $headers, $body);
self::splitMessage($parts[$i], $headers, $journal, $body);
$boundary = self::getBoundary($headers);
if($boundary) {
@ -86,9 +86,29 @@ class Piler_Mime_Decode {
}
public static function splitMessage($message, &$headers, &$body, $EOL = "\n") {
public static function splitMessage($message, &$headers, &$journal, &$body, $EOL = "\n") {
$journal = '';
self::splitMessageRaw($message, $headers, $body);
$headers = self::splitHeaders($headers);
if(isset($headers['x-ms-journal-report']) && isset($headers['content-type']['boundary'])) {
$boundary = $headers['content-type']['boundary'];
$headers = self::splitMime($body, $boundary);
self::splitMessageRaw($headers[0], $s, $journal);
$i = strpos($headers[1], "\n");
$msg = substr($headers[1], $i);
$i = 0;
while(ctype_space($msg[$i])) { $i++; }
if($i > 0) { $msg = substr($msg, $i); }
self::splitMessageRaw($msg, $headers, $body);
}
$headers .= $EOL . $EOL;
}