function testContainsEmailAddress() { $validStrings = array('my e-mail address is will.buckner [at] eggheads [dot] org', 'Email: will.buckner (at) eggheads (dot) org', 'E-Mail:wcc@nospammonkeys.org', 'E-Mail: wcc [at] lists [dot] nospammonkeys [dot] org'); $invalidStrings = array('i am at the movies dot dot dot', 'not@valid', '*****@*****.**'); foreach ($validStrings as $key => $value) { $this->assertTrue(StringUtility::containsEmailAddress($value), sprintf("'%s' should be recognized as containing an e-mail address", $value)); } foreach ($invalidStrings as $key => $value) { $this->assertFalse(StringUtility::containsEmailAddress($value), sprintf("'%s' should not be recognized as containing an e-mail address", $value)); } /* Some sample text to test with. */ $fairyTale = implode('', file('./modules/tests/SampleText.txt')); /* I can assure you that none of Grimm's fairy tales contain e-mail addresses. */ $this->assertFalse(StringUtility::containsEmailAddress($fairyTale)); }
protected function _extractEmailAddress() { foreach ($this->_addressBlock as $lineNumber => $line) { if (!StringUtility::containsEmailAddress($line)) { continue; } /* Extract and properly format the e-mail address. */ $emailAddress = StringUtility::extractEmailAddress($line); /* If there is more on this line, remove the e-mail address from * the line. Otherwise, just delete the line. */ if (!StringUtility::isEmailAddress($line)) { $line = StringUtility::removeEmailAddress($line, true); $this->_addressBlock[$lineNumber] = $line; } else { unset($this->_addressBlock[$lineNumber]); $this->_addressBlock = array_merge($this->_addressBlock); } return $emailAddress; } return ''; }