Skip to content

Commit

Permalink
fix(mail): new action to fetch the flags of a mailbox
Browse files Browse the repository at this point in the history
  • Loading branch information
cgx committed Oct 21, 2021
1 parent 642db85 commit 175e380
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions UI/MailerUI/UIxMailFolderActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
- (WOResponse *) emptyTrashAction;
- (WOResponse *) subscribeAction;
- (WOResponse *) unsubscribeAction;
- (id <WOActionResults>) getLabelsAction;

@end

Expand Down
57 changes: 57 additions & 0 deletions UI/MailerUI/UIxMailFolderActions.m
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,63 @@ - (WOResponse *) unsubscribeAction
return [self _subscribeOrUnsubscribeAction: NO];
}

- (id <WOActionResults>) getLabelsAction
{
NGImap4Client *client;
NSArray *labels, *userLabel;
NSDictionary *result, *userLabels, *labelRecord;
NSEnumerator *labelsList;
NSMutableArray *allLabels;
NSString *label;
SOGoMailFolder *co;
WOResponse *response;
unsigned int i;
static NSArray *imapKeywords = nil;

if (!imapKeywords)
{
imapKeywords = [[NSArray alloc] initWithObjects: @"ANSWERED", @"DELETED",
@"DRAFT", @"FLAGGED", @"NEW", @"OLD", @"RECENT",
@"SEEN", @"UNANSWERED", @"UNDELETED", @"UNDRAFT",
@"UNFLAGGED", @"UNSEEN", nil];
[imapKeywords retain];
}

i = 0;
allLabels = [NSMutableArray array];
co = [self clientObject];
client = [[co imap4Connection] client];
result = [client select: [[co imap4URL] path]];
labels = [result objectForKey: @"flags"];
userLabels = [[[context activeUser] userDefaults] mailLabelsColors];
labelsList = [[labels sortedArrayUsingSelector: @selector(compareAscending:)] objectEnumerator];
while ((label = [labelsList nextObject]))
{
if (![imapKeywords containsObject: [label uppercaseString]])
{
if ((userLabel = [userLabels objectForKey: label]))
{
labelRecord = [NSDictionary dictionaryWithObjectsAndKeys:
label, @"imapName",
[userLabel objectAtIndex: 0], @"name",
[userLabel objectAtIndex: 1], @"color", nil];
[allLabels insertObject: labelRecord atIndex: i];
i++;
}
else
{
labelRecord = [NSDictionary dictionaryWithObjectsAndKeys:
label, @"imapName", nil];
[allLabels addObject: labelRecord];
}
}
}

response = [self responseWithStatus: 200 andJSONRepresentation: allLabels];

return response;
}

- (WOResponse *) addOrRemoveLabelAction
{
WOResponse *response;
Expand Down
5 changes: 5 additions & 0 deletions UI/MailerUI/product.plist
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@
pageName = "UIxMailUserRightsEditor";
actionName = "saveUserRights";
};
labels = {
protectedBy = "View";
actionClass = "UIxMailFolderActions";
actionName = "getLabels";
};
addOrRemoveLabel = {
protectedBy = "View";
actionClass = "UIxMailFolderActions";
Expand Down

0 comments on commit 175e380

Please sign in to comment.