diff options
Diffstat (limited to 'apps/mm/models/Message.class.php')
-rw-r--r-- | apps/mm/models/Message.class.php | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/apps/mm/models/Message.class.php b/apps/mm/models/Message.class.php new file mode 100644 index 0000000..b2a2b7e --- /dev/null +++ b/apps/mm/models/Message.class.php @@ -0,0 +1,116 @@ +<?php +require_once('MimeMailParser.class.php'); +require_once('Database.class.php'); + +class Message extends Model { + public static function add($infile) { + $parser = new MimeMailParser(); + $parser->setPath($infile); + $id = preg_replace('/<(.*)>/', '$1', + $parser->getHeader('message-id')); + $id = str_replace('/', '', $id); // For security purposes + + $db = Database::getInstance(); + $msgdir = $db->getSysConf('msgdir'); + $msg_file = "$msgdir/$id"; + + rename($infile, $msg_file); + return new Message($id); + } + + private $_msgid; + private $_msgdir; + private $_parser; + + public function __construct($msgid) { + $this->_msgid = str_replace('/', '', $msgid); + if (!file_exists($this->file())) { + return false; + } + } + + public function msgid() { + return $this->_msgid; + } + + private function msgdir() { + if (!isset($this->_msgdir)) { + $db = Database::getInstance(); + $this->_msgdir = $db->getSysConf('msgdir'); + } + return $this->_msgdir; + } + + private function file() { + return $this->msgdir().'/'.$this->msgid(); + } + + private function parser() { + if (!isset($this->_parser)) { + $this->_parser = new MimeMailParser(); + $this->_parser->setPath($this->file()); + } + return $this->_parser; + } + + /** + * Retrieve the Email Headers + * @return Array + */ + public function getHeaders() { + return $this->parser()->getHeaders(); + } + + /** + * Retrieve the raw Email Headers + * @return string + */ + public function getHeadersRaw() { + return $this->parser()->getHeadersRaw(); + } + + /** + * Retrieve a specific Email Header + * @return String + * @param $name String Header name + */ + public function getHeader($name) { + return $this->parser()->getHeader($name); + } + + /** + * Returns the part for the message body in the specified format + * @return Part or False if not found + * @param $type String[optional] + */ + public function getMessageBodyPart($type = 'text') { + return $this->parser()->getMessageBodyPart($type); + } + + /** + * Returns the email message body in the specified format + * @return Mixed String Body or False if not found + * @param $type Object[optional] + */ + public function getMessageBody($type = 'text') { + return $this->parser()->getMessageBody($type); + } + + /** + * get the headers for the message body part. + * @return Array + * @param $type Object[optional] + */ + public function getMessageBodyHeaders($type = 'text') { + return $this->parser()->getMessageBodyHeaders($type); + } + + /** + * Returns the attachments contents in order of appearance + * @return Array + * @param $type Object[optional] + */ + public function getAttachments() { + return $this->parser()->getAttachments(); + } +} |