summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruckelman <uckelman@nomic.net>2010-03-20 15:33:53 +0000
committeruckelman <uckelman@nomic.net>2010-03-20 15:33:53 +0000
commit78fe98c7f6f2097d466b6351de0c259cf2db57a9 (patch)
tree4535cc5492b8e4b78813e226124b47adfba9e460
parent946b326a1b3aa6f1f01161c4c385a3efb1d24d0a (diff)
Refactored to make EmailMessage abstract.
git-svn-id: https://vassalengine.svn.sourceforge.net/svnroot/vassalengine/site-src/trunk@6621 67b53d14-2c14-4ace-a08f-0dab2b34000c
-rw-r--r--src/MailmanMessage.php17
-rw-r--r--src/MessageTest.php (renamed from src/EmailMessage.php)12
-rw-r--r--test/MessageTest.php (renamed from test/EmailMessageTest.php)26
3 files changed, 37 insertions, 18 deletions
diff --git a/src/MailmanMessage.php b/src/MailmanMessage.php
new file mode 100644
index 0000000..c284a8e
--- /dev/null
+++ b/src/MailmanMessage.php
@@ -0,0 +1,17 @@
+<?php
+
+require_once(__DIR__ . '/EmailMessage.php');
+
+class MailmanMessage extends EmailMessage {
+ public function __construct($input) {
+ parent::__construct($input);
+ }
+
+ public function getSource() {
+ return self::parse_addr(
+ substr_replace($this->msg->headers['list-post'], '', 1, 7)
+ );
+ }
+}
+
+?>
diff --git a/src/EmailMessage.php b/src/MessageTest.php
index d6ff762..ce04cf6 100644
--- a/src/EmailMessage.php
+++ b/src/MessageTest.php
@@ -5,26 +5,22 @@ require_once('Mail/RFC822.php');
require_once('Message.php');
-class EMailMessage implements Message {
+abstract class EmailMessage implements Message {
protected $msg;
public function __construct($input) {
- $this->msg = EMailMessage::decode_raw_message($input);
+ $this->msg = self::decode_raw_message($input);
}
- public function getSource() {
-# FIXME: fill in!
- return null;
- }
+ public abstract function getSource();
public function getPostId() {
-# FIXME: get from message-id to post-id database
return null;
}
public function getFrom() {
- return EMailMessage::parse_addr($this->msg->headers['from']);
+ return self::parse_addr($this->msg->headers['from']);
}
public function getSubject() {
diff --git a/test/EmailMessageTest.php b/test/MessageTest.php
index c3269f5..2338e60 100644
--- a/test/EmailMessageTest.php
+++ b/test/MessageTest.php
@@ -1,16 +1,16 @@
<?php
require_once('PHPUnit/Framework.php');
+require_once('src/Message.php');
-require_once('src/EmailMessage.php');
-
-class EmailMessageTest extends PHPUnit_Framework_TestCase {
+class MessageTest extends PHPUnit_Framework_TestCase {
public function provider() {
return array(
array(array(
- 'file' => file_get_contents(__DIR__ . '/1'),
- 'source' => '',
+ 'class' => 'MailmanMessage',
+ 'data' => file_get_contents(__DIR__ . '/1'),
+ 'source' => 'messages@forums.vassalengine.org',
'post_id' => '',
'from' => 'uckelman@nomic.net',
'subject' => 'Re: [Developers]Re: Adding developers?',
@@ -22,6 +22,12 @@ class EmailMessageTest extends PHPUnit_Framework_TestCase {
);
}
+ protected function buildMessage($params) {
+ require_once('src/' . $params['class'] . '.php');
+ $cl = new ReflectionClass($params['class']);
+ return $cl->newInstance($params['data']);
+ }
+
/**
* @dataProvider provider
*/
@@ -40,7 +46,7 @@ class EmailMessageTest extends PHPUnit_Framework_TestCase {
* @dataProvider provider
*/
public function testGetFrom($expected) {
- $msg = new EmailMessage($expected['file']);
+ $msg = $this->buildMessage($expected);
$this->assertEquals($expected['from'], $msg->getFrom());
}
@@ -48,7 +54,7 @@ class EmailMessageTest extends PHPUnit_Framework_TestCase {
* @dataProvider provider
*/
public function testGetSubject($expected) {
- $msg = new EmailMessage($expected['file']);
+ $msg = $this->buildMessage($expected);
$this->assertEquals($expected['subject'], $msg->getSubject());
}
@@ -56,7 +62,7 @@ class EmailMessageTest extends PHPUnit_Framework_TestCase {
* @dataProvider provider
*/
public function testGetMessageId($expected) {
- $msg = new EmailMessage($expected['file']);
+ $msg = $this->buildMessage($expected);
$this->assertEquals($expected['message_id'], $msg->getMessageId());
}
@@ -64,7 +70,7 @@ class EmailMessageTest extends PHPUnit_Framework_TestCase {
* @dataProvider provider
*/
public function testGetInReplyTo($expected) {
- $msg = new EmailMessage($expected['file']);
+ $msg = $this->buildMessage($expected);
$this->assertEquals($expected['in_reply_to'], $msg->getInReplyTo());
}
@@ -72,7 +78,7 @@ class EmailMessageTest extends PHPUnit_Framework_TestCase {
* @dataProvider provider
*/
public function testGetReferences($expected) {
- $msg = new EmailMessage($expected['file']);
+ $msg = $this->buildMessage($expected);
$this->assertEquals($expected['references'], $msg->getReferences());
}