Monotone-Parent: 4820885b1e556f6d0177021967d8b07cb1154aff

Monotone-Revision: b85ba9f2eec26821837bb7890dcb3fd9f82c2eb5

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2012-02-24T20:10:56
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Wolfgang Sourdeau 2012-02-24 20:10:56 +00:00
parent 0056906629
commit 20a336eecd
2 changed files with 169 additions and 86 deletions

View file

@ -1,3 +1,10 @@
2012-02-24 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* SoObjects/Mailer/SOGoMailFolder.m: ensure the imap connection is
available before performing certain operations, otherwise return
an exception. This only applies on methods that return an
exception, others were left untouched.
2012-02-23 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* OpenChange/MAPIStoreMailContext.m

View file

@ -279,32 +279,38 @@ static NSString *defaultUserID = @"anyone";
{
[self imap4URL];
[self imap4Connection];
client = [imap4 client];
if ([self imap4Connection])
{
client = [imap4 client];
inbox = [[self mailAccountFolder] inboxFolderInContext: context];
[client select: [inbox absoluteImap4Name]];
inbox = [[self mailAccountFolder] inboxFolderInContext: context];
[client select: [inbox absoluteImap4Name]];
path = [[imap4URL path] stringByDeletingLastPathComponent];
if (![path hasSuffix: @"/"])
path = [path stringByAppendingString: @"/"];
destURL = [[NSURL alloc] initWithScheme: [imap4URL scheme]
host: [imap4URL host]
path: [NSString stringWithFormat: @"%@%@",
path, newName]];
[destURL autorelease];
error = [imap4 moveMailboxAtURL: imap4URL
toURL: destURL];
if (!error)
{
// We unsubscribe to the old one, and subscribe back to the new one
if ([[[context activeUser] userDefaults]
mailShowSubscribedFoldersOnly])
{
[client subscribe: [destURL path]];
[client unsubscribe: [imap4URL path]];
}
}
path = [[imap4URL path] stringByDeletingLastPathComponent];
if (![path hasSuffix: @"/"])
path = [path stringByAppendingString: @"/"];
destURL = [[NSURL alloc] initWithScheme: [imap4URL scheme]
host: [imap4URL host]
path: [NSString stringWithFormat: @"%@%@",
path, newName]];
[destURL autorelease];
error = [imap4 moveMailboxAtURL: imap4URL
toURL: destURL];
if (!error)
{
// We unsubscribe to the old one, and subscribe back to the new one
if ([[[context activeUser] userDefaults]
mailShowSubscribedFoldersOnly])
{
[client subscribe: [destURL path]];
[client unsubscribe: [imap4URL path]];
}
}
}
else
error = [NSException exceptionWithName: @"SOGoMailException"
reason: @"IMAP connection is invalid"
userInfo: nil];
}
else
error = [NSException exceptionWithName: @"SOGoMailException"
@ -390,33 +396,41 @@ static NSString *defaultUserID = @"anyone";
error = (NSException *) trashFolder;
else
{
client = [[self imap4Connection] client];
[imap4 selectFolder: [self imap4URL]];
folderName = [imap4 imap4FolderNameForURL: [trashFolder imap4URL]];
b = YES;
if ([self imap4Connection])
{
error = nil;
client = [imap4 client];
[imap4 selectFolder: [self imap4URL]];
folderName = [imap4 imap4FolderNameForURL: [trashFolder imap4URL]];
b = YES;
// If we are deleting messages within the Trash folder itself, we
// do not, of course, try to move messages to the Trash folder.
if ([folderName isEqualToString: [self relativeImap4Name]])
{
*withTrash = NO;
}
else
{
// If our Trash folder doesn't exist when we try to copy messages
// to it, we create it.
result = [[client status: folderName flags: [NSArray arrayWithObject: @"UIDVALIDITY"]]
objectForKey: @"result"];
// If we are deleting messages within the Trash folder itself, we
// do not, of course, try to move messages to the Trash folder.
if ([folderName isEqualToString: [self relativeImap4Name]])
{
*withTrash = NO;
}
else
{
// If our Trash folder doesn't exist when we try to copy messages
// to it, we create it.
result = [[client status: folderName flags: [NSArray arrayWithObject: @"UIDVALIDITY"]]
objectForKey: @"result"];
if (![result boolValue])
[[self imap4Connection] createMailbox: folderName
atURL: [[self mailAccountFolder] imap4URL]];
if (![result boolValue])
[imap4 createMailbox: folderName
atURL: [[self mailAccountFolder] imap4URL]];
result = [[client copyUids: uids toFolder: folderName]
objectForKey: @"result"];
result = [[client copyUids: uids toFolder: folderName]
objectForKey: @"result"];
b = [result boolValue];
b = [result boolValue];
}
}
else
error = [NSException exceptionWithName: @"SOGoMailException"
reason: @"IMAP connection is invalid"
userInfo: nil];
}
}
else
@ -602,23 +616,32 @@ static NSString *defaultUserID = @"anyone";
}
client = [[self imap4Connection] client];
[imap4 selectFolder: [self imap4URL]];
if (client)
{
[imap4 selectFolder: [self imap4URL]];
// We make sure the destination IMAP folder exist, if not, we create it.
result = [[client status: imapDestinationFolder
flags: [NSArray arrayWithObject: @"UIDVALIDITY"]]
objectForKey: @"result"];
if (![result boolValue])
result = [[self imap4Connection] createMailbox: imapDestinationFolder
atURL: [[self mailAccountFolder] imap4URL]];
if (!result || [result boolValue])
result = [client copyUids: uids toFolder: imapDestinationFolder];
// We make sure the destination IMAP folder exist, if not, we create it.
result = [[client status: imapDestinationFolder
flags: [NSArray arrayWithObject: @"UIDVALIDITY"]]
objectForKey: @"result"];
if (![result boolValue])
result = [[self imap4Connection] createMailbox: imapDestinationFolder
atURL: [[self mailAccountFolder] imap4URL]];
if (!result || [result boolValue])
result = [client copyUids: uids toFolder: imapDestinationFolder];
if ([[result valueForKey: @"result"] boolValue])
result = nil;
if ([[result valueForKey: @"result"] boolValue])
result = nil;
else
result = [NSException exceptionWithHTTPStatus: 500
reason: [[[result objectForKey: @"RawResponse"]
objectForKey: @"ResponseResult"]
objectForKey: @"description"]];
}
else
result = [NSException exceptionWithHTTPStatus: 500
reason: [[[result objectForKey: @"RawResponse"] objectForKey: @"ResponseResult"] objectForKey: @"description"]];
result = [NSException exceptionWithName: @"SOGoMailException"
reason: @"IMAP connection is invalid"
userInfo: nil];
}
else
result = [NSException exceptionWithHTTPStatus: 500
@ -639,18 +662,24 @@ static NSString *defaultUserID = @"anyone";
NGImap4Client *client;
client = [[self imap4Connection] client];
result = [self copyUIDs: uids toFolder: destinationFolder inContext: localContext];
if (![result isNotNull])
if (client)
{
result = [client storeFlags: [NSArray arrayWithObject: @"Deleted"]
forUIDs: uids addOrRemove: YES];
if ([[result valueForKey: @"result"] boolValue])
{
[self markForExpunge];
result = nil;
}
result = [self copyUIDs: uids toFolder: destinationFolder inContext: localContext];
if (![result isNotNull])
{
result = [client storeFlags: [NSArray arrayWithObject: @"Deleted"]
forUIDs: uids addOrRemove: YES];
if ([[result valueForKey: @"result"] boolValue])
{
[self markForExpunge];
result = nil;
}
}
}
else
result = [NSException exceptionWithName: @"SOGoMailException"
reason: @"IMAP connection is invalid"
userInfo: nil];
return result;
}
@ -734,7 +763,15 @@ static NSString *defaultUserID = @"anyone";
- (NSException *) expunge
{
return [[self imap4Connection] expungeAtURL: [self imap4URL]];
NSException *error;
if ([self imap4Connection])
error = [imap4 expungeAtURL: [self imap4URL]];
else
error = [NSException exceptionWithName: @"SOGoMailException"
reason: @"IMAP connection is invalid"
userInfo: nil];
return error;
}
- (void) markForExpunge
@ -790,8 +827,17 @@ static NSString *defaultUserID = @"anyone";
- (NSException *) addFlagsToAllMessages: (id) _f
{
return [[self imap4Connection] addFlags:_f
toAllMessagesInURL: [self imap4URL]];
NSException *error;
if ([self imap4Connection])
error = [imap4 addFlags:_f
toAllMessagesInURL: [self imap4URL]];
else
error = [NSException exceptionWithName: @"SOGoMailException"
reason: @"IMAP connection is invalid"
userInfo: nil];
return error;
}
/* name lookup */
@ -860,7 +906,16 @@ static NSString *defaultUserID = @"anyone";
- (NSException *) davCreateCollection: (NSString *) _name
inContext: (id) _ctx
{
return [[self imap4Connection] createMailbox:_name atURL:[self imap4URL]];
NSException *error;
if ([self imap4Connection])
error = [imap4 createMailbox:_name atURL:[self imap4URL]];
else
error = [NSException exceptionWithName: @"SOGoMailException"
reason: @"IMAP connection is invalid"
userInfo: nil];
return error;
}
- (BOOL) exists
@ -873,29 +928,43 @@ static NSString *defaultUserID = @"anyone";
NSException *error;
BOOL rc;
[self imap4Connection];
error = [imap4 createMailbox: [self relativeImap4Name]
atURL: [container imap4URL]];
if (error)
rc = NO;
else
if ([self imap4Connection])
{
[[imap4 client] subscribe: [self absoluteImap4Name]];
rc = YES;
error = [imap4 createMailbox: [self relativeImap4Name]
atURL: [container imap4URL]];
if (error)
rc = NO;
else
{
[[imap4 client] subscribe: [self absoluteImap4Name]];
rc = YES;
}
}
else
rc = NO;
return rc;
}
- (NSException *) delete
{
return [[self imap4Connection] deleteMailboxAtURL:[self imap4URL]];
NSException *error;
if ([self imap4Connection])
error = [imap4 deleteMailboxAtURL: [self imap4URL]];
else
error = [NSException exceptionWithName: @"SOGoMailException"
reason: @"IMAP connection is invalid"
userInfo: nil];
return error;
}
- (NSException *) davMoveToTargetObject: (id) _target
newName: (NSString *) _name
inContext: (id)_ctx
{
NSException *error;
NSURL *destImapURL;
if ([_name length] == 0) { /* target already exists! */
@ -920,9 +989,16 @@ static NSString *defaultUserID = @"anyone";
[self logWithFormat:@"TODO: should move collection as '%@' to: %@",
[[self imap4URL] absoluteString],
[destImapURL absoluteString]];
return [[self imap4Connection] moveMailboxAtURL:[self imap4URL]
toURL:destImapURL];
if ([self imap4Connection])
error = [imap4 moveMailboxAtURL: [self imap4URL]
toURL: destImapURL];
else
error = [NSException exceptionWithName: @"SOGoMailException"
reason: @"IMAP connection is invalid"
userInfo: nil];
return error;
}
- (NSException *) davCopyToTargetObject: (id) _target