Beneath is my code for fetching the mails from IMAPSession. I’m calling the under technique with startingAt=0 and I need to fetch mails in batches of 25, however when i get error(errror.code == 3) then I need to fetch 1 by 1.
Right here is the working When this perform is named we attempt to fetch a batch of 25, nevertheless it fails as a result of it will get error. So then it enter the if block and the subsequent worth is ready to fetching mails to 1 by 1 by recurively calling the identical perform. When it’s known as recursively then it set the batch to 1 mail after which the recursive name will get ended and batch once more turns into 25 after which once more enter the getMessageHeadersForUids with batch of 25.
- (void)fetchMessageHeadersForUids:(NSArray*)uids inFolder:(NSString*)folder startingAt:(NSUInteger)begin {
@strive {
NSUInteger initialBatchSize = INITIAL_MESSAGE_BATCH_SIZE; //InitialBatchSize = 25
// international var errorBatchSize = 25 (Initialized above)
if (begin >= initialBatchSize) {
begin = begin + initialBatchSize;
}
__block NSUInteger newStart = begin;
NSLog(@"MessageData Preliminary begin==> %ld", begin);
NSLog(@"MessageData Preliminary newSstart==> %ld", newStart);
NSLog(@"MessageData Preliminary errorBatchSize==> %ld", errorBatchSize);
NSLog(@"MessageData Preliminary errorBatchSize==> %@", folder);
NSUInteger batchSize = newStart + errorBatchSize > [uids count] ? [uids count] - begin : errorBatchSize;
NSArray* batch = [uids subarrayWithRange:NSMakeRange(newStart,batchSize)];
NSLog(@"MessageData Initial2 begin ==> %ld", begin);
NSLog(@"MessageData Initial2 newstart ==> %ld", newStart);
NSLog(@"MessageData Initial2 batchSize ==> %ld", batchSize);
NSLog(@"MessageData Initial2 batch ==> %@", batch);
if (batchSize > 0) {
double progress = (double) begin / (double) [uids count];
bool cancelOperation = NO;
REPORT_REFRESH_PROGRESS(RefreshStateFetchMessageHeaders, @(progress), &cancelOperation);
if (cancelOperation) {
COMPLETE_REFRESH_CANCEL;
COMPLETE_REFRESH_SUCCESS;
}
[[self imap] getMessageHeadersForUids:batch inFolder:folder completion:^(NSError* error, NSArray* messages, MCOIndexSet* vanishedMessages) {
NSLog(@"MessageData BatchSize after perform execution ==> %@", batch);
NSLog(@"Fetching just one folder %@" , folder);
if (error.code == 3){
NSLog(@"MessageData Error fetching knowledge once more from the server %@", error);
NSLog(@"MessageData Error earlier than begin==> %ld", begin);
NSLog(@"MessageData Error earlier than errorBatchSize==> %ld", begin);
NSUInteger subsequent = 0;
if(errorBatchSize - begin == 0){
subsequent = begin + 1;
NSLog(@"IF block executedd");
NSLog(@"Subsequent and begin worth to be fetched throughout worth change might be %ld %ld" , subsequent, begin);
NSLog(@"MessageData Error in IF block Subsequent And Begin ==> %ld %ld",subsequent, begin);
}else{
errorBatchSize = 1;
subsequent = newStart;
newStart++;
NSLog(@"ELSE block executedd");
NSLog(@"MessageData Error in ELSE block errorBatchSize , Subsequent And Begin ==> %ld %ld %ld",errorBatchSize, subsequent, newStart);
}
@strive {
[self fetchMessageHeadersForUids:uids inFolder:folder startingAt:next];
NSLog(@"Dispatch Ended");
NSLog(@"MessageData BatchSize ========> %@", batch);
}
@catch (NSException *exception) {
NSLog(@"MessageData Catch exception");
NSLog(@"MailMessageManager:fetchMessageHeadersForUids failed with %@", exception.motive);
NSError* exceptionError = MAIL_MANAGER_ERROR(MMErrorGeneric, exception.motive);
COMPLETE_ON_REFRESH_ERROR(exceptionError, RefreshStateFetchMessageHeaders);
}
}
COMPLETE_ON_REFRESH_ERROR(error, RefreshStateFetchMessageHeaders);
@strive {
NSLog(@"MessageData Success earlier than begin==> %ld", begin);
NSLog(@"MessageData Success earlier than errorBatch==> %ld", errorBatchSize);
// pump the messages into the info retailer
MailMessageDataManager* dataManager = [MailMessageDataManager mailMessageDataManager];
[dataManager addMessages:_accountId folderName:folder messages:messages checkIfExist:YES];
// attempt to go for an additional batch
NSUInteger subsequent = newStart + initialBatchSize;
NSLog(@"MessageData Success Subsequent==> %ld", subsequent);
NSLog(@"MessageData Success begin==> %ld", begin);
NSLog(@"MessageData Success neeStart==> %ld", newStart);
NSLog(@"MessageData Success errorBatch==> %ld", errorBatchSize);
[self fetchMessageHeadersForUids:uids inFolder:folder startingAt:next];
}
@catch (NSException* exception) {
NSLog(@"MessageData Catch exception");
NSLog(@"MailMessageManager:fetchMessageHeadersForUids failed with %@", exception.motive);
NSError* exceptionError = MAIL_MANAGER_ERROR(MMErrorGeneric, exception.motive);
COMPLETE_ON_REFRESH_ERROR(exceptionError, RefreshStateFetchMessageHeaders);
}
}];
} else {
// we're all executed. Buh bye
NSLog(@"MessageData executed");
_isFetchInprogress = NO;
bool cancelOperation = NO;
REPORT_REFRESH_PROGRESS(RefreshStateFetchMessageHeadersComplete, @1.0, &cancelOperation);
[[NSNotificationCenter defaultCenter] postNotificationName:@"updateBadgeCount" object:nil];
COMPLETE_REFRESH_SUCCESS;
}
}
@catch (NSException* exception) {
NSLog(@"MessageData final catch ");
NSLog(@"MailMessageManager:fetchMessageHeadersForUids failed with %@", exception.motive);
NSError* exceptionError = MAIL_MANAGER_ERROR(MMErrorGeneric, exception.motive);
COMPLETE_ON_REFRESH_ERROR_DELAYED(exceptionError, RefreshStateFetchMessageHeaders);
}
}
I need that this getMessageHeadersForUids func is ready to 1 whereas we get error.Please somebody look into this