Index: trunk/docs/version.txt
===================================================================
--- trunk/docs/version.txt	(revision 620)
+++ trunk/docs/version.txt	(revision 622)
@@ -1,1 +1,1 @@
-2.2.0
+2.2.1-1
Index: trunk/js/Msg.js
===================================================================
--- trunk/js/Msg.js	(revision 620)
+++ trunk/js/Msg.js	(revision 622)
@@ -56,5 +56,5 @@
         // Warn if the target doesn't exist.
         if (!$(options.container).length) {
-            console.warn('Strangecode.Msg container not found: ' + this.o.container);
+            console.warn('Strangecode.Msg container not found: ' + options.container);
         }
     });
Index: trunk/lib/Auth_SQL.inc.php
===================================================================
--- trunk/lib/Auth_SQL.inc.php	(revision 620)
+++ trunk/lib/Auth_SQL.inc.php	(revision 622)
@@ -826,5 +826,5 @@
             $db->query("
                 UPDATE " . $this->_params['db_table'] . " SET
-                blocked = '',
+                blocked = NULL,
                 blocked_reason = ''
                 WHERE " . $this->_params['db_primary_key'] . " = '" . $db->escapeString($user_id) . "'
Index: trunk/lib/Email.inc.php
===================================================================
--- trunk/lib/Email.inc.php	(revision 620)
+++ trunk/lib/Email.inc.php	(revision 622)
@@ -73,4 +73,7 @@
         'wrap' => true,
         'line_length' => 75,
+
+        'sandbox_mode' => null,
+        'sandbox_to_addr' => null,
     );
 
@@ -80,4 +83,8 @@
     // String that contains the email body after replacements.
     protected $_template_replaced;
+
+    // Email debug modes.
+    const SANDBOX_MODE_REDIRECT = 1; // Send all mail to 'sandbox_to_addr'
+    const SANDBOX_MODE_STDERR = 2; // Log all mail to stderr
 
     /**
@@ -359,6 +366,12 @@
             }
             // If the envelope_sender_address was given as a header, move it to the correct place.
-            if ('envelope_sender_address' == $key) {
+            if ('envelope_sender_address' == strtolower($key)) {
                 $this->_params['envelope_sender_address'] = isset($this->_params['envelope_sender_address']) ? $this->_params['envelope_sender_address'] : $val;
+                continue;
+            }
+            // If we're sending in sandbox mode, remove any headers with recipient addresses.
+            if ($this->getParam('sandbox_mode') == self::SANDBOX_MODE_REDIRECT && in_array(strtolower($key), array('to', 'cc', 'bcc')) && mb_strpos($val, '@') !== false) {
+                // Don't carry this into the $final_headers.
+                $app->logMsg(sprintf('Skipping header in sandbox mode: %s=%s', $key, $val), LOG_DEBUG, __FILE__, __LINE__);
                 continue;
             }
@@ -384,4 +397,19 @@
             $app->logMsg(sprintf('Mail header injection attack in content: %s', $full_mail_content), LOG_WARNING, __FILE__, __LINE__);
             return false;
+        }
+
+        // Enter sandbox mode, if specified.
+        switch ($this->getParam('sandbox_mode')) {
+        case self::SANDBOX_MODE_REDIRECT:
+            if (!$this->getParam('sandbox_to_addr')) {
+                $app->logMsg(sprintf('Email sandbox_mode is SANDBOX_MODE_REDIRECT but sandbox_to_addr is not set.', null), LOG_ERR, __FILE__, __LINE__);
+                break;
+            }
+            $final_to = $this->getParam('sandbox_to_addr');
+            break;
+
+        case self::SANDBOX_MODE_STDERR:
+            file_put_contents('php://stderr', sprintf("Subject: %s\nTo: %s\n%s\n\n%s", $this->getParam('subject'), $final_to, str_replace($this->getParam('crlf'), "\n", $final_headers), $final_body), FILE_APPEND);
+            return true;
         }
 
Index: trunk/tests/EmailTest.php
===================================================================
--- trunk/tests/EmailTest.php	(revision 620)
+++ trunk/tests/EmailTest.php	(revision 622)
@@ -5,5 +5,5 @@
  * For details visit the project site: <http://trac.strangecode.com/codebase/>
  * Copyright 2001-2012 Strangecode, LLC
- * 
+ *
  * This file is part of The Strangecode Codebase.
  *
@@ -12,10 +12,10 @@
  * Free Software Foundation, either version 3 of the License, or (at your option)
  * any later version.
- * 
+ *
  * The Strangecode Codebase is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  * details.
- * 
+ *
  * You should have received a copy of the GNU General Public License along with
  * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
@@ -83,10 +83,26 @@
 //     }
 //
-//     function testsend()
-//     {
-//         $result   = $this->Email->send(PARAM);
-//         $expected = EXPECTED_VAL;
-//         $this->assertEquals($expected, $result);
-//     }
+    function testsend()
+    {
+
+        $this->Email = new Email(array(
+            'to' => 'Rob Recipient <to@example.com>',
+            'from' => 'Sam Sender <from@example.com>',
+            'subject' => 'EmailTest',
+            'headers' => array(
+                'CC' => 'This header removed in REDIRECT sandbox mode <remove-me@example.com>',
+                'X-Hello' => 'Hi there',
+            ),
+            'sandbox_mode' => Email::SANDBOX_MODE_REDIRECT,
+            'sandbox_to_addr' => 'quinn@strangecode.com',
+        ));
+        $this->Email->setString('This is a {TEST}');
+        $this->Email->replace(array(
+            'test' => 'â you guessed it â a test!'
+        ));
+        $result   = $this->Email->send();
+        $expected = true;
+        $this->assertEquals($expected, $result);
+    }
 
     function testvalidemail()
Index: trunk/tests/run_tests.sh
===================================================================
--- trunk/tests/run_tests.sh	(revision 620)
+++ trunk/tests/run_tests.sh	(revision 622)
@@ -38,4 +38,4 @@
 # Config options go in phpunit.xml
 # phpunit --tap | grep -v '^ok '
-phpunit --stderr || err "\nSomething went wrong (code $?). If there is no output above, check the php_error_log";
+../vendor/phpunit/phpunit/composer/bin/phpunit --stderr || err "\nSomething went wrong (code $?). If there is no output above, check the php_error_log";
 
