aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc/imap/MCOIMAPSession.h
blob: 99d67532959a49b034d502b1f7be02860dd2c433 (plain)
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
//
//  MCOIMAPSession.h
//  mailcore2
//
//  Created by Matt Ronge on 1/31/13.
//  Copyright (c) 2013 MailCore. All rights reserved.
//

#ifndef __MAILCORE_MCOIMAPSESSION_H_

#define __MAILCORE_MCOIMAPSESSION_H_

#import <Foundation/Foundation.h>
#import <MailCore/MCOConstants.h>

@class MCOIMAPFetchFoldersOperation;
@class MCOIMAPOperation;
@class MCOIMAPNamespace;
@class MCOIMAPFolderInfoOperation;
@class MCOIMAPAppendMessageOperation;
@class MCOIMAPCopyMessagesOperation;
@class MCOIndexSet;
@class MCOIMAPFetchMessagesOperation;
@class MCOIMAPFetchContentOperation;
@class MCOIMAPSearchOperation;
@class MCOIMAPIdleOperation;
@class MCOIMAPFetchNamespaceOperation;
@class MCOIMAPSearchExpression;
@class MCOIMAPIdentityOperation;
@class MCOIMAPCapabilityOperation;

// This class implements asynchronous IMAP protocol.

@interface MCOIMAPSession : NSObject

// This is the hostname of the POP3 server to connect to.
@property (nonatomic, strong) NSString *hostname;

// This is the port of the IMAP server to connect to.
@property (nonatomic, assign) unsigned int port;

// This is the username of the account.
@property (nonatomic, strong) NSString *username;

// This is the password of the account.
@property (nonatomic, strong) NSString *password;

// This is the authentication type to use to connect.
// MCOAuthTypeSASLNone means that it uses the clear-text password authentication.
// It's the default.
// Note: However, over a encrypted connection, the password will be safe.
@property (nonatomic, assign) MCOAuthType authType;

// This is the encryption type to use.
// See MCOConnectionType for more information.
@property (nonatomic, assign) MCOConnectionType connectionType;

// This is the timeout of the connection.
@property (nonatomic, assign) NSTimeInterval timeout;

// When set to YES, the connection will fail if the certificate is incorrect.
@property (nonatomic, assign) BOOL checkCertificateEnabled;

// When set to YES, VoIP capability will be enabled on the IMAP connection on iOS.
@property (nonatomic, assign, getter=isVoIPEnabled) BOOL VoIPEnabled;

// The default delimiter for the folder paths.
@property (nonatomic, assign) char delimiter;

// The default namespace.
@property (nonatomic, strong) MCOIMAPNamespace * defaultNamespace;

// When set to YES, the session is allowed open to open several connections
// to the same folder.
@property (nonatomic, assign) BOOL allowsFolderConcurrentAccessEnabled;

// Maximum number of connections to the server allowed.
@property (nonatomic, assign) unsigned int maximumConnections;

// Returns a request operation for some info of the folder
// The operation needs to be started.
// (uidNext uidValidity, modSequenceValue, messageCount).
//
// {
//   ...
//   MCOIMAPFolderInfoOperation * op = [session folderInfoOperation:@"INBOX"];
//   [op start:^(NSError *error, MCOIMAPFolderInfo * info) {
//        NSLog(@"UIDNEXT: %lu", (unsigned long) [info uidNext]);
//        NSLog(@"UIDVALIDITY: %lu", (unsigned long) [info uidValidity]);
//        NSLog(@"HIGHESTMODSEQ: %llu", (unsigned long long) [info modSequenceValue]);
//        NSLog(@"messages count: %lu", [info messageCount]);
//   }]];
//
- (MCOIMAPFolderInfoOperation *) folderInfoOperation:(NSString *)folder;

// Returns an operation to fetch subscribed folders.
// The operation needs to be started.
//
// {
//   ...
//   MCOIMAPFetchFoldersOperation * op = [session fetchAllFoldersOperation];
//   [op start:^(NSError * error, NSArray * /* MCOIMAPFolder */ folders) {
//        ...
//   }]];
//
- (MCOIMAPFetchFoldersOperation *) fetchSubscribedFoldersOperation;

// Returns an operation to fetch all folders.
// The operation needs to be started.
//
// {
//   ...
//   MCOIMAPFetchFoldersOperation * op = [session fetchAllFoldersOperation];
//   [op start:^(NSError * error, NSArray * /* MCOIMAPFolder */ folders) {
//        ...
//   }]];
//
- (MCOIMAPFetchFoldersOperation *) fetchAllFoldersOperation;

// Returns an operation to rename a folder.
// The operation needs to be started.
//
// {
//   ...
//   MCOIMAPOperation * op = [session renameFolderOperation:@"my documents" otherName:@"Documents"];
//   [op start:^(NSError * error) {
//        ...
//   }]];
//
- (MCOIMAPOperation *) renameFolderOperation:(NSString *)folder otherName:(NSString *)otherName;

// Returns an operation to delete a folder.
// The operation needs to be started.
//
// {
//   ...
//   MCOIMAPOperation * op = [session deleteFolderOperation:@"holidays 2009"];
//   [op start:^(NSError * error) {
//        ...
//   }]];
//
- (MCOIMAPOperation *) deleteFolderOperation:(NSString *)folder;

// Returns an operation to create a folder.
// The operation needs to be started.
//
// {
//   ...
//   MCOIMAPOperation * op = [session createFolderOperation:@"holidays 2013"];
//   [op start:^(NSError * error) {
//        ...
//   }];
//
- (MCOIMAPOperation *) createFolderOperation:(NSString *)folder;

// Returns an operation to subscribe a folder.
// The operation needs to be started.
//
// {
//   ...
//   MCOIMAPOperation * op = [session createFolderOperation:@"holidays 2013"];
//   [op start:^(NSError * error) {
//     if (error != nil)
//       return;
//     MCOIMAPOperation * op = [session subscribeFolderOperation:@"holidays 2013"] {
//     ...
//     }];
//   }]];
//
- (MCOIMAPOperation *) subscribeFolderOperation:(NSString *)folder;

// Returns an operation to unsubscribe a folder.
// The operation needs to be started.
//
// {
//   ...
//   MCOIMAPOperation * op = [session unsubscribeFolderOperation:@"holidays 2009"];
//   [op start:^(NSError * error) {
//     if (error != nil)
//       return;
//     MCOIMAPOperation * op = [session deleteFolderOperation:@"holidays 2009"] {
//     ...
//     }];
//   }]];
//
- (MCOIMAPOperation *) unsubscribeFolderOperation:(NSString *)folder;

// Returns an operation to add a message to a folder.
// The operation needs to be started.
// {
//   ...
//   MCOIMAPOperation * op = [session appendMessageOperationWithFolder:@"Sent Mail" messageData:rfc822Data flags:MCOMessageFlagNone];
//   [op start:^(NSError * error, uint32_t createdUID) {
//     if (error == nil) {
//       NSLog(@"created message with UID %lu", (unsigned long) createdUID);
//     }
//   }];
//
- (MCOIMAPAppendMessageOperation *)appendMessageOperationWithFolder:(NSString *)folder
                                                        messageData:(NSData *)messageData
                                                              flags:(MCOMessageFlag)flags;

// Returns an operation to copy messages to a folder.
// The operation needs to be started.
//
// {
//   ...
//   MCOIMAPCopyMessagesOperation * op = [session copyMessagesOperationWithFolder:@"INBOX"
//                                                                           uids:[MCIndexSet indexSetWithIndex:456]
//                                                                     destFolder:@"Cocoa"];
//   [op start:^(NSError * error, MCOIndexSet * destUids) {
//        NSLog(@"copied to folder with UID %@", destUids);
//   }];
//
- (MCOIMAPCopyMessagesOperation *)copyMessagesOperationWithFolder:(NSString *)folder
                                                             uids:(MCOIndexSet *)uids
                                                       destFolder:(NSString *)destFolder;


// Returns an operation to expunge a folder.
// The operation needs to be started.
//
// {
//   ...
//   MCOIMAPOperation * op = [session expungeOperation:@"INBOX"];
//   [op start:^(NSError * error) {
//        ...
//   }];
//
- (MCOIMAPOperation *) expungeOperation:(NSString *)folder;

// Returns an operation to fetch messages by UID.
// The operation needs to be started.
//
// {
//   ...
//   MCOIMAPFetchMessagesOperation * op = [session fetchMessagesByUIDOperationWithFolder:@"INBOX"
//                                                                           requestKind:MCOIMAPMessagesRequestKindHeaders | MCOIMAPMessagesRequestKindStructure
//                                                                                  uids:MCORangeMake(1, UINT64_MAX)];
//   [op start:^(NSError * error, NSArray * /* MCOIMAPMessage */ messages, MCOIndexSet * vanishedMessages) {
//      for(MCOIMAPMessage * msg in messages) {
//        NSLog(@"%lu: %@", [msg uid], [msg header]);
//      }
//   }];
//
- (MCOIMAPFetchMessagesOperation *) fetchMessagesByUIDOperationWithFolder:(NSString *)folder
                                                              requestKind:(MCOIMAPMessagesRequestKind)requestKind
                                                                     uids:(MCOIndexSet *)uids;

// Returns an operation to fetch messages by number.
// The operation needs to be started.
//
// {
//   ...
//   // show 50 most recent uids.
//   MCOIMAPFetchMessagesOperation * op = [session fetchMessagesByNumberOperationWithFolder:@"INBOX"
//                                                                              requestKind:MCOIMAPMessagesRequestKindUID
//                                                                                     uids:MCORangeMake(messageCount - 50, messageCount)];
//   [op start:^(NSError * error, NSArray * /* MCOIMAPMessage */ messages, MCOIndexSet * vanishedMessages) {
//      for(MCOIMAPMessage * msg in messages) {
//        NSLog(@"%lu", [msg uid]);
//      }
//   }];
//
- (MCOIMAPFetchMessagesOperation *) fetchMessagesByNumberOperationWithFolder:(NSString *)folder
                                                                 requestKind:(MCOIMAPMessagesRequestKind)requestKind
                                                                     numbers:(MCOIndexSet *)numbers;

// Returns an operation to sync the last changes related to the given message list given a modSeq.
// The operation needs to be started.
//
// {
//   ...
//   MCOIMAPFetchMessagesOperation * op = [session syncMessagesByUIDWithFolder:@"INBOX"
//                                                                 requestKind:MCOIMAPMessagesRequestKindUID
//                                                                        uids:MCORangeMake(1, UINT64_MAX)
//                                                                      modSeq:lastModSeq];
//   [op start:^(NSError * error, NSArray * /* MCOIMAPMessage */ messages, MCOIndexSet * vanishedMessages) {
//     NSLog(@"added or modified messages: %@", messages);
//     NSLog(@"deleted messages: %@", vanishedMessages);
//   }];
//
- (MCOIMAPFetchMessagesOperation *) syncMessagesByUIDWithFolder:(NSString *)folder
                                                    requestKind:(MCOIMAPMessagesRequestKind)requestKind
                                                           uids:(MCOIndexSet *)uids
                                                         modSeq:(uint64_t)modSeq;

// Returns an operation to fetch the content of a message.
// The operation needs to be started.
// If urgent is set to YES, an additional connection to the same folder might be opened to fetch the content.
//
// {
//   ...
//   MCOIMAPFetchContentOperation * op = [session fetchMessageByUIDOperationWithFolder:@"INBOX" uid:456 urgent:NO];
//   [op start:^(NSError * error, NSData * messageData) {
//      MCOMessageParser * parser = [MCOMessageParser messageParserWithData:messageData]
//      ...
//   }];
//
- (MCOIMAPFetchContentOperation *) fetchMessageByUIDOperationWithFolder:(NSString *)folder
                                                                    uid:(uint32_t)uid
                                                                 urgent:(BOOL)urgent;

// Returns an operation to fetch the content of a message.
// The operation needs to be started.
//
// {
//   ...
//   MCOIMAPFetchContentOperation * op = [session fetchMessageByUIDOperationWithFolder:@"INBOX" uid:456];
//   [op start:^(NSError * error, NSData * messageData) {
//      MCOMessageParser * parser = [MCOMessageParser messageParserWithData:messageData]
//      ...
//   }];
//
- (MCOIMAPFetchContentOperation *) fetchMessageByUIDOperationWithFolder:(NSString *)folder
                                                                    uid:(uint32_t)uid;

// Returns an operation to fetch an attachment.
// The operation needs to be started.
// If urgent is set to YES, an additional connection to the same folder might be opened to fetch the content.
//
// {
//   ...
//   MCOIMAPFetchContentOperation * op = [session fetchMessageAttachmentByUIDOperationWithFolder:@"INBOX"
//                                                                                           uid:456
//                                                                                        partID:@"1.2"
//                                                                                      encoding:MCOEncodingBase64
//                                                                                        urgent:YES];
//   [op start:^(NSError * error, NSData * partData) {
//      ...
//   }];
//
- (MCOIMAPFetchContentOperation *) fetchMessageAttachmentByUIDOperationWithFolder:(NSString *)folder
                                                                              uid:(uint32_t)uid
                                                                           partID:(NSString *)partID
                                                                         encoding:(MCOEncoding)encoding
                                                                           urgent:(BOOL)urgent;

// Returns an operation to fetch an attachment.
// The operation needs to be started.
//
// Example 1:
// {
//   ...
//   MCOIMAPFetchContentOperation * op = [session fetchMessageAttachmentByUIDOperationWithFolder:@"INBOX"
//                                                                                           uid:456
//                                                                                        partID:@"1.2"
//                                                                                      encoding:MCOEncodingBase64];
//   [op start:^(NSError * error, NSData * partData) {
//      ...
//   }];
//
// Example 2:
// {
//   ...
//   MCOIMAPFetchContentOperation * op = [session fetchMessageAttachmentByUIDOperationWithFolder:@"INBOX"
//                                                                                           uid:[message uid]
//                                                                                        partID:[part partID]
//                                                                                      encoding:[part encoding]];
//   [op start:^(NSError * error, NSData * partData) {
//      ...
//   }];
//
- (MCOIMAPFetchContentOperation *) fetchMessageAttachmentByUIDOperationWithFolder:(NSString *)folder
                                                                              uid:(uint32_t)uid
                                                                           partID:(NSString *)partID
                                                                         encoding:(MCOEncoding)encoding;

// Returns an operation to change flags of messages.
// The operation needs to be started.
//
// Adds the seen flag to the message with UID 456.
// {
//   ...
//   MCOIMAPOperation * op = [session storeFlagsOperationWithFolder:@"INBOX"
//                                                             uids:[MCOIndexSet indexSetWithIndex:456]
//                                                             kind:MCOIMAPStoreFlagsRequestKindAdd
//                                                            flags:MCOMessageFlagSeen];
//   [op start:^(NSError * error) {
//        ...
//   }];
//
- (MCOIMAPOperation *) storeFlagsOperationWithFolder:(NSString *)folder
                                                uids:(MCOIndexSet *)uids
                                                kind:(MCOIMAPStoreFlagsRequestKind)kind
                                               flags:(MCOMessageFlag)flags;

// Returns an operation to change labels of messages.
// The operation needs to be started.
//
// Adds the label "Home" flag to the message with UID 456.
// {
//   ...
//   MCOIMAPOperation * op = [session storeFlagsOperationWithFolder:@"INBOX"
//                                                             uids:[MCOIndexSet indexSetWithIndex:456]
//                                                             kind:MCOIMAPStoreFlagsRequestKindAdd
//                                                           labels:[NSArray arrayWithObject:@"Home"]];
//   [op start:^(NSError * error) {
//        ...
//   }];
//
- (MCOIMAPOperation *) storeLabelsOperationWithFolder:(NSString *)folder
                                                 uids:(MCOIndexSet *)uids
                                                 kind:(MCOIMAPStoreFlagsRequestKind)kind
                                               labels:(NSArray *)labels;

// Returns an operation to search for messages with a simple match.
// The operation needs to be started.
//
//   ...
//   MCOIMAPSearchOperation * op = [session searchOperationWithFolder:@"INBOX"
//                                                               kind:MCOIMAPSearchKindFrom
//                                                       searchString:@"laura"];
//   [op start:^(NSError * error, MCOIndexSet * searchResult) {
//        ...
//   }];
//
- (MCOIMAPSearchOperation *) searchOperationWithFolder:(NSString *)folder
                                                  kind:(MCOIMAPSearchKind)kind
                                          searchString:(NSString *)searchString;

// Returns an operation to search for messages.
// The operation needs to be started.
//
//   ...
//   MCOIMAPSearchExpression * expr = [MCOIMAPSearchExpression searchFrom:@"laura@etpan.org"]
//   MCOIMAPSearchOperation * op = [session searchExpressionOperationWithFolder:@"INBOX"
//                                                                   expression:expr];
//   [op start:^(NSError * error, MCOIndexSet * searchResult) {
//        ...
//   }];
//
- (MCOIMAPSearchOperation *) searchExpressionOperationWithFolder:(NSString *)folder
                                                      expression:(MCOIMAPSearchExpression *)expression;

// Returns an operation to wait for something to happen in the folder.
// The operation needs to be started.
//
//   ...
//   MCOIMAPIdleOperation * op = [session idleOperationWithFolder:@"INBOX"
//                                                   lastKnownUID:0];
//   [op start:^(NSError * error) {
//        ...
//   }];
//
- (MCOIMAPIdleOperation *) idleOperationWithFolder:(NSString *)folder
                                      lastKnownUID:(uint32_t)lastKnownUID;

// Returns an operation to fetch the list of namespaces.
// The operation needs to be started.
//
//   ...
//   MCOIMAPFetchNamespaceOperation * op = [session fetchNamespaceOperation];
//   [op start:^(NSError * error, NSDictionary * namespaces) {
//     if (error != nil)
//       return;
//     MCOIMAPNamespace * ns = [namespace objectForKey:MCOIMAPNamespacePersonal];
//     NSString * path = [ns pathForComponents:[NSArray arrayWithObject:]];
//     MCOIMAPOperation * createOp = [session createFolderOperation:foobar];
//     [createOp start:^(NSError * error) {
//       ...
//     }];
//   }];
//
- (MCOIMAPFetchNamespaceOperation *) fetchNamespaceOperation;

// Returns an operation to send/get identity.
// The operation needs to be started.
//
//   ...
//   MCOIMAPIdentityOperation * op = [session identityOperationWithVendor:@"Mozilla"
//                                                                   name:@"Thunderbird"
//                                                                version:@"17.0.5"];
//   [op start:^(NSError * error, NSDictionary * serverIdentity) {
//        ...
//   }];
//
- (MCOIMAPIdentityOperation *) identityOperationWithVendor:(NSString *)vendor
                                                      name:(NSString *)name
                                                   version:(NSString *)version;

// Returns an operation that will check whether the IMAP account is valid.
// The operation needs to be started.
//
// {
//   ...
//   MCOIMAPOperation * op = [session checkAccountOperation];
//   [op start:^(NSError * error) {
//        ...
//   }]];
//
- (MCOIMAPOperation *) checkAccountOperation;

// Returns an operation to request capabilities of the server.
// See MCOIMAPCapability for the list of capabilities.
// The operation needs to be started.
//
// {
//   ...
//   canIdle = NO;
//   MCOIMAPCapabilityOperation * op = [session capabilityOperation];
//   [op start:^(NSError * error, MCOIndexSet * capabilities) {
//     if ([capabilities containsIndex:MCOIMAPCapabilityIdle]) {
//       canIdle = YES;
//     }
//   }]];
//
- (MCOIMAPCapabilityOperation *) capabilityOperation;

@end

#endif