(fix) fixed EAS search for iOS devices

This commit is contained in:
Ludovic Marcotte
2016-09-22 12:54:37 -04:00
parent 677df619fd
commit ed4c2b3dca

View File

@@ -1384,13 +1384,13 @@ void handle_eas_terminate(int signum)
inResponse: (WOResponse *) theResponse
{
NSString *fileReference, *realCollectionId, *serverId, *bodyPreferenceType, *mimeSupport, *collectionId;
NSMutableString *s;
NSArray *fetchRequests;
id aFetch;
NSMutableString *s;
NSData *d;
int i;
id aFetch;
SOGoMicrosoftActiveSyncFolderType folderType;
int i;
s = [NSMutableString string];
@@ -1417,6 +1417,20 @@ void handle_eas_terminate(int signum)
aFetch = [fetchRequests objectAtIndex: i];
fileReference = [[[(id)[aFetch getElementsByTagName: @"FileReference"] lastObject] textValue] stringByUnescapingURL];
collectionId = [[(id)[theDocumentElement getElementsByTagName: @"CollectionId"] lastObject] textValue];
serverId = nil;
// We might not have a CollectionId in our request if the ItemOperation (Fetch) is for getting
// Search results with a LongId. Apple iOS does that.
if (!collectionId)
{
NSString *longId;
NSRange r;
longId = [[(id)[theDocumentElement getElementsByTagName: @"LongId"] lastObject] textValue];
r = [longId rangeOfString: @"+" options: NSBackwardsSearch];
collectionId = [longId substringToIndex: r.location];
serverId = [longId substringFromIndex: r.location+1];
}
// its either a itemOperation to fetch an attachment or an email
if ([fileReference length])
@@ -1494,7 +1508,12 @@ void handle_eas_terminate(int signum)
{
// fetch mail
realCollectionId = [self globallyUniqueIDToIMAPFolderName: realCollectionId type: folderType];
serverId = [[(id)[theDocumentElement getElementsByTagName: @"ServerId"] lastObject] textValue];
// ServerId might have been set if LongId was defined in the initial request. If not, it is
// a normal ItemOperations (Fetch) to get a complete email
if (!serverId)
serverId = [[(id)[theDocumentElement getElementsByTagName: @"ServerId"] lastObject] textValue];
bodyPreferenceType = [[(id)[[(id)[theDocumentElement getElementsByTagName: @"BodyPreference"] lastObject] getElementsByTagName: @"Type"] lastObject] textValue];
[context setObject: bodyPreferenceType forKey: @"BodyPreferenceType"];
mimeSupport = [[(id)[theDocumentElement getElementsByTagName: @"MIMESupport"] lastObject] textValue];
@@ -2783,7 +2802,7 @@ void handle_eas_terminate(int signum)
}
}
[s appendFormat: @"<Range>0-%d</Range>", total-1];
[s appendFormat: @"<Range>0-%d</Range>", (total ? total-1 : 0)];
[s appendFormat: @"<Total>%d</Total>", total];
[s appendString: @"</Store>"];
[s appendString: @"</Response>"];
@@ -2920,10 +2939,13 @@ void handle_eas_terminate(int signum)
total = [sortedUIDs count];
for (i = 0; i < total; i++)
{
itemId = [[sortedUIDs objectAtIndex: i] stringValue];
[s appendString: @"<Result xmlns=\"Search:\">"];
[s appendFormat: @"<LongId>%@+%@</LongId>", folderId, itemId];
[s appendFormat: @"<CollectionId xmlns=\"AirSyncBase:\">%@</CollectionId>", folderId];
[s appendString: @"<Properties>"];
itemId = [[sortedUIDs objectAtIndex: i] stringValue];
mailObject = [currentFolder lookupName: itemId inContext: context acquire: NO];
if ([mailObject isKindOfClass: [NSException class]])
@@ -2934,7 +2956,7 @@ void handle_eas_terminate(int signum)
[s appendFormat: @"</Result>"];
}
[s appendFormat: @"<Range>0-%d</Range>", total-1];
[s appendFormat: @"<Range>0-%d</Range>",(total ? total-1 : 0)];
[s appendFormat: @"<Total>%d</Total>", total];
[s appendString: @"</Store>"];
[s appendString: @"</Response>"];