diff options
author | DINH Viêt Hoà <dinh.viet.hoa@gmail.com> | 2013-06-12 07:33:35 -0700 |
---|---|---|
committer | DINH Viêt Hoà <dinh.viet.hoa@gmail.com> | 2013-06-12 07:33:35 -0700 |
commit | a17b5f3dda61452934acf70f1756e8ea2ecc6f30 (patch) | |
tree | ef42f6e7cc879160aac0374b2859ca5fce3a60a8 /src/objc | |
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')
-rw-r--r-- | src/objc/imap/MCOIMAP.h | 2 | ||||
-rw-r--r-- | src/objc/imap/MCOIMAPFolderInfo.h | 3 | ||||
-rw-r--r-- | src/objc/imap/MCOIMAPFolderInfo.m | 2 | ||||
-rw-r--r-- | src/objc/imap/MCOIMAPFolderInfoOperation.mm | 2 | ||||
-rw-r--r-- | src/objc/imap/MCOIMAPFolderStatus.h | 43 | ||||
-rw-r--r-- | src/objc/imap/MCOIMAPFolderStatus.m | 35 | ||||
-rw-r--r-- | src/objc/imap/MCOIMAPFolderStatusOperation.h | 39 | ||||
-rw-r--r-- | src/objc/imap/MCOIMAPFolderStatusOperation.mm | 66 | ||||
-rw-r--r-- | src/objc/imap/MCOIMAPSession.h | 27 | ||||
-rw-r--r-- | src/objc/imap/MCOIMAPSession.mm | 6 |
10 files changed, 225 insertions, 0 deletions
diff --git a/src/objc/imap/MCOIMAP.h b/src/objc/imap/MCOIMAP.h index 55e430ae..a6c1ff0c 100644 --- a/src/objc/imap/MCOIMAP.h +++ b/src/objc/imap/MCOIMAP.h @@ -22,6 +22,8 @@ #import <MailCore/MCOIMAPPart.h> #import <MailCore/MCOIMAPFolderInfoOperation.h> #import <MailCore/MCOIMAPFolderInfo.h> +#import <MailCore/MCOIMAPFolderStatusOperation.h> +#import <MailCore/MCOIMAPFolderStatus.h> #import <MailCore/MCOIMAPAppendMessageOperation.h> #import <MailCore/MCOIMAPCopyMessagesOperation.h> #import <MailCore/MCOIMAPFetchMessagesOperation.h> diff --git a/src/objc/imap/MCOIMAPFolderInfo.h b/src/objc/imap/MCOIMAPFolderInfo.h index 39713e80..949e900e 100644 --- a/src/objc/imap/MCOIMAPFolderInfo.h +++ b/src/objc/imap/MCOIMAPFolderInfo.h @@ -31,6 +31,9 @@ /** Total number of messages in the folder */ @property (nonatomic, assign) int messageCount; +// first uid of the unseen messages. +@property (nonatomic, assign) uint32_t firstUnseenUid; + @end #endif diff --git a/src/objc/imap/MCOIMAPFolderInfo.m b/src/objc/imap/MCOIMAPFolderInfo.m index f23336bf..e39551a4 100644 --- a/src/objc/imap/MCOIMAPFolderInfo.m +++ b/src/objc/imap/MCOIMAPFolderInfo.m @@ -13,12 +13,14 @@ uint32_t _uidValidity; uint64_t _modSequenceValue; int _messageCount; + uint32_t _firstUnseenUid; } @synthesize uidNext = _uidNext; @synthesize uidValidity = _uidValidity; @synthesize modSequenceValue = _modSequenceValue; @synthesize messageCount = _messageCount; +@synthesize firstUnseenUid = _firstUnseenUid; + (MCOIMAPFolderInfo *) info { diff --git a/src/objc/imap/MCOIMAPFolderInfoOperation.mm b/src/objc/imap/MCOIMAPFolderInfoOperation.mm index fd555508..37b1a649 100644 --- a/src/objc/imap/MCOIMAPFolderInfoOperation.mm +++ b/src/objc/imap/MCOIMAPFolderInfoOperation.mm @@ -55,6 +55,8 @@ typedef void (^CompletionType)(NSError *error, MCOIMAPFolderInfo *info); [info setUidValidity:MCO_NATIVE_INSTANCE->uidValidity()]; [info setModSequenceValue:MCO_NATIVE_INSTANCE->modSequenceValue()]; [info setMessageCount:MCO_NATIVE_INSTANCE->messageCount()]; + [info setFirstUnseenUid:MCO_NATIVE_INSTANCE->firstUnseenUid()]; + _completionBlock(nil, info); } else { _completionBlock([NSError mco_errorWithErrorCode:op->error()], nil); diff --git a/src/objc/imap/MCOIMAPFolderStatus.h b/src/objc/imap/MCOIMAPFolderStatus.h new file mode 100644 index 00000000..9ee1813d --- /dev/null +++ b/src/objc/imap/MCOIMAPFolderStatus.h @@ -0,0 +1,43 @@ +// +// MCOIMAPFolderStatus.h +// mailcore2 +// +// Created by Sebastian on 6/5/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#ifndef __MAILCORE_MCOIMAPFOLDERSTATUS_H_ + +#define __MAILCORE_MCOIMAPFOLDERSTATUS_H_ + +#import <Foundation/Foundation.h> + +/* This class holds IMAP folder metadata */ + +@interface MCOIMAPFolderStatus : NSObject + +/** Create an empty instance */ ++ (MCOIMAPFolderStatus *) status; + +/** The folder's IMAP UIDNEXT value. Used to determine the uid for the next received message. */ +@property (nonatomic, assign) uint32_t uidNext; + +/** The folders IMAP UIDVALIDITY value. Must be used to determine if the server has changed assigned UIDs */ +@property (nonatomic, assign) uint32_t uidValidity; + +/** Number of recent messages received in the folder */ +@property (nonatomic, assign) uint32_t totalRecent; + +/** Number of unseen messages in the folder */ +@property (nonatomic, assign) uint32_t totalUnseen; + +// Number of messages in the folder +@property (nonatomic, assign) uint32_t totalMessages; + +// We need also the the folder path + + + +@end + +#endif diff --git a/src/objc/imap/MCOIMAPFolderStatus.m b/src/objc/imap/MCOIMAPFolderStatus.m new file mode 100644 index 00000000..ceab8a00 --- /dev/null +++ b/src/objc/imap/MCOIMAPFolderStatus.m @@ -0,0 +1,35 @@ +// +// MCOIMAPFolderStatus.m +// mailcore2 +// +// Created by Sebastian on 6/5/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#import "MCOIMAPFolderStatus.h" + + +@implementation MCOIMAPFolderStatus { + uint32_t total_unseen; + uint32_t total_messages; + uint32_t total_recent; + uint32_t _uidNext; + uint32_t _uidValidity; +} + +@synthesize uidNext = _uidNext; +@synthesize uidValidity = _uidValidity; +@synthesize totalMessages = total_messages; +@synthesize totalRecent = total_recent; +@synthesize totalUnseen = total_unseen; + + + ++ (MCOIMAPFolderStatus *) status +{ + return [[[MCOIMAPFolderStatus alloc] init] autorelease]; +} + + + +@end diff --git a/src/objc/imap/MCOIMAPFolderStatusOperation.h b/src/objc/imap/MCOIMAPFolderStatusOperation.h new file mode 100644 index 00000000..476b597d --- /dev/null +++ b/src/objc/imap/MCOIMAPFolderStatusOperation.h @@ -0,0 +1,39 @@ +// +// MCOIMAPFolderStatusOperation.h +// mailcore2 +// +// Created by Sebastian on 6/5/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#ifndef __MAILCORE_MCOIMAPFOLDERSTATUSOPERATION_H_ + +#define __MAILCORE_MCOIMAPFOLDERSTATUSOPERATION_H_ + +#import <MailCore/MCOIMAPBaseOperation.h> + +/** + The class is used to get folder metadata (like UIDVALIDITY, UIDNEXT, etc). + @see MCOIMAPFolderStatus + */ + +@class MCOIMAPFolderStatus; + +@interface MCOIMAPFolderStatusOperation : MCOIMAPBaseOperation + +/** + Starts the asynchronous operation. + + @param completionBlock Called when the operation is finished. + + - On success `error` will be nil and `status` will contain the status metadata + + - On failure, `error` will be set with `MCOErrorDomain` as domain and an + error code available in `MCOConstants.h`, `info` will be nil + */ + +- (void) start:(void (^)(NSError * error, MCOIMAPFolderStatus * status))completionBlock; + +@end + +#endif 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 diff --git a/src/objc/imap/MCOIMAPSession.h b/src/objc/imap/MCOIMAPSession.h index eec0d152..55295d89 100644 --- a/src/objc/imap/MCOIMAPSession.h +++ b/src/objc/imap/MCOIMAPSession.h @@ -17,6 +17,7 @@ @class MCOIMAPOperation; @class MCOIMAPNamespace; @class MCOIMAPFolderInfoOperation; +@class MCOIMAPFolderStatusOperation; @class MCOIMAPAppendMessageOperation; @class MCOIMAPCopyMessagesOperation; @class MCOIndexSet; @@ -113,6 +114,32 @@ ... }]; */ + + +/** + Returns an operation that retrieves folder status (like UIDNext - Unseen -) + + MCOIMAPFolderStatusOperation * op = [session folderStatusOperation:@"INBOX"]; + [op start:^(NSError *error, MCOIMAPFolderStatus * info) { + NSLog(@"UIDNEXT: %lu", (unsigned long) [info uidNext]); + NSLog(@"UIDVALIDITY: %lu", (unsigned long) [info uidValidity]); + NSLog(@"messages count: %lu", [info totalMessages]); + }]; + */ + +- (MCOIMAPFolderStatusOperation *) folderStatusOperation:(NSString *)folder; + +/** + Returns an operation that gets the list of subscribed folders. + + MCOIMAPFetchFoldersOperation * op = [session fetchAllFoldersOperation]; + [op start:^(NSError * error, NSArray * folders) { + ... + }]; + */ + + + - (MCOIMAPFetchFoldersOperation *) fetchSubscribedFoldersOperation; /** diff --git a/src/objc/imap/MCOIMAPSession.mm b/src/objc/imap/MCOIMAPSession.mm index 9f00d1e7..a13724ae 100644 --- a/src/objc/imap/MCOIMAPSession.mm +++ b/src/objc/imap/MCOIMAPSession.mm @@ -66,6 +66,12 @@ MCO_OBJC_SYNTHESIZE_SCALAR(unsigned int, unsigned int, setMaximumConnections, ma return MCO_TO_OBJC(coreOp); } +- (MCOIMAPFolderStatusOperation *) folderStatusOperation:(NSString *)folder +{ + IMAPFolderStatusOperation * coreOp = MCO_NATIVE_INSTANCE->folderStatusOperation([folder mco_mcString]); + return MCO_TO_OBJC(coreOp); +} + - (MCOIMAPFetchFoldersOperation *) fetchSubscribedFoldersOperation { IMAPOperation *coreOp = MCO_NATIVE_INSTANCE->fetchSubscribedFoldersOperation(); |