Page 1 of 1

Email validation regular expression

Posted: Mon Dec 29, 2008 12:19 am
by ganchiku
Hello,

I was developing a web site to send email to Japanese mobile phone user. Because of their selfish discipline, the major two mobile service phone companies do not follow RFC.
They accept ridiculous addresses such as:
foobar..@example.com

and some of our users have such addresses. :(

This is big trouble for developers in Japan, because web service for mobile phone users is big market.
If I passed the above address to send method of swift class, it throws exception that explain the address is wrong. I know it is wrong, but I have to send to the address anyhow.
To avoid this problem, one of our solution is doublequotating the wrong dot-atom part as follows:
"foobar.."@example.com

If I could do this, I can send the mail to the address and the rule follows RFC.
So, I wonder if developers of Swift Mailer can fix the Swift_Message_Encoder::CHEAP_ADDRESS_RE value as:

const CHEAP_ADDRESS_RE = '(?:[^(\040)<>@,;:".\\\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\\\[\]\000-\037\x80-\xff])|"[^\\\\\x80-\xff\n\015"]*(?:\\\\[^\x80-\xff][^\\\\\x80-\xff\n\015"]*)*")(?:\.(?:[^(\040)<>@,;:".\\\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\\\[\]\000-\037\x80-\xff])|"[^\\\\\x80-\xff\n\015"]*(?:\\\\[^\x80-\xff][^\\\\\x80-\xff\n\015"]*)*"))*@(?:[^(\040)<>@,;:".\\\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\\\x80-\xff\n\015\[\]]|\\\\[^\x80-\xff])*\])(?:\.(?:[^(\040)<>@,;:".\\\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\\\x80-\xff\n\015\[\]]|\\\\[^\x80-\xff])*\]))*'

Because symfony is good combination with Swift Mailer, I would like to use Swift, but with rejecting some mail address as I showed above, many developers in Japan have to give up using Swift Mailer.

Thanks,
Shin

Re: Email validation regular expression

Posted: Wed Jan 07, 2009 7:34 pm
by ganchiku
I solved this problem.

I was passing $recipients parameter as string, so there was validator, but when I passed an object of Swift_RecipientList, it works!

Because Swift_Recipients class is a subclass of Swift_AddressContainer, it go through the email validation! Well, I don't know if this is right solution, but as long as it works, I',m happy.

Thank you for your time.

Shin

Re: Email validation regular expression

Posted: Thu Jan 08, 2009 11:06 pm
by Chris Corbyn
The whole way recipients are specified has been greatly improved in version 4. Feel free to check out the beta (linked to in an announcement at the top this sub-forum).