summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoruckelman <uckelman@nomic.net>2010-03-20 15:49:47 +0000
committeruckelman <uckelman@nomic.net>2010-03-20 15:49:47 +0000
commit35b7540e71e25062ec7f0cbfd1485a2517d3552a (patch)
tree94da79f594862f07d15cfce45a5432e8a89ea32e /src
parent78fe98c7f6f2097d466b6351de0c259cf2db57a9 (diff)
Added missed file.
git-svn-id: https://vassalengine.svn.sourceforge.net/svnroot/vassalengine/site-src/trunk@6622 67b53d14-2c14-4ace-a08f-0dab2b34000c
Diffstat (limited to 'src')
-rw-r--r--src/EmailMessage.php67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/EmailMessage.php b/src/EmailMessage.php
new file mode 100644
index 0000000..b677574
--- /dev/null
+++ b/src/EmailMessage.php
@@ -0,0 +1,67 @@
+<?php
+
+require_once('Mail/mimeDecode.php');
+require_once('Mail/RFC822.php');
+
+require_once(__DIR__ . '/Message.php');
+
+abstract class EmailMessage implements Message {
+
+ protected $msg;
+
+ public function __construct($input) {
+ $this->msg = self::decode_raw_message($input);
+ }
+
+ 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);
+ }
+}
+
+?>