IOS-2659 cleans code, API and encapsulation.

IOS-2659
Andreas Buff 2 years ago
parent 49363f08d2
commit d47ae7b490

@ -185,7 +185,7 @@ extern NSString * _Nonnull PantomimeMessageStoreFailed;
If there are new messages: list of UIDs of the new messages
Otherwize: the UID of the last message that exists on server (that is already fetched)
*/
- (void)fetchUidsForNewMailsIgnoringMessagesWithHeaderDefined:(NSArray<NSString*> *_Nullable)headersToIgnore;
- (void)fetchUidsForNewMails;
#pragma mark - FLAGS

@ -101,7 +101,7 @@ typedef enum {
IMAP_UID_FETCH_FLAGS, //26
IMAP_UID_FETCH_HEADER_FIELDS_NOT, //27
IMAP_UID_FETCH_RFC822, //28
IMAP_UID_FETCH_UIDS_IGNORING_HEADERS, //29
IMAP_UID_FETCH_UIDS, //29
IMAP_UID_SEARCH, //30
IMAP_UID_SEARCH_ALL, //31
IMAP_UID_SEARCH_ANSWERED, //32

@ -253,15 +253,26 @@ static NSString *CRLF = @"\r\n";
- (void)test_uniqueIdentifiersFromFetchUidsResponseData
{
NSDictionary *testInputs = @{@"* 9 FETCH (UID 9 BODY[HEADER.FIELDS (pEp-auto-consume)] {0}": @[@(9)],
@"* 9 FETCH (UID 91 BODY[HEADER.FIELDS (pEp-auto-consume)] {0}": @[@(91)],
@"* 9 FETCH (UID 191 BODY[HEADER.FIELDS (pEp-auto-consume)] {0}": @[@(191)],
@"* 3 FETCH (UID 3819 BODY[HEADER.FIELDS (PEP-AUTO-CONSUME)] {2}": @[@(3819)],
@"": @[],
@"* 10 FETCH (UID 10 BODY[HEADER.FIELDS (pEp-auto-consume)] {23}": @[@(10)],
@"* 5 FETCH (UID 666 BODY[HEADER.FIELDS (PEP-AUTO-CONSUME)] {25}": @[@(666)],
@"* 5 FETCH (UID INVALID_BUT_SHOULD_PARSE_AS_WELL ANYWAY BODY[HEADER.FIELDS (PEP-AUTO-CONSUME)] {25}": @[],
@"* 5 FETCH (UID 1 AND UID 2 INVALID_BUT_SHOULD_PARSE_AS_WELL ANYWAY BODY[HEADER.FIELDS (PEP-AUTO-CONSUME)] {25}": @[@(1), @(2)]
NSDictionary *testInputs = @{@"* 1 FETCH (UID 1)": @[@(1)],
@"* 1 FETCH (UID 12)": @[@(12)],
@"* 1 FETCH (UID 123)": @[@(123)],
@"* 1 FETCH (UID 1234)": @[@(1234)],
@"* 1 FETCH (UID 12345)": @[@(12345)],
@"* 12 FETCH (UID 1)": @[@(1)],
@"* 12 FETCH (UID 12)": @[@(12)],
@"* 12 FETCH (UID 123)": @[@(123)],
@"* 12 FETCH (UID 1234)": @[@(1234)],
@"* 12 FETCH (UID 12345)": @[@(12345)],
@"* 123 FETCH (UID 1)": @[@(1)],
@"* 123 FETCH (UID 12)": @[@(12)],
@"* 123 FETCH (UID 123)": @[@(123)],
@"* 123 FETCH (UID 1234)": @[@(1234)],
@"* 123 FETCH (UID 12345)": @[@(12345)],
@"* 1235 FETCH (UID 1)": @[@(1)],
@"* 1235 FETCH (UID 12)": @[@(12)],
@"* 1235 FETCH (UID 123)": @[@(123)],
@"* 1235 FETCH (UID 1234)": @[@(1234)],
@"* 1235 FETCH (UID 12345)": @[@(12345)]
};
CWIMAPStore *store = [CWIMAPStore new];
for (int i = 0; i < testInputs.count; ++i) {

@ -397,28 +397,11 @@
Correct would be to fetch the headers and handle affected messages on a higher level.
We did it like this as the high level operation is extremely timing critical (background fetch).
*/
- (void)
fetchUidsForNewMailsIgnoringMessagesWithHeaderDefined:(NSArray<NSString*> *_Nullable)headersToIgnore;
- (void)fetchUidsForNewMails;
{
NSInteger lastUid = [self lastUID] ? [self lastUID] : 0;
NSInteger from = lastUid + 1;
if (!headersToIgnore || headersToIgnore.count == 0) {
[_store sendCommand: IMAP_UID_FETCH_UIDS_IGNORING_HEADERS info:nil arguments:@"UID FETCH %u:* (UID)", from];
} else {
NSMutableString *headers = [NSMutableString stringWithString:@""];
NSString *delimiter = @" ";
for (NSString *header in headersToIgnore) {
if (![headers isEqualToString:@""]) {
[headers appendString:delimiter];
}
[headers appendString:header];
}
[_store sendCommand: IMAP_UID_FETCH_UIDS_IGNORING_HEADERS
info:nil
arguments:@"UID FETCH %u:* (UID BODY.PEEK[HEADER.FIELDS (%@)])", from, headers];
}
[_store sendCommand: IMAP_UID_FETCH_UIDS info:nil arguments:@"UID FETCH %u:* (UID)", from];
}
#pragma mark -

@ -117,7 +117,7 @@ static inline int has_literal(char *buf, NSUInteger c)
- (void) _parseCAPABILITY;
- (void) _parseEXISTS;
- (void) _parseEXPUNGE;
- (void) _parseFETCH_UIDS_IGNORING_HEADERS;
- (void) _parseFETCH_UIDS;
- (void) _parseFETCH: (NSInteger) theMSN;
- (void) _parseLIST;
- (void) _parseLSUB;
@ -655,8 +655,8 @@ static inline int has_literal(char *buf, NSUInteger c)
{
switch (_lastCommand)
{
case IMAP_UID_FETCH_UIDS_IGNORING_HEADERS:
[self _parseFETCH_UIDS_IGNORING_HEADERS];
case IMAP_UID_FETCH_UIDS:
[self _parseFETCH_UIDS];
break;
default:
[self _parseFETCH: msn];
@ -1403,20 +1403,17 @@ static inline int has_literal(char *buf, NSUInteger c)
}
//
// This method parses a IMAP_UID_FETCH_UIDS_IGNORING_HEADERS response in order to decode
// This method parses a IMAP_UID_FETCH_UIDS response in order to decode
// all UIDs in the result.
//
// Examples:
// "* 9 FETCH (UID 9 BODY[HEADER.FIELDS (pEp-auto-consume)] {0}"
// "* 3 FETCH (UID 4808 BODY[HEADER.FIELDS (PEP-AUTO-CONSUME)] {2}"
// "* 170 FETCH (UID 95516)"
//
- (NSArray<NSNumber*> *)_uniqueIdentifiersFromFetchUidsResponseData:(NSData *)response
{
NSString *searchResponsePrefix = @"* X FETCH";
NSString *searchResponsePostfix = @"{*}";
return [self _uniqueIdentifiersFromData: response
skippingFirstNumberOfChars: searchResponsePrefix.length
skippingLastNumberOfChars: searchResponsePostfix.length];
skippingFirstNumberOfChars: searchResponsePrefix.length];
}
//
@ -1432,17 +1429,15 @@ static inline int has_literal(char *buf, NSUInteger c)
{
NSString *searchResponsePrefix = @"* SEARCH";
return [self _uniqueIdentifiersFromData: response
skippingFirstNumberOfChars: searchResponsePrefix.length
skippingLastNumberOfChars:0];
skippingFirstNumberOfChars: searchResponsePrefix.length];
}
- (NSArray<NSNumber*> *)_uniqueIdentifiersFromData:(NSData *)theData
skippingFirstNumberOfChars:(NSUInteger)numSkipPre
skippingLastNumberOfChars:(NSUInteger)numSkipPost
{
NSMutableArray<NSNumber*> *results = [NSMutableArray new];
if (numSkipPre + numSkipPost >= theData.length) {
if (numSkipPre >= theData.length) {
// Nothing to scan.
return results;
}
@ -1452,14 +1447,6 @@ static inline int has_literal(char *buf, NSUInteger c)
return results;
}
if (numSkipPost) {
theData = [theData subdataToIndex: theData.length - numSkipPost];
if (![theData length]) {
// Nothing to scan.
return results;
}
}
// We scan all our UIDs.
NSScanner *scanner = [[NSScanner alloc] initWithString: [theData asciiString]];
NSUInteger value = 0;
@ -1788,21 +1775,9 @@ static inline int has_literal(char *buf, NSUInteger c)
/**
Examples:
Message without the given header (pEp-auto-consume) defined:
"* 9 FETCH (UID 9 BODY[HEADER.FIELDS (pEp-auto-consume)] {0}"
"* 3 FETCH (UID 4808 BODY[HEADER.FIELDS (PEP-AUTO-CONSUME)] {2}"
Message with the given header (pEp-auto-consume) defined:
"* 10 FETCH (UID 10 BODY[HEADER.FIELDS (pEp-auto-consume)] {23}"
"* 5 FETCH (UID 4810 BODY[HEADER.FIELDS (PEP-AUTO-CONSUME)] {25}"
Note: Regarding the "{x}":
- The x is the lenght of the data of the fetched headers
- In case none of headersToIgnore is defined in the message, {0} is returned.
- Otherwize x > 0 is returned.
At least in theory. In practice (see example above "none of headersToIgnore" with x == 2)
"* 170 FETCH (UID 95516)"
*/
- (void) _parseFETCH_UIDS_IGNORING_HEADERS
- (void) _parseFETCH_UIDS
{
NSArray<NSNumber*> *uidsFromResponse =
[self _uniqueIdentifiersFromFetchUidsResponseData:[_responsesFromServer lastObject]];
@ -2764,7 +2739,7 @@ static inline int has_literal(char *buf, NSUInteger c)
break;
}
case IMAP_UID_FETCH_UIDS_IGNORING_HEADERS: {
case IMAP_UID_FETCH_UIDS: {
_connection_state.opening_mailbox = NO;
NSMutableDictionary *info = [NSMutableDictionary new];
if (_selectedFolder) {

Loading…
Cancel
Save