Permalink
Browse files

Merge branch 'sandvox-2.6.6'

  • Loading branch information...
2 parents 3eec08d + f3ba44b commit 32d10fd995ee3780589604ad858bfdc3616f5914 @mikeabdullah mikeabdullah committed Aug 29, 2012
Showing with 19 additions and 1 deletion.
  1. +1 −0 KSURLFormatter.h
  2. +18 −1 KSURLFormatter.m
View
@@ -49,6 +49,7 @@
+ (NSURL *)URLFromString:(NSString *)string;
+ (BOOL)isValidEmailAddress:(NSString *)address;
++ (BOOL)isLikelyEmailAddress:(NSString *)address; // much the same as above, but ignores some rarities
#pragma mark Managing Behavior
View
@@ -76,6 +76,23 @@ + (BOOL)isValidEmailAddress:(NSString *)address;
return OK;
}
++ (BOOL)isLikelyEmailAddress:(NSString *)address;
+{
+ BOOL result = [self isValidEmailAddress:address];
+ if (result)
+ {
+ NSURL *URL = [[NSURL alloc] initWithString:address];
+ if (URL)
+ {
+ // Account for strings like http://example.com/@foo which seem to be technically valid as an email address, but unlikely to be one
+ if ([URL scheme]) result = NO;
+ [URL release];
+ }
+ }
+
+ return result;
+}
+
#pragma mark Init & Dealloc
- (id)init
@@ -163,7 +180,7 @@ + (NSURL *)URLFromString:(NSString *)string defaultScheme:(NSString *)fallbackSc
(![result host])) // e.g. foo.com:8888
{
// if it looks like an email address, use mailto:
- if ([self isValidEmailAddress:string])
+ if ([self isLikelyEmailAddress:string])
{
result = [NSURL URLWithString:[NSString stringWithFormat:@"mailto:%@", string]];
}

0 comments on commit 32d10fd

Please sign in to comment.