File size: 701 Bytes
d2897cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php

namespace Mautic\CoreBundle\Helper;

class EmailAddressHelper
{
    /**
     * Clean the email for comparison.
     *
     * @param string $email
     */
    public function cleanEmail($email): string
    {
        return strtolower(preg_replace("/[^a-z0-9\+\.@]/i", '', $email));
    }

    /**
     * @return array<string>
     */
    public function getVariations(string $email): array
    {
        $emails = [$email, $this->cleanEmail($email)];
        // email without suffix
        preg_match('#^(.*?)\+(.*?)@(.*?)$#', $email, $parts);
        if (!empty($parts)) {
            $emails[] = $parts[1].'@'.$parts[3];
        }

        return array_values(array_unique($emails));
    }
}