summaryrefslogtreecommitdiff
path: root/apps/mm/models
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2012-01-08 17:45:50 -0800
committerLuke Shumaker <LukeShu@sbcglobal.net>2012-01-08 17:45:50 -0800
commit4c58c41d818918b1690b56f05876d9af642354c0 (patch)
treeb07c0f2925a5753ab3c34379db5c90c5dc38bad1 /apps/mm/models
parent83e460cdc3fc09867a3adb48c3d0894579dd3050 (diff)
parent3d64793a1ee45857856be1cd71c3a0a040a3e869 (diff)
add message manager back as another app depending on umummm
Diffstat (limited to 'apps/mm/models')
-rw-r--r--apps/mm/models/Message.class.php116
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();
+ }
+}