What i would do is the following:
Create an interface for email matching:
interface IEmailMatcher {
function matches($rawEmail);
function toEmail($rawEmail);
}
Then implement every currently known possibilities:
//Matcher for regular emails
class BasicEmailMatcher implements IEmailMatcher {
public function matches($rawEmail) {
// PHP has a built in for this
return filter_var($email, FILTER_VALIDATE_EMAIL);
}
public function toEmail($rawEmail) {
// If we passed the filter, it doesn't need any transformation.
return $rawEmail;
}
}
And another:
class OtherEmailMatcher implements IEmailMatcher {
public function matches($rawEmail) {
return preg_match(/*pattern for one format*/, $rawEmail);
}
public function toEmail($rawEmail) {
// return the funky looking email transformed to normal email.
}
}
Then where you validate, simply create an array of all the matchers:
$matchers = [new BasicEmailMatcher(), new OtherEmailMatcher(), ...];
foreach($matchers as $matcher) {
if($matcher->matches($inputEmail)){
// format it back to normal.
$email = $matcher->toEmail($inputEmail);
}
}
This way it is extensible, clear, and easy to understand, if you need to add more of these (or need to remove one later), but possibly a bit slower.