Your class stays in conflict with the Single Responsibility P...

Recommend this page to a friend!

      PHP Email validation  >  All threads  >  Your class stays in conflict with...  >  (Un) Subscribe thread alerts  
Subject:Your class stays in conflict with...
Summary:Package rating comment
Messages:7
Author:Matthias Kaschubowski
Date:2016-04-24 13:44:01
 

Matthias Kaschubowski rated this package as follows:

Utility: Not sure
Consistency: Not sure
Examples: Good

  1. Your class stays in conflict with...   Reply   Report abuse  
Picture of Matthias Kaschubowski Matthias Kaschubowski - 2016-04-24 13:44:01
Your class stays in conflict with the Single Responsibility Principle. It also prevents IDN-domains from being validated. So, your class will automatically invalidate many many valid email addresses.

I recommend to use filter_var and a IDN transport for email validation.

  2. Re: Your class stays in conflict with...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2016-04-24 20:18:55 - In reply to message 1 from Matthias Kaschubowski
The purpose of the class is to perform several levels of email validation. I believe it is still a single responsibility.

As for IDN I have not came across one example. Can you provide an example?

I suspect that is a matter of adjusting the validation regular expression, which is a class configuration parameter.

  3. Re: Your class stays in conflict with...   Reply   Report abuse  
Picture of Matthias Kaschubowski Matthias Kaschubowski - 2016-04-24 22:18:26 - In reply to message 2 from Manuel Lemos
foobar@müller.de ( as an example )

en.wikipedia.org/wiki/International ...

  4. Re: Your class stays in conflict with...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2016-05-03 22:38:36 - In reply to message 3 from Matthias Kaschubowski
I tested here with Thunderbird and it seems email addresses like that need to be encoded as UTF-8, so the regular expression would validate it if I included higher 8 bit characters.

  5. Re: Your class stays in conflict with...   Reply   Report abuse  
Picture of Ian Ian - 2017-12-28 15:07:25 - In reply to message 4 from Manuel Lemos
No, they need to be encoded as ascii.

See http://php.net/manual/en/function.idn-to-ascii.php

Unfortunately, idn-to-ascii does not exist in most typical PHP installs so you'll want to provide a class like you do with getmxrr.

  6. Re: Your class stays in conflict with...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2017-12-28 21:24:44 - In reply to message 5 from Ian
I am not sure what you mean? Do you mean the class validate addresses with unicode characters? Can you give me an example?

  7. Re: Your class stays in conflict with...   Reply   Report abuse  
Picture of Ian Ian - 2017-12-28 23:37:03 - In reply to message 6 from Manuel Lemos
Sure, take example of teßt@düsseldorf.de

It will not pass your regex and getmxrr will not work with "düsseldorf.de." (note good practise to use final dot for fqdn)

You can change your regex to allow it, but getmxrr will still fail.

You must convert to Punycode representation in ASCII:

teßt@düsseldorf.de -> xn--tet-6ka@xn--dsseldorf-q9a.de

Now "xn--tet-6ka@xn--dsseldorf-q9a.de" will pass the unmodified regex and it will work correctly with getmxrr.

I tested all of this :-)

The issue, as I mentioned, is how best to do the conversion when function_exists('idn_to_ascii') fails on most systems. This will do it:

github.com/phpWhois/idna-convert

$IDNversion=2008;
$IDN=new idna_convert(array('idn_version'=>$IDNversion));
$ascii=$IDN->encode($fqdn);

 

For more information send a message to info at phpclasses dot org.