diff options
author | 2013-06-12 07:33:35 -0700 | |
---|---|---|
committer | 2013-06-12 07:33:35 -0700 | |
commit | a17b5f3dda61452934acf70f1756e8ea2ecc6f30 (patch) | |
tree | ef42f6e7cc879160aac0374b2859ca5fce3a60a8 /src/objc/imap/MCOIMAPFolderStatusOperation.mm | |
parent | c4353b9989faac04ad5b2e0e45fb35220123eb9f (diff) | |
parent | c164e9f868fa101bcc344c083af33765e48cf732 (diff) |
Merge pull request #87 from silenteh/master
Added: IMAP Status command - first unread uid from the SELECT IMAP command
Diffstat (limited to 'src/objc/imap/MCOIMAPFolderStatusOperation.mm')
-rw-r--r-- | src/objc/imap/MCOIMAPFolderStatusOperation.mm | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/objc/imap/MCOIMAPFolderStatusOperation.mm b/src/objc/imap/MCOIMAPFolderStatusOperation.mm new file mode 100644 index 00000000..990a71cc --- /dev/null +++ b/src/objc/imap/MCOIMAPFolderStatusOperation.mm @@ -0,0 +1,66 @@ +// +// MCOIMAPFolderStatusOperation.mm +// mailcore2 +// +// Created by Sebastian on 6/5/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#import "MCOIMAPFolderStatusOperation.h" + +#include "MCAsyncIMAP.h" + +#import "MCOOperation+Private.h" +#import "MCOIMAPFolderStatus.h" +#import "MCOUtils.h" + +typedef void (^CompletionType)(NSError *error, MCOIMAPFolderStatus *status); + +@implementation MCOIMAPFolderStatusOperation { + CompletionType _completionBlock; +} + +#define nativeType mailcore::IMAPFolderStatusOperation + ++ (void) load +{ + MCORegisterClass(self, &typeid(nativeType)); +} + ++ (NSObject *) mco_objectWithMCObject:(mailcore::Object *)object +{ + nativeType * op = (nativeType *) object; + return [[[self alloc] initWithMCOperation:op] autorelease]; +} + +- (void) dealloc +{ + [_completionBlock release]; + [super dealloc]; +} + +- (void)start:(void (^)(NSError * error, MCOIMAPFolderStatus * status))completionBlock { + _completionBlock = [completionBlock copy]; + [self start]; +} + +- (void)operationCompleted { + if (_completionBlock == NULL) + return; + + nativeType *op = MCO_NATIVE_INSTANCE; + if (op->error() == mailcore::ErrorNone) { + MCOIMAPFolderStatus * status = [MCOIMAPFolderStatus status]; + [status setUidNext:MCO_NATIVE_INSTANCE->uidNext()]; + [status setUidValidity:MCO_NATIVE_INSTANCE->uidValidity()]; + [status setTotalMessages:MCO_NATIVE_INSTANCE->messageCount()]; + [status setTotalRecent:MCO_NATIVE_INSTANCE->recentCount()]; + [status setTotalUnseen:MCO_NATIVE_INSTANCE->unreadCount()]; + + _completionBlock(nil, status); + } else { + _completionBlock([NSError mco_errorWithErrorCode:op->error()], nil); + } +} + +@end |