aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Hoà V. DINH <dinh.viet.hoa@gmail.com>2013-08-09 10:15:17 -0700
committerGravatar Hoà V. DINH <dinh.viet.hoa@gmail.com>2013-08-09 10:15:17 -0700
commit9bb099e06a626e6614628c25002a78ca7b2a01bf (patch)
tree6a6e1edc25854c5b32b3ead90e9157182ee14842 /src
parentd5ed180d3615e668a59d098156189616b596a67a (diff)
parent1e05ee7ea55905b26b4b9e8545c881f63b2cdf6f (diff)
Merge pull request #289 from soxjke/getQuotaBranch
Added quotaOperation to get used and total space in IMAP account.
Diffstat (limited to 'src')
-rwxr-xr-x[-rw-r--r--]src/async/imap/MCAsyncIMAP.h1
-rwxr-xr-x[-rw-r--r--]src/async/imap/MCIMAPAsyncConnection.cc9
-rwxr-xr-x[-rw-r--r--]src/async/imap/MCIMAPAsyncConnection.h2
-rwxr-xr-x[-rw-r--r--]src/async/imap/MCIMAPAsyncSession.cc6
-rwxr-xr-x[-rw-r--r--]src/async/imap/MCIMAPAsyncSession.h2
-rw-r--r--src/async/imap/MCIMAPQuotaOperation.cc41
-rw-r--r--src/async/imap/MCIMAPQuotaOperation.h39
-rwxr-xr-x[-rw-r--r--]src/core/imap/MCIMAPSession.cc35
-rwxr-xr-x[-rw-r--r--]src/core/imap/MCIMAPSession.h1
-rwxr-xr-x[-rw-r--r--]src/objc/imap/MCOIMAP.h1
-rw-r--r--src/objc/imap/MCOIMAPQuotaOperation.h15
-rw-r--r--src/objc/imap/MCOIMAPQuotaOperation.mm69
-rwxr-xr-x[-rw-r--r--]src/objc/imap/MCOIMAPSession.h3
-rwxr-xr-x[-rw-r--r--]src/objc/imap/MCOIMAPSession.mm6
14 files changed, 230 insertions, 0 deletions
diff --git a/src/async/imap/MCAsyncIMAP.h b/src/async/imap/MCAsyncIMAP.h
index a6bf40d0..66ba6c7b 100644..100755
--- a/src/async/imap/MCAsyncIMAP.h
+++ b/src/async/imap/MCAsyncIMAP.h
@@ -27,6 +27,7 @@
#include <MailCore/MCIMAPFetchNamespaceOperation.h>
#include <MailCore/MCIMAPIdentityOperation.h>
#include <MailCore/MCIMAPCapabilityOperation.h>
+#include <MailCore/MCIMAPQuotaOperation.h>
#include <MailCore/MCIMAPOperationCallback.h>
#include <MailCore/MCIMAPMessageRenderingOperation.h>
diff --git a/src/async/imap/MCIMAPAsyncConnection.cc b/src/async/imap/MCIMAPAsyncConnection.cc
index 85c411a8..1472d974 100644..100755
--- a/src/async/imap/MCIMAPAsyncConnection.cc
+++ b/src/async/imap/MCIMAPAsyncConnection.cc
@@ -30,6 +30,7 @@
#include "MCIMAPIdleOperation.h"
#include "MCIMAPIdentityOperation.h"
#include "MCIMAPCapabilityOperation.h"
+#include "MCIMAPQuotaOperation.h"
#include "MCOperationQueueCallback.h"
#include "MCIMAPDisconnectOperation.h"
#include "MCIMAPAsyncSession.h"
@@ -494,6 +495,14 @@ IMAPCapabilityOperation * IMAPAsyncConnection::capabilityOperation()
return op;
}
+IMAPQuotaOperation * IMAPAsyncConnection::quotaOperation()
+{
+ IMAPQuotaOperation * op = new IMAPQuotaOperation();
+ op->setSession(this);
+ op->autorelease();
+ return op;
+}
+
IMAPSession * IMAPAsyncConnection::session()
{
return mSession;
diff --git a/src/async/imap/MCIMAPAsyncConnection.h b/src/async/imap/MCIMAPAsyncConnection.h
index 45acb707..13f9ff7b 100644..100755
--- a/src/async/imap/MCIMAPAsyncConnection.h
+++ b/src/async/imap/MCIMAPAsyncConnection.h
@@ -25,6 +25,7 @@ namespace mailcore {
class IMAPFetchNamespaceOperation;
class IMAPIdentityOperation;
class IMAPCapabilityOperation;
+ class IMAPQuotaOperation;
class IMAPOperationQueueCallback;
class IMAPAsyncSession;
class IMAPConnectionLogger;
@@ -120,6 +121,7 @@ namespace mailcore {
virtual IMAPOperation * checkAccountOperation();
virtual IMAPCapabilityOperation * capabilityOperation();
+ virtual IMAPQuotaOperation * quotaOperation();
virtual IMAPMessageRenderingOperation * htmlRenderingOperation(IMAPMessage * message, String * folder);
virtual IMAPMessageRenderingOperation * htmlBodyRenderingOperation(IMAPMessage * message, String * folder);
diff --git a/src/async/imap/MCIMAPAsyncSession.cc b/src/async/imap/MCIMAPAsyncSession.cc
index 7aa37d83..26c0feca 100644..100755
--- a/src/async/imap/MCIMAPAsyncSession.cc
+++ b/src/async/imap/MCIMAPAsyncSession.cc
@@ -449,6 +449,12 @@ IMAPCapabilityOperation * IMAPAsyncSession::capabilityOperation()
return session->capabilityOperation();
}
+IMAPQuotaOperation * IMAPAsyncSession::quotaOperation()
+{
+ IMAPAsyncConnection * session = sessionForFolder(MCSTR("INBOX"));
+ return session->quotaOperation();
+}
+
void IMAPAsyncSession::setConnectionLogger(ConnectionLogger * logger)
{
mConnectionLogger = logger;
diff --git a/src/async/imap/MCIMAPAsyncSession.h b/src/async/imap/MCIMAPAsyncSession.h
index 68e8899a..e5c17078 100644..100755
--- a/src/async/imap/MCIMAPAsyncSession.h
+++ b/src/async/imap/MCIMAPAsyncSession.h
@@ -33,6 +33,7 @@ namespace mailcore {
class IMAPIdentityOperation;
class IMAPAsyncConnection;
class IMAPCapabilityOperation;
+ class IMAPQuotaOperation;
class IMAPMessageRenderingOperation;
class IMAPMessage;
@@ -133,6 +134,7 @@ namespace mailcore {
virtual IMAPOperation * checkAccountOperation();
virtual IMAPCapabilityOperation * capabilityOperation();
+ virtual IMAPQuotaOperation * quotaOperation();
virtual IMAPMessageRenderingOperation * htmlRenderingOperation(IMAPMessage * message, String * folder);
virtual IMAPMessageRenderingOperation * htmlBodyRenderingOperation(IMAPMessage * message, String * folder);
diff --git a/src/async/imap/MCIMAPQuotaOperation.cc b/src/async/imap/MCIMAPQuotaOperation.cc
new file mode 100644
index 00000000..6744ac4b
--- /dev/null
+++ b/src/async/imap/MCIMAPQuotaOperation.cc
@@ -0,0 +1,41 @@
+//
+// MCIMAPQuotaOperation.cc
+// mailcore2
+//
+// Created by Petro Korenev on 8/2/13.
+// Copyright (c) 2013 MailCore. All rights reserved.
+//
+
+#include "MCIMAPQuotaOperation.h"
+
+#include "MCIMAPSession.h"
+#include "MCIMAPAsyncConnection.h"
+
+using namespace mailcore;
+
+IMAPQuotaOperation::IMAPQuotaOperation()
+{
+ mLimit = 0;
+ mUsage = 0;
+}
+
+IMAPQuotaOperation::~IMAPQuotaOperation()
+{
+}
+
+uint32_t IMAPQuotaOperation::limit()
+{
+ return mLimit;
+}
+
+uint32_t IMAPQuotaOperation::usage()
+{
+ return mUsage;
+}
+
+void IMAPQuotaOperation::main()
+{
+ ErrorCode error;
+ session()->session()->getQuota(&mUsage, &mLimit, &error);
+ setError(error);
+}
diff --git a/src/async/imap/MCIMAPQuotaOperation.h b/src/async/imap/MCIMAPQuotaOperation.h
new file mode 100644
index 00000000..5cef943c
--- /dev/null
+++ b/src/async/imap/MCIMAPQuotaOperation.h
@@ -0,0 +1,39 @@
+//
+// MCIMAPQuotaOperation.h
+// mailcore2
+//
+// Created by Petro Korenev on 8/2/13.
+// Copyright (c) 2013 MailCore. All rights reserved.
+//
+
+#ifndef __MAILCORE_MCIMAPQuotaOperation_H_
+
+#define __MAILCORE_MCIMAPQuotaOperation_H_
+
+#include "MCIMAPOperation.h"
+
+#ifdef __cplusplus
+
+namespace mailcore {
+
+ class IMAPQuotaOperation : public IMAPOperation {
+ public:
+ IMAPQuotaOperation();
+ virtual ~IMAPQuotaOperation();
+
+ // Result.
+ virtual uint32_t limit();
+ virtual uint32_t usage();
+
+ public: // subclass behavior
+ virtual void main();
+
+ private:
+ uint32_t mLimit;
+ uint32_t mUsage;
+ };
+}
+
+#endif
+
+#endif
diff --git a/src/core/imap/MCIMAPSession.cc b/src/core/imap/MCIMAPSession.cc
index 7ebe4354..09f78ec1 100644..100755
--- a/src/core/imap/MCIMAPSession.cc
+++ b/src/core/imap/MCIMAPSession.cc
@@ -2471,6 +2471,41 @@ IndexSet * IMAPSession::search(String * folder, IMAPSearchExpression * expressio
return result;
}
+void IMAPSession::getQuota(uint32_t *usage, uint32_t *limit, ErrorCode * pError)
+{
+ static char * const inboxFolderName = "INBOX";
+ mailimap_quota_complete_data *quota_data;
+ selectIfNeeded(MCSTR("INBOX"), pError);
+
+ if (* pError != ErrorNone)
+ return;
+
+ int r = mailimap_quota_getquotaroot(mImap, inboxFolderName, &quota_data);
+ if (r == MAILIMAP_ERROR_STREAM) {
+ * pError = ErrorConnection;
+ return;
+ }
+ else if (r == MAILIMAP_ERROR_PARSE) {
+ * pError = ErrorParse;
+ return;
+ }
+ else if (hasError(r)) {
+ * pError = ErrorFetch;
+ return;
+ }
+ for(clistiter * cur = clist_begin(quota_data->quota_list); cur != NULL; cur = clist_next(cur)) {
+ mailimap_quota_quota_data *quota = (mailimap_quota_quota_data*)clist_content(cur);
+ for (clistiter *cur2 = clist_begin(quota->quota_list); cur2 != NULL; cur2 = clist_next(cur2)) {
+ mailimap_quota_quota_resource *res = (mailimap_quota_quota_resource*)clist_content(cur2);
+ if (!strcasecmp("STORAGE", res->resource_name)) {
+ *usage = res->usage;
+ *limit = res->limit;
+ }
+ }
+ }
+ mailimap_quota_complete_data_free(quota_data);
+}
+
bool IMAPSession::setupIdle()
{
// main thread
diff --git a/src/core/imap/MCIMAPSession.h b/src/core/imap/MCIMAPSession.h
index 4128b516..97567d65 100644..100755
--- a/src/core/imap/MCIMAPSession.h
+++ b/src/core/imap/MCIMAPSession.h
@@ -126,6 +126,7 @@ namespace mailcore {
virtual IndexSet * search(String * folder, IMAPSearchKind kind, String * searchString, ErrorCode * pError);
virtual IndexSet * search(String * folder, IMAPSearchExpression * expression, ErrorCode * pError);
+ virtual void getQuota(uint32_t *usage, uint32_t *limit, ErrorCode * pError);
virtual bool setupIdle();
virtual void idle(String * folder, uint32_t lastKnownUID, ErrorCode * pError);
diff --git a/src/objc/imap/MCOIMAP.h b/src/objc/imap/MCOIMAP.h
index f0994042..e2036291 100644..100755
--- a/src/objc/imap/MCOIMAP.h
+++ b/src/objc/imap/MCOIMAP.h
@@ -36,6 +36,7 @@
#import <MailCore/MCOIMAPFetchNamespaceOperation.h>
#import <MailCore/MCOIMAPIdentityOperation.h>
#import <MailCore/MCOIMAPCapabilityOperation.h>
+#import <MailCore/MCOIMAPQuotaOperation.h>
#import <MailCore/MCOIMAPSearchExpression.h>
#import <MailCore/MCOIMAPMessageRenderingOperation.h>
diff --git a/src/objc/imap/MCOIMAPQuotaOperation.h b/src/objc/imap/MCOIMAPQuotaOperation.h
new file mode 100644
index 00000000..c0463bb0
--- /dev/null
+++ b/src/objc/imap/MCOIMAPQuotaOperation.h
@@ -0,0 +1,15 @@
+//
+// MCOIMAPQuotaOperation.h
+// mailcore2
+//
+// Created by Petro Korenev on 8/2/13.
+// Copyright (c) 2013 MailCore. All rights reserved.
+//
+
+#import "MCOIMAPBaseOperation.h"
+
+@interface MCOIMAPQuotaOperation : MCOIMAPBaseOperation
+
+- (void) start:(void (^)(NSError * error, NSUInteger usage, NSUInteger limit))completionBlock;
+
+@end
diff --git a/src/objc/imap/MCOIMAPQuotaOperation.mm b/src/objc/imap/MCOIMAPQuotaOperation.mm
new file mode 100644
index 00000000..5be2571f
--- /dev/null
+++ b/src/objc/imap/MCOIMAPQuotaOperation.mm
@@ -0,0 +1,69 @@
+//
+// MCOIMAPQuotaOperation.m
+// mailcore2
+//
+// Created by Petro Korenev on 8/2/13.
+// Copyright (c) 2013 MailCore. All rights reserved.
+//
+
+#import "MCOIMAPQuotaOperation.h"
+
+#include "MCAsyncIMAP.h"
+
+#import "MCOOperation+Private.h"
+#import "MCOUtils.h"
+
+typedef void (^CompletionType)(NSError *error, NSUInteger usage, NSUInteger limit);
+
+@implementation MCOIMAPQuotaOperation {
+ CompletionType _completionBlock;
+}
+
+#define nativeType mailcore::IMAPQuotaOperation
+
++ (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, NSUInteger usage, NSUInteger limit))completionBlock
+{
+ _completionBlock = [completionBlock copy];
+ [self start];
+}
+
+- (void) cancel
+{
+ [_completionBlock release];
+ _completionBlock = nil;
+ [super cancel];
+}
+
+- (void) operationCompleted
+{
+ if (_completionBlock == NULL)
+ return;
+
+ nativeType *op = MCO_NATIVE_INSTANCE;
+ if (op->error() == mailcore::ErrorNone) {
+ _completionBlock(nil, op->usage(), op->limit());
+ } else {
+ _completionBlock([NSError mco_errorWithErrorCode:op->error()], 0, 0);
+ }
+ [_completionBlock release];
+ _completionBlock = nil;
+}
+
+@end
diff --git a/src/objc/imap/MCOIMAPSession.h b/src/objc/imap/MCOIMAPSession.h
index 5db608f7..ea920114 100644..100755
--- a/src/objc/imap/MCOIMAPSession.h
+++ b/src/objc/imap/MCOIMAPSession.h
@@ -29,6 +29,7 @@
@class MCOIMAPSearchExpression;
@class MCOIMAPIdentityOperation;
@class MCOIMAPCapabilityOperation;
+@class MCOIMAPQuotaOperation;
@class MCOIMAPMessageRenderingOperation;
@class MCOIMAPMessage;
@@ -507,6 +508,8 @@
*/
- (MCOIMAPCapabilityOperation *) capabilityOperation;
+- (MCOIMAPQuotaOperation *) quotaOperation;
+
/** @name Search Operations */
/**
diff --git a/src/objc/imap/MCOIMAPSession.mm b/src/objc/imap/MCOIMAPSession.mm
index 2546e612..a9bbeb5c 100644..100755
--- a/src/objc/imap/MCOIMAPSession.mm
+++ b/src/objc/imap/MCOIMAPSession.mm
@@ -362,6 +362,12 @@ MCO_OBJC_SYNTHESIZE_SCALAR(unsigned int, unsigned int, setMaximumConnections, ma
return MCO_TO_OBJC_OP(coreOp);
}
+- (MCOIMAPQuotaOperation *) quotaOperation
+{
+ IMAPQuotaOperation * coreOp = MCO_NATIVE_INSTANCE->quotaOperation();
+ return MCO_TO_OBJC_OP((IMAPOperation*)coreOp);
+}
+
- (void) _logWithSender:(void *)sender connectionType:(MCOConnectionLogType)logType data:(NSData *)data
{
_connectionLogger(sender, logType, data);