From 693f80dc9a7dd5db375accca630dcc33df88ad8a Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Wed, 10 Feb 2016 10:00:59 -0500 Subject: [PATCH] (feat) now supports RFC6154 and NoInferiors IMAP flag --- NEWS | 1 + SoObjects/Mailer/SOGoMailAccount.m | 39 +++++++++++++++---- UI/Templates/MailerUI/UIxMailMainFrame.wox | 2 +- .../js/Mailer/Mailbox.service.js | 13 ++++++- 4 files changed, 45 insertions(+), 10 deletions(-) diff --git a/NEWS b/NEWS index 7445948e0..606b8f8ac 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,7 @@ Enhancements - [web] updated Material Icons font to version 2.1.3 - [web] don't offer forward/vacation options in filters if not enabled - [web] mail filters are now sortable + - [web] now supports RFC6154 and NoInferiors IMAP flag Bug fixes - [web] handle birthday dates before 1970 diff --git a/SoObjects/Mailer/SOGoMailAccount.m b/SoObjects/Mailer/SOGoMailAccount.m index e2c9730bb..24c73a7e3 100644 --- a/SoObjects/Mailer/SOGoMailAccount.m +++ b/SoObjects/Mailer/SOGoMailAccount.m @@ -410,23 +410,42 @@ static NSString *inboxFolderName = @"INBOX"; // // - (NSString *) _folderType: (NSString *) folderName + flags: (NSMutableArray *) flags { - NSString *folderType; + NSString *folderType, *key; + NSDictionary *metadata; + SOGoUserDefaults *ud; + ud = [[context activeUser] userDefaults]; + + metadata = [[[self imap4Connection] allFoldersMetadataForURL: [self imap4URL] + onlySubscribedFolders: [ud mailShowSubscribedFoldersOnly]] + objectForKey: @"list"]; + + key = [NSString stringWithFormat: @"/%@", folderName]; + [flags addObjectsFromArray: [metadata objectForKey: key]]; + + // RFC6154 (https://tools.ietf.org/html/rfc6154) describes special uses for IMAP mailboxes. + // We do honor them, as long as your SOGo{Drafts,Trash,Sent,Junk}FolderName are properly configured + // See http://wiki.dovecot.org/MailboxSettings for a Dovecot example. if ([folderName isEqualToString: inboxFolderName]) folderType = @"inbox"; - else if ([folderName isEqualToString: [self draftsFolderNameInContext: context]]) + else if ([flags containsObject: [self draftsFolderNameInContext: context]] || + [folderName isEqualToString: [self draftsFolderNameInContext: context]]) folderType = @"draft"; - else if ([folderName isEqualToString: [self sentFolderNameInContext: context]]) + else if ([flags containsObject: [self sentFolderNameInContext: context]] || + [folderName isEqualToString: [self sentFolderNameInContext: context]]) folderType = @"sent"; - else if ([folderName isEqualToString: [self trashFolderNameInContext: context]]) + else if ([flags containsObject: [self trashFolderNameInContext: context]] || + [folderName isEqualToString: [self trashFolderNameInContext: context]]) folderType = @"trash"; + else if ([flags containsObject: [self junkFolderNameInContext: context]] || + [folderName isEqualToString: [self junkFolderNameInContext: context]]) + folderType = @"junk"; else if ([folderName isEqualToString: otherUsersFolderName]) folderType = @"otherUsers"; else if ([folderName isEqualToString: sharedFoldersName]) folderType = @"shared"; - else if ([folderName isEqualToString: [self junkFolderNameInContext: context]]) - folderType = @"junk"; else folderType = @"folder"; @@ -437,7 +456,7 @@ static NSString *inboxFolderName = @"INBOX"; foldersList: (NSMutableArray *) theFolders { NSArray *pathComponents; - NSMutableArray *folders; + NSMutableArray *folders, *flags; NSMutableDictionary *currentFolder, *parentFolder, *folder; NSString *currentFolderName, *currentPath, *fullName, *folderType; SOGoUserManager *userManager; @@ -519,8 +538,11 @@ static NSString *inboxFolderName = @"INBOX"; currentFolderName = [self labelForKey: @"SharedFoldersName"]; } + flags = [NSMutableArray array];; + if (last) - folderType = [self _folderType: currentPath]; + folderType = [self _folderType: currentPath + flags: flags]; else folderType = @"additional"; @@ -529,6 +551,7 @@ static NSString *inboxFolderName = @"INBOX"; folderType, @"type", currentFolderName, @"name", [NSMutableArray array], @"children", + flags, @"flags", nil]; // Either add this new folder to its parent or the list of root folders [folders addObject: folder]; diff --git a/UI/Templates/MailerUI/UIxMailMainFrame.wox b/UI/Templates/MailerUI/UIxMailMainFrame.wox index 7325a31db..3d61ae5d0 100644 --- a/UI/Templates/MailerUI/UIxMailMainFrame.wox +++ b/UI/Templates/MailerUI/UIxMailMainFrame.wox @@ -120,7 +120,7 @@ - + diff --git a/UI/WebServerResources/js/Mailer/Mailbox.service.js b/UI/WebServerResources/js/Mailer/Mailbox.service.js index 8b9e86275..c925984a3 100644 --- a/UI/WebServerResources/js/Mailer/Mailbox.service.js +++ b/UI/WebServerResources/js/Mailer/Mailbox.service.js @@ -165,6 +165,7 @@ if (this.type) { this.$isEditable = this.isEditable(); } + this.$isNoInferiors = this.isNoInferiors(); if (angular.isUndefined(this.$shadowData)) { // Make a copy of the data for an eventual reset this.$shadowData = this.$omit(); @@ -375,6 +376,16 @@ return this.type == 'folder'; }; + /** + * @function isNoInferiors + * @memberof Mailbox.prototype + * @desc Checks if the mailbox can contain submailboxes + * @returns true if the mailbox can not contain submailboxes + */ + Mailbox.prototype.isNoInferiors = function() { + return this.flags.indexOf('noinferiors') >= 0; + }; + /** * @function $rename * @memberof AddressBook.prototype @@ -721,7 +732,7 @@ Mailbox.$timeout(function() { var uids, headers; - if (_this.$topIndex > data.uids.length - 1) + if (!data.uids || _this.$topIndex > data.uids.length - 1) _this.$topIndex = 0; _this.init(data);