Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.875
diff -u -p -r1.875 common.inc
--- includes/common.inc	11 Apr 2009 22:19:44 -0000	1.875
+++ includes/common.inc	15 Apr 2009 16:27:16 -0000
@@ -1160,15 +1160,228 @@ function t($string, $args = array(), $la
 /**
  * Verify the syntax of the given e-mail address.
  *
- * Empty e-mail addresses are allowed. See RFC 2822 for details.
- *
- * @param $mail
+ * Email Check By Dominic Sayers http://www.dominicsayers.com/isemail/.
+ * Keeping with standard string functions as not all the functions used
+ * here have a drupal equivalent
+ * @param $email
  *   A string containing an e-mail address.
  * @return
  *   TRUE if the address is in a valid format.
  */
-function valid_email_address($mail) {
-  return (bool)filter_var($mail, FILTER_VALIDATE_EMAIL);
+function valid_email_address($email) {
+ 
+  $email_length = strlen($email);
+  if ($email_length > 256)  return FALSE;
+  $at_index = strrpos($email,  '@');
+
+  if ($at_index === FALSE)    return FALSE;
+  if ($at_index === 0)    return FALSE;
+  if ($at_index === $email_length)  return FALSE;
+  $brace_depth  = 0;
+  $in_quote  = FALSE;
+  $escape_this_char  = FALSE;
+
+  for ($i = 0; $i < $email_length; ++$i) {
+    $char = $email[$i];
+    $replace_char = FALSE;
+
+    if ($char === '\\') {
+      $escape_this_char = !$escape_this_char;
+    } 
+    else {
+      switch ($char) {
+      case '(':
+        if ($escape_this_char) {
+          $replace_char = TRUE;
+        }
+        else {
+          if ($in_quote) {
+            $replace_char = TRUE;
+          }
+          else {
+            if ($brace_depth++ > 0) $replace_char = TRUE;
+          }
+        }
+
+        break;
+      case ')':
+        if ($escape_this_char) {
+          $replace_char = TRUE;
+        }
+        else {
+          if ($in_quote) {
+            $replace_char = TRUE;
+          }
+          else {
+            if (--$brace_depth > 0) $replace_char = TRUE;
+            if ($brace_depth < 0) $brace_depth = 0;
+          }
+        }
+
+        break;
+      case '"':
+        if ($escape_this_char) {
+          $replace_char = TRUE;
+        }
+        else {
+          if ($brace_depth === 0) {
+            $in_quote = !$in_quote;
+          }
+          else {
+            $replace_char = TRUE;
+          }
+        }
+
+        break;
+      case '.':
+        if ($escape_this_char) {
+          $replace_char = TRUE;
+        }
+        else {
+          if ($brace_depth > 0) $replace_char = TRUE;
+        }
+
+        break;
+      default:
+      }
+
+      $escape_this_char = FALSE;
+      if ($replace_char) $email[$i] = 'x';
+    }
+  }
+
+  $local_part  = substr($email, 0, $at_index);
+  $domain    = substr($email, $at_index + 1);
+  $FWS    = "(?:(?:(?:[ \\t]*(?:\\r\\n))?[ \\t]+)|(?:[ \\t]+(?:(?:\\r\\n)[ \\t]+)*))";
+  $dot_array  = preg_split('/\\.(?=(?:[^\\"]*\\"[^\\"]*\\")*(?![^\\"]*\\"))/m', $local_part);
+  $part_length  = 0;
+
+  foreach ($dot_array as $element) {
+    $element = preg_replace("/^$FWS|$FWS\$/", '', $element);
+    $element_length = strlen($element);
+
+    if ($element_length > 0 and $element[0] === '(') {
+      $index_brace = strpos($element, ')');
+      if ($index_brace !== FALSE) {
+        if (preg_match('/(?<!\\\\)[\\(\\)]/', substr($element, 1, $index_brace - 1)) > 0) {
+                          return FALSE;
+        }
+        $element  = substr($element, $index_brace + 1, $element_length - $index_brace - 1);
+        $element_length  = strlen($element);
+      }
+    }
+    
+    if ($element_length > 1 and $element[$element_length - 1] === ')') {
+      $index_brace = strrpos($element, '(');
+      if ($index_brace !== FALSE) {
+        if (preg_match('/(?<!\\\\)(?:[\\(\\)])/', substr($element, $index_brace + 1, $element_length - $index_brace - 2)) > 0) {
+                          return FALSE;
+        }
+        $element  = substr($element, 0, $index_brace);
+        $element_length  = strlen($element);
+      }
+    }
+    $element = preg_replace("/^$FWS|$FWS\$/", '', $element);
+    if ($part_length > 0) $part_length++;
+    $part_length += strlen($element);
+    if (preg_match('/^"(?:.)*"$/s', $element) > 0) {
+      $element = preg_replace("/(?<!\\\\)$FWS/", '', $element);
+      $element = preg_replace('/\\\\\\\\/', ' ', $element);
+      if (preg_match('/(?<!\\\\|^)["\\r\\n\\x00](?!$)|\\\\"$|""/', $element) > 0)  return FALSE;
+    }
+    else {
+      if ($element === '')                return FALSE;
+      if (preg_match('/[\\x00-\\x20\\(\\)<>\\[\\]:;@\\\\,\\."]/', $element) > 0)  return FALSE;
+    }
+  }
+
+  if ($part_length > 64) return FALSE;
+  if (preg_match('/^\\[(.)+]$/', $domain) === 1) {
+    $address_literal = substr($domain, 1, strlen($domain) - 2);
+    $matches_IP  = array();
+    if (preg_match('/\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/', $address_literal, $matches_IP) > 0) {
+      $index = strrpos($address_literal, $matches_IP[0]);
+      
+      if ($index === 0) {
+        return TRUE;
+      }
+      else {
+        if ($address_literal[$index - 1] !== ':')  return FALSE;
+        if (substr($address_literal, 0, 5) !== 'IPv6:')  return FALSE;
+
+        $IP_v6    = substr($address_literal, 5, ($index ===7) ? 2 : $index - 6);
+        $group_max  = 6;
+      }
+    }
+    else {
+      if (substr($address_literal, 0, 5) !== 'IPv6:')    return FALSE;
+      $IP_v6 = substr($address_literal, 5);
+      $group_max = 8;
+    }
+
+    $group_count  = preg_match_all('/^[0-9a-fA-F]{0,4}|\\:[0-9a-fA-F]{0,4}|(.)/', $IP_v6, $matches_IP);
+    $index    = strpos($IP_v6, '::');
+
+    if ($index === FALSE) {
+      if ($group_count !== $group_max)        return FALSE;
+    }
+    else {
+      if ($index !== strrpos($IP_v6, '::'))      return FALSE;
+      $group_max = ($index === 0 || $index === (strlen($IP_v6) - 2)) ? $group_max : $group_max - 1;
+      if ($group_count > $group_max)        return FALSE;
+    }
+    array_multisort($matches_IP[1], SORT_DESC);
+    if ($matches_IP[1][0] !== '')          return FALSE;
+    return TRUE;
+  }
+  else {
+    $dot_array  = preg_split('/\\.(?=(?:[^\\"]*\\"[^\\"]*\\")*(?![^\\"]*\\"))/m', $domain);
+    $part_length = 0;
+
+    if (count($dot_array) === 1)          return FALSE;
+
+    foreach ($dot_array as $element) {
+      $element = preg_replace("/^$FWS|$FWS\$/", '', $element);
+      $element_length = strlen($element);
+  
+      if ($element_length > 0 and $element[0] === '(') {
+        $index_brace = strpos($element, ')');
+        if ($index_brace !== FALSE) {
+          if (preg_match('/(?<!\\\\)[\\(\\)]/', substr($element, 1, $index_brace - 1)) > 0) {
+                    return FALSE;
+          }
+          $element  = substr($element, $index_brace + 1, $element_length - $index_brace - 1);
+          $element_length  = strlen($element);
+        }
+      }
+      
+      if ($element_length > 0 and $element[$element_length - 1] === ')') {
+        $index_brace = strrpos($element, '(');
+        if ($index_brace !== FALSE) {
+          if (preg_match('/(?<!\\\\)(?:[\\(\\)])/', substr($element, $index_brace + 1, $element_length - $index_brace - 2)) > 0) {
+	          return FALSE;
+          }
+          $element  = substr($element, 0, $index_brace);
+          $element_length  = strlen($element);
+        }
+      }
+      $element = preg_replace("/^$FWS|$FWS\$/", '', $element);
+      if ($part_length > 0) $part_length++;
+      $part_length += strlen($element);
+      if ($element_length > 63) return FALSE;
+      if ($element_length === 0) return FALSE;
+      if (preg_match('/[\\x00-\\x20\\(\\)<>\\[\\]:;@\\\\,\\."]|^-|-$/', $element) > 0) {
+                    return FALSE;
+      }
+    }
+
+    if ($part_length > 255) return FALSE;
+
+    if (preg_match('/^[0-9]+$/', $element) > 0)return FALSE;
+
+    
+  }
+  return TRUE;
 }
 
 /**
Index: modules/simpletest/tests/common.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/common.test,v
retrieving revision 1.32
diff -u -p -r1.32 common.test
--- modules/simpletest/tests/common.test	31 Mar 2009 01:49:53 -0000	1.32
+++ modules/simpletest/tests/common.test	15 Apr 2009 16:27:16 -0000
@@ -961,3 +961,288 @@ class DrupalErrorCollectionUnitTest exte
   }
 }
 
+class CommonValidEmailAddressTestCase extends DrupalWebTestCase {
+
+  /**
+   * Implementation of getInfo().
+   */
+  function getInfo() {
+    return array(
+      'name' => t('Valid email address'),
+      'description' => t('Check predefined email addresses against valid_email_address().'),
+      'group' => t('System')
+    );
+  }
+
+  /**
+   * Implementation of setUp().
+   */
+  function setUp() {
+    $this->test_cases = array( // '<user@domain.ext>' => (bool)'<expected result>',
+      'foo@example.com'     => TRUE,
+      'foo@example-foo.com' => TRUE,
+      'foo@example.co.uk'   => TRUE,
+      'foo@example.com.'    => FALSE,
+      'foo@example.com..'   => FALSE,
+      'foo@-example.com'    => FALSE,
+      'foo@example-.com'    => FALSE,
+      'foo@example-.'       => FALSE,
+      '@example.com'        => FALSE,
+      'foo@.example.com'    => FALSE,
+      'foo@example.com-'    => FALSE,
+      'foo@example'         => FALSE,
+      'foo@192.168.1.1'       => FALSE,
+      "first.last@example.com" => TRUE,
+      "1234567890123456789012345678901234567890123456789012345678901234@example.com" => TRUE,
+      "\"first last\"@example.com" => TRUE,
+      "\"first\\\"last\"@example.com" => TRUE,
+      "first\\@last@example.com" => FALSE,
+      "\"first@last\"@example.com" => TRUE,
+      "\"first\\\\last\"@example.com" => TRUE,
+      "x@x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x234" => TRUE,
+      "123456789012345678901234567890123456789012345678901234567890@12345678901234567890123456789012345678901234567890123456789.12345678901234567890123456789012345678901234567890123456789.123456789012345678901234567890123456789012345678901234567890123.example.com" => TRUE,
+      "first.last@[12.34.56.78]" => TRUE,
+      "first.last@[IPv6:::12.34.56.78]" => TRUE,
+      "first.last@[IPv6:1111:2222:3333::4444:12.34.56.78]" => TRUE,
+      "first.last@[IPv6:1111:2222:3333:4444:5555:6666:12.34.56.78]" => TRUE,
+      "first.last@[IPv6:::1111:2222:3333:4444:5555:6666]" => TRUE,
+      "first.last@[IPv6:1111:2222:3333::4444:5555:6666]" => TRUE,
+      "first.last@[IPv6:1111:2222:3333:4444:5555:6666::]" => TRUE,
+      "first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777:8888]" => TRUE,
+      "first.last@x23456789012345678901234567890123456789012345678901234567890123.example.com" => TRUE,
+      "first.last@1xample.com" => TRUE,
+      "first.last@123.example.com" => TRUE,
+      "123456789012345678901234567890123456789012345678901234567890@12345678901234567890123456789012345678901234567890123456789.12345678901234567890123456789012345678901234567890123456789.12345678901234567890123456789012345678901234567890123456789.1234.example.com" => FALSE,
+      "first.last" => FALSE,
+      "12345678901234567890123456789012345678901234567890123456789012345@example.com" => FALSE,
+      ".first.last@example.com" => FALSE,
+      "first.last.@example.com" => FALSE,
+      "first..last@example.com" => FALSE,
+      "\"first\"last\"@example.com" => FALSE,
+      "\"first\\last\"@example.com" => TRUE,
+      "\"\"\"@example.com" => FALSE,
+      "\"\\\"@example.com" => FALSE,
+      "\"\"@example.com" => FALSE,
+      "first\\\\@last@example.com" => FALSE,
+      "first.last@" => FALSE,
+      "x@x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456" => FALSE,
+      "first.last@[.12.34.56.78]" => FALSE,
+      "first.last@[12.34.56.789]" => FALSE,
+      "first.last@[::12.34.56.78]" => FALSE,
+      "first.last@[IPv5:::12.34.56.78]" => FALSE,
+      "first.last@[IPv6:1111:2222:3333::4444:5555:12.34.56.78]" => FALSE,
+      "first.last@[IPv6:1111:2222:3333:4444:5555:12.34.56.78]" => FALSE,
+      "first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777:12.34.56.78]" => FALSE,
+      "first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777]" => FALSE,
+      "first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777:8888:9999]" => FALSE,
+      "first.last@[IPv6:1111:2222::3333::4444:5555:6666]" => FALSE,
+      "first.last@[IPv6:1111:2222:3333::4444:5555:6666:7777]" => FALSE,
+      "first.last@[IPv6:1111:2222:333x::4444:5555]" => FALSE,
+      "first.last@[IPv6:1111:2222:33333::4444:5555]" => FALSE,
+      "first.last@example.123" => FALSE,
+      "first.last@com" => FALSE,
+      "first.last@-xample.com" => FALSE,
+      "first.last@exampl-.com" => FALSE,
+      "first.last@x234567890123456789012345678901234567890123456789012345678901234.example.com" => FALSE,
+      "\"Abc\\@def\"@example.com" => TRUE,
+      "\"Fred\\ Bloggs\"@example.com" => TRUE,
+      "\"Joe.\\\\Blow\"@example.com" => TRUE,
+      "\"Abc@def\"@example.com" => TRUE,
+      "\"Fred Bloggs\"@example.com" => TRUE,
+      "user+mailbox@example.com" => TRUE,
+      "customer/department=shipping@example.com" => TRUE,
+      "\$A12345@example.com" => TRUE,
+      "!def!xyz%abc@example.com" => TRUE,
+      "_somename@example.com" => TRUE,
+      "dclo@us.ibm.com" => TRUE,
+      "abc\\@def@example.com" => FALSE,
+      "abc\\\\@example.com" => FALSE,
+      "peter.piper@example.com" => TRUE,
+      "Doug\\ \\\"Ace\\\"\\ Lovell@example.com" => FALSE,
+      "\"Doug \\\"Ace\\\" L.\"@example.com" => TRUE,
+      "abc@def@example.com" => FALSE,
+      "abc\\\\@def@example.com" => FALSE,
+      "abc\\@example.com" => FALSE,
+      "@example.com" => FALSE,
+      "doug@" => FALSE,
+      "\"qu@example.com" => FALSE,
+      "ote\"@example.com" => FALSE,
+      ".dot@example.com" => FALSE,
+      "dot.@example.com" => FALSE,
+      "two..dot@example.com" => FALSE,
+      "\"Doug \"Ace\" L.\"@example.com" => FALSE,
+      "Doug\\ \\\"Ace\\\"\\ L\\.@example.com" => FALSE,
+      "hello world@example.com" => FALSE,
+      "gatsby@f.sc.ot.t.f.i.tzg.era.l.d." => FALSE,
+      "test@example.com" => TRUE,
+      "TEST@example.com" => TRUE,
+      "1234567890@example.com" => TRUE,
+      "test+test@example.com" => TRUE,
+      "test-test@example.com" => TRUE,
+      "t*est@example.com" => TRUE,
+      "+1~1+@example.com" => TRUE,
+      "{_test_}@example.com" => TRUE,
+      "\"[[ test ]]\"@example.com" => TRUE,
+      "test.test@example.com" => TRUE,
+      "\"test.test\"@example.com" => TRUE,
+      "test.\"test\"@example.com" => TRUE,
+      "\"test@test\"@example.com" => TRUE,
+      "test@123.123.123.x123" => TRUE,
+      "test@123.123.123.123" => FALSE,
+      "test@[123.123.123.123]" => TRUE,
+      "test@example.example.com" => TRUE,
+      "test@example.example.example.com" => TRUE,
+      "test.example.com" => FALSE,
+      "test.@example.com" => FALSE,
+      "test..test@example.com" => FALSE,
+      ".test@example.com" => FALSE,
+      "test@test@example.com" => FALSE,
+      "test@@example.com" => FALSE,
+      "-- test --@example.com" => FALSE,
+      "[test]@example.com" => FALSE,
+      "\"test\\test\"@example.com" => TRUE,
+      "\"test\"test\"@example.com" => FALSE,
+      "()[]\\;:,><@example.com" => FALSE,
+      "test@." => FALSE,
+      "test@example." => FALSE,
+      "test@.org" => FALSE,
+      "test@123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012.com" => FALSE,
+      "test@example" => FALSE,
+      "test@[123.123.123.123" => FALSE,
+      "test@123.123.123.123]" => FALSE,
+      "NotAnEmail" => FALSE,
+      "@NotAnEmail" => FALSE,
+      "\"test\\\\blah\"@example.com" => TRUE,
+      "\"test\\blah\"@example.com" => TRUE,
+      "\"test\\\rblah\"@example.com" => TRUE,
+      "\"test\rblah\"@example.com" => FALSE,
+      "\"test\\\"blah\"@example.com" => TRUE,
+      "\"test\"blah\"@example.com" => FALSE,
+      "customer/department@example.com" => TRUE,
+      "_Yosemite.Sam@example.com" => TRUE,
+      "~@example.com" => TRUE,
+      ".wooly@example.com" => FALSE,
+      "wo..oly@example.com" => FALSE,
+      "pootietang.@example.com" => FALSE,
+      ".@example.com" => FALSE,
+      "\"Austin@Powers\"@example.com" => TRUE,
+      "Ima.Fool@example.com" => TRUE,
+      "\"Ima.Fool\"@example.com" => TRUE,
+      "\"Ima Fool\"@example.com" => TRUE,
+      "Ima Fool@example.com" => FALSE,
+      "phil.h\\@\\@ck@haacked.com" => FALSE,
+      "\"first\".\"last\"@example.com" => TRUE,
+      "\"first\".middle.\"last\"@example.com" => TRUE,
+      "\"first\\\\\"last\"@example.com" => FALSE,
+      "\"first\".last@example.com" => TRUE,
+      "first.\"last\"@example.com" => TRUE,
+      "\"first\".\"middle\".\"last\"@example.com" => TRUE,
+      "\"first.middle\".\"last\"@example.com" => TRUE,
+      "\"first.middle.last\"@example.com" => TRUE,
+      "\"first..last\"@example.com" => TRUE,
+      "foo@[\\1.2.3.4]" => FALSE,
+      "\"first\\\\\\\"last\"@example.com" => TRUE,
+      "first.\"mid\\dle\".\"last\"@example.com" => TRUE,
+      "Test.\r\n Folding.\r\n Whitespace@example.com" => TRUE,
+      "first.\"\".last@example.com" => FALSE,
+      "first\\last@example.com" => FALSE,
+      "Abc\\@def@example.com" => FALSE,
+      "Fred\\ Bloggs@example.com" => FALSE,
+      "Joe.\\\\Blow@example.com" => FALSE,
+      "first.last@[IPv6:1111:2222:3333:4444:5555:6666:12.34.567.89]" => FALSE,
+      "\"test\\\r\n blah\"@example.com" => FALSE,
+      "\"test\r\n blah\"@example.com" => TRUE,
+      "{^c\\@**Dog^}@cartoon.com" => FALSE,
+      "(foo)cal(bar)@(baz)iamcal.com(quux)" => TRUE,
+      "cal@iamcal(woo).(yay)com" => TRUE,
+      "\"foo\"(yay)@(hoopla)[1.2.3.4]" => FALSE,
+      "cal(woo(yay)hoopla)@iamcal.com" => TRUE,
+      "cal(foo\\@bar)@iamcal.com" => TRUE,
+      "cal(foo\\)bar)@iamcal.com" => TRUE,
+      "cal(foo(bar)@iamcal.com" => FALSE,
+      "cal(foo)bar)@iamcal.com" => FALSE,
+      "cal(foo\\)@iamcal.com" => FALSE,
+      "first().last@example.com" => TRUE,
+      "first.(\r\n middle\r\n )last@example.com" => TRUE,
+      "first(12345678901234567890123456789012345678901234567890)last@(1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890)example.com" => FALSE,
+      "first(Welcome to\r\n the (\"wonderful\" (!)) world\r\n of email)@example.com" => TRUE,
+      "pete(his account)@silly.test(his host)" => TRUE,
+      "c@(Chris\'s host.)public.example" => TRUE,
+      "jdoe@machine(comment).  example" => TRUE,
+      "1234   @   local(blah)  .machine .example" => TRUE,
+      "first(middle)last@example.com" => FALSE,
+      "first(abc.def).last@example.com" => TRUE,
+      "first(a\"bc.def).last@example.com" => TRUE,
+      "first.(\")middle.last(\")@example.com" => TRUE,
+      "first(abc(\"def\".ghi).mno)middle(abc(\"def\".ghi).mno).last@(abc(\"def\".ghi).mno)example(abc(\"def\".ghi).mno).(abc(\"def\".ghi).mno)com(abc(\"def\".ghi).mno)" => FALSE,
+      "first(abc\\(def)@example.com" => TRUE,
+      "first.last@x(1234567890123456789012345678901234567890123456789012345678901234567890).com" => TRUE,
+      "a(a(b(c)d(e(f))g)h(i)j)@example.com" => TRUE,
+      "a(a(b(c)d(e(f))g)(h(i)j)@example.com" => FALSE,
+      "name.lastname@domain.com" => TRUE,
+      ".@" => FALSE,
+      "a@b" => FALSE,
+      "@bar.com" => FALSE,
+      "@@bar.com" => FALSE,
+      "a@bar.com" => TRUE,
+      "aaa.com" => FALSE,
+      "aaa@.com" => FALSE,
+      "aaa@.123" => FALSE,
+      "aaa@[123.123.123.123]" => TRUE,
+      "aaa@[123.123.123.123]a" => FALSE,
+      "aaa@[123.123.123.333]" => FALSE,
+      "a@bar.com." => FALSE,
+      "a@bar" => FALSE,
+      "a-b@bar.com" => TRUE,
+      "+@b.c" => TRUE,
+      "+@b.com" => TRUE,
+      "a@-b.com" => FALSE,
+      "a@b-.com" => FALSE,
+      "-@..com" => FALSE,
+      "-@a..com" => FALSE,
+      "a@b.co-foo.uk" => TRUE,
+      "\"hello my name is\"@stutter.com" => TRUE,
+      "\"Test \\\"Fail\\\" Ing\"@example.com" => TRUE,
+      "valid@special.museum" => TRUE,
+      "invalid@special.museum-" => FALSE,
+      "shaitan@my-domain.thisisminekthx" => TRUE,
+      "test@...........com" => FALSE,
+      "foobar@192.168.0.1" => FALSE,
+      "\"Joe\\\\Blow\"@example.com" => TRUE,
+      "Invalid \\\n Folding \\\n Whitespace@example.com" => FALSE,
+      "HM2Kinsists@(that comments are allowed)this.is.ok" => TRUE,
+      "user%uucp!path@somehost.edu" => TRUE,
+      "\"first(last)\"@example.com" => TRUE,
+      " \r\n (\r\n x \r\n ) \r\n first\r\n ( \r\n x\r\n ) \r\n .\r\n ( \r\n x) \r\n last \r\n (  x \r\n ) \r\n @example.com" => TRUE,
+      "test. \r\n \r\n obs@syntax.com" => TRUE,
+      "test. \r\n \r\n obs@syntax.com" => TRUE,
+      "test.\r\n\r\n obs@syntax.com" => FALSE,
+      "\"null \\\0\"@char.com" => TRUE,
+      "\"null \0\"@char.com" => FALSE,
+      "null\\\0@char.com" => FALSE,
+      
+    );
+    parent::setUp();
+  }
+
+  /**
+   * testCommonValidEmailAddress
+   */
+  function testCommonValidEmailAddress() {
+    foreach ($this->test_cases as $address => $expected) {
+      if ($expected === TRUE) {
+        $this->assertTrue(
+          (bool)valid_email_address($address),
+          "Checking valid email address: '". $address ."' %s"
+        );
+      }
+      else {
+        $this->assertFalse(
+          (bool)valid_email_address($address),
+          "Checking invalid email address: '". $address ."' %s"
+        );
+      }
+    }
+  }
+}
+
