From d66be7a76410f30a4509ab154a5e1610dd9dd6ba Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Thu, 13 Dec 2007 00:00:55 +0000 Subject: [PATCH] Monotone-Parent: 138d10664c297f2945644209ec2c4b488844af1b Monotone-Revision: 680b3d6bcb1de20bb28768ebf727ed9053b9e2a0 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2007-12-13T00:00:55 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 4 ++++ SoObjects/SOGo/NSString+Utilities.m | 22 ++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5d5854f00..c0cf8e7b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2007-12-12 Wolfgang Sourdeau + * SoObjects/SOGo/NSString+Utilities.m ([NSString + -stringByDetectingURLs]): we now go back until the real start of + the found url. + * SoObjects/Mailer/SOGoMailObject.m ([SOGoMailObject -fetchAttachmentIds]): new method that wanders through the mail structure to collect the attachment content ids and to associate diff --git a/SoObjects/SOGo/NSString+Utilities.m b/SoObjects/SOGo/NSString+Utilities.m index 1192ccd70..ff0c38d03 100644 --- a/SoObjects/SOGo/NSString+Utilities.m +++ b/SoObjects/SOGo/NSString+Utilities.m @@ -33,6 +33,7 @@ static NSMutableCharacterSet *urlNonEndingChars = nil; static NSMutableCharacterSet *urlAfterEndingChars = nil; +static NSMutableCharacterSet *urlStartChars = nil; @implementation NSString (SOGoURLExtension) @@ -150,12 +151,12 @@ static NSMutableCharacterSet *urlAfterEndingChars = nil; if (!urlNonEndingChars) { urlNonEndingChars = [NSMutableCharacterSet new]; - [urlNonEndingChars addCharactersInString: @">=,.:;\t \r\n"]; + [urlNonEndingChars addCharactersInString: @"=,.:;\t \r\n"]; } if (!urlAfterEndingChars) { urlAfterEndingChars = [NSMutableCharacterSet new]; - [urlAfterEndingChars addCharactersInString: @"[]\t \r\n"]; + [urlAfterEndingChars addCharactersInString: @"&;[]\t \r\n"]; } start = refRange.location; @@ -187,9 +188,26 @@ static NSMutableCharacterSet *urlAfterEndingChars = nil; NSRange httpRange, currentURL, rest; NSString *urlText, *newUrlText; unsigned int length, matchLength; + int startLocation; + if (!urlStartChars) + { + urlStartChars = [NSMutableCharacterSet new]; + [urlStartChars addCharactersInString: @"abcdefghijklmnopqrstuvwxyz" + @"ABCDEFGHIJKLMNOPQRSTUVWXYZ" + @"0123456789:@"]; + } matchLength = [match length]; httpRange = [selfCopy rangeOfString: match]; + if (httpRange.location != NSNotFound) + { + startLocation = httpRange.location; + while (startLocation > -1 + && [urlStartChars characterIsMember: + [selfCopy characterAtIndex: startLocation]]) + startLocation--; + httpRange.location = startLocation + 1; + } while (httpRange.location != NSNotFound) { if ([ranges hasRangeIntersection: httpRange])