diff --git a/ChangeLog b/ChangeLog index fcf609223..68a5162a8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2011-07-12 Francis Lachapelle + * UI/MailerUI/UIxMailFolderActions.m (-batchDeleteAction): we + only return the quota when not using the trash folder. + * SoObjects/SOGo/SOGoFolder.m (-compare:): handle the case when the display name is not defined. diff --git a/SoObjects/Mailer/SOGoMailAccount.m b/SoObjects/Mailer/SOGoMailAccount.m index e733e3953..526db748c 100644 --- a/SoObjects/Mailer/SOGoMailAccount.m +++ b/SoObjects/Mailer/SOGoMailAccount.m @@ -261,6 +261,7 @@ static NSString *inboxFolderName = @"INBOX"; { // A soft quota ratio is imposed for all users quota = quota * [(NSNumber*)[inboxQuota objectForKey: @"maxQuota"] intValue]; + NSLog(@"*** quota %@/%@", [inboxQuota objectForKey: @"usedSpace"], [inboxQuota objectForKey: @"maxQuota"]); inboxQuota = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithLong: (long)(quota+0.5)], @"maxQuota", [inboxQuota objectForKey: @"usedSpace"], @"usedSpace", diff --git a/SoObjects/Mailer/SOGoMailFolder.m b/SoObjects/Mailer/SOGoMailFolder.m index 7b96c8683..b03d70369 100644 --- a/SoObjects/Mailer/SOGoMailFolder.m +++ b/SoObjects/Mailer/SOGoMailFolder.m @@ -1167,17 +1167,11 @@ static NSString *defaultUserID = @"anyone"; - (NSString *) httpURLForAdvisoryToUser: (NSString *) uid { - SOGoUser *user; NSString *otherUsersPath, *url; - SOGoMailAccount *thisAccount; - NSDictionary *mailAccount; - user = [SOGoUser userWithLogin: uid roles: nil]; otherUsersPath = [self otherUsersPathToFolder]; if (otherUsersPath) { - thisAccount = [self mailAccountFolder]; - mailAccount = [[user mailAccounts] objectAtIndex: 0]; url = [NSString stringWithFormat: @"%@/0%@", [self soURLToBaseContainerForUser: uid], otherUsersPath]; diff --git a/UI/MailerUI/UIxMailAccountActions.m b/UI/MailerUI/UIxMailAccountActions.m index 35677d068..60adae168 100644 --- a/UI/MailerUI/UIxMailAccountActions.m +++ b/UI/MailerUI/UIxMailAccountActions.m @@ -187,11 +187,7 @@ rawFolders = [[co allFolderPaths] objectEnumerator]; folders = [self _jsonFolders: rawFolders]; - // The parameters order is important here, as if the server doesn't support - // quota, inboxQuota will be nil and it'll terminate the list of objects/keys. - data = [NSDictionary dictionaryWithObjectsAndKeys: folders, @"mailboxes", - [co getInboxQuota], @"quotas", - nil]; + data = [NSDictionary dictionaryWithObjectsAndKeys: folders, @"mailboxes", nil]; response = [self responseWithStatus: 200 andString: [data jsonRepresentation]]; [response setHeader: @"application/json" diff --git a/UI/MailerUI/UIxMailActions.m b/UI/MailerUI/UIxMailActions.m index e4a2cf72f..652ffd7ee 100644 --- a/UI/MailerUI/UIxMailActions.m +++ b/UI/MailerUI/UIxMailActions.m @@ -94,30 +94,22 @@ - (id) markMessageUnflaggedAction { id response; - SOGoMailFolder *mailFolder; response = [[self clientObject] removeFlags: @"\\Flagged"]; if (!response) - { - mailFolder = [[self clientObject] container]; - response = [self responseWith204]; - } - + response = [self responseWith204]; + return response; } - (id) markMessageFlaggedAction { id response; - SOGoMailFolder *mailFolder; response = [[self clientObject] addFlags: @"\\Flagged"]; if (!response) - { - mailFolder = [[self clientObject] container]; - response = [self responseWith204]; - } - + response = [self responseWith204]; + return response; } @@ -125,30 +117,22 @@ - (id) markMessageUnreadAction { id response; - SOGoMailFolder *mailFolder; - + response = [[self clientObject] removeFlags: @"seen"]; if (!response) - { - mailFolder = [[self clientObject] container]; - response = [self responseWith204]; - } - + response = [self responseWith204]; + return response; } - (id) markMessageReadAction { id response; - SOGoMailFolder *mailFolder; response = [[self clientObject] addFlags: @"seen"]; if (!response) - { - mailFolder = [[self clientObject] container]; - response = [self responseWith204]; - } - + response = [self responseWith204]; + return response; } diff --git a/UI/MailerUI/UIxMailFolderActions.m b/UI/MailerUI/UIxMailFolderActions.m index 693a255c0..33dab148d 100644 --- a/UI/MailerUI/UIxMailFolderActions.m +++ b/UI/MailerUI/UIxMailFolderActions.m @@ -247,10 +247,16 @@ response = (WOResponse *) [co deleteUIDs: uids useTrashFolder: !withoutTrash inContext: context]; if (!response) { - account = [co mailAccountFolder]; - data = [NSDictionary dictionaryWithObjectsAndKeys: [account getInboxQuota], @"quotas", nil]; - response = [self responseWithStatus: 200 - andString: [data jsonRepresentation]]; + if (withoutTrash) + { + // When not using a trash folder, return the quota + account = [co mailAccountFolder]; + data = [NSDictionary dictionaryWithObjectsAndKeys: [account getInboxQuota], @"quotas", nil]; + response = [self responseWithStatus: 200 + andString: [data jsonRepresentation]]; + } + else + response = [self responseWith204]; } } else diff --git a/UI/MailerUI/UIxMailListActions.h b/UI/MailerUI/UIxMailListActions.h index 569df1775..bd80c7357 100644 --- a/UI/MailerUI/UIxMailListActions.h +++ b/UI/MailerUI/UIxMailListActions.h @@ -49,9 +49,10 @@ - (NSArray *) getSortedUIDsInFolder: (SOGoMailFolder *) mailFolder; - (NSArray *) getHeadersForUIDs: (NSArray *) uids inFolder: (SOGoMailFolder *) mailFolder; -- (NSDictionary *) getUIDsAndHeadersInFolder: (SOGoMailFolder *) mailFolder; +- (NSDictionary *) getUIDsInFolder: (SOGoMailFolder *) folder + withHeaders: (BOOL) includeHeaders; -- (id ) getSortedUIDsAction; +- (id ) getUIDsAction; - (id ) getHeadersAction; @end diff --git a/UI/MailerUI/UIxMailListActions.m b/UI/MailerUI/UIxMailListActions.m index 4a9d6dd88..89e90c38f 100644 --- a/UI/MailerUI/UIxMailListActions.m +++ b/UI/MailerUI/UIxMailListActions.m @@ -623,55 +623,64 @@ } */ -- (NSDictionary *) getUIDsAndHeadersInFolder: (SOGoMailFolder *) mailFolder +- (NSDictionary *) getUIDsInFolder: (SOGoMailFolder *) folder + withHeaders: (BOOL) includeHeaders { + NSMutableDictionary *data; NSArray *uids, *threadedUids, *headers; - NSDictionary *data; NSRange r; - int count; SOGoMailAccount *account; id quota; - - uids = [self getSortedUIDsInFolder: mailFolder]; // retrieves the form parameters "sort" and "asc" + int count; - // Also retrieve the first headers, up to 'headersPrefetchMaxSize' - count = [uids count]; - if (count > headersPrefetchMaxSize) count = headersPrefetchMaxSize; - r = NSMakeRange(0, count); - headers = [self getHeadersForUIDs: [[uids flattenedArray] subarrayWithRange: r] - inFolder: mailFolder]; + data = [NSMutableDictionary dictionary]; + // TODO: we might want to flush the caches? + //[folder flushMailCaches]; + [folder expungeLastMarkedFolder]; + + // Retrieve messages UIDs using form parameters "sort" and "asc" + uids = [self getSortedUIDsInFolder: folder]; + + if (includeHeaders) + { + // Also retrieve the first headers, up to 'headersPrefetchMaxSize' + count = [uids count]; + if (count > headersPrefetchMaxSize) count = headersPrefetchMaxSize; + r = NSMakeRange(0, count); + headers = [self getHeadersForUIDs: [[uids flattenedArray] subarrayWithRange: r] + inFolder: folder]; + + [data setObject: headers forKey: @"headers"]; + } + if (sortByThread) { + // Add threads information threadedUids = [self threadedUIDs: uids]; if (threadedUids != nil) uids = threadedUids; else sortByThread = NO; } - - // We also return the inbox quota - account = [mailFolder mailAccountFolder]; - quota = [account getInboxQuota]; + [data setObject: uids forKey: @"uids"]; + [data setObject: [NSNumber numberWithBool: sortByThread] forKey: @"threaded"]; - data = [NSDictionary dictionaryWithObjectsAndKeys: uids, @"uids", - headers, @"headers", - [NSNumber numberWithBool: sortByThread], @"threaded", - quota, @"quotas", nil]; + // We also return the inbox quota + account = [folder mailAccountFolder]; + quota = [account getInboxQuota]; + [data setObject: quota forKey: @"quotas"]; return data; } /* Module actions */ -- (id ) getSortedUIDsAction +- (id ) getUIDsAction { NSDictionary *data; - NSArray *uids, *threadedUids; NSString *noHeaders; - SOGoMailAccount *account; SOGoMailFolder *folder; - id quota; WORequest *request; WOResponse *response; @@ -681,33 +690,9 @@ forKey: @"content-type"]; folder = [self clientObject]; - // TODO: we might want to flush the caches? - //[folder flushMailCaches]; - [folder expungeLastMarkedFolder]; - noHeaders = [request formValueForKey: @"no_headers"]; - if ([noHeaders length]) - { - uids = [self getSortedUIDsInFolder: folder]; - if (sortByThread) - { - threadedUids = [self threadedUIDs: uids]; - if (threadedUids != nil) - uids = threadedUids; - else - sortByThread = NO; - } - - // We also return the inbox quota - account = [folder mailAccountFolder]; - quota = [account getInboxQuota]; - - data = [NSDictionary dictionaryWithObjectsAndKeys: uids, @"uids", - [NSNumber numberWithBool: sortByThread], @"threaded", - quota, @"quotas", nil]; - } - else - data = [self getUIDsAndHeadersInFolder: folder]; + data = [self getUIDsInFolder: folder + withHeaders: ([noHeaders length] == 0)]; [response appendContentString: [data jsonRepresentation]]; diff --git a/UI/MailerUI/UIxMailMainFrame.m b/UI/MailerUI/UIxMailMainFrame.m index ba0297bee..a03336e58 100644 --- a/UI/MailerUI/UIxMailMainFrame.m +++ b/UI/MailerUI/UIxMailMainFrame.m @@ -173,7 +173,7 @@ account = [accounts lookupName: @"0" inContext: context acquire: NO]; inbox = [account inboxFolderInContext: context]; - data = [actions getUIDsAndHeadersInFolder: inbox]; + data = [actions getUIDsInFolder: inbox withHeaders: YES]; return [data jsonRepresentation]; } diff --git a/UI/MailerUI/UIxMailView.m b/UI/MailerUI/UIxMailView.m index f9aa93cb6..f9d104dce 100644 --- a/UI/MailerUI/UIxMailView.m +++ b/UI/MailerUI/UIxMailView.m @@ -590,9 +590,6 @@ static NSString *mailETag = nil; inContext: (WOContext *) _ctx { UIxMailRenderingContext *mctx; - WORequest *request; - - request = [_ctx request]; [[_ctx response] setHeader:mailETag forKey:@"etag"]; diff --git a/UI/MailerUI/product.plist b/UI/MailerUI/product.plist index 89ba0d7a7..a35b3ecdb 100644 --- a/UI/MailerUI/product.plist +++ b/UI/MailerUI/product.plist @@ -80,7 +80,7 @@ uids = { protectedBy = ""; actionClass = "UIxMailListActions"; - actionName = "getSortedUIDs"; + actionName = "getUIDs"; }; headers = { protectedBy = ""; diff --git a/UI/WebServerResources/MailerUI.js b/UI/WebServerResources/MailerUI.js index 51f3ee1b6..e515c42ac 100644 --- a/UI/WebServerResources/MailerUI.js +++ b/UI/WebServerResources/MailerUI.js @@ -14,7 +14,6 @@ var Mailer = { cachedMessages: new Array(), foldersStateTimer: false, popups: new Array(), - quotas: null, dataTable: null, dataSources: new Hash(), @@ -524,11 +523,14 @@ function deleteSelectedMessages(sender) { } function deleteSelectedMessagesCallback(http) { - if (http.status == 200) { + if (isHttpStatus204(http.status) || http.status == 200) { var data = http.callbackData; - var rdata = http.responseText.evalJSON(true); - if (rdata.quotas && data["mailbox"].startsWith('/0/')) - updateQuotas(rdata.quotas); + if (http.status == 200) { + // The answer contains quota information + var rdata = http.responseText.evalJSON(true); + if (rdata.quotas && data["mailbox"].startsWith('/0/')) + updateQuotas(rdata.quotas); + } if (data["refreshUnseenCount"]) // TODO : the unseen count should be returned when calling the batchDelete remote action, // in order to avoid this extra AJAX call. @@ -821,7 +823,7 @@ function openMailbox(mailbox, reload) { if (inboxData) { // Use UIDs and headers from the WOX template; this only // happens once and only with the inbox - dataSource.init(inboxData['uids'], inboxData['threaded'], inboxData['headers']); + dataSource.init(inboxData['uids'], inboxData['threaded'], inboxData['headers'], inboxData['quotas']); inboxData = null; // invalidate this initial lookup } else @@ -2067,14 +2069,12 @@ function updateMailboxTreeInPage() { } } - updateQuotas(); + //updateQuotas(); } function updateQuotas(quotas) { - if (quotas) - Mailer.quotas = quotas; - if (Mailer.quotas && parseInt(Mailer.quotas.maxQuota) > 0) { - log ("updating quotas " + Mailer.quotas.usedSpace + "/" + Mailer.quotas.maxQuota); + if (quotas && parseInt(quotas.maxQuota) > 0) { + log ("updating quotas " + quotas.usedSpace + "/" + quotas.maxQuota); var treeContent = $("folderTreeContent"); var tree = $("mailboxTree"); var quotaDiv = $("quotaIndicator"); @@ -2082,13 +2082,13 @@ function updateQuotas(quotas) { treeContent.removeChild(quotaDiv); } // Build quota indicator, show values in MB - var percents = (Math.round(Mailer.quotas.usedSpace * 10000 - / Mailer.quotas.maxQuota) + var percents = (Math.round(quotas.usedSpace * 10000 + / quotas.maxQuota) / 100); var level = (percents > 85)? "alert" : (percents > 70)? "warn" : "ok"; var format = _("quotasFormat"); var text = format.formatted(percents, - Math.round(Mailer.quotas.maxQuota/10.24)/100); + Math.round(quotas.maxQuota/10.24)/100); quotaDiv = new Element('div', { 'id': 'quotaIndicator', 'class': 'quota', 'info': text }); @@ -2215,9 +2215,6 @@ function buildMailboxes(accountIdx, encoded) { var mailboxes = data.mailboxes; var unseen = (data.status? data.status.unseen : 0); - if (accountIdx == 0 && data.quotas) - Mailer.quotas = data.quotas; - for (var i = 0; i < mailboxes.length; i++) { var currentNode = account; var names = mailboxes[i].path.split("/");