From 87a3d613b36e0e4f0500afb80dcff39b0d2e8ff5 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Tue, 10 Jul 2007 19:23:39 +0000 Subject: [PATCH] Monotone-Parent: 066bfc11f82275269e5bf2cc1cbbf0e9427e8d96 Monotone-Revision: 716ad11e755f3a78bb0353df886cf08096149a36 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2007-07-10T19:23:39 Monotone-Branch: ca.inverse.sogo --- SoObjects/Mailer/SOGoMailAccount.m | 60 +++++++++------------------ SoObjects/Mailer/SOGoMailBaseObject.m | 27 ++++++------ SoObjects/Mailer/SOGoMailFolder.m | 16 ++++--- SoObjects/Mailer/SOGoMailObject.h | 2 +- SoObjects/Mailer/SOGoMailObject.m | 57 +++++++++++++++---------- 5 files changed, 80 insertions(+), 82 deletions(-) diff --git a/SoObjects/Mailer/SOGoMailAccount.m b/SoObjects/Mailer/SOGoMailAccount.m index 56f00e441..b82b1451b 100644 --- a/SoObjects/Mailer/SOGoMailAccount.m +++ b/SoObjects/Mailer/SOGoMailAccount.m @@ -175,49 +175,29 @@ static BOOL useAltNamespace = NO; return [creds objectAtIndex:0]; /* the user */ } -- (NSString *)imap4URLString { - /* private, overridden by SOGoSharedMailAccount */ - NSString *s; - NSRange r; - - s = [self nameInContainer]; - r = [s rangeOfString:@"@"]; - if (r.length == 0) { - NSString *u; - - u = [self imap4LoginFromHTTP]; - if ([u length] == 0) { - [self errorWithFormat:@"missing login in account folder name: %@", s]; - return nil; - } - s = [[u stringByAppendingString:@"@"] stringByAppendingString:s]; - } - if ([s hasSuffix:@":80"]) { // HACK - [self logWithFormat:@"WARNING: incorrect value for IMAP4 URL: '%@'", s]; - s = [s substringToIndex:([s length] - 3)]; - } - - s = [([self useSSL] ? @"imaps://" : @"imap://") stringByAppendingString:s]; - s = [s stringByAppendingString:@"/"]; - return s; -} - -- (NSURL *) imap4URL +- (NSMutableString *) imap4URLString { - /* imap://agenortest@mail.opengroupware.org/ */ - NSString *s; - - if (!imap4URL) - { - s = [self imap4URLString]; - if (s) - imap4URL = [[NSURL alloc] initWithString: s]; - } - - return imap4URL; + /* private, overridden by SOGoSharedMailAccount */ + NSMutableString *urlString; + NSString *host; + + urlString = [NSMutableString string]; + + if ([self useSSL]) + [urlString appendString: @"imaps://"]; + else + [urlString appendString: @"imap://"]; + + host = [self nameInContainer]; + if (![host rangeOfString: @"@"].length) + [urlString appendFormat: @"%@@", [self imap4LoginFromHTTP]]; + [urlString appendFormat: @"%@/", host]; + + return urlString; } -- (NSString *)imap4Login { +- (NSString *) imap4Login +{ return [[self imap4URL] user]; } diff --git a/SoObjects/Mailer/SOGoMailBaseObject.m b/SoObjects/Mailer/SOGoMailBaseObject.m index 5d292cc77..4ba1c62ca 100644 --- a/SoObjects/Mailer/SOGoMailBaseObject.m +++ b/SoObjects/Mailer/SOGoMailBaseObject.m @@ -139,24 +139,23 @@ static BOOL debugOn = YES; return url; } +- (NSMutableString *) imap4URLString +{ + NSMutableString *urlString; + + urlString = [container imap4URLString]; + [urlString appendFormat: @"%@/", [nameInContainer stringByEscapingURL]]; + + return urlString; +} + - (NSURL *) imap4URL { - NSString *thisName, *urlFormat, *urlString; - + /* this could probably be handled better from NSURL but it's buggy in + GNUstep */ if (!imap4URL) { - /* this could probably be handled better from NSURL but it's buggy in - GNUstep */ - urlString = [[container imap4URL] absoluteString]; - thisName = [[self relativeImap4Name] stringByEscapingURL]; - if ([urlString hasSuffix: @"/"]) - urlFormat = @"%@%@"; - else - urlFormat = @"%@/%@"; - imap4URL = [[NSURL alloc] - initWithString: [NSString stringWithFormat: urlFormat, - urlString, - thisName]]; + imap4URL = [[NSURL alloc] initWithString: [self imap4URLString]]; } return imap4URL; diff --git a/SoObjects/Mailer/SOGoMailFolder.m b/SoObjects/Mailer/SOGoMailFolder.m index 71a35d05d..ab951bda1 100644 --- a/SoObjects/Mailer/SOGoMailFolder.m +++ b/SoObjects/Mailer/SOGoMailFolder.m @@ -260,10 +260,12 @@ static BOOL useAltNamespace = NO; /* check whether URL exists */ sf = [self imap4URL]; - sf = [NSURL URLWithString:[[sf path] stringByAppendingPathComponent:_key] - relativeToURL:sf]; + sf = [NSURL URLWithString: _key relativeToURL: sf]; + +// - sf = [NSURL URLWithString:[[sf path] stringByAppendingPathComponent:_key] +// - relativeToURL:sf]; - if (![[self imap4Connection] doesMailboxExistAtURL:sf]) { + if (![[self imap4Connection] doesMailboxExistAtURL: sf]) { /* We may not return 404, confuses path traversal - but we still do in the calling method. Probably the traversal process should be fixed to @@ -351,9 +353,11 @@ static BOOL useAltNamespace = NO; /* build IMAP4 URL for target */ destImapURL = [_target imap4URL]; - destImapURL = [NSURL URLWithString:[[destImapURL path] - stringByAppendingPathComponent:_name] - relativeToURL:destImapURL]; +// - destImapURL = [NSURL URLWithString:[[destImapURL path] +// - stringByAppendingPathComponent:_name] +// - relativeToURL:destImapURL]; + destImapURL = [NSURL URLWithString: _name + relativeToURL: destImapURL]; [self logWithFormat:@"TODO: should move collection as '%@' to: %@", [[self imap4URL] absoluteString], diff --git a/SoObjects/Mailer/SOGoMailObject.h b/SoObjects/Mailer/SOGoMailObject.h index 7e46daadd..72dae3885 100644 --- a/SoObjects/Mailer/SOGoMailObject.h +++ b/SoObjects/Mailer/SOGoMailObject.h @@ -22,7 +22,7 @@ #ifndef __Mailer_SOGoMailObject_H__ #define __Mailer_SOGoMailObject_H__ -#include +#import /* SOGoMailObject diff --git a/SoObjects/Mailer/SOGoMailObject.m b/SoObjects/Mailer/SOGoMailObject.m index e8a72944b..db704eb93 100644 --- a/SoObjects/Mailer/SOGoMailObject.m +++ b/SoObjects/Mailer/SOGoMailObject.m @@ -36,6 +36,7 @@ #import #import #import +#import #import #import #import @@ -100,16 +101,27 @@ static BOOL debugSoParts = NO; } - (void)dealloc { - [self->headers release]; - [self->headerPart release]; - [self->coreInfos release]; + [headers release]; + [headerPart release]; + [coreInfos release]; [super dealloc]; } /* IMAP4 */ -- (NSString *)relativeImap4Name { - return [[self nameInContainer] stringByDeletingPathExtension]; +- (NSString *) relativeImap4Name +{ + return [nameInContainer stringByDeletingPathExtension]; +} + +- (NSMutableString *) imap4URLString +{ + NSMutableString *urlString; + + urlString = [container imap4URLString]; + [urlString appendFormat: @"%@", [nameInContainer stringByEscapingURL]]; + + return urlString; } /* hierarchy */ @@ -200,8 +212,8 @@ static BOOL debugSoParts = NO; static NSArray *existsKey = nil; id msgs; - if (self->coreInfos != nil) /* if we have coreinfos, we can use them */ - return [self->coreInfos isNotNull]; + if (coreInfos != nil) /* if we have coreinfos, we can use them */ + return [coreInfos isNotNull]; /* otherwise fetch something really simple */ @@ -216,8 +228,8 @@ static BOOL debugSoParts = NO; - (id)fetchCoreInfos { id msgs; - if (self->coreInfos != nil) - return [self->coreInfos isNotNull] ? self->coreInfos : nil; + if (coreInfos != nil) + return [coreInfos isNotNull] ? coreInfos : nil; #if 0 // TODO: old code, why was it using clientObject?? msgs = [[self clientObject] fetchParts:coreInfoKeys]; // returns dict @@ -229,8 +241,8 @@ static BOOL debugSoParts = NO; if ([msgs count] == 0) return nil; - self->coreInfos = [[msgs objectAtIndex:0] retain]; - return self->coreInfos; + coreInfos = [[msgs objectAtIndex:0] retain]; + return coreInfos; } - (id)bodyStructure { @@ -284,27 +296,30 @@ static BOOL debugSoParts = NO; NGMimeMessageParser *parser; NSData *data; - if (self->headerPart != nil) - return [self->headerPart isNotNull] ? self->headerPart : nil; + if (headerPart != nil) + return [headerPart isNotNull] ? headerPart : nil; if ([(data = [self mailHeaderData]) length] == 0) return nil; // TODO: do we need to set some delegate method which stops parsing the body? parser = [[NGMimeMessageParser alloc] init]; - self->headerPart = [[parser parsePartFromData:data] retain]; + headerPart = [[parser parsePartFromData:data] retain]; [parser release]; parser = nil; - if (self->headerPart == nil) { - self->headerPart = [[NSNull null] retain]; + if (headerPart == nil) { + headerPart = [[NSNull null] retain]; return nil; } - return self->headerPart; + return headerPart; } -- (NSDictionary *)mailHeaders { - if (self->headers == nil) - self->headers = [[[self mailHeaderPart] headers] copy]; - return self->headers; + +- (NSDictionary *) mailHeaders +{ + if (!headers) + headers = [[[self mailHeaderPart] headers] copy]; + + return headers; } - (id)lookupInfoForBodyPart:(id)_path {