Skip to content

Commit e514f7c

Browse files
authored
Merge pull request #2 from utopia-php/feat-add-walla-provider
Add Walla provider to Email class for enhanced email handling
2 parents b831dc9 + 458a83b commit e514f7c

File tree

4 files changed

+124
-10
lines changed

4 files changed

+124
-10
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Utopia\Emails\Canonicals\Providers;
4+
5+
use Utopia\Emails\Canonicals\Provider;
6+
7+
/**
8+
* Walla
9+
*
10+
* Handles Walla email normalization
11+
* - Supports both walla.co.il and walla.com domains
12+
* - Normalizes to walla.co.il domain
13+
* - Preserves all characters in local part (no plus addressing or dot removal)
14+
*/
15+
class Walla extends Provider
16+
{
17+
private const SUPPORTED_DOMAINS = ['walla.co.il', 'walla.com'];
18+
19+
private const CANONICAL_DOMAIN = 'walla.co.il';
20+
21+
public function supports(string $domain): bool
22+
{
23+
return in_array($domain, self::SUPPORTED_DOMAINS, true);
24+
}
25+
26+
public function getCanonical(string $local, string $domain): array
27+
{
28+
// Convert to lowercase
29+
$normalizedLocal = $this->toLowerCase($local);
30+
31+
return [
32+
'local' => $normalizedLocal,
33+
'domain' => self::CANONICAL_DOMAIN,
34+
];
35+
}
36+
37+
public function getCanonicalDomain(): string
38+
{
39+
return self::CANONICAL_DOMAIN;
40+
}
41+
42+
public function getSupportedDomains(): array
43+
{
44+
return self::SUPPORTED_DOMAINS;
45+
}
46+
}

src/Emails/Email.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Utopia\Emails\Canonicals\Providers\Icloud;
1212
use Utopia\Emails\Canonicals\Providers\Outlook;
1313
use Utopia\Emails\Canonicals\Providers\Protonmail;
14+
use Utopia\Emails\Canonicals\Providers\Walla;
1415
use Utopia\Emails\Canonicals\Providers\Yahoo;
1516

1617
class Email
@@ -288,14 +289,6 @@ public function hasSubdomain(): bool
288289
return ! empty($this->domainInstance->getSub());
289290
}
290291

291-
/**
292-
* Get the email address (as provided, just lowercased and trimmed)
293-
*/
294-
public function getAddress(): string
295-
{
296-
return $this->email;
297-
}
298-
299292
/**
300293
* Get the canonical email address by removing aliases and provider-specific variations
301294
* This method removes plus addressing, dot notation (for Gmail), and other aliasing techniques
@@ -345,6 +338,7 @@ protected static function initializeProviders(): void
345338
new Icloud,
346339
new Protonmail,
347340
new Fastmail,
341+
new Walla,
348342
];
349343
}
350344
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
namespace Utopia\Tests\Canonicals\Providers;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Utopia\Emails\Canonicals\Providers\Walla;
7+
8+
class WallaTest extends TestCase
9+
{
10+
private Walla $provider;
11+
12+
protected function setUp(): void
13+
{
14+
$this->provider = new Walla;
15+
}
16+
17+
public function test_supports(): void
18+
{
19+
$this->assertTrue($this->provider->supports('walla.co.il'));
20+
$this->assertTrue($this->provider->supports('walla.com'));
21+
$this->assertFalse($this->provider->supports('gmail.com'));
22+
$this->assertFalse($this->provider->supports('outlook.com'));
23+
$this->assertFalse($this->provider->supports('yahoo.com'));
24+
$this->assertFalse($this->provider->supports('example.com'));
25+
}
26+
27+
public function test_get_canonical(): void
28+
{
29+
$testCases = [
30+
// walla.co.il domain
31+
['user.name', 'walla.co.il', 'user.name', 'walla.co.il'],
32+
['user.name+tag', 'walla.co.il', 'user.name+tag', 'walla.co.il'],
33+
['user.name+spam', 'walla.co.il', 'user.name+spam', 'walla.co.il'],
34+
['user.name+newsletter', 'walla.co.il', 'user.name+newsletter', 'walla.co.il'],
35+
['user.name+work', 'walla.co.il', 'user.name+work', 'walla.co.il'],
36+
['user.name+personal', 'walla.co.il', 'user.name+personal', 'walla.co.il'],
37+
['user.name+test123', 'walla.co.il', 'user.name+test123', 'walla.co.il'],
38+
['user.name+anything', 'walla.co.il', 'user.name+anything', 'walla.co.il'],
39+
['user.name+verylongtag', 'walla.co.il', 'user.name+verylongtag', 'walla.co.il'],
40+
['user.name+tag.with.dots', 'walla.co.il', 'user.name+tag.with.dots', 'walla.co.il'],
41+
['user.name+tag-with-hyphens', 'walla.co.il', 'user.name+tag-with-hyphens', 'walla.co.il'],
42+
['user.name+tag_with_underscores', 'walla.co.il', 'user.name+tag_with_underscores', 'walla.co.il'],
43+
['user.name+tag123', 'walla.co.il', 'user.name+tag123', 'walla.co.il'],
44+
['u.s.e.r.n.a.m.e', 'walla.co.il', 'u.s.e.r.n.a.m.e', 'walla.co.il'],
45+
['u.s.e.r.n.a.m.e+tag', 'walla.co.il', 'u.s.e.r.n.a.m.e+tag', 'walla.co.il'],
46+
['user+', 'walla.co.il', 'user+', 'walla.co.il'],
47+
['user.', 'walla.co.il', 'user.', 'walla.co.il'],
48+
['.user', 'walla.co.il', '.user', 'walla.co.il'],
49+
['user..name', 'walla.co.il', 'user..name', 'walla.co.il'],
50+
// walla.com domain (should normalize to walla.co.il)
51+
['user.name+tag', 'walla.com', 'user.name+tag', 'walla.co.il'],
52+
['user.name+spam', 'walla.com', 'user.name+spam', 'walla.co.il'],
53+
['user.name', 'walla.com', 'user.name', 'walla.co.il'],
54+
['u.s.e.r.n.a.m.e', 'walla.com', 'u.s.e.r.n.a.m.e', 'walla.co.il'],
55+
['u.s.e.r.n.a.m.e+tag', 'walla.com', 'u.s.e.r.n.a.m.e+tag', 'walla.co.il'],
56+
];
57+
58+
foreach ($testCases as [$inputLocal, $inputDomain, $expectedLocal, $expectedDomain]) {
59+
$result = $this->provider->getCanonical($inputLocal, $inputDomain);
60+
$this->assertEquals($expectedLocal, $result['local'], "Failed for local: {$inputLocal}@{$inputDomain}");
61+
$this->assertEquals($expectedDomain, $result['domain'], "Failed for domain: {$inputLocal}@{$inputDomain}");
62+
}
63+
}
64+
65+
public function test_get_canonical_domain(): void
66+
{
67+
$this->assertEquals('walla.co.il', $this->provider->getCanonicalDomain());
68+
}
69+
70+
public function test_get_supported_domains(): void
71+
{
72+
$domains = $this->provider->getSupportedDomains();
73+
$this->assertEquals(['walla.co.il', 'walla.com'], $domains);
74+
}
75+
}

tests/EmailTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function test_valid_email(): void
2626
$this->assertEquals('company.org', $email->getProvider());
2727
$this->assertEquals('', $email->getSubdomain());
2828
$this->assertEquals(false, $email->hasSubdomain());
29-
$this->assertEquals('[email protected]', $email->getAddress());
29+
$this->assertEquals('[email protected]', $email->get());
3030
}
3131

3232
public function test_email_with_subdomain(): void
@@ -154,7 +154,6 @@ public function test_email_normalization(): void
154154
$email = new Email(' [email protected] ');
155155

156156
$this->assertEquals('[email protected]', $email->get());
157-
$this->assertEquals('[email protected]', $email->getAddress());
158157
}
159158

160159
public function test_invalid_email_empty(): void

0 commit comments

Comments
 (0)