Repository navigation
Expand file tree
/
Copy pathMCIMAPAsyncConnection.h
More file actions
190 lines (150 loc) · 7.65 KB
/
Copy pathMCIMAPAsyncConnection.h
File metadata and controls
190 lines (150 loc) · 7.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#ifndef MAILCORE_MCIMAPASYNCCONNECTION_H
#define MAILCORE_MCIMAPASYNCCONNECTION_H
#include <MailCore/MCBaseTypes.h>
#include <MailCore/MCMessageConstants.h>
#ifdef __cplusplus
namespace mailcore {
class IMAPOperation;
class IMAPFetchFoldersOperation;
class IMAPAppendMessageOperation;
class IMAPCopyMessagesOperation;
class IMAPFetchMessagesOperation;
class IMAPFetchContentOperation;
class IMAPFetchContentToFileOperation;
class IMAPFetchParsedContentOperation;
class IMAPIdleOperation;
class IMAPFolderInfoOperation;
class IMAPFolderStatusOperation;
class IMAPSession;
class IMAPNamespace;
class IMAPSearchOperation;
class IMAPSearchExpression;
class IMAPFetchNamespaceOperation;
class IMAPIdentityOperation;
class IMAPCapabilityOperation;
class IMAPQuotaOperation;
class IMAPOperationQueueCallback;
class IMAPAsyncSession;
class IMAPConnectionLogger;
class IMAPMessageRenderingOperation;
class IMAPMessage;
class IMAPIdentity;
class MAILCORE_EXPORT IMAPAsyncConnection : public Object {
public:
IMAPAsyncConnection();
virtual ~IMAPAsyncConnection();
virtual void setHostname(String * hostname);
virtual String * hostname();
virtual void setPort(unsigned int port);
virtual unsigned int port();
virtual void setUsername(String * username);
virtual String * username();
virtual void setPassword(String * password);
virtual String * password();
virtual void setOAuth2Token(String * token);
virtual String * OAuth2Token();
virtual void setAuthType(AuthType authType);
virtual AuthType authType();
virtual void setConnectionType(ConnectionType connectionType);
virtual ConnectionType connectionType();
virtual void setTimeout(time_t timeout);
virtual time_t timeout();
virtual void setCheckCertificateEnabled(bool enabled);
virtual bool isCheckCertificateEnabled();
virtual void setVoIPEnabled(bool enabled);
virtual bool isVoIPEnabled();
virtual void setQResyncCompatible(bool compatible);
virtual bool isQResyncCompatible();
virtual void setAutomaticConfigurationEnabled(bool enabled);
virtual bool isAutomaticConfigurationEnabled();
// Needs to be run before starting a connection.
virtual void setDefaultNamespace(IMAPNamespace * ns);
virtual IMAPNamespace * defaultNamespace();
virtual void setClientIdentity(IMAPIdentity * identity);
virtual IMAPIdentity * clientIdentity();
virtual void setConnectionLogger(ConnectionLogger * logger);
virtual ConnectionLogger * connectionLogger();
#if MC_HAS_GCD
virtual void setDispatchQueue(dispatch_queue_t dispatchQueue);
virtual dispatch_queue_t dispatchQueue();
#endif
virtual IMAPOperation * disconnectOperation();
// How long an idle connection stays open once its queue drains.
virtual void setAutomaticDisconnectDelay(time_t delay);
private:
IMAPSession * mSession;
OperationQueue * mQueue;
IMAPNamespace * mDefaultNamespace;
IMAPIdentity * mClientIdentity;
String * mLastFolder;
IMAPOperationQueueCallback * mQueueCallback;
IMAPAsyncSession * mOwner;
ConnectionLogger * mConnectionLogger;
IMAPConnectionLogger * mInternalLogger;
MCB_LOCK_TYPE mConnectionLoggerLock;
bool mAutomaticConfigurationEnabled;
bool mQueueRunning;
bool mScheduledAutomaticDisconnect;
// Guarded: the session writes these while acquiring or releasing, and reads them back
// from sessionWithMinQueue, which runs on whatever thread called IMAPOperation::start.
MCB_LOCK_TYPE mReservationLock;
bool mReserved;
unsigned int mLeaseGeneration;
time_t mAutomaticDisconnectDelay;
virtual void tryAutomaticDisconnectAfterDelay(void * context);
virtual void scheduleAutomaticDisconnectOnQueue(void * context);
public: // private
virtual void runOperation(IMAPOperation * operation);
virtual IMAPSession * session();
virtual void cancelAllOperations();
virtual bool interruptCurrentCommand(IMAPOperation * operation);
// Wall-clock moment of this connection's last successful LOGIN (see
// IMAPSession::lastLoginTime), 0 when it has never logged in.
virtual double lastLoginTime();
virtual unsigned int operationsCount();
// A reserved connection belongs to one lease holder: the session selection skips it,
// so only operations explicitly pointed at it (IMAPOperation::setSession) run there.
// reserve() fails on a connection already reserved; endLease() fails unless the
// connection is reserved under exactly that lease generation. Each is one step under the
// reservation lock, so a release racing an acquire from another thread cannot slip a
// check past a set - and endLease enqueues its disconnect before unreserving, so no
// newcomer lands ahead of it.
virtual bool reserve();
virtual bool endLease(unsigned int leaseGeneration, bool disconnect);
virtual bool isReserved();
// Counts the reservations this connection has had. Reserving bumps it, so a holder that
// remembers the value it saw can tell its own lease from the next one on the same
// connection — which is what stops a late release from cancelling somebody else's lease
// (see IMAPAsyncSession::releaseConnection).
virtual unsigned int leaseGeneration();
virtual void setLastFolder(String * folder);
virtual String * lastFolder();
virtual void tryAutomaticDisconnect();
// tryAutomaticDisconnect for a caller on a foreign thread - a lease release. The idle
// timer's bookkeeping (the scheduled flag, the owner retain it holds) is touched only
// from the connection's dispatch queue, where the timer fires and the drain re-arms it;
// this hops there instead of joining in from outside.
virtual void scheduleAutomaticDisconnect();
virtual void queueStartRunning();
virtual void queueStoppedRunning();
virtual void setOwner(IMAPAsyncSession * owner);
virtual IMAPAsyncSession * owner();
virtual void logConnection(ConnectionLogType logType, Data * buffer);
virtual bool isQueueRunning();
virtual void setQueueRunning(bool running);
// Whether the next command on this connection has to build it again before it can run -
// never connected, torn down, or left with a stream a failed command marked for teardown
// (see IMAPSession::needsReconnect). Declared last on purpose: this class is exported, and
// a virtual inserted among the existing ones would shift every vtable slot after it.
virtual bool needsReconnect();
// Makes the next command on this connection rebuild it first; same contract as
// IMAPSession::scheduleReconnect(). Declared last, like needsReconnect().
virtual void scheduleReconnect();
// Cuts this connection's stream whatever is running on it - IMAPSession::interruptCurrentCommand()
// without the queue's check that an operation is running. For tests, which need a cut that
// lands with nothing on the wire. Declared last, like needsReconnect().
virtual void cancelStream();
};
}
#endif
#endif