multiple collections support for GetItemEstimate - patch from tfu

pull/65/merge
Ludovic Marcotte 2015-02-26 17:46:34 -05:00
parent 5ceddc213e
commit 9160e34134
2 changed files with 78 additions and 57 deletions

View File

@ -1127,6 +1127,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
id currentCollection;
NSMutableString *s;
NSData *d;
NSArray *allCollections;
int j;
SOGoMicrosoftActiveSyncFolderType folderType;
int status, count;
@ -1135,66 +1137,83 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
status = 1;
count = 0;
collectionId = [[(id)[theDocumentElement getElementsByTagName: @"CollectionId"] lastObject] textValue];
realCollectionId = [collectionId realCollectionIdWithFolderType: &folderType];
if (folderType == ActiveSyncMailFolder)
nameInCache = [NSString stringWithFormat: @"folder%@", realCollectionId];
else
nameInCache = collectionId;
realCollectionId = [self globallyUniqueIDToIMAPFolderName: realCollectionId type: folderType];
currentCollection = [self collectionFromId: realCollectionId type: folderType];
//
// For IMAP, we simply build a request like this:
//
// . UID SORT (SUBJECT) UTF-8 SINCE 1-Jan-2014 NOT DELETED
// * SORT 124576 124577 124579 124578
// . OK Completed (4 msgs in 0.000 secs)
//
if (folderType == ActiveSyncMailFolder)
{
EOQualifier *notDeletedQualifier, *sinceDateQualifier;
EOAndQualifier *qualifier;
NSCalendarDate *filter;
NSArray *uids;
filter = [NSCalendarDate dateFromFilterType: [[(id)[theDocumentElement getElementsByTagName: @"FilterType"] lastObject] textValue]];
notDeletedQualifier = [EOQualifier qualifierWithQualifierFormat:
@"(not (flags = %@))",
@"deleted"];
sinceDateQualifier = [EOQualifier qualifierWithQualifierFormat:
@"(DATE >= %@)", filter];
qualifier = [[EOAndQualifier alloc] initWithQualifiers: notDeletedQualifier, sinceDateQualifier,
nil];
AUTORELEASE(qualifier);
uids = [currentCollection fetchUIDsMatchingQualifier: qualifier
sortOrdering: @"REVERSE ARRIVAL"
threaded: NO];
count = [uids count];
// Add the number of UIDs expected to "soft delete"
count += [self _softDeleteCountWithFilter: filter collectionId: nameInCache];
}
else
{
count = [[currentCollection toOneRelationshipKeys] count];
}
[s appendString: @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"];
[s appendString: @"<!DOCTYPE ActiveSync PUBLIC \"-//MICROSOFT//DTD ActiveSync//EN\" \"http://www.microsoft.com/\">"];
[s appendFormat: @"<GetItemEstimate xmlns=\"GetItemEstimate:\"><Response><Status>%d</Status><Collection>", status];
[s appendString: @"<GetItemEstimate xmlns=\"GetItemEstimate:\">"];
allCollections = (id)[theDocumentElement getElementsByTagName: @"Collection"];
for (j = 0; j < [allCollections count]; j++)
{
collectionId = [[(id)[[allCollections objectAtIndex: j] getElementsByTagName: @"CollectionId"] lastObject] textValue];
realCollectionId = [collectionId realCollectionIdWithFolderType: &folderType];
if (folderType == ActiveSyncMailFolder)
nameInCache = [NSString stringWithFormat: @"folder%@", realCollectionId];
else
nameInCache = collectionId;
realCollectionId = [self globallyUniqueIDToIMAPFolderName: realCollectionId type: folderType];
currentCollection = [self collectionFromId: realCollectionId type: folderType];
[s appendFormat: @"<CollectionId>%@</CollectionId>", collectionId];
[s appendFormat: @"<Estimate>%d</Estimate>", count];
//
// For IMAP, we simply build a request like this:
//
// . UID SORT (SUBJECT) UTF-8 SINCE 1-Jan-2014 NOT DELETED
// * SORT 124576 124577 124579 124578
// . OK Completed (4 msgs in 0.000 secs)
//
if (folderType == ActiveSyncMailFolder)
{
EOQualifier *notDeletedQualifier, *sinceDateQualifier;
EOAndQualifier *qualifier;
NSCalendarDate *filter;
NSArray *uids;
filter = [NSCalendarDate dateFromFilterType: [[(id)[[allCollections objectAtIndex: j] getElementsByTagName: @"FilterType"] lastObject] textValue]];
notDeletedQualifier = [EOQualifier qualifierWithQualifierFormat:
@"(not (flags = %@))",
@"deleted"];
sinceDateQualifier = [EOQualifier qualifierWithQualifierFormat:
@"(DATE >= %@)", filter];
qualifier = [[EOAndQualifier alloc] initWithQualifiers: notDeletedQualifier, sinceDateQualifier,
nil];
AUTORELEASE(qualifier);
uids = [currentCollection fetchUIDsMatchingQualifier: qualifier
sortOrdering: @"REVERSE ARRIVAL"
threaded: NO];
count = [uids count];
// Add the number of UIDs expected to "soft delete"
count += [self _softDeleteCountWithFilter: filter collectionId: nameInCache];
}
else
{
count = [[currentCollection toOneRelationshipKeys] count];
}
[s appendString: @"<Response>"];
[s appendFormat: @"<Status>%d</Status><Collection>", status];
if (folderType == ActiveSyncMailFolder)
[s appendString: @"<Class>Email</Class>"];
else if (folderType == ActiveSyncContactFolder)
[s appendString: @"<Class>Contacts</Class>"];
else if (folderType == ActiveSyncEventFolder)
[s appendString: @"<Class>Calendar</Class>"];
else if (folderType == ActiveSyncTaskFolder)
[s appendString: @"<Class>Tasks</Class>"];
[s appendFormat: @"<CollectionId>%@</CollectionId>",collectionId];
[s appendFormat: @"<Estimate>%d</Estimate></Collection></Response>", count];
}
[s appendString: @"</Collection></Response></GetItemEstimate>"];
[s appendString: @"</GetItemEstimate>"];
d = [[s dataUsingEncoding: NSUTF8StringEncoding] xml2wbxml];
@ -2543,7 +2562,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// If the MS-ASProtocolVersion header is set to "12.1", the body of the SendMail request is
// is a "message/rfc822" payload - otherwise, it's a WBXML blob.
//
if ([cmdName caseInsensitiveCompare: @"SendMail"] == NSOrderedSame &&
if ([cmdName caseInsensitiveCompare: @"SendMail"] == NSOrderedSame ||
[[theRequest headerForKey: @"content-type"] caseInsensitiveCompare: @"message/rfc822"] == NSOrderedSame)
{
NSString *s, *xml;
@ -2562,6 +2581,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
}
xml = [NSString stringWithFormat: @"<?xml version=\"1.0\"?><!DOCTYPE ActiveSync PUBLIC \"-//MICROSOFT//DTD ActiveSync//EN\" \"http://www.microsoft.com/\"><SendMail xmlns=\"ComposeMail:\"><SaveInSentItems/><MIME>%@</MIME></SendMail>", [s stringByEncodingBase64]];
d = [xml dataUsingEncoding: NSASCIIStringEncoding];
}

1
NEWS
View File

@ -4,6 +4,7 @@
Bug fixes
- fixed login issue after password change (#2601)
- fixed potential encoding issue using EAS and 8-bit mails (#3116)
- multiple collections support for GetItemEstimate using EAS
2.2.16 (2015-02-12)
-------------------