Created
July 11, 2012 14:04
-
-
Save pjbeardsley/3090564 to your computer and use it in GitHub Desktop.
fEmail.php.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: fEmail.php | |
=================================================================== | |
--- fEmail.php (revision 71) | |
+++ fEmail.php (working copy) | |
@@ -12,12 +12,15 @@ | |
* @copyright Copyright (c) 2008-2011 Will Bond, others | |
* @author Will Bond [wb] <will@flourishlib.com> | |
* @author Bill Bushee, iMarc LLC [bb-imarc] <bill@imarc.net> | |
* @author netcarver [n] <fContrib@netcarving.com> | |
* @license http://flourishlib.com/license | |
* | |
* @package Flourish | |
* @link http://flourishlib.com/fEmail | |
* | |
- * @version 1.0.0b30 | |
+ * @version 1.0.0b31 | |
+ * @changes 1.0.0b31 Updated the email regexes to be more strict with domain names and follow RFC 5322 instead of RFC 822 [wb, 2011-10-13] | |
* @changes 1.0.0b30 Changed methods to return instance for method chaining [n, 2011-09-12] | |
* @changes 1.0.0b29 Changed ::combineNameEmail() to be a static method and to be exposed publicly for use by other classes [wb, 2011-07-26] | |
* @changes 1.0.0b28 Fixed ::addAttachment() and ::addRelatedFile() to properly handle duplicate filenames [wb, 2011-05-17] | |
* @changes 1.0.0b27 Fixed a bug with generating FQDNs on some Windows machines [wb, 2011-02-24] | |
@@ -69,13 +72,38 @@ | |
* | |
* @var string | |
*/ | |
- const EMAIL_REGEX = '~^[ \t]*( # Allow leading whitespace | |
- (?:[^\x00-\x20\(\)<>@,;:\\\\"\.\[\]]+|"[^"\\\\\n\r]+") # An "atom" or a quoted string | |
- (?:\.[ \t]*(?:[^\x00-\x20\(\)<>@,;:\\\\"\.\[\]]+|"[^"\\\\\n\r]+"[ \t]*))* # A . plus another "atom" or a quoted string, any number of times | |
- )@( # The @ symbol | |
- (?:[a-z0-9\\-]+\.)+[a-z]{2,}| # Domain name | |
- \[(?:(?:[01]?\d?\d|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d?\d|2[0-4]\d|25[0-5])\] # (or) IP addresses | |
- )[ \t]*$~ixD'; # Allow Trailing whitespace | |
+ const EMAIL_REGEX = '~^[ \t]*(?: # Allow leading whitespace | |
+ (?=.{6,254}$) # limit total length to 254 characters | |
+ ((?=.{1,64}@(?!.*@)) # limit local part before @ to 64 characters | |
+ (?: | |
+ (?: # atom | |
+ (?:(?<!^|[ \t])\.)? # dot before subsequent atoms | |
+ (?> | |
+ [^\x00-\x20\x7F-\xFF()<>@,;:\\\\"\.[\]]+| # non-specials | |
+ \\\\[^\x00-\x1F\x7F-\xFF\n\r"] # backslash with following character | |
+ )+ | |
+ )* | |
+ | | |
+ "(?> # quoted string | |
+ [^\x00-\x1F\x7F-\xFF\\\\"\n\r]+| | |
+ \\\\[^\x00-\x1F\x7F-\xFF\n\r] | |
+ )+" | |
+ ) | |
+ )@( # The @ symbol | |
+ (?: # domain name | |
+ (?=.{3,252}$) # domain name length limit | |
+ [a-z0-9](?:[a-z0-9\\-]{0,61}[a-z0-9])?\.)+ # parts | |
+ [a-z](?:[a-z]+|[a-z]*-+[a-z0-9]+ # tld, optionally with punycode | |
+ ) | |
+ | | |
+ \[(?!\.) # bracketed IP address | |
+ (?: | |
+ \.? # dot before 2-4th numbers | |
+ (?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5]) # 0-255 | |
+ ){4} | |
+ \] | |
+ ) | |
+ )[ \t]*$~ixD'; # Allow Trailing whitespace | |
/** | |
* A regular expression to match a `name <email>` string, exluding those with comments and folding whitespace | |
@@ -90,16 +118,57 @@ | |
* | |
* @var string | |
*/ | |
- const NAME_EMAIL_REGEX = '~^[ \t]*( # Allow leading whitespace | |
- (?:[^\x00-\x20\(\)<>@,;:\\\\"\.\[\]]+[ \t]*|"[^"\\\\\n\r]+"[ \t]*) # An "atom" or a quoted string | |
- (?:\.?[ \t]*(?:[^\x00-\x20\(\)<>@,;:\\\\"\.\[\]]+[ \t]*|"[^"\\\\\n\r]+"[ \t]*))*) # Another "atom" or a quoted string or a . followed by one of those, any number of times | |
- [ \t]*<[ \t]*(( # The < encapsulating the email address | |
- (?:[^\x00-\x20\(\)<>@,;:\\\\"\.\[\]]+|"[^"\\\\\n\r]+") # An "atom" or a quoted string | |
- (?:\.[ \t]*(?:[^\x00-\x20\(\)<>@,;:\\\\"\.\[\]]+|"[^"\\\\\n\r]+"[ \t]*))* # A . plus another "atom" or a quoted string, any number of times | |
- )@( # The @ symbol | |
- (?:[a-z0-9\\-]+\.)+[a-z]{2,}| # Domain nam | |
- \[(?:(?:[01]?\d?\d|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d?\d|2[0-4]\d|25[0-5])\] # (or) IP addresses | |
- ))[ \t]*>[ \t]*$~ixD'; # Closing > and trailing whitespace | |
+ const NAME_EMAIL_REGEX = '~^[ \t]*( # Allow leading whitespace | |
+ (?: # An atom or a quoted string | |
+ [ \t]*\.?[ \t]* # the . from obs-phrase (RFC 5322) for a more robust parsing | |
+ (?: | |
+ (?> # atom | |
+ [^\x00-\x1F\x7F()<>@,;:\\\\"\.[\]]+| # non-specials | |
+ \\\\[^\x00-\x1F\x7F\n\r"] # backslash with following character | |
+ )+ | |
+ | | |
+ "(?> # quoted string | |
+ [^\\\\"\n\r]+| | |
+ \\\\[^\x00-\x1F\x7F\n\r] | |
+ )+" | |
+ ) | |
+ [ \t]*\.?[ \t]* # the . from obs-phrase | |
+ )* | |
+ ) | |
+ [ \t]*<[ \t]* # Opening < | |
+ ( | |
+ (?=.{6,254}[ t]*>(?!.*>)) # limit total length to 254 characters | |
+ ((?=.{1,64}@(?!.*@)) # limit local part before @ to 64 characters | |
+ (?: | |
+ (?: # atom | |
+ (?:(?<!<|[ \t])\.)? # dot before subsequent atoms | |
+ (?> | |
+ [^\x00-\x20\x7F-\xFF()<>@,;:\\\\"\.[\]]+| # non-specials | |
+ \\\\[^\x00-\x1F\x7F-\xFF\n\r"] # backslash with following character | |
+ )+ | |
+ )* | |
+ | | |
+ "(?> # quoted string | |
+ [^\x00-\x1F\x7F-\xFF\\\\"\n\r]+| | |
+ \\\\[^\x00-\x1F\x7F-\xFF\n\r] | |
+ )+" | |
+ ) | |
+ )@( # The @ symbol | |
+ (?: # domain name | |
+ (?=.{3,252}$) # domain name length limit | |
+ [a-z0-9](?:[a-z0-9\\-]{0,61}[a-z0-9])?\.)+ # parts | |
+ [a-z](?:[a-z]+|[a-z]*-+[a-z0-9]+ # tld, optionally with punycode | |
+ ) | |
+ | | |
+ \[(?!\.) # bracketed IP address | |
+ (?: | |
+ \.? # dot before 2-4th numbers | |
+ (?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5]) # 0-255 | |
+ ){4} | |
+ \] | |
+ ) | |
+ ) | |
+ [ \t]*>[ \t]*$~ixD'; # Closing > and trailing whitespace | |
/** |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment