Skip to content
This repository has been archived by the owner on Nov 17, 2021. It is now read-only.

How to configure email validation #999

Closed
madflow opened this issue Sep 8, 2017 · 4 comments
Closed

How to configure email validation #999

madflow opened this issue Sep 8, 2017 · 4 comments

Comments

@madflow
Copy link

madflow commented Sep 8, 2017

According to the closed issue #382 it is now possible to configure the email adress ("to" part) validation. However I fail how to do that.

As far as I can see the validation is hardcoded here:

   //Swift_Mime_Headers_MailboxHeader::344
    /**
     * Throws an Exception if the address passed does not comply with RFC 2822.
     *
     * @param string $address
     *
     * @throws Swift_RfcComplianceException If invalid.
     */
    private function assertValidAddress($address)
    {
        if (!$this->emailValidator->isValid($address, new RFCValidation())) {
            throw new Swift_RfcComplianceException(
                'Address in mailbox given ['.$address.'] does not comply with RFC 2822, 3.6.2.'
            );
        }
    }

Am I missing something? I understand I can change the validator class by replacing it in the dependency injection - but I do not get how I could configure the validation when doing this.

@marden
Copy link

marden commented Sep 21, 2017

The same for me. I don't see the way how to configure the validation.

@stayallive
Copy link

Same here... this does not seem to be very configurable at all right now?

@madflow
Copy link
Author

madflow commented Oct 7, 2017

I did a little more searching in the code base: I believe it is save to say that the email validation cannot be extended ("configured") like the author of the library intended: https://github.com/egulias/EmailValidator#how-to-extend

What you can do is something like this:

class MyValidator extends \Egulias\EmailValidator\EmailValidator
{
    public function isValid($email, \Egulias\EmailValidator\Validation\EmailValidation $emailValidation)
    {
       // Ommit the second parameter $emailValidation and do some other magic
        return true;
    }
}

Swift_DependencyContainer::getInstance()
    ->register('email.validator')
    ->asSharedInstanceOf('MyValidator');

I would argue that not the "EmailValidator" but the "EmailValidation" should have been incorporated in the dependency map and the assertValid* methods.

I tinkered with this in my fork https://github.com/madflow/swiftmailer/tree/email_validation and introduced the EmailValidation in the dependency map. Not sure if a PR will make sense.

@aquibbaig
Copy link

I want to fetch the email from swiftmailer username from the yaml file using ContainerInterface and set it inside setFrom(). Please share some insight on why getParameter echos the email address but value passed in setFrom() is [*\id]. So, I see an R.F.C error

@fabpot fabpot closed this as completed Nov 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants