From 78fe98c7f6f2097d466b6351de0c259cf2db57a9 Mon Sep 17 00:00:00 2001 From: uckelman Date: Sat, 20 Mar 2010 15:33:53 +0000 Subject: Refactored to make EmailMessage abstract. git-svn-id: https://vassalengine.svn.sourceforge.net/svnroot/vassalengine/site-src/trunk@6621 67b53d14-2c14-4ace-a08f-0dab2b34000c --- src/EmailMessage.php | 73 ------------------------------------- src/MailmanMessage.php | 17 +++++++++ src/MessageTest.php | 69 +++++++++++++++++++++++++++++++++++ test/EmailMessageTest.php | 87 -------------------------------------------- test/MessageTest.php | 93 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 179 insertions(+), 160 deletions(-) delete mode 100644 src/EmailMessage.php create mode 100644 src/MailmanMessage.php create mode 100644 src/MessageTest.php delete mode 100644 test/EmailMessageTest.php create mode 100644 test/MessageTest.php diff --git a/src/EmailMessage.php b/src/EmailMessage.php deleted file mode 100644 index d6ff762..0000000 --- a/src/EmailMessage.php +++ /dev/null @@ -1,73 +0,0 @@ -msg = EMailMessage::decode_raw_message($input); - } - - public function getSource() { -# FIXME: fill in! - return null; - } - - 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']); - } - - 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); - } -} - -?> 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 @@ +msg->headers['list-post'], '', 1, 7) + ); + } +} + +?> 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 @@ +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); + } +} + +?> diff --git a/test/EmailMessageTest.php b/test/EmailMessageTest.php deleted file mode 100644 index c3269f5..0000000 --- a/test/EmailMessageTest.php +++ /dev/null @@ -1,87 +0,0 @@ - file_get_contents(__DIR__ . '/1'), - 'source' => '', - 'post_id' => '', - 'from' => 'uckelman@nomic.net', - 'subject' => 'Re: [Developers]Re: Adding developers?', - 'message_id' => '<20100302094228.33F0310091@charybdis.ellipsis.cx>', - 'in_reply_to' => '<1267473003.m2f.17543@www.vassalengine.org>', - 'references' => '<1267171317.m2f.17507@www.vassalengine.org> <1267473003.m2f.17543@www.vassalengine.org>', - 'body' => '' - )) - ); - } - - /** - * @dataProvider provider - */ - public function testGetSource($expected) { - $this->markTestIncomplete(); - } - - /** - * @dataProvider provider - */ - public function testGetPostId($expected) { - $this->markTestIncomplete(); - } - - /** - * @dataProvider provider - */ - public function testGetFrom($expected) { - $msg = new EmailMessage($expected['file']); - $this->assertEquals($expected['from'], $msg->getFrom()); - } - - /** - * @dataProvider provider - */ - public function testGetSubject($expected) { - $msg = new EmailMessage($expected['file']); - $this->assertEquals($expected['subject'], $msg->getSubject()); - } - - /** - * @dataProvider provider - */ - public function testGetMessageId($expected) { - $msg = new EmailMessage($expected['file']); - $this->assertEquals($expected['message_id'], $msg->getMessageId()); - } - - /** - * @dataProvider provider - */ - public function testGetInReplyTo($expected) { - $msg = new EmailMessage($expected['file']); - $this->assertEquals($expected['in_reply_to'], $msg->getInReplyTo()); - } - - /** - * @dataProvider provider - */ - public function testGetReferences($expected) { - $msg = new EmailMessage($expected['file']); - $this->assertEquals($expected['references'], $msg->getReferences()); - } - - /** - * @dataProvider provider - */ - public function testGetBody($expected) { - $this->markTestIncomplete(); - } -} - -?> diff --git a/test/MessageTest.php b/test/MessageTest.php new file mode 100644 index 0000000..2338e60 --- /dev/null +++ b/test/MessageTest.php @@ -0,0 +1,93 @@ + 'MailmanMessage', + 'data' => file_get_contents(__DIR__ . '/1'), + 'source' => 'messages@forums.vassalengine.org', + 'post_id' => '', + 'from' => 'uckelman@nomic.net', + 'subject' => 'Re: [Developers]Re: Adding developers?', + 'message_id' => '<20100302094228.33F0310091@charybdis.ellipsis.cx>', + 'in_reply_to' => '<1267473003.m2f.17543@www.vassalengine.org>', + 'references' => '<1267171317.m2f.17507@www.vassalengine.org> <1267473003.m2f.17543@www.vassalengine.org>', + 'body' => '' + )) + ); + } + + protected function buildMessage($params) { + require_once('src/' . $params['class'] . '.php'); + $cl = new ReflectionClass($params['class']); + return $cl->newInstance($params['data']); + } + + /** + * @dataProvider provider + */ + public function testGetSource($expected) { + $this->markTestIncomplete(); + } + + /** + * @dataProvider provider + */ + public function testGetPostId($expected) { + $this->markTestIncomplete(); + } + + /** + * @dataProvider provider + */ + public function testGetFrom($expected) { + $msg = $this->buildMessage($expected); + $this->assertEquals($expected['from'], $msg->getFrom()); + } + + /** + * @dataProvider provider + */ + public function testGetSubject($expected) { + $msg = $this->buildMessage($expected); + $this->assertEquals($expected['subject'], $msg->getSubject()); + } + + /** + * @dataProvider provider + */ + public function testGetMessageId($expected) { + $msg = $this->buildMessage($expected); + $this->assertEquals($expected['message_id'], $msg->getMessageId()); + } + + /** + * @dataProvider provider + */ + public function testGetInReplyTo($expected) { + $msg = $this->buildMessage($expected); + $this->assertEquals($expected['in_reply_to'], $msg->getInReplyTo()); + } + + /** + * @dataProvider provider + */ + public function testGetReferences($expected) { + $msg = $this->buildMessage($expected); + $this->assertEquals($expected['references'], $msg->getReferences()); + } + + /** + * @dataProvider provider + */ + public function testGetBody($expected) { + $this->markTestIncomplete(); + } +} + +?> -- cgit v1.2.3