(fix) added global search for Android 6
parent
56e8883a94
commit
fcd61abc41
|
@ -829,7 +829,7 @@ void handle_eas_terminate(int signum)
|
||||||
[o setObjectType: ActiveSyncFolderCacheObject];
|
[o setObjectType: ActiveSyncFolderCacheObject];
|
||||||
[o setTableUrl: folderTableURL];
|
[o setTableUrl: folderTableURL];
|
||||||
|
|
||||||
foldersInCache = [o cacheEntriesForDeviceId: [context objectForKey: @"DeviceId"] newerThanVersion: -1];
|
foldersInCache = [o cacheEntriesForDeviceId: [context objectForKey: @"DeviceId"] newerThanVersion: -1];
|
||||||
|
|
||||||
// get guids of folders stored in cache
|
// get guids of folders stored in cache
|
||||||
for (i = 0; i < [foldersInCache count]; i++)
|
for (i = 0; i < [foldersInCache count]; i++)
|
||||||
|
@ -2893,6 +2893,7 @@ void handle_eas_terminate(int signum)
|
||||||
inResponse: (WOResponse *) theResponse
|
inResponse: (WOResponse *) theResponse
|
||||||
{
|
{
|
||||||
NSString *folderId, *realCollectionId, *itemId;
|
NSString *folderId, *realCollectionId, *itemId;
|
||||||
|
NSMutableArray *folderIdentifiers;
|
||||||
SOGoMailAccounts *accountsFolder;
|
SOGoMailAccounts *accountsFolder;
|
||||||
SOGoMailAccount *accountFolder;
|
SOGoMailAccount *accountFolder;
|
||||||
SOGoMailFolder *currentFolder;
|
SOGoMailFolder *currentFolder;
|
||||||
|
@ -2904,19 +2905,7 @@ void handle_eas_terminate(int signum)
|
||||||
NSData *d;
|
NSData *d;
|
||||||
|
|
||||||
SOGoMicrosoftActiveSyncFolderType folderType;
|
SOGoMicrosoftActiveSyncFolderType folderType;
|
||||||
int i, total;
|
int i, j, total;
|
||||||
|
|
||||||
// FIXME: support more than one CollectionId tag + DeepTraversal
|
|
||||||
folderId = [[(id)[[(id)[theDocumentElement getElementsByTagName: @"Query"] lastObject] getElementsByTagName: @"CollectionId"] lastObject] textValue];
|
|
||||||
realCollectionId = [folderId realCollectionIdWithFolderType: &folderType];
|
|
||||||
realCollectionId = [self globallyUniqueIDToIMAPFolderName: realCollectionId type: folderType];
|
|
||||||
|
|
||||||
userFolder = [[context activeUser] homeFolderInContext: context];
|
|
||||||
accountsFolder = [userFolder lookupName: @"Mail" inContext: context acquire: NO];
|
|
||||||
accountFolder = [accountsFolder lookupName: @"0" inContext: context acquire: NO];
|
|
||||||
currentFolder = [accountFolder lookupName: [NSString stringWithFormat: @"folder%@", realCollectionId]
|
|
||||||
inContext: context
|
|
||||||
acquire: NO];
|
|
||||||
|
|
||||||
// We build the qualifier and we launch our search operation
|
// We build the qualifier and we launch our search operation
|
||||||
qualifier = [self _qualifierFromMailboxSearchQuery: [(id)[theDocumentElement getElementsByTagName: @"Query"] lastObject]];
|
qualifier = [self _qualifierFromMailboxSearchQuery: [(id)[theDocumentElement getElementsByTagName: @"Query"] lastObject]];
|
||||||
|
@ -2927,13 +2916,45 @@ void handle_eas_terminate(int signum)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sortedUIDs = [currentFolder fetchUIDsMatchingQualifier: qualifier
|
// FIXME: support more than one CollectionId tag + DeepTraversal
|
||||||
sortOrdering: @"REVERSE ARRIVAL"
|
folderId = [[(id)[[(id)[theDocumentElement getElementsByTagName: @"Query"] lastObject] getElementsByTagName: @"CollectionId"] lastObject] textValue];
|
||||||
threaded: NO];
|
folderIdentifiers = [NSMutableArray array];
|
||||||
|
|
||||||
|
// Android 6 will send search requests with no collection ID - so we search in all folders.
|
||||||
|
if (!folderId)
|
||||||
|
{
|
||||||
|
NSArray *foldersInCache;
|
||||||
|
SOGoCacheGCSObject *o;
|
||||||
|
NSString *prefix;
|
||||||
|
|
||||||
|
o = [SOGoCacheGCSObject objectWithName: @"0" inContainer: nil];
|
||||||
|
[o setObjectType: ActiveSyncFolderCacheObject];
|
||||||
|
[o setTableUrl: folderTableURL];
|
||||||
|
|
||||||
|
foldersInCache = [o cacheEntriesForDeviceId: [context objectForKey: @"DeviceId"] newerThanVersion: -1];
|
||||||
|
prefix = [NSString stringWithFormat: @"/%@+folder", [context objectForKey: @"DeviceId"]];
|
||||||
|
|
||||||
|
for (i = 0; i < [foldersInCache count]; i++)
|
||||||
|
{
|
||||||
|
folderId = [foldersInCache objectAtIndex: i];
|
||||||
|
if ([folderId hasPrefix: prefix])
|
||||||
|
{
|
||||||
|
folderId = [NSString stringWithFormat: @"mail/%@", [folderId substringFromIndex: [prefix length]]];
|
||||||
|
[folderIdentifiers addObject: folderId];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[folderIdentifiers addObject: folderId];
|
||||||
|
}
|
||||||
|
|
||||||
|
userFolder = [[context activeUser] homeFolderInContext: context];
|
||||||
|
accountsFolder = [userFolder lookupName: @"Mail" inContext: context acquire: NO];
|
||||||
|
accountFolder = [accountsFolder lookupName: @"0" inContext: context acquire: NO];
|
||||||
|
|
||||||
// Prepare the response
|
// Prepare the response
|
||||||
s = [NSMutableString string];
|
s = [NSMutableString string];
|
||||||
|
|
||||||
[s appendString: @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"];
|
[s appendString: @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"];
|
||||||
[s appendString: @"<!DOCTYPE ActiveSync PUBLIC \"-//MICROSOFT//DTD ActiveSync//EN\" \"http://www.microsoft.com/\">"];
|
[s appendString: @"<!DOCTYPE ActiveSync PUBLIC \"-//MICROSOFT//DTD ActiveSync//EN\" \"http://www.microsoft.com/\">"];
|
||||||
[s appendString: @"<Search xmlns=\"Search:\">"];
|
[s appendString: @"<Search xmlns=\"Search:\">"];
|
||||||
|
@ -2942,22 +2963,36 @@ void handle_eas_terminate(int signum)
|
||||||
[s appendFormat: @"<Store>"];
|
[s appendFormat: @"<Store>"];
|
||||||
[s appendFormat: @"<Status>1</Status>"];
|
[s appendFormat: @"<Status>1</Status>"];
|
||||||
|
|
||||||
total = [sortedUIDs count];
|
for (i = 0; i < [folderIdentifiers count]; i++)
|
||||||
for (i = 0; i < total; i++)
|
|
||||||
{
|
{
|
||||||
itemId = [[sortedUIDs objectAtIndex: i] stringValue];
|
folderId = [folderIdentifiers objectAtIndex: i];
|
||||||
mailObject = [currentFolder lookupName: itemId inContext: context acquire: NO];
|
realCollectionId = [folderId realCollectionIdWithFolderType: &folderType];
|
||||||
|
realCollectionId = [self globallyUniqueIDToIMAPFolderName: realCollectionId type: folderType];
|
||||||
|
|
||||||
if ([mailObject isKindOfClass: [NSException class]])
|
currentFolder = [accountFolder lookupName: [NSString stringWithFormat: @"folder%@", realCollectionId]
|
||||||
continue;
|
inContext: context
|
||||||
|
acquire: NO];
|
||||||
|
|
||||||
[s appendString: @"<Result xmlns=\"Search:\">"];
|
sortedUIDs = [currentFolder fetchUIDsMatchingQualifier: qualifier
|
||||||
[s appendFormat: @"<LongId>%@+%@</LongId>", folderId, itemId];
|
sortOrdering: @"REVERSE ARRIVAL"
|
||||||
[s appendFormat: @"<CollectionId xmlns=\"AirSyncBase:\">%@</CollectionId>", folderId];
|
threaded: NO];
|
||||||
[s appendString: @"<Properties>"];
|
total = [sortedUIDs count];
|
||||||
[s appendFormat: [mailObject activeSyncRepresentationInContext: context]];
|
for (j = 0; j < total; j++)
|
||||||
[s appendString: @"</Properties>"];
|
{
|
||||||
[s appendFormat: @"</Result>"];
|
itemId = [[sortedUIDs objectAtIndex: j] stringValue];
|
||||||
|
mailObject = [currentFolder lookupName: itemId inContext: context acquire: NO];
|
||||||
|
|
||||||
|
if ([mailObject isKindOfClass: [NSException class]])
|
||||||
|
continue;
|
||||||
|
|
||||||
|
[s appendString: @"<Result xmlns=\"Search:\">"];
|
||||||
|
[s appendFormat: @"<LongId>%@+%@</LongId>", folderId, itemId];
|
||||||
|
[s appendFormat: @"<CollectionId xmlns=\"AirSyncBase:\">%@</CollectionId>", folderId];
|
||||||
|
[s appendString: @"<Properties>"];
|
||||||
|
[s appendFormat: [mailObject activeSyncRepresentationInContext: context]];
|
||||||
|
[s appendString: @"</Properties>"];
|
||||||
|
[s appendFormat: @"</Result>"];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[s appendFormat: @"<Range>0-%d</Range>",(total ? total-1 : 0)];
|
[s appendFormat: @"<Range>0-%d</Range>",(total ? total-1 : 0)];
|
||||||
|
|
Loading…
Reference in New Issue