From 809671070efe8ff29c633e9be03d0d41a5cf6560 Mon Sep 17 00:00:00 2001 From: Joel Uckelman Date: Mon, 27 Feb 2012 05:08:35 +0100 Subject: Renamed functions in build_email.php. --- src/PhpBB3ToMailman.php | 12 ++++++------ src/build_email.php | 31 +++++++++++++++-------------- test/build_email_test.php | 50 +++++++++++++++++++++++------------------------ 3 files changed, 47 insertions(+), 46 deletions(-) diff --git a/src/PhpBB3ToMailman.php b/src/PhpBB3ToMailman.php index 08fb244..9e90b28 100644 --- a/src/PhpBB3ToMailman.php +++ b/src/PhpBB3ToMailman.php @@ -104,11 +104,11 @@ class PhpBB3ToMailman { dirname($_SERVER['SCRIPT_NAME']); $editId = $this->bridge->reserveEditId($postId); - $messageId = build_message_id($postId, $editId, - $time, $_SERVER['SERVER_NAME']); + $messageId = build_email_message_id($postId, $editId, + $time, $_SERVER['SERVER_NAME']); # Assemble the message headers - $headers = build_headers( + $headers = build_email_headers( $userName, $userEmail, $to, @@ -125,10 +125,10 @@ class PhpBB3ToMailman { # Build the message body $parser = new BBCodeParser(); $text = $parser->parse($data['message'], $data['bbcode_uid']); - $text = build_text($text, $mode == 'edit'); + $text = build_email_text($text, $mode == 'edit'); # Build the bridge footer - $footer = build_footer($postId, $forumURL); + $footer = build_email_footer($postId, $forumURL); $attachments = array(); foreach ($data['attachment_data'] as $a) { @@ -146,7 +146,7 @@ class PhpBB3ToMailman { } # Build the message body - $body = build_body($headers, $text, $attachments, $footer); + $body = build_email_body($headers, $text, $attachments, $footer); # Register the message $seen = !$this->bridge->registerByEditId($editId, $messageId, $inReplyTo); diff --git a/src/build_email.php b/src/build_email.php index cad2968..a5bb7bd 100644 --- a/src/build_email.php +++ b/src/build_email.php @@ -2,7 +2,7 @@ require_once(__DIR__ . '/Util.php'); -function build_text($text, $edit) { +function build_email_text($text, $edit) { if ($edit) { $edit_notice = <<encode(); @@ -78,7 +78,7 @@ function build_body(array &$headers, $text, $attachments, $footer) { return $body; } -function build_from($name, $email) { +function build_email_from($name, $email) { $qname = ''; if (is_ascii($name)) { @@ -112,10 +112,11 @@ function build_email_subject($forumtag, $reply, $subject) { return utf8_quote_non_ascii($subject); } -function build_headers($userName, $userEmail, $to, $sender, $subject, $edit, - $time, $messageId, $forumURL, $inReplyTo, $references) { - - $from = build_from($userName, $userEmail); +function build_email_headers( + $userName, $userEmail, $to, $sender, $subject, $edit, + $time, $messageId, $forumURL, $inReplyTo, $references) +{ + $from = build_email_from($userName, $userEmail); $subject = utf8_quote_non_ascii($subject); $date = date(DATE_RFC2822, $time); @@ -145,7 +146,7 @@ function build_headers($userName, $userEmail, $to, $sender, $subject, $edit, return $headers; } -function build_text_part(Mail_mimePart $mime, $text) { +function build_email_text_part(Mail_mimePart $mime, $text) { $params = array( 'content_type' => 'text/plain', 'charset' => 'utf-8', @@ -155,8 +156,8 @@ function build_text_part(Mail_mimePart $mime, $text) { $mime->addSubPart($text, $params); } -function build_attachment(Mail_mimePart $mime, $type, - $filename, $descr, $data) { +function build_email_attachment(Mail_mimePart $mime, $type, + $filename, $descr, $data) { $params = array( 'content_type' => $type, 'encoding' => 'base64', @@ -167,7 +168,7 @@ function build_attachment(Mail_mimePart $mime, $type, $mime->addSubPart($data, $params); } -function build_message_id($postId, $editId, $time, $forumHost) { +function build_email_message_id($postId, $editId, $time, $forumHost) { return "<$time.$postId.$editId.bridge@$forumHost>"; } diff --git a/test/build_email_test.php b/test/build_email_test.php index b4d250c..80768b5 100644 --- a/test/build_email_test.php +++ b/test/build_email_test.php @@ -3,12 +3,12 @@ require_once(__DIR__ . '/../src/build_email.php'); class build_email_test extends PHPUnit_Framework_TestCase { - /** @dataProvider build_text_data */ - public function test_build_text($text, $edit, $expected) { - $this->assertEquals($expected, build_text($text, $edit)); + /** @dataProvider build_email_text_data */ + public function test_build_email_text($text, $edit, $expected) { + $this->assertEquals($expected, build_email_text($text, $edit)); } - public function build_text_data() { + public function build_email_text_data() { return array( array('foo bar', false, 'foo bar'), array('foo bar', true, "[This message has been edited.] @@ -17,22 +17,22 @@ foo bar") ); } - public function test_build_footer() { + public function test_build_email_footer() { $this->assertEquals( " _______________________________________________ Read this topic online here: http://www.example.com/viewtopic.php?p=42#p42", - build_footer(42, 'http://www.example.com') + build_email_footer(42, 'http://www.example.com') ); } - /** @dataProvider build_from_data */ - public function test_build_from($name, $email, $expected) { - $this->assertEquals($expected, build_from($name, $email)); + /** @dataProvider build_email_from_data */ + public function test_build_email_from($name, $email, $expected) { + $this->assertEquals($expected, build_email_from($name, $email)); } - public function build_from_data() { + public function build_email_from_data() { return array( array('Heizölrückstoßabdämpfung', 'foo@example.com', '=?UTF-8?B?SGVpesO2bHLDvGNrc3Rvw59hYmTDpG1wZnVuZw==?= '), array('Joel Uckelman', 'uckelman@nomic.net', 'Joel Uckelman '), @@ -83,11 +83,11 @@ http://www.example.com/viewtopic.php?p=42#p42", '<1267171317.m2f.17507@www.vassalengine.org> <1267473003.m2f.17543@www.vassalengine.org>' ); - protected function call_build_headers(array $headers, array $params) { + protected function call_build_email_headers(array $headers, array $params) { date_default_timezone_set('America/Phoenix'); $this->assertEquals( $headers, - build_headers( + build_email_headers( $params[0], $params[1], $params[2], @@ -103,53 +103,53 @@ http://www.example.com/viewtopic.php?p=42#p42", ); } - public function test_build_headers() { + public function test_build_email_headers() { $headers = $this->default_headers; $headers_params = $this->default_headers_params; - $this->call_build_headers($headers, $headers_params); + $this->call_build_email_headers($headers, $headers_params); } - public function test_build_headers_no_in_reply_to() { + public function test_build_email_headers_no_in_reply_to() { $headers = $this->default_headers; $headers_params = $this->default_headers_params; unset($headers['In-Reply-To']); $headers_params[9] = null; - $this->call_build_headers($headers, $headers_params); + $this->call_build_email_headers($headers, $headers_params); } - public function test_build_headers_no_references() { + public function test_build_email_headers_no_references() { $headers = $this->default_headers; $headers_params = $this->default_headers_params; unset($headers['References']); $headers_params[10] = null; - $this->call_build_headers($headers, $headers_params); + $this->call_build_email_headers($headers, $headers_params); } - public function test_build_headers_utf8_subject() { + public function test_build_email_headers_utf8_subject() { $headers = $this->default_headers; $headers_params = $this->default_headers_params; $headers['Subject'] = '=?UTF-8?B?SGVpesO2bHLDvGNrc3Rvw59hYmTDpG1wZnVuZw==?='; $headers_params[4] = 'Heizölrückstoßabdämpfung'; - $this->call_build_headers($headers, $headers_params); + $this->call_build_email_headers($headers, $headers_params); } - public function test_build_headers_utf8_username() { + public function test_build_email_headers_utf8_username() { $headers = $this->default_headers; $headers_params = $this->default_headers_params; $headers['From'] = '=?UTF-8?B?SGVpesO2bHLDvGNrc3Rvw59hYmTDpG1wZnVuZw==?= '; $headers_params[0] = 'Heizölrückstoßabdämpfung'; - $this->call_build_headers($headers, $headers_params); + $this->call_build_email_headers($headers, $headers_params); } - public function test_build_body_no_attachments() { + public function test_build_email_body_no_attachments() { $headers = array(); $text = 'This is some test text.'; $footer = " @@ -158,7 +158,7 @@ Read this topic online here: http://www.example.com/viewtopic.php?p=42#p42"; $attachments = null; - $body = build_body($headers, $text, $attachments, $footer); + $body = build_email_body($headers, $text, $attachments, $footer); $this->assertEquals('text/plain; charset=UTF-8; format=flowed', $headers['Content-Type']); @@ -166,7 +166,7 @@ http://www.example.com/viewtopic.php?p=42#p42"; $this->assertEquals("$text\n$footer", $body); } - public function test_build_body_attachments() { + public function test_build_email_body_attachments() { // FIXME: This is kind of a complex test to write, because the result // is a Mail_mimePart object. $this->markTestIncomplete(); -- cgit v1.2.1