propagate from branch 'ca.inverse.sogo.1_3_13' (head 837142c1df31bc292adff9513b1f7c35f896ea83)

to branch 'ca.inverse.sogo' (head d33b0adee86f35e2abaffd30306c1e5ed174b08c)

Monotone-Parent: 837142c1df31bc292adff9513b1f7c35f896ea83
Monotone-Parent: d33b0adee86f35e2abaffd30306c1e5ed174b08c
Monotone-Revision: 950ec4b3237bbed086e9876da2e597c7e074531a

Monotone-Author: flachapelle@inverse.ca
Monotone-Date: 2012-03-07T20:48:51
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Francis Lachapelle
2012-03-07 20:48:51 +00:00
33 changed files with 920 additions and 770 deletions
+162 -86
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
@@ -612,23 +626,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
@@ -649,18 +672,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;
}
@@ -744,7 +773,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
@@ -800,8 +837,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 */
@@ -870,7 +916,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
@@ -883,29 +938,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! */
@@ -930,9 +999,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