From bc3e745673385e0f48da3fa90cda5cc6fbaddf26 Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Mon, 24 May 2010 22:24:58 -0300 Subject: [PATCH 1/6] Support to EHLO in SMTP server for EmailComponent. Fixes #54, #712, #737 --- cake/libs/controller/components/email.php | 16 ++++-- .../libs/controller/components/email.test.php | 55 +++++++++++++++++++ 2 files changed, 65 insertions(+), 6 deletions(-) diff --git a/cake/libs/controller/components/email.php b/cake/libs/controller/components/email.php index 94ef82a3b..d18784abb 100755 --- a/cake/libs/controller/components/email.php +++ b/cake/libs/controller/components/email.php @@ -808,7 +808,7 @@ class EmailComponent extends Object{ $host = 'localhost'; } - if (!$this->_smtpSend("HELO {$host}", '250')) { + if (!$this->_smtpSend("EHLO {$host}", '250') || !$this->_smtpSend("HELO {$host}", '250')) { return false; } @@ -868,22 +868,26 @@ class EmailComponent extends Object{ } /** - * Private method for sending data to SMTP connection + * Protected method for sending data to SMTP connection * * @param string $data data to be sent to SMTP server * @param mixed $checkCode code to check for in server response, false to skip * @return bool Success - * @access private + * @access protected */ function _smtpSend($data, $checkCode = '250') { if (!is_null($data)) { $this->__smtpConnection->write($data . "\r\n"); } - if ($checkCode !== false) { + while ($checkCode !== false) { $response = $this->__smtpConnection->read(); + $response = end(explode("\r\n", rtrim($response, "\r\n"))); - if (preg_match('/^(' . $checkCode . ')/', $response, $code)) { - return $code[0]; + if (preg_match('/^(' . $checkCode . ')(.)/', $response, $code)) { + if ($code[2] === '-') { + continue; + } + return $code[1]; } $this->smtpError = $response; return false; diff --git a/cake/tests/cases/libs/controller/components/email.test.php b/cake/tests/cases/libs/controller/components/email.test.php index 1267c96a7..f5de3e9d2 100755 --- a/cake/tests/cases/libs/controller/components/email.test.php +++ b/cake/tests/cases/libs/controller/components/email.test.php @@ -295,6 +295,61 @@ TEMPDOC; $this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect)); } +/** + * testSmtpEhlo method + * + * @access public + * @return void + */ + function testSmtpEhlo() { + if (!$this->skipIf(!@fsockopen('localhost', 25), '%s No SMTP server running on localhost')) { + return; + } + + $connection =& new CakeSocket(array('protocol'=>'smtp', 'host' => 'localhost', 'port' => 25)); + $this->Controller->EmailTest->setConnectionSocket($connection); + $this->assertTrue($connection->connect()); + $this->assertTrue($this->Controller->EmailTest->smtpSend(null, '220') !== false); + $this->skipIf($this->Controller->EmailTest->smtpSend('EHLO locahost', '250') === false, '%s do not support EHLO.'); + $connection->disconnect(); + + $this->Controller->EmailTest->to = 'postmaster@localhost'; + $this->Controller->EmailTest->from = 'noreply@example.com'; + $this->Controller->EmailTest->subject = 'Cake SMTP test'; + $this->Controller->EmailTest->replyTo = 'noreply@example.com'; + $this->Controller->EmailTest->template = null; + + $this->Controller->EmailTest->delivery = 'smtp'; + $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message')); + + $this->Controller->EmailTest->_debug = true; + $this->Controller->EmailTest->sendAs = 'text'; + $expect = <<Host: localhost +Port: 25 +Timeout: 30 +To: postmaster@localhost +From: noreply@example.com +Subject: Cake SMTP test +Header: + +To: postmaster@localhost +From: noreply@example.com +Reply-To: noreply@example.com +Subject: Cake SMTP test +X-Mailer: CakePHP Email Component +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 7bitParameters: + +Message: + +This is the body of the message + + +TEMPDOC; + $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message')); + $this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect)); + } /** * testSmtpSendMultipleTo method From 64adfacd3ec9ef11c9c29218e972059bdb6be9f7 Mon Sep 17 00:00:00 2001 From: Martin Radosta Date: Wed, 19 May 2010 05:54:51 -0300 Subject: [PATCH 2/6] Making DboSource::order() accept an expression object. Fixes issues with sql parsing over quoting special SQL syntax. Tests added. Fixes #747 Signed-off-by: mark_story --- cake/libs/model/datasources/dbo_source.php | 3 +++ .../libs/model/datasources/dbo_source.test.php | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index db5dca354..4bd56e849 100755 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -2411,6 +2411,9 @@ class DboSource extends DataSource { } } continue; + } elseif (is_object($key) && isset($key->type) && $key->type === 'expression') { + $result[] = $key->value; + continue; } if (preg_match('/\\x20(ASC|DESC).*/i', $key, $_dir)) { diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index ead5a9d7b..73f86be55 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -2966,6 +2966,19 @@ class DboSourceTest extends CakeTestCase { ); $this->assertEqual($result, $expected); } + +/** + * test that order() will accept objects made from DboSource::expression + * + * @return void + */ + function testOrderWithExpression() { + $expression = $this->testDb->expression("CASE Sample.id WHEN 1 THEN 'Id One' ELSE 'Other Id' END AS case_col"); + $result = $this->testDb->order($expression); + $expected = " ORDER BY CASE Sample.id WHEN 1 THEN 'Id One' ELSE 'Other Id' END AS case_col"; + $this->assertEqual($result, $expected); + } + /** * testMergeAssociations method * From 8b6c974cd0879228a5f9363450763eeaf71963cd Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 27 May 2010 00:01:17 -0400 Subject: [PATCH 3/6] Making FileEngine not greedily clear files in a directory that may belong to another cache configuration. Tests added. Fixes #754 --- cake/libs/cache/file.php | 4 ++++ cake/tests/cases/libs/cache/file.test.php | 28 +++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/cake/libs/cache/file.php b/cake/libs/cache/file.php index e8e8ffdad..3494c62ce 100644 --- a/cake/libs/cache/file.php +++ b/cake/libs/cache/file.php @@ -209,7 +209,11 @@ class FileEngine extends CacheEngine { $now = time(); $threshold = $now - $this->settings['duration']; } + $prefixLength = strlen($this->settings['prefix']); while (($entry = $dir->read()) !== false) { + if (substr($entry, 0, $prefixLength) !== $this->settings['prefix']) { + continue; + } if ($this->_setKey($entry) === false) { continue; } diff --git a/cake/tests/cases/libs/cache/file.test.php b/cake/tests/cases/libs/cache/file.test.php index 15ee52673..ffb571f73 100644 --- a/cake/tests/cases/libs/cache/file.test.php +++ b/cake/tests/cases/libs/cache/file.test.php @@ -273,6 +273,34 @@ class FileEngineTest extends CakeTestCase { Cache::config('default', array('engine' => 'File', 'path' => CACHE)); } +/** + * test that clear() doesn't wipe files not in the current engine's prefix. + * + * @return void + */ + function testClearWithPrefixes() { + $FileOne =& new FileEngine(); + $FileOne->init(array( + 'prefix' => 'prefix_one_', + 'duration' => DAY + )); + $FileTwo =& new FileEngine(); + $FileTwo->init(array( + 'prefix' => 'prefix_two_', + 'duration' => DAY + )); + + $data1 = $data2 = $expected = 'content to cache'; + $FileOne->write('key_one', $data1, DAY); + $FileTwo->write('key_two', $data2, DAY); + + $this->assertEqual($FileOne->read('key_one'), $expected); + $this->assertEqual($FileTwo->read('key_two'), $expected); + + $FileOne->clear(false); + $this->assertEqual($FileTwo->read('key_two'), $expected, 'secondary config was cleared by accident.'); + } + /** * testKeyPath method * From e02cb81a6707332bf01d8268a0073ae47d8c228f Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Sat, 29 May 2010 12:04:29 -0300 Subject: [PATCH 4/6] Reading a smtp response until EOL. Fixes #378 --- cake/libs/controller/components/email.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cake/libs/controller/components/email.php b/cake/libs/controller/components/email.php index d18784abb..5ee9f531f 100755 --- a/cake/libs/controller/components/email.php +++ b/cake/libs/controller/components/email.php @@ -880,7 +880,15 @@ class EmailComponent extends Object{ $this->__smtpConnection->write($data . "\r\n"); } while ($checkCode !== false) { - $response = $this->__smtpConnection->read(); + $response = ''; + $startTime = time(); + while (substr($response, -2) !== "\r\n" && ((time() - $startTime) < $this->smtpOptions['timeout'])) { + $response .= $this->__smtpConnection->read(); + } + if (substr($response, -2) === "\r\n") { + $this->smtpError = 'timeout'; + return false; + } $response = end(explode("\r\n", rtrim($response, "\r\n"))); if (preg_match('/^(' . $checkCode . ')(.)/', $response, $code)) { From f06f0dae8be7be2cf6ed571d5e46c58959814f53 Mon Sep 17 00:00:00 2001 From: predominant Date: Sun, 30 May 2010 01:10:48 +1000 Subject: [PATCH 5/6] Numerous "Enter description here" block comments updated to have meaningful descriptions. --- app/webroot/css.php | 10 ++-- cake/console/templates/skel/webroot/css.php | 6 +-- cake/libs/model/datasources/datasource.php | 2 +- cake/libs/model/datasources/dbo/dbo_mysql.php | 4 +- .../libs/model/datasources/dbo/dbo_mysqli.php | 4 +- .../libs/model/datasources/dbo/dbo_oracle.php | 46 +++++++++---------- .../libs/model/datasources/dbo/dbo_sqlite.php | 4 +- cake/libs/view/helpers/number.php | 2 +- 8 files changed, 40 insertions(+), 38 deletions(-) diff --git a/app/webroot/css.php b/app/webroot/css.php index 445b2fb2e..aae68cba8 100644 --- a/app/webroot/css.php +++ b/app/webroot/css.php @@ -1,6 +1,6 @@ array('name' => 'inet')); /** - * Enter description here... + * Connection object * - * @var unknown_type + * @var mixed * @access protected */ var $connection; /** - * Enter description here... + * Query limit * - * @var unknown_type + * @var int * @access protected */ var $_limit = -1; /** - * Enter description here... + * Query offset * - * @var unknown_type + * @var int * @access protected */ var $_offset = 0; @@ -109,25 +109,25 @@ class DboOracle extends DboSource { var $_map; /** - * Enter description here... + * Current Row * - * @var unknown_type + * @var mixed * @access protected */ var $_currentRow; /** - * Enter description here... + * Number of rows * - * @var unknown_type + * @var int * @access protected */ var $_numRows; /** - * Enter description here... + * Query results * - * @var unknown_type + * @var mixed * @access protected */ var $_results; @@ -378,9 +378,9 @@ class DboOracle extends DboSource { } /** - * Enter description here... + * Fetch result row * - * @return unknown + * @return array * @access public */ function fetchRow() { @@ -444,10 +444,10 @@ class DboOracle extends DboSource { } /** - * Enter description here... + * Create trigger * - * @param unknown_type $table - * @return unknown + * @param string $table + * @return mixed * @access public */ function createTrigger($table) { diff --git a/cake/libs/model/datasources/dbo/dbo_sqlite.php b/cake/libs/model/datasources/dbo/dbo_sqlite.php index 1fdba32a8..efc660f33 100644 --- a/cake/libs/model/datasources/dbo/dbo_sqlite.php +++ b/cake/libs/model/datasources/dbo/dbo_sqlite.php @@ -29,9 +29,9 @@ class DboSqlite extends DboSource { /** - * Enter description here... + * Datasource Description * - * @var unknown_type + * @var string */ var $description = "SQLite DBO Driver"; diff --git a/cake/libs/view/helpers/number.php b/cake/libs/view/helpers/number.php index da8a565a6..236732a92 100644 --- a/cake/libs/view/helpers/number.php +++ b/cake/libs/view/helpers/number.php @@ -69,7 +69,7 @@ class NumberHelper extends AppHelper { * * @param float $number A floating point number. * @param integer $precision The precision of the returned number. - * @return float Enter description here... + * @return float Formatted float. * @access public * @link http://book.cakephp.org/view/1454/precision */ From 8decc683ac46f5f00e026ef2cbeb4873330f3e2e Mon Sep 17 00:00:00 2001 From: predominant Date: Sun, 30 May 2010 01:20:28 +1000 Subject: [PATCH 6/6] Numerous 'shoer description' documentation entries updated to contain useful comments. --- cake/console/libs/console.php | 2 +- cake/console/libs/i18n.php | 2 +- cake/console/templates/skel/app_controller.php | 4 ++-- cake/console/templates/skel/app_helper.php | 2 +- cake/console/templates/skel/config/acl.ini.php | 2 +- cake/console/templates/skel/config/routes.php | 2 +- cake/console/templates/skel/webroot/css.php | 2 +- cake/libs/controller/app_controller.php | 2 +- cake/libs/controller/components/cookie.php | 2 +- cake/libs/controller/components/email.php | 2 +- cake/libs/controller/components/security.php | 5 +++-- cake/libs/i18n.php | 2 +- cake/libs/l10n.php | 4 ++-- cake/libs/model/behaviors/acl.php | 2 +- cake/libs/model/behaviors/translate.php | 4 ++-- cake/libs/model/datasources/dbo/dbo_mssql.php | 2 +- cake/libs/model/datasources/dbo/dbo_oracle.php | 2 +- cake/libs/model/datasources/dbo_source.php | 2 +- cake/libs/model/db_acl.php | 2 +- cake/libs/security.php | 2 +- cake/libs/view/helpers/app_helper.php | 2 +- cake/tests/cases/libs/controller/components/acl.test.php | 2 +- 22 files changed, 27 insertions(+), 26 deletions(-) diff --git a/cake/console/libs/console.php b/cake/console/libs/console.php index 41e4d4634..ac7b595bb 100644 --- a/cake/console/libs/console.php +++ b/cake/console/libs/console.php @@ -1,6 +1,6 @@ ; SVN FILE: $Id$ ;/** -; * Short description for file. +; * ACL Configuration ; * ; * ; * PHP versions 4 and 5 diff --git a/cake/console/templates/skel/config/routes.php b/cake/console/templates/skel/config/routes.php index 696c49a87..9e4a28c14 100644 --- a/cake/console/templates/skel/config/routes.php +++ b/cake/console/templates/skel/config/routes.php @@ -1,6 +1,6 @@