diff --git a/Tools/SOGoToolExpireAutoReply.m b/Tools/SOGoToolExpireAutoReply.m index 08ae18487..5e65e6a82 100644 --- a/Tools/SOGoToolExpireAutoReply.m +++ b/Tools/SOGoToolExpireAutoReply.m @@ -180,7 +180,7 @@ - (BOOL) run { - NSError *err; + NSData *credsData; NSRange r; NSString *creds, *credsFile, *authname, *authpwd; BOOL rc; @@ -195,15 +195,17 @@ credsFile = [[NSUserDefaults standardUserDefaults] stringForKey: @"p"]; if (credsFile) { - creds = [NSString stringWithContentsOfFile: credsFile - encoding: NSUTF8StringEncoding - error: &err]; - if (!creds) + credsData = [NSData dataWithContentsOfFile: credsFile]; + if (credsData == nil) { - NSLog(@"Error reading credential file '%@': %@", credsFile, err); + NSLog(@"Error reading credential file '%@'", credsFile); + return NO; } - creds = [creds stringByTrimmingCharactersInSet: - [NSCharacterSet newlineCharacterSet]]; + creds = [[NSString alloc] initWithData: credsData + encoding: NSUTF8StringEncoding]; + [creds autorelease]; + creds = [creds stringByTrimmingCharactersInSet: + [NSCharacterSet characterSetWithCharactersInString: @"\r\n"]]; } if (max > 0) diff --git a/Tools/SOGoToolUserPreferences.m b/Tools/SOGoToolUserPreferences.m index 7f5c6d99b..39118e777 100644 --- a/Tools/SOGoToolUserPreferences.m +++ b/Tools/SOGoToolUserPreferences.m @@ -109,25 +109,30 @@ typedef enum [theKey caseInsensitiveCompare: @"Vacation"] == NSOrderedSame) { /* credentials file handling */ + NSData *credsData; NSRange r; NSString *credsFile, *creds, *authname, *authpwd; authname = nil; authpwd = nil; + credsFile = [[NSUserDefaults standardUserDefaults] stringForKey: @"p"]; if (credsFile) { /* TODO: add back support for user:pwd here? */ - creds = [NSString stringWithContentsOfFile: credsFile - encoding: NSUTF8StringEncoding - error: NULL]; - if (creds == nil) + credsData = [NSData dataWithContentsOfFile: credsFile]; + if (credsData == nil) { NSLog(@"Error reading credential file '%@'", credsFile); return NO; } - creds = [creds stringByTrimmingCharactersInSet: - [NSCharacterSet newlineCharacterSet]]; + + creds = [[NSString alloc] initWithData: credsData + encoding: NSUTF8StringEncoding]; + [creds autorelease]; + creds = [creds stringByTrimmingCharactersInSet: + [NSCharacterSet characterSetWithCharactersInString: @"\r\n"]]; + r = [creds rangeOfString: @":"]; authname = [creds substringToIndex: r.location]; authpwd = [creds substringFromIndex: r.location+1];