<?php

namespace App\Support;

class DisposableEmails
{
    /**
     * Common disposable/temporary email providers. Admins can extend this
     * via the protection_disposable_email_domains site setting.
     */
    private const DOMAINS = [
        '10minutemail.com', '10minutemail.net', '20minutemail.com', '33mail.com',
        'anonbox.net', 'anonymbox.com', 'bccto.me', 'boun.cr', 'burnermail.io',
        'byom.de', 'chacuo.net', 'correotemporal.org', 'crazymailing.com',
        'deadaddress.com', 'discard.email', 'discardmail.com', 'dispostable.com',
        'dropmail.me', 'emailondeck.com', 'emailfake.com', 'emailtemporanea.net',
        'ethereal.email', 'fakeinbox.com', 'fakemail.net', 'fakemailgenerator.com',
        'getairmail.com', 'getnada.com', 'guerrillamail.biz', 'guerrillamail.com',
        'guerrillamail.de', 'guerrillamail.info', 'guerrillamail.net', 'guerrillamail.org',
        'harakirimail.com', 'inboxbear.com', 'inboxkitten.com', 'incognitomail.org',
        'jetable.org', 'kleemail.com', 'linshiyouxiang.net', 'mail-temp.com',
        'mail.tm', 'mail1a.de', 'mail7.io', 'mailcatch.com', 'maildrop.cc',
        'mailexpire.com', 'mailinator.com', 'mailinator.net', 'mailnesia.com',
        'mailpoof.com', 'mailsac.com', 'mailtemp.uk', 'mintemail.com', 'moakt.com',
        'mohmal.com', 'mytemp.email', 'nada.email', 'no-spam.ws', 'nospam.today',
        'owlymail.com', 'protonmail.com.invalid', 'sharklasers.com', 'spam4.me',
        'spamgourmet.com', 'spambog.com', 'spambox.us', 'tempail.com', 'temp-mail.io',
        'temp-mail.org', 'tempinbox.com', 'tempmail.com', 'tempmail.dev',
        'tempmail.net', 'tempmail.plus', 'tempmailo.com', 'tempr.email',
        'throwawaymail.com', 'tmail.ws', 'tmpmail.net', 'tmpmail.org',
        'trash-mail.com', 'trashmail.com', 'trashmail.de', 'trashmail.me',
        'wegwerfmail.de', 'yepmail.net', 'yopmail.com', 'yopmail.fr', 'yopmail.net',
        'zmail.ru',
    ];

    public static function isDisposable(string $email): bool
    {
        $domain = strtolower(substr(strrchr($email, '@') ?: '', 1));

        if ($domain === '') {
            return false;
        }

        $extra = site_list('protection_disposable_email_domains');

        return in_array($domain, self::DOMAINS, true) || in_array($domain, $extra, true);
    }
}
