From 08fcee67bd65fc4686897eebd5e8497ace3a1082 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Tue, 11 Apr 2017 11:47:47 -0400 Subject: [PATCH] Improve IMAP error handling in Mailer module --- UI/MailerUI/English.lproj/Localizable.strings | 2 ++ UI/MailerUI/UIxMailListActions.m | 27 ++++++++++++++++--- UI/WebServerResources/js/Mailer/Mailer.app.js | 20 +++++++------- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/UI/MailerUI/English.lproj/Localizable.strings b/UI/MailerUI/English.lproj/Localizable.strings index 0918b210e..71fa1b592 100644 --- a/UI/MailerUI/English.lproj/Localizable.strings +++ b/UI/MailerUI/English.lproj/Localizable.strings @@ -70,6 +70,8 @@ /* No mailbox is selected (usually resulting from an IMAP connection problem) */ "No mailbox selected" = "No mailbox selected"; +"An error occured while communicating with the mail server" = "An error occured while communicating with the mail server"; + /* Mailbox actions */ /* Compact Folder success message */ "Folder compacted" = "Folder compacted"; diff --git a/UI/MailerUI/UIxMailListActions.m b/UI/MailerUI/UIxMailListActions.m index 84241a266..096ebafe1 100644 --- a/UI/MailerUI/UIxMailListActions.m +++ b/UI/MailerUI/UIxMailListActions.m @@ -671,6 +671,9 @@ headers = [self getHeadersForUIDs: [a subarrayWithRange: r] inFolder: folder]; + if (headers == nil) + return nil; + [data setObject: headers forKey: @"headers"]; } @@ -764,7 +767,15 @@ data = [self getUIDsInFolder: folder withHeaders: !noHeaders]; - response = [self responseWithStatus: 200 andJSONRepresentation: data]; + if (data != nil) + response = [self responseWithStatus: 200 andJSONRepresentation: data]; + else + { + data = [NSDictionary dictionaryWithObjectsAndKeys: + @"An error occured while communicating with the mail server", @"message", nil]; + response = [self responseWithStatus: 500 /* Error */ + andJSONRepresentation: data]; + } return response; } @@ -785,6 +796,8 @@ // Fetch headers msgs = (NSDictionary *)[mailFolder fetchUIDs: uids parts: [self fetchKeys]]; + if (msgs == nil) + return nil; msgsList = [[msgs objectForKey: @"fetch"] objectEnumerator]; [self setMessage: [msgsList nextObject]]; @@ -905,8 +918,16 @@ uids = [data objectForKey: @"uids"]; headers = [self getHeadersForUIDs: uids inFolder: [self clientObject]]; - response = [self responseWithStatus: 200 - andJSONRepresentation: headers]; + if (headers) + response = [self responseWithStatus: 200 + andJSONRepresentation: headers]; + else + { + data = [NSDictionary dictionaryWithObjectsAndKeys: + @"An error occured while communicating with the mail server", @"message", nil]; + response = [self responseWithStatus: 500 /* Error */ + andJSONRepresentation: data]; + } return response; } diff --git a/UI/WebServerResources/js/Mailer/Mailer.app.js b/UI/WebServerResources/js/Mailer/Mailer.app.js index 200caff7d..1d9ec4bce 100644 --- a/UI/WebServerResources/js/Mailer/Mailer.app.js +++ b/UI/WebServerResources/js/Mailer/Mailer.app.js @@ -213,9 +213,12 @@ */ onEnterInbox.$inject = ['$window', '$state', 'encodeUriFilter', 'stateAccount']; function onEnterInbox($window, $state, encodeUriFilter, stateAccount) { - $window.location.hash = $state.href('mail.account.mailbox', - {accountId: stateAccount.id, - mailboxId: encodeUriFilter(stateAccount.$mailboxes[0].path)}); + if (stateAccount.$mailboxes.length > 0) + $window.location.hash = $state.href('mail.account.mailbox', + {accountId: stateAccount.id, + mailboxId: encodeUriFilter(stateAccount.$mailboxes[0].path)}); + else + $state.go('mail'); } /** @@ -314,15 +317,14 @@ /** * @ngInject */ - runBlock.$inject = ['$rootScope', '$log', '$state']; - function runBlock($rootScope, $log, $state) { + runBlock.$inject = ['$rootScope', '$log', '$state', 'Mailbox']; + function runBlock($rootScope, $log, $state, Mailbox) { $rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) { $log.error(error); event.preventDefault(); - if (toState.name != 'mail.account.inbox') - $state.go('mail.account.inbox'); - else - $state.go('mail'); + // Unselect everything + Mailbox.selectedFolder = false; + $state.go('mail'); }); $rootScope.$on('$routeChangeError', function(event, current, previous, rejection) { $log.error(event, current, previous, rejection);