feat(mail): add support for UID MOVE operation
parent
534bea674b
commit
d1fc15b3a4
|
@ -78,6 +78,7 @@ typedef enum {
|
|||
- (BOOL) hasCapability: (NSString *) capability;
|
||||
- (BOOL) supportsQuotas;
|
||||
- (BOOL) supportsQResync;
|
||||
- (BOOL) supportsMove;
|
||||
|
||||
- (id) getInboxQuota;
|
||||
- (NSException *) updateFilters;
|
||||
|
|
|
@ -267,6 +267,11 @@ static NSString *inboxFolderName = @"INBOX";
|
|||
return [self hasCapability: @"qresync"];
|
||||
}
|
||||
|
||||
- (BOOL) supportsMove
|
||||
{
|
||||
return [self hasCapability: @"move"];
|
||||
}
|
||||
|
||||
- (id) getInboxQuota
|
||||
{
|
||||
SOGoMailFolder *inbox;
|
||||
|
|
|
@ -70,6 +70,10 @@
|
|||
- (NSArray *) fetchUIDs: (NSArray *) _uids parts: (NSArray *) _parts;
|
||||
- (NSArray *) fetchUIDsOfVanishedItems: (uint64_t) modseq;
|
||||
|
||||
- (WOResponse *) moveUIDs: (NSArray *) uids
|
||||
toFolder: (NSString *) destinationFolder
|
||||
inContext: (id) localContext
|
||||
keepCopy: (BOOL) copy;
|
||||
- (WOResponse *) copyUIDs: (NSArray *) uids
|
||||
toFolder: (NSString *) destinationFolder
|
||||
inContext: (id) localContext;
|
||||
|
|
|
@ -636,6 +636,27 @@ static NSComparisonResult _compareFetchResultsByUID (id entry1, id entry2, NSArr
|
|||
- (WOResponse *) copyUIDs: (NSArray *) uids
|
||||
toFolder: (NSString *) destinationFolder
|
||||
inContext: (id) localContext
|
||||
{
|
||||
return [self moveUIDs: uids
|
||||
toFolder: destinationFolder
|
||||
inContext: localContext
|
||||
keepCopy: YES];
|
||||
}
|
||||
|
||||
- (WOResponse *) moveUIDs: (NSArray *) uids
|
||||
toFolder: (NSString *) destinationFolder
|
||||
inContext: (id) localContext
|
||||
{
|
||||
return [self moveUIDs: uids
|
||||
toFolder: destinationFolder
|
||||
inContext: localContext
|
||||
keepCopy: NO];
|
||||
}
|
||||
|
||||
- (WOResponse *) moveUIDs: (NSArray *) uids
|
||||
toFolder: (NSString *) destinationFolder
|
||||
inContext: (id) localContext
|
||||
keepCopy: (BOOL) copy
|
||||
{
|
||||
NSArray *folders;
|
||||
NSString *currentFolderName, *currentAccountName, *destinationAccountName;
|
||||
|
@ -673,15 +694,35 @@ static NSComparisonResult _compareFetchResultsByUID (id entry1, id entry2, NSArr
|
|||
result = [[self imap4Connection] createMailbox: imapDestinationFolder
|
||||
atURL: [[self mailAccountFolder] imap4URL]];
|
||||
if (!result || [result boolValue])
|
||||
result = [client copyUids: uids toFolder: imapDestinationFolder];
|
||||
{
|
||||
if (copy || ![[self mailAccountFolder] supportsMove])
|
||||
result = [client copyUids: uids toFolder: imapDestinationFolder];
|
||||
else
|
||||
result = [client moveUids: uids toFolder: imapDestinationFolder];
|
||||
}
|
||||
|
||||
if ([[result valueForKey: @"result"] boolValue])
|
||||
result = nil;
|
||||
{
|
||||
result = nil;
|
||||
if (!copy && ![[self mailAccountFolder] supportsMove])
|
||||
{
|
||||
// Server doesn't support MOVE -- delete messages
|
||||
result = [client storeFlags: [NSArray arrayWithObject: @"Deleted"]
|
||||
forUIDs: uids addOrRemove: YES];
|
||||
if ([[result valueForKey: @"result"] boolValue])
|
||||
{
|
||||
[self markForExpunge];
|
||||
result = nil;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
result = [NSException exceptionWithHTTPStatus: 500
|
||||
reason: [[[result objectForKey: @"RawResponse"]
|
||||
objectForKey: @"ResponseResult"]
|
||||
objectForKey: @"description"]];
|
||||
{
|
||||
result = [NSException exceptionWithHTTPStatus: 500
|
||||
reason: [[[result objectForKey: @"RawResponse"]
|
||||
objectForKey: @"ResponseResult"]
|
||||
objectForKey: @"description"]];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -759,36 +800,6 @@ static NSComparisonResult _compareFetchResultsByUID (id entry1, id entry2, NSArr
|
|||
return result;
|
||||
}
|
||||
|
||||
- (WOResponse *) moveUIDs: (NSArray *) uids
|
||||
toFolder: (NSString *) destinationFolder
|
||||
inContext: (id) localContext
|
||||
{
|
||||
id result;
|
||||
NGImap4Client *client;
|
||||
|
||||
client = [[self imap4Connection] client];
|
||||
if (client)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
- (WOResponse *) markMessagesAsJunkOrNotJunk: (NSArray *) uids
|
||||
junk: (BOOL) isJunk
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue