diff --git a/webui/model/search/message.php b/webui/model/search/message.php index 8c303096..a854a8cc 100644 --- a/webui/model/search/message.php +++ b/webui/model/search/message.php @@ -8,6 +8,7 @@ class ModelSearchMessage extends Model { 'GB2312' => 'GBK', 'GB231280' => 'GBK' ); + public $message; public function get_boundary($line='') { @@ -212,6 +213,11 @@ class ModelSearchMessage extends Model { public function extract_message($id = '', $terms = '') { + $from = "From: "; + $to = "To: "; + $subject = "Subject: "; + $date = "Date: "; + $msg = $this->get_raw_message($id); if(ENABLE_ON_THE_FLY_VERIFICATION == 0) { @@ -225,17 +231,37 @@ class ModelSearchMessage extends Model { if(is_array($headers['date'])) { $headers['date'] = $headers['date'][0]; } - $from = "From: " . $this->escape_lt_gt_symbols($headers['from']); - $to = "To: " . $this->escape_lt_gt_symbols($headers['to']); - $subject = "Subject: " . $headers['subject']; - $date = "Date: " . $headers['date']; + if(isset($headers['from'])) $from .= $this->escape_lt_gt_symbols($headers['from']); + if(isset($headers['to'])) $to .= $this->escape_lt_gt_symbols($headers['to']); + if(isset($headers['subject'])) $subject .= $this->escape_lt_gt_symbols($headers['subject']); + if(isset($headers['date'])) $date .= $headers['date']; - $message = array( - 'text' => '', - 'html' => '' - ); + $this->message = array( + 'text/plain' => '', + 'text/html' => '' + ); - $mime_parts = Zend_Mime_Decode::splitMessageStruct($body, $boundary); + $this->extract_textuals_from_mime_parts($headers, $body, $boundary); + + return array('from' => $from, + 'to' => $to, + 'subject' => $this->highlight_search_terms($subject, $terms), + 'date' => $date, + 'message' => $this->message['text/html'] ? $this->message['text/html'] : $this->message['text/plain'], + 'has_journal' => $has_journal, + 'verification' => $verification + ); + } + + + private function extract_textuals_from_mime_parts($headers = array(), $body = '', $boundary = '') { + $mime_parts = array(); + + if($boundary) { + $mime_parts = Zend_Mime_Decode::splitMessageStruct($body, $boundary); + } else { + $mime_parts[] = array('header' => $headers, 'body' => $body); + } for($i=0; $iextract_textuals_from_mime_parts($mime_parts[$i]['header'], $mime_parts[$i]['body'], $mime['content-type']['boundary']); + if(isset($mime_parts[$i]['header']['content-transfer-encoding'])) $mime['encoding'] = $mime_parts[$i]['header']['content-transfer-encoding']; - if($mime['encoding'] == 'quoted-printable') - $mime_parts[$i]['body'] = Zend_Mime_Decode::decodeQuotedPrintable($mime_parts[$i]['body']); - - if($mime['encoding'] == 'base64') - $mime_parts[$i]['body'] = base64_decode($mime_parts[$i]['body']); - - if(strtolower($mime['content-type']['charset']) != 'utf-8') - $mime_parts[$i]['body'] = iconv($mime['content-type']['charset'], 'utf-8' . '//IGNORE', $mime_parts[$i]['body']); - - // some text/plain fixes - - if(strtolower($mime['content-type']['type']) == 'text/plain') { - - $mime_parts[$i]['body'] = $this->escape_lt_gt_symbols($mime_parts[$i]['body']); - - $mime_parts[$i]['body'] = preg_replace("/\n/", "
\n", $mime_parts[$i]['body']); - $mime_parts[$i]['body'] = "\n" . $this->print_nicely($mime_parts[$i]['body']); - - $message['text'] .= $mime_parts[$i]['body']; - } - - if(strtolower($mime['content-type']['type']) == 'text/html') { - - $mime_parts[$i]['body'] = preg_replace("/\/", "", $mime_parts[$i]['body']); - - if(ENABLE_REMOTE_IMAGES == 0) { - $mime_parts[$i]['body'] = preg_replace("/style([\s]{0,}=[\s]{0,})\"([^\"]+)/", "style=\"xxxx", $mime_parts[$i]['body']); - $mime_parts[$i]['body'] = preg_replace("/style([\s]{0,}=[\s]{0,})\'([^\']+)/", "style='xxxx", $mime_parts[$i]['body']); - - $mime_parts[$i]['body'] = preg_replace("/\]+)\>/i", "", $mime_parts[$i]['body']); - } - - $mime_parts[$i]['body'] = preg_replace("/\/i", "", $mime_parts[$i]['body']); - - $mime_parts[$i]['body'] = preg_replace("/\/i", "", $mime_parts[$i]['body']); + if(in_array($mime['content-type']['type'], array('text/plain', 'text/html'))) + $this->message[$mime['content-type']['type']] .= $this->fix_mime_body_part($mime, $mime_parts[$i]['body']); + } + } - $message['html'] .= $mime_parts[$i]['body']; - } + private function fix_mime_body_part($mime = array(), $body = '') { + if($mime['encoding'] == 'quoted-printable') + $body = Zend_Mime_Decode::decodeQuotedPrintable($body); + if($mime['encoding'] == 'base64') + $body = base64_decode($body); + + if(strtolower($mime['content-type']['charset']) != 'utf-8') + $body = iconv($mime['content-type']['charset'], 'utf-8' . '//IGNORE', $body); + + + if(strtolower($mime['content-type']['type']) == 'text/plain') { + + $body = $this->escape_lt_gt_symbols($body); + + $body = preg_replace("/\n/", "
\n", $body); + $body = "\n" . $this->print_nicely($body); } - return array('from' => $from, - 'to' => $to, - 'subject' => $this->highlight_search_terms($subject, $terms), - 'date' => $date, - 'message' => $message['html'] ? $message['html'] : $message['text'], - 'has_journal' => $has_journal, - 'verification' => $verification - ); + if(strtolower($mime['content-type']['type']) == 'text/html') { + + $body = preg_replace("/\/", "", $body); + + if(ENABLE_REMOTE_IMAGES == 0) { + $body = preg_replace("/style([\s]{0,}=[\s]{0,})\"([^\"]+)/", "style=\"xxxx", $body); + $body = preg_replace("/style([\s]{0,}=[\s]{0,})\'([^\']+)/", "style='xxxx", $body); + + $body = preg_replace("/\]+)\>/i", "", $body); + } + + $body = preg_replace("/\/i", "", $body); + + $body = preg_replace("/\/i", "", $body); + } + + return $body; }