Skip to content

Commit

Permalink
- Issue #6: googlemail.com is now recognized as a Gmail address
Browse files Browse the repository at this point in the history
- Issue #6: `.` are now removed when sanitizing Gmail addresses (to get to the root email address)
  • Loading branch information
stymiee committed Apr 5, 2024
1 parent 2395d08 commit e80e6bb
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 35 deletions.
33 changes: 0 additions & 33 deletions CHANGELOG

This file was deleted.

64 changes: 64 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.4] - 2024-XX-XX

### Changed
- Issue #6: `googlemail.com` is now recognized as a Gmail address
- Issue #6: `.` are now removed when sanitizing Gmail addresses (to get to the root email address)

- CHANGELOG format

### Fixed

- Issue #6: `googlemail.com` is now considered a Gmail email address

## [1.1.3] - 2022-10-12

### Fixed

- Handled potential for null being returned when validating a banned domain name


## [1.1.1] - 2022-10-11

### Changed

- Banned domain check to use pattern matching for more robust validation including subdomains


## [1.1.1] - 2022-02-22

### Fixed

- When getting an email address' username, if there was none, return an empty string instead of NULL
-

## [1.1.0] - 2022-02-02

### Added

- Support for identifying and working with Gmail addresses using the "plus trick" to create unique addresses


## [1.0.2] - 2022-01-24

### Fixed

- Issue #2: Error state not clearing between validations


## [1.0.1] - 2021-09-20

### Added

- Pull Request #1: Added EmailValidator::getErrorCode()


## [1.0.0] - 2020-08-02

- Initial release
20 changes: 18 additions & 2 deletions src/EmailValidator/EmailAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ private function getUsername(): ?string
public function isGmailWithPlusChar(): bool
{
$result = false;
if ($this->getDomain() === 'gmail.com') {
if (in_array($this->getDomain(), ['gmail.com', 'googlemail.com'])) {
$result = strpos($this->getUsername(), '+') !== false;
}

return $result;
}

/**
* Returns a gmail address with the "plus trick" portion of the email address.
* Returns a gmail address without the "plus trick" portion of the email address.
*
* @since 1.1.0
* @return string
Expand All @@ -73,4 +73,20 @@ public function getGmailAddressWithoutPlus(): string
{
return preg_replace('/^(.+?)(\+.+?)(@.+)/', '$1$3', $this->getEmailAddress());
}

/**
* Returns a gmail address without the "plus trick" portion of the email address and all dots removed.
*
* @since 1.1.4
* @return string
*/
public function getSanitizedGmailAddress(): string
{
$email = new EmailAddress($this->getGmailAddressWithoutPlus());
return sprintf(
'%s@%s',
str_replace('.', '', $email->getUsername()),
$email->getDomain()
);
}
}
22 changes: 22 additions & 0 deletions tests/EmailValidator/EmailAddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,26 @@ public function testGetGmailAddressWithoutPlus(): void
$email = new EmailAddress('[email protected]');
self::assertEquals('[email protected]', $email->getGmailAddressWithoutPlus());
}

public function gmailAddressDataProvider(): array
{
return [
['[email protected]' , '[email protected]'],
['[email protected]' , '[email protected]'],
['[email protected]' , '[email protected]'],
['[email protected]' , '[email protected]'],
['[email protected]' , '[email protected]'],
];
}

/**
* @dataProvider gmailAddressDataProvider
* @param string $emailAddress
* @param string $resultAddress
*/
public function testGetSanitizedGmailAddress(string $emailAddress, string $resultAddress): void
{
$email = new EmailAddress($emailAddress);
self::assertEquals($email->getSanitizedGmailAddress(), $resultAddress);
}
}

0 comments on commit e80e6bb

Please sign in to comment.