Problem/Motivation

The core mail validator service directly uses \Egulias\MailValidator\MailValidator class, without enforcing a specific interface to generalize the behaviour of such a service.

If you want to replace that service, you don't have a reference interface, you have to make sure you match exactly what the original MailValidator exposed if you don't want to break code using the mail validator service.

Use case for replacing the service:

The e-mail validator service does not only check syntax but also that the domain exists. Yo can go a step further and also attempt delivery to see if the account effectively exists. I already have this in contrib email validator module, but it's prompt to break due to lack of contract through an interface.

Other issues:

Egulias EmailValidator has changed its interface in version 2. Proxying it would provide backward compatibility.

Proposed resolution

Introduce a new interface to define what the mail validator service should look like, and make a bridge class to the Egulias implementation that implements that interface.

Remaining tasks

Doit.

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

david_garcia created an issue. See original summary.

dawehner’s picture

Why do you need an alternative implementation in the first place? Aren't emails a standard so one reference implementation should be enough? I'm just trying to be curious here.

dawehner’s picture

The alternative way would be to add an interface upstream, any reason that we have to do that in Drupal itself?

cilefen’s picture

Why is this Major?

david_garcia’s picture

The e-mail validator service does not only check syntax but also that the domain exists. Yo can go a step further and also attempt delivery to see if the account effectively exists. I already have this in contrib email validator module, but it's prompt to break due to lack of contract through an interface.

cilefen’s picture

The e-mail validator service does not only check syntax but also that the domain exists.

No, it does not. DNS check is false by default.

This may help https://github.com/egulias/EmailValidator/pull/119

cilefen’s picture

cilefen’s picture

The EmailValidator 2.x interface breaks existing implementations which is a +1 for this issue.

cilefen’s picture

Also interesting is that Symfony maintains its own interface in the form of Symfony\Component\Validator\Constraints\EmailValidator (part of its family of validators), which Drupal uses in some situations and the email.validator service in others.

cilefen’s picture

cilefen’s picture

cilefen’s picture

Status: Active » Needs review
StatusFileSize
new2.22 KB

This should match the current core service.

Status: Needs review » Needs work

The last submitted patch, 12: email_validator_core-2749873-12.patch, failed testing.

cilefen’s picture

Status: Needs work » Needs review
StatusFileSize
new4.9 KB
new7.12 KB

Status: Needs review » Needs work

The last submitted patch, 14: email_validator_core-2749873-14.patch, failed testing.

The last submitted patch, 14: email_validator_core-2749873-14.patch, failed testing.

cilefen’s picture

Status: Needs work » Needs review

We are going to need something like this as a BC layer to move to 2.x of EmailValidator.

dawehner’s picture

  1. +++ b/core/lib/Drupal/Component/Utility/EmailValidator.php
    @@ -0,0 +1,36 @@
    +/**
    + * Validates email addresses.
    + */
    +class EmailValidator implements EmailValidatorInterface {
    

    What about using "Valides email addresses using the egulias\EmailValidator" library or something like that?

  2. +++ b/core/lib/Drupal/Component/Utility/EmailValidator.php
    @@ -0,0 +1,36 @@
    +   * @var EmailValidator
    ...
    +   * @param EmailValidatorUtility $emailValidator
    

    Let's use the FQCN

  3. +++ b/core/lib/Drupal/Component/Utility/EmailValidatorInterface.php
    @@ -0,0 +1,24 @@
    +/**
    + *
    + */
    

    Nitpick: Let's kill that, it is not longer needed.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

cilefen’s picture

Issue tags: +Needs reroll
markdorison’s picture

Issue tags: -Needs reroll
StatusFileSize
new7.39 KB

Patch re-rolled.

dawehner’s picture

Issue summary: View changes
cilefen’s picture

Issue summary: View changes
naveenvalecha’s picture

Status: Needs review » Needs work

Thanks great work!

  1. +++ b/core/lib/Drupal/Component/Utility/EmailValidatorInterface.php
    @@ -0,0 +1,24 @@
    +/**
    + *
    + */
    

    What this is for ? if not needed. remove it.

  2. +++ b/core/lib/Drupal/Component/Utility/EmailValidatorInterface.php
    @@ -0,0 +1,24 @@
    +   * Verifies the validity of the given email address.
    

    "Validates an email address."

mohit_aghera’s picture

Status: Needs work » Needs review
StatusFileSize
new7.48 KB

Updating patch as it was not getting applied to recent 8.3.x branch.
Fixing suggestions mentioned by @naveenvalecha

Status: Needs review » Needs work

The last submitted patch, 25: email_validator_core-2749873-25.patch, failed testing.

mohit_aghera’s picture

There are some random failures in ArgumentPlaceholderUpdatePathTest, which doesn't seems relevant to this patch.
Any help or suggestions are appreciated.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mohit_aghera’s picture

Status: Needs work » Needs review
StatusFileSize
new7.48 KB

Straight re-roll of previous patch.

naveenvalecha’s picture

Status: Needs review » Reviewed & tested by the community

Thanks!

catch’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs change record

The patch looks OK to me, but it needs a change record.

naveenvalecha’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs change record

Added draft CR https://www.drupal.org/node/2886353 .however, I felt that it needs more finishing before gets published. Back to RTBC.

//Naveen

dawehner’s picture

Won't this break now if anyone typehints the validator via the class? I fear what you want to do is this instead:

class EmailValidator extends OldEmailValidator implements EmailValidatorInterface {
}
tstoeckler’s picture

Status: Reviewed & tested by the community » Needs work

I think @dawehner is right, moving back to needs work.

cilefen’s picture

naveenvalecha’s picture

Assigned: Unassigned » naveenvalecha
Related issues: +#2755401: Upgrade EmailValidator to 2.x

@cilefen,
The current issue will open the way for #2755401: Upgrade EmailValidator to 2.x once the current issue will lands.

Assigned to me for #33
Question:
Do we require any empty hook_update_n or hook_post_update_name as we're adding a new service here?

//Naveen

cilefen’s picture

Will it? If memory serves, emailvalidator has a new interface.

naveenvalecha’s picture

Status: Needs work » Needs review
StatusFileSize
new7.22 KB
new7.7 KB
new1.96 KB
new1.48 KB

Attached two patches:

2749873-38.patch: This accommodated #33. As we're extending the OldEmailValidator so we don't need the isvalid function in the new service now, we could use the existing one.

2749873-38-2.patch: 2749873-38.patch + It includes an empty hook_update_n to ensure the container is actually rebuild.

Edit:
#37, Not sure about it, However, added two patches one with empty hook_update_n and other without it.
//Naveen

The last submitted patch, 38: 2749873-38.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 38: 2749873-38-2.patch, failed testing. View results

dawehner’s picture

+++ b/core/lib/Drupal/Component/Utility/EmailValidator.php
@@ -0,0 +1,29 @@
+   *
+   * @param EmailValidatorUtility $emailValidator
+   *   The email validator utility.
+   */
+  public function __construct(EmailValidatorUtility $emailValidator) {
+    $this->emailValidator = $emailValidator;
+  }

You miss the call to parent::__construct()

cilefen’s picture

Whatever we do here must be compatible with upgrading the library. And I'm not sure it's possible in a simple way. We may be forced to deprecate the current service and introduce a new one.

naveenvalecha’s picture

Status: Needs work » Needs review
StatusFileSize
new7.25 KB
new7.73 KB

#41,
Addressed.

#42,
you are right Chris, it does not look that we could upgrade without the BC break. I have updated the patch there with the interdiff from 2749873-43-2.patch

//Naveen

cilefen’s picture

I suggest we close this in favor of #2755401: Upgrade EmailValidator to 2.x.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

alexpott’s picture

Status: Needs review » Closed (duplicate)

@cilefen I agree... I'll add the people who worked on this to the credits on the other issue.