Skip to content

Commit

Permalink
feat(mail): add support for UID MOVE operation
Browse files Browse the repository at this point in the history
  • Loading branch information
cgx committed Sep 10, 2021
1 parent 534bea6 commit d1fc15b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 36 deletions.
1 change: 1 addition & 0 deletions SoObjects/Mailer/SOGoMailAccount.h
Expand Up @@ -78,6 +78,7 @@ typedef enum {
- (BOOL) hasCapability: (NSString *) capability;
- (BOOL) supportsQuotas;
- (BOOL) supportsQResync;
- (BOOL) supportsMove;

- (id) getInboxQuota;
- (NSException *) updateFilters;
Expand Down
5 changes: 5 additions & 0 deletions SoObjects/Mailer/SOGoMailAccount.m
Expand Up @@ -267,6 +267,11 @@ - (BOOL) supportsQResync
return [self hasCapability: @"qresync"];
}

- (BOOL) supportsMove
{
return [self hasCapability: @"move"];
}

- (id) getInboxQuota
{
SOGoMailFolder *inbox;
Expand Down
4 changes: 4 additions & 0 deletions SoObjects/Mailer/SOGoMailFolder.h
Expand Up @@ -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;
Expand Down
83 changes: 47 additions & 36 deletions SoObjects/Mailer/SOGoMailFolder.m
Expand Up @@ -636,6 +636,27 @@ - (WOResponse *) archiveAllMessagesInContext: (id) localContext
- (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;
Expand Down Expand Up @@ -673,15 +694,35 @@ - (WOResponse *) copyUIDs: (NSArray *) uids
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
{
Expand Down Expand Up @@ -759,36 +800,6 @@ - (WOResponse *) copyUIDs: (NSArray *) uids
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
{
Expand Down

0 comments on commit d1fc15b

Please sign in to comment.