summaryrefslogtreecommitdiff
path: root/src/MessageTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/MessageTest.php')
-rw-r--r--src/MessageTest.php69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/MessageTest.php b/src/MessageTest.php
new file mode 100644
index 0000000..ce04cf6
--- /dev/null
+++ b/src/MessageTest.php
@@ -0,0 +1,69 @@
+<?php
+
+require_once('Mail/mimeDecode.php');
+require_once('Mail/RFC822.php');
+
+require_once('Message.php');
+
+abstract class EmailMessage implements Message {
+
+ protected $msg;
+
+ public function __construct($input) {
+ $this->msg = self::decode_raw_message($input);
+ }
+
+ public abstract function getSource();
+
+ public function getPostId() {
+ return null;
+ }
+
+ public function getFrom() {
+ return self::parse_addr($this->msg->headers['from']);
+ }
+
+ public function getSubject() {
+ return $this->msg->headers['subject'];
+ }
+
+ public function getMessageId() {
+ return $this->msg->headers['message-id'];
+ }
+
+ public function getInReplyTo() {
+ return $this->msg->headers['in-reply-to'];
+ }
+
+ public function getReferences() {
+ return $this->msg->headers['references'];
+ }
+
+ public function getBody() {
+ return $this->msg->body;
+ }
+
+ protected static function decode_raw_message($input) {
+ $params['include_bodies'] = true;
+ $params['decode_bodies'] = true;
+ $params['decode_headers'] = true;
+ $params['input'] = $input;
+ $params['crlf'] = "\r\n";
+
+ $msg = Mail_mimeDecode::decode($params);
+
+ if (count($msg->headers) == 1 && array_key_exists(null, $msg->headers)) {
+ # An empty message has one null header.
+ trigger_error('No message', E_USER_ERROR);
+ }
+
+ return $msg;
+ }
+
+ protected static function parse_addr($s) {
+ $addr = Mail_RFC822::parseAddressList($s);
+ return strtolower($addr[0]->mailbox . '@' . $addr[0]->host);
+ }
+}
+
+?>