function testExtractEmailAddress() { $emailAddressesToExtract = array(array('*****@*****.**', '*****@*****.**'), array('*****@*****.**', '*****@*****.**'), array('wcc at nospammonkeys dot org', '*****@*****.**'), array('wcc [at] nospammonkeys [dot] org', '*****@*****.**'), array('wcc [at] lists [dot] nospammonkeys [dot] org', '*****@*****.**'), array('wcc (at) nospammonkeys (dot) org', '*****@*****.**'), array('wcc.test (at) nospammonkeys (dot) org', '*****@*****.**'), array('wcc_test(at)nospammonkeys(dot)org', '*****@*****.**'), array('my e-mail address is wcc (at) no (DOT) spammonkeys (DOT) org, but thanks anyway.', '*****@*****.**')); foreach ($emailAddressesToExtract as $key => $value) { $formattedEmailAddress = StringUtility::extractEmailAddress($value[0]); $this->assertTrue($formattedEmailAddress === $value[1], sprintf("Extracting e-mail address from '%s' should result in '%s'", $value[0], $value[1])); } }
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 ''; }