Improve IMAP error handling in Mailer module

This commit is contained in:
Francis Lachapelle
2017-04-11 11:47:47 -04:00
parent cc9602fbc8
commit 08fcee67bd
3 changed files with 37 additions and 12 deletions

View File

@@ -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";

View File

@@ -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;
}

View File

@@ -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);