Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 48 additions & 50 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions src/Emails/Canonicals/Providers/Protonmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
* ProtonMail
*
* Handles ProtonMail email normalization
* - Preserves all characters in local part (no subaddress or dot removal)
* - Normalizes to protonmail.com domain
* - Removes plus addressing (subaddress) from local part
* - Preserves dots in local part
* - Does not normalize domains
*
* Docs: https://proton.me/support/creating-aliases#+Aliases
*/
class Protonmail extends Provider
{
private const SUPPORTED_DOMAINS = ['protonmail.com', 'proton.me', 'pm.me'];
private const SUPPORTED_DOMAINS = ['protonmail.com', 'proton.me', 'pm.me', 'protonmail.ch'];

private const CANONICAL_DOMAIN = 'protonmail.com';

Expand All @@ -27,12 +30,14 @@ public function getCanonical(string $local, string $domain): array
// Convert to lowercase
$normalizedLocal = $this->toLowerCase($local);

// ProtonMail doesn't remove subaddresses or dots
// Just normalize case and domain
// Remove plus addressing (subaddress) - everything after +
$normalizedLocal = $this->removePlusAddressing($normalizedLocal);

// protonmail.ch, protonmail.com - not subaddress, just different options during sign up
// pm.me - technically subaddress, but costs monthly fee, and gives just +1 email. Costly already, no need to block. People get it for shorter email to type it quicker anyway
return [
'local' => $normalizedLocal,
'domain' => self::CANONICAL_DOMAIN,
'domain' => \in_array($domain, self::SUPPORTED_DOMAINS, true) ? $domain : self::CANONICAL_DOMAIN,
];
Comment thread
Meldiron marked this conversation as resolved.
}

Expand Down
45 changes: 24 additions & 21 deletions tests/Canonicals/Providers/ProtonmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function test_supports(): void
$this->assertTrue($this->provider->supports('protonmail.com'));
$this->assertTrue($this->provider->supports('proton.me'));
$this->assertTrue($this->provider->supports('pm.me'));
$this->assertTrue($this->provider->supports('protonmail.ch'));
$this->assertFalse($this->provider->supports('gmail.com'));
$this->assertFalse($this->provider->supports('outlook.com'));
$this->assertFalse($this->provider->supports('example.com'));
Expand All @@ -27,31 +28,33 @@ public function test_supports(): void
public function test_get_canonical(): void
{
$testCases = [
// ProtonMail preserves all characters (no subaddress or dot removal)
// ProtonMail removes plus addressing but preserves dots
['user.name', 'protonmail.com', 'user.name', 'protonmail.com'],
['user.name+tag', 'protonmail.com', 'user.name+tag', 'protonmail.com'],
['user.name+spam', 'protonmail.com', 'user.name+spam', 'protonmail.com'],
['user.name+newsletter', 'protonmail.com', 'user.name+newsletter', 'protonmail.com'],
['user.name+work', 'protonmail.com', 'user.name+work', 'protonmail.com'],
['user.name+personal', 'protonmail.com', 'user.name+personal', 'protonmail.com'],
['user.name+test123', 'protonmail.com', 'user.name+test123', 'protonmail.com'],
['user.name+anything', 'protonmail.com', 'user.name+anything', 'protonmail.com'],
['user.name+verylongtag', 'protonmail.com', 'user.name+verylongtag', 'protonmail.com'],
['user.name+tag.with.dots', 'protonmail.com', 'user.name+tag.with.dots', 'protonmail.com'],
['user.name+tag-with-hyphens', 'protonmail.com', 'user.name+tag-with-hyphens', 'protonmail.com'],
['user.name+tag_with_underscores', 'protonmail.com', 'user.name+tag_with_underscores', 'protonmail.com'],
['user.name+tag123', 'protonmail.com', 'user.name+tag123', 'protonmail.com'],
['user.name+tag', 'protonmail.com', 'user.name', 'protonmail.com'],
['user.name+spam', 'protonmail.com', 'user.name', 'protonmail.com'],
['user.name+newsletter', 'protonmail.com', 'user.name', 'protonmail.com'],
['user.name+work', 'protonmail.com', 'user.name', 'protonmail.com'],
['user.name+personal', 'protonmail.com', 'user.name', 'protonmail.com'],
['user.name+test123', 'protonmail.com', 'user.name', 'protonmail.com'],
['user.name+anything', 'protonmail.com', 'user.name', 'protonmail.com'],
['user.name+verylongtag', 'protonmail.com', 'user.name', 'protonmail.com'],
['user.name+tag.with.dots', 'protonmail.com', 'user.name', 'protonmail.com'],
['user.name+tag-with-hyphens', 'protonmail.com', 'user.name', 'protonmail.com'],
['user.name+tag_with_underscores', 'protonmail.com', 'user.name', 'protonmail.com'],
['user.name+tag123', 'protonmail.com', 'user.name', 'protonmail.com'],
['u.s.e.r.n.a.m.e', 'protonmail.com', 'u.s.e.r.n.a.m.e', 'protonmail.com'],
['u.s.e.r.n.a.m.e+tag', 'protonmail.com', 'u.s.e.r.n.a.m.e+tag', 'protonmail.com'],
['user+', 'protonmail.com', 'user+', 'protonmail.com'],
['u.s.e.r.n.a.m.e+tag', 'protonmail.com', 'u.s.e.r.n.a.m.e', 'protonmail.com'],
['user+', 'protonmail.com', 'user', 'protonmail.com'],
['user.', 'protonmail.com', 'user.', 'protonmail.com'],
['.user', 'protonmail.com', '.user', 'protonmail.com'],
['user..name', 'protonmail.com', 'user..name', 'protonmail.com'],
// Other ProtonMail domains
['user.name+tag', 'proton.me', 'user.name+tag', 'protonmail.com'],
['user.name+tag', 'pm.me', 'user.name+tag', 'protonmail.com'],
['user.name', 'proton.me', 'user.name', 'protonmail.com'],
['user.name', 'pm.me', 'user.name', 'protonmail.com'],
// Other ProtonMail domains (kept as canonical, not aliases)
['user.name+tag', 'proton.me', 'user.name', 'proton.me'],
['user.name+tag', 'pm.me', 'user.name', 'pm.me'],
['user.name', 'proton.me', 'user.name', 'proton.me'],
['user.name', 'pm.me', 'user.name', 'pm.me'],
['user.name', 'protonmail.ch', 'user.name', 'protonmail.ch'],
['user.name+tag', 'protonmail.ch', 'user.name', 'protonmail.ch'],
];

foreach ($testCases as [$inputLocal, $inputDomain, $expectedLocal, $expectedDomain]) {
Expand All @@ -69,7 +72,7 @@ public function test_get_canonical_domain(): void
public function test_get_supported_domains(): void
{
$domains = $this->provider->getSupportedDomains();
$expected = ['protonmail.com', 'proton.me', 'pm.me'];
$expected = ['protonmail.com', 'proton.me', 'pm.me', 'protonmail.ch'];
$this->assertSame($expected, $domains);
}
}
Loading
Loading