mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-08-30 18:57:18 +00:00
Fix for bug #2688
This commit is contained in:
@@ -123,7 +123,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
[o setTableUrl: [self folderTableURL]];
|
||||
[o reloadIfNeeded];
|
||||
|
||||
[[o properties] removeAllObjects];
|
||||
[[o properties] removeObjectForKey: @"SyncCache"];
|
||||
[[o properties] removeObjectForKey: @"DateCache"];
|
||||
|
||||
[[o properties] addEntriesFromDictionary: theFolderMetadata];
|
||||
[o save];
|
||||
}
|
||||
@@ -627,21 +629,23 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
sequence: [[[allMessages objectAtIndex: i] allValues] lastObject]]];
|
||||
}
|
||||
|
||||
// If it's a new Sync operation, ignore anything we might have
|
||||
// in our preferences.
|
||||
// If it's a new Sync operation, DateCache and SyncCache need to be deleted
|
||||
// but GUID stored by folderSync shouldn't be touched
|
||||
folderMetadata = [self _folderMetadataForKey: [theCollection nameInContainer]];
|
||||
if ([theSyncKey isEqualToString: @"-1"])
|
||||
{
|
||||
folderMetadata = [NSMutableDictionary dictionary];
|
||||
|
||||
[folderMetadata setObject: [NSMutableDictionary dictionary] forKey: @"SyncCache"];
|
||||
[folderMetadata setObject: [NSMutableDictionary dictionary] forKey: @"DateCache"];
|
||||
|
||||
// TODO - Generate GUID
|
||||
//[folderMetadata setObject: @"FOO-BAR-BAZ" forKey: @"GUID"];
|
||||
}
|
||||
else
|
||||
folderMetadata = [self _folderMetadataForKey: [theCollection nameInContainer]];
|
||||
|
||||
// Check whether GUID in cache is equal to the GUID from imap - this is to avoid cache corruptions if a folder has been renamed and a new folder
|
||||
// with the same name has been created but folderSync has not yet updated the cache
|
||||
if (!([[theCollection nameInContainer] isEqualToString:
|
||||
[NSString stringWithFormat: @"folder%@", [self globallyUniqueIDToIMAPFolderName: [folderMetadata objectForKey: @"GUID"] type: theFolderType]]]))
|
||||
{
|
||||
NSLog(@"GUID mismatch don't sync now!");
|
||||
return;
|
||||
}
|
||||
|
||||
syncCache = [folderMetadata objectForKey: @"SyncCache"];
|
||||
dateCache = [folderMetadata objectForKey: @"DateCache"];
|
||||
|
||||
@@ -711,6 +715,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
[s appendString: @"</Delete>"];
|
||||
|
||||
[syncCache removeObjectForKey: [aCacheObject uid]];
|
||||
[dateCache removeObjectForKey: [aCacheObject uid]];
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -773,13 +778,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//NSLog(@"skipping old deleted UID: %@", [aCacheObject uid]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (more_available)
|
||||
[folderMetadata setObject: [NSNumber numberWithBool: YES] forKey: @"MoreAvailable"];
|
||||
else
|
||||
[folderMetadata removeObjectForKey: @"MoreAvailable"];
|
||||
|
||||
|
||||
[self _setFolderMetadata: folderMetadata
|
||||
forKey: [theCollection nameInContainer]];
|
||||
} // default:
|
||||
@@ -890,6 +897,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
collectionId = [[(id)[theDocumentElement getElementsByTagName: @"CollectionId"] lastObject] textValue];
|
||||
realCollectionId = [collectionId realCollectionIdWithFolderType: &folderType];
|
||||
realCollectionId = [self globallyUniqueIDToIMAPFolderName: realCollectionId type: folderType];
|
||||
collection = [self collectionFromId: realCollectionId type: folderType];
|
||||
|
||||
syncKey = davCollectionTag = [[(id)[theDocumentElement getElementsByTagName: @"SyncKey"] lastObject] textValue];
|
||||
@@ -988,6 +996,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
davCollectionTag = [collection davCollectionTag];
|
||||
}
|
||||
|
||||
|
||||
// Generate the response buffer
|
||||
[theBuffer appendString: @"<Collection>"];
|
||||
|
||||
|
||||
@@ -43,6 +43,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
- (id) collectionFromId: (NSString *) theCollectionId
|
||||
type: (SOGoMicrosoftActiveSyncFolderType) theFolderType;
|
||||
|
||||
- (id) globallyUniqueIDToIMAPFolderName: (NSString *) theIdToTranslate
|
||||
type: (SOGoMicrosoftActiveSyncFolderType) theFolderType;
|
||||
|
||||
- (NSException *) dispatchRequest: (id) theRequest
|
||||
inResponse: (id) theResponse
|
||||
context: (id) theContext;
|
||||
|
||||
@@ -129,7 +129,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
[super init];
|
||||
|
||||
folderTableURL = nil;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -165,6 +164,30 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
return [o properties];
|
||||
}
|
||||
|
||||
- (id) globallyUniqueIDToIMAPFolderName: (NSString *) theIdToTranslate
|
||||
type: (SOGoMicrosoftActiveSyncFolderType) theFolderType
|
||||
{
|
||||
if (theFolderType == ActiveSyncMailFolder)
|
||||
{
|
||||
SOGoMailAccounts *accountsFolder;
|
||||
SOGoMailAccount *accountFolder;
|
||||
SOGoUserFolder *userFolder;
|
||||
NSDictionary *imapGUIDs;
|
||||
|
||||
userFolder = [[context activeUser] homeFolderInContext: context];
|
||||
accountsFolder = [userFolder lookupName: @"Mail" inContext: context acquire: NO];
|
||||
accountFolder = [accountsFolder lookupName: @"0" inContext: context acquire: NO];
|
||||
|
||||
// Get the GUID of the IMAP folder
|
||||
imapGUIDs = [accountFolder imapFolderGUIDs];
|
||||
|
||||
return [[imapGUIDs allKeysForObject: theIdToTranslate] objectAtIndex: 0];
|
||||
}
|
||||
|
||||
return theIdToTranslate;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
@@ -198,7 +221,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
userFolder = [[context activeUser] homeFolderInContext: context];
|
||||
accountsFolder = [userFolder lookupName: @"Mail" inContext: context acquire: NO];
|
||||
currentFolder = [accountsFolder lookupName: @"0" inContext: context acquire: NO];
|
||||
|
||||
|
||||
collection = [currentFolder lookupName: [NSString stringWithFormat: @"folder%@", theCollectionId]
|
||||
inContext: context
|
||||
acquire: NO];
|
||||
@@ -251,20 +274,45 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
inContext: context
|
||||
acquire: NO];
|
||||
else
|
||||
newFolder = [currentFolder lookupName: [NSString stringWithFormat: @"folder%@/%@", [[parentId stringByUnescapingURL] substringFromIndex: 5],
|
||||
[displayName stringByEncodingImap4FolderName]]
|
||||
inContext: context
|
||||
acquire: NO];
|
||||
|
||||
{
|
||||
parentId = [self globallyUniqueIDToIMAPFolderName: [[parentId stringByUnescapingURL] substringFromIndex: 5] type: ActiveSyncMailFolder];
|
||||
newFolder = [currentFolder lookupName: [NSString stringWithFormat: @"folder%@/%@", [parentId stringByEncodingImap4FolderName],
|
||||
[displayName stringByEncodingImap4FolderName]]
|
||||
inContext: context
|
||||
acquire: NO];
|
||||
}
|
||||
|
||||
// FIXME
|
||||
// handle exists (status == 2)
|
||||
// handle right synckey
|
||||
if ([newFolder create])
|
||||
{
|
||||
SOGoMailAccount *accountFolder;
|
||||
NSDictionary *imapGUIDs;
|
||||
SOGoCacheGCSObject *o;
|
||||
NSString *key;
|
||||
|
||||
nameInContainer = [newFolder nameInContainer];
|
||||
|
||||
// We strip the "folder" prefix
|
||||
nameInContainer = [nameInContainer substringFromIndex: 6];
|
||||
|
||||
// save new guid into cache
|
||||
accountFolder = [accountsFolder lookupName: @"0" inContext: context acquire: NO];
|
||||
|
||||
// update GUID in cache
|
||||
imapGUIDs = [accountFolder imapFolderGUIDs];
|
||||
|
||||
key = [NSString stringWithFormat: @"%@+folder%@", [context objectForKey: @"DeviceId"], nameInContainer ];
|
||||
o = [SOGoCacheGCSObject objectWithName: key inContainer: nil];
|
||||
[o setObjectType: ActiveSyncFolderCacheObject];
|
||||
[o setTableUrl: [self folderTableURL]];
|
||||
[o reloadIfNeeded];
|
||||
nameInContainer =[imapGUIDs objectForKey: nameInContainer];
|
||||
|
||||
[[o properties ] setObject: nameInContainer forKey: @"GUID"];
|
||||
[o save];
|
||||
|
||||
nameInContainer = [[NSString stringWithFormat: @"mail/%@", nameInContainer] stringByEscapingURL];
|
||||
}
|
||||
else
|
||||
@@ -345,9 +393,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
NSString *serverId;
|
||||
|
||||
SOGoMicrosoftActiveSyncFolderType folderType;
|
||||
|
||||
|
||||
serverId = [[[(id)[theDocumentElement getElementsByTagName: @"ServerId"] lastObject] textValue] realCollectionIdWithFolderType: &folderType];
|
||||
serverId = [self globallyUniqueIDToIMAPFolderName: serverId type: folderType];
|
||||
|
||||
userFolder = [[context activeUser] homeFolderInContext: context];
|
||||
accountsFolder = [userFolder lookupName: @"Mail" inContext: context acquire: NO];
|
||||
@@ -408,6 +456,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
int status;
|
||||
|
||||
serverId = [[[(id)[theDocumentElement getElementsByTagName: @"ServerId"] lastObject] textValue] realCollectionIdWithFolderType: &folderType];
|
||||
serverId = [self globallyUniqueIDToIMAPFolderName: serverId type: folderType];
|
||||
parentId = [[(id)[theDocumentElement getElementsByTagName: @"ParentId"] lastObject] textValue];
|
||||
displayName = [[(id)[theDocumentElement getElementsByTagName: @"DisplayName"] lastObject] textValue];
|
||||
|
||||
@@ -427,7 +476,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
}
|
||||
else
|
||||
{
|
||||
error = [folderToUpdate renameTo: [NSString stringWithFormat: @"%@/%@", [[parentId stringByUnescapingURL] substringFromIndex: 5],
|
||||
parentId = [self globallyUniqueIDToIMAPFolderName: [[parentId stringByUnescapingURL] substringFromIndex: 5] type: folderType];
|
||||
error = [folderToUpdate renameTo: [NSString stringWithFormat: @"%@/%@", [parentId stringByEncodingImap4FolderName],
|
||||
[displayName stringByEncodingImap4FolderName]]];
|
||||
}
|
||||
|
||||
@@ -445,7 +495,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// See http://msdn.microsoft.com/en-us/library/gg675615(v=exchg.80).aspx
|
||||
// we return '9' - we force a FolderSync
|
||||
status = 9;
|
||||
status = 1;
|
||||
|
||||
[self _setFolderSyncKey: syncKey];
|
||||
|
||||
@@ -481,11 +531,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
- (void) processFolderSync: (id <DOMElement>) theDocumentElement
|
||||
inResponse: (WOResponse *) theResponse
|
||||
{
|
||||
|
||||
NSMutableDictionary *metadata;
|
||||
NSMutableString *s;
|
||||
NSString *syncKey;
|
||||
NSData *d;
|
||||
|
||||
|
||||
BOOL first_sync;
|
||||
int status;
|
||||
|
||||
@@ -512,34 +563,107 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
[s appendString: @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"];
|
||||
[s appendString: @"<!DOCTYPE ActiveSync PUBLIC \"-//MICROSOFT//DTD ActiveSync//EN\" \"http://www.microsoft.com/\">"];
|
||||
[s appendFormat: @"<FolderSync xmlns=\"FolderHierarchy:\"><Status>%d</Status><SyncKey>%@</SyncKey><Changes>", status, syncKey];
|
||||
|
||||
// Initial sync, let's return the complete folder list
|
||||
if (first_sync)
|
||||
|
||||
if (status == 1)
|
||||
{
|
||||
SOGoMailAccounts *accountsFolder;
|
||||
SOGoMailAccount *accountFolder;
|
||||
SOGoUserFolder *userFolder;
|
||||
id currentFolder;
|
||||
|
||||
NSDictionary *folderMetadata;
|
||||
NSArray *allFoldersMetadata;
|
||||
NSString *name, *serverId, *parentId;
|
||||
NSString *key, *cKey, *nkey, *name, *serverId, *parentId;
|
||||
NSDictionary *folderMetadata, *imapGUIDs;
|
||||
NSArray *allFoldersMetadata, *allKeys;
|
||||
NSMutableDictionary *cachedGUIDs;
|
||||
NSMutableString *commands;
|
||||
SOGoCacheGCSObject *o;
|
||||
|
||||
int i, type, command_count;
|
||||
|
||||
int i, type;
|
||||
|
||||
userFolder = [[context activeUser] homeFolderInContext: context];
|
||||
accountsFolder = [userFolder lookupName: @"Mail" inContext: context acquire: NO];
|
||||
accountFolder = [accountsFolder lookupName: @"0" inContext: context acquire: NO];
|
||||
accountsFolder = [userFolder lookupName: @"Mail" inContext: context acquire: NO];
|
||||
accountFolder = [accountsFolder lookupName: @"0" inContext: context acquire: NO];
|
||||
|
||||
allFoldersMetadata = [accountFolder allFoldersMetadata];
|
||||
|
||||
// Get GUIDs of folder (IMAP)
|
||||
// e.g. {INBOX = "sogo_73c_192bd57b_d8"
|
||||
imapGUIDs = [accountFolder imapFolderGUIDs];
|
||||
|
||||
// See 2.2.3.170.3 Type (FolderSync) - http://msdn.microsoft.com/en-us/library/gg650877(v=exchg.80).aspx
|
||||
[s appendFormat: @"<Count>%d</Count>", [allFoldersMetadata count]+3];
|
||||
cachedGUIDs = [NSMutableDictionary dictionary];
|
||||
|
||||
// No need to read cached folder infos during first sync. Otherwise, pull it from the database.
|
||||
// e.g. {"sogo_73c_192bd57b_d8" = INBOX} - guid = foldername for easy reverse lookup with imapGUIDs
|
||||
if (!first_sync)
|
||||
{
|
||||
NSArray *foldersInCache;
|
||||
NSString *folderName;
|
||||
|
||||
// get the list of folder stored in cache
|
||||
key = [NSString stringWithFormat: @"%@+%@", [context objectForKey: @"DeviceId"], @"0"];
|
||||
o = [SOGoCacheGCSObject objectWithName: key inContainer: nil];
|
||||
[o setObjectType: ActiveSyncFolderCacheObject];
|
||||
[o setTableUrl: [self folderTableURL]];
|
||||
[o reloadIfNeeded];
|
||||
foldersInCache = [o folderList: [context objectForKey: @"DeviceId"] newerThanVersion: -1];
|
||||
|
||||
// get guids of folders stored in cache
|
||||
for (i = 0; i < [foldersInCache count]; i++)
|
||||
{
|
||||
folderName = [foldersInCache objectAtIndex: i];
|
||||
key = [folderName substringFromIndex: 1];
|
||||
|
||||
o = [SOGoCacheGCSObject objectWithName: key inContainer: nil];
|
||||
[o setObjectType: ActiveSyncFolderCacheObject];
|
||||
[o setTableUrl: [self folderTableURL]];
|
||||
[o reloadIfNeeded];
|
||||
|
||||
if ([[o properties ] objectForKey: @"GUID"])
|
||||
[cachedGUIDs setObject: [key substringFromIndex: [key rangeOfString: @"+"].location+7]
|
||||
forKey: [[o properties] objectForKey: @"GUID"]];
|
||||
}
|
||||
}
|
||||
|
||||
// Handle folders that have been deleted over IMAP
|
||||
command_count = 0;
|
||||
commands = [NSMutableString string];
|
||||
allKeys = [cachedGUIDs allKeys];
|
||||
|
||||
for (i = 0; i < [allKeys count]; i++)
|
||||
{
|
||||
cKey = [allKeys objectAtIndex: i];
|
||||
|
||||
if (![imapGUIDs allKeysForObject: cKey])
|
||||
{
|
||||
// Delete folders cache content to avoid stale data if a new folder gets created with the same name
|
||||
key = [NSString stringWithFormat: @"%@+folder%@", [context objectForKey: @"DeviceId"], [cachedGUIDs objectForKey: cKey]];
|
||||
o = [SOGoCacheGCSObject objectWithName: key inContainer: nil];
|
||||
[o setObjectType: ActiveSyncFolderCacheObject];
|
||||
[o setTableUrl: [self folderTableURL]];
|
||||
[o reloadIfNeeded];
|
||||
|
||||
// Only send a delete command if GUID is found
|
||||
if ([[o properties] objectForKey: @"GUID"])
|
||||
{
|
||||
[commands appendFormat: @"<Delete><ServerId>%@</ServerId></Delete>", [[NSString stringWithFormat: @"mail/%@", [[o properties ] objectForKey: @"GUID"]] stringByEscapingURL] ];
|
||||
command_count++;
|
||||
}
|
||||
|
||||
[[o properties] removeAllObjects];
|
||||
[o save];
|
||||
}
|
||||
}
|
||||
|
||||
// Handle addition and changes
|
||||
for (i = 0; i < [allFoldersMetadata count]; i++)
|
||||
{
|
||||
folderMetadata = [allFoldersMetadata objectAtIndex: i];
|
||||
serverId = [NSString stringWithFormat: @"mail%@", [folderMetadata objectForKey: @"path"]];
|
||||
|
||||
// No GUID -> no sync
|
||||
if (!([imapGUIDs objectForKey: [[folderMetadata objectForKey: @"path"] substringFromIndex: 1]]))
|
||||
continue;
|
||||
|
||||
serverId = [NSString stringWithFormat: @"mail/%@", [imapGUIDs objectForKey: [[folderMetadata objectForKey: @"path"] substringFromIndex: 1]]];
|
||||
name = [folderMetadata objectForKey: @"displayName"];
|
||||
|
||||
if ([name hasPrefix: @"/"])
|
||||
@@ -547,49 +671,105 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
if ([name hasSuffix: @"/"])
|
||||
name = [name substringToIndex: [name length]-1];
|
||||
|
||||
|
||||
type = [[folderMetadata objectForKey: @"type"] activeSyncFolderType];
|
||||
|
||||
parentId = @"0";
|
||||
|
||||
|
||||
if ([folderMetadata objectForKey: @"parent"])
|
||||
{
|
||||
parentId = [NSString stringWithFormat: @"mail%@", [folderMetadata objectForKey: @"parent"]];
|
||||
parentId = [NSString stringWithFormat: @"mail/%@", [imapGUIDs objectForKey: [[folderMetadata objectForKey: @"parent"] substringFromIndex: 1]]];
|
||||
name = [[name pathComponents] lastObject];
|
||||
}
|
||||
|
||||
[s appendFormat: @"<Add><ServerId>%@</ServerId><ParentId>%@</ParentId><Type>%d</Type><DisplayName>%@</DisplayName></Add>",
|
||||
[serverId stringByEscapingURL],
|
||||
[parentId stringByEscapingURL],
|
||||
type,
|
||||
[name activeSyncRepresentationInContext: context]];
|
||||
|
||||
// Decide between add and change
|
||||
if ([cachedGUIDs objectForKey: [imapGUIDs objectForKey: [[folderMetadata objectForKey: @"path"] substringFromIndex: 1]]])
|
||||
{
|
||||
// Search GUID to check name change in cache (diff between IMAP and cache)
|
||||
if ((![[[folderMetadata objectForKey: @"path"] substringFromIndex: 1] isEqualToString: [imapGUIDs objectForKey: [cachedGUIDs objectForKey:
|
||||
[[folderMetadata objectForKey: @"path"] substringFromIndex: 1]]]]))
|
||||
{
|
||||
key = [NSString stringWithFormat: @"%@+folder%@", [context objectForKey: @"DeviceId"], [cachedGUIDs objectForKey:
|
||||
[imapGUIDs objectForKey: [[folderMetadata objectForKey: @"path"] substringFromIndex: 1]]]];
|
||||
nkey = [NSString stringWithFormat: @"%@+folder%@", [context objectForKey: @"DeviceId"], [[folderMetadata objectForKey: @"path"] substringFromIndex: 1] ];
|
||||
|
||||
if (![key isEqualToString: nkey])
|
||||
{
|
||||
[commands appendFormat: @"<Update><ServerId>%@</ServerId><ParentId>%@</ParentId><Type>%d</Type><DisplayName>%@</DisplayName></Update>",
|
||||
[serverId stringByEscapingURL],
|
||||
[parentId stringByEscapingURL],
|
||||
type,
|
||||
[name activeSyncRepresentationInContext: context]];
|
||||
|
||||
|
||||
// Change path in cache
|
||||
o = [SOGoCacheGCSObject objectWithName: key inContainer: nil];
|
||||
[o setObjectType: ActiveSyncFolderCacheObject];
|
||||
[o setTableUrl: [self folderTableURL]];
|
||||
[o reloadIfNeeded];
|
||||
[o changePathTo: [NSString stringWithFormat: @"/%@", nkey]]; // ?? why is '/' prefix needed - problem in changePathTo?
|
||||
|
||||
command_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
[commands appendFormat: @"<Add><ServerId>%@</ServerId><ParentId>%@</ParentId><Type>%d</Type><DisplayName>%@</DisplayName></Add>",
|
||||
[serverId stringByEscapingURL],
|
||||
[parentId stringByEscapingURL],
|
||||
type,
|
||||
[name activeSyncRepresentationInContext: context]];
|
||||
|
||||
// Store folder's GUID in cache
|
||||
key = [NSString stringWithFormat: @"%@+folder%@", [context objectForKey: @"DeviceId"], [[folderMetadata objectForKey: @"path"] substringFromIndex: 1]];
|
||||
o = [SOGoCacheGCSObject objectWithName: key inContainer: nil];
|
||||
[o setObjectType: ActiveSyncFolderCacheObject];
|
||||
[o setTableUrl: [self folderTableURL]];
|
||||
[o reloadIfNeeded];
|
||||
|
||||
[[o properties ] setObject: [imapGUIDs objectForKey: [[folderMetadata objectForKey: @"path"] substringFromIndex: 1]] forKey: @"GUID"];
|
||||
[o save];
|
||||
|
||||
command_count++;
|
||||
}
|
||||
}
|
||||
|
||||
// We add the personal calendar - events
|
||||
// FIXME: add all calendars
|
||||
currentFolder = [[context activeUser] personalCalendarFolderInContext: context];
|
||||
name = [NSString stringWithFormat: @"vevent/%@", [currentFolder nameInContainer]];
|
||||
[s appendFormat: @"<Add><ServerId>%@</ServerId><ParentId>%@</ParentId><Type>%d</Type><DisplayName>%@</DisplayName></Add>", name, @"0", 8, [[currentFolder displayName] activeSyncRepresentationInContext: context]];
|
||||
|
||||
// We add the personal calendar - tasks
|
||||
// FIXME: add all calendars
|
||||
currentFolder = [[context activeUser] personalCalendarFolderInContext: context];
|
||||
name = [NSString stringWithFormat: @"vtodo/%@", [currentFolder nameInContainer]];
|
||||
[s appendFormat: @"<Add><ServerId>%@</ServerId><ParentId>%@</ParentId><Type>%d</Type><DisplayName>%@</DisplayName></Add>", name, @"0", 7, [[currentFolder displayName] activeSyncRepresentationInContext: context]];
|
||||
|
||||
// We add the personal address book
|
||||
// FIXME: add all address books
|
||||
currentFolder = [[context activeUser] personalContactsFolderInContext: context];
|
||||
name = [NSString stringWithFormat: @"vcard/%@", [currentFolder nameInContainer]];
|
||||
[s appendFormat: @"<Add><ServerId>%@</ServerId><ParentId>%@</ParentId><Type>%d</Type><DisplayName>%@</DisplayName></Add>", name, @"0", 9, [[currentFolder displayName] activeSyncRepresentationInContext: context]];
|
||||
if (first_sync)
|
||||
[s appendFormat: @"<Count>%d</Count>", command_count+3];
|
||||
else
|
||||
[s appendFormat: @"<Count>%d</Count>", command_count];
|
||||
|
||||
if (command_count > 0)
|
||||
[s appendFormat: @"%@", commands];
|
||||
|
||||
if (first_sync)
|
||||
{
|
||||
// We add the personal calendar - events
|
||||
// FIXME: add all calendars
|
||||
currentFolder = [[context activeUser] personalCalendarFolderInContext: context];
|
||||
name = [NSString stringWithFormat: @"vevent/%@", [currentFolder nameInContainer]];
|
||||
[s appendFormat: @"<Add><ServerId>%@</ServerId><ParentId>%@</ParentId><Type>%d</Type><DisplayName>%@</DisplayName></Add>", name, @"0", 8, [[currentFolder displayName] activeSyncRepresentationInContext: context]];
|
||||
|
||||
// We add the personal calendar - tasks
|
||||
// FIXME: add all calendars
|
||||
currentFolder = [[context activeUser] personalCalendarFolderInContext: context];
|
||||
name = [NSString stringWithFormat: @"vtodo/%@", [currentFolder nameInContainer]];
|
||||
[s appendFormat: @"<Add><ServerId>%@</ServerId><ParentId>%@</ParentId><Type>%d</Type><DisplayName>%@</DisplayName></Add>", name, @"0", 7, [[currentFolder displayName] activeSyncRepresentationInContext: context]];
|
||||
|
||||
// We add the personal address book
|
||||
// FIXME: add all address books
|
||||
currentFolder = [[context activeUser] personalContactsFolderInContext: context];
|
||||
name = [NSString stringWithFormat: @"vcard/%@", [currentFolder nameInContainer]];
|
||||
[s appendFormat: @"<Add><ServerId>%@</ServerId><ParentId>%@</ParentId><Type>%d</Type><DisplayName>%@</DisplayName></Add>", name, @"0", 9, [[currentFolder displayName] activeSyncRepresentationInContext: context]];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[s appendString: @"</Changes></FolderSync>"];
|
||||
|
||||
|
||||
d = [[s dataUsingEncoding: NSUTF8StringEncoding] xml2wbxml];
|
||||
|
||||
|
||||
[theResponse setContent: d];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// From: http://msdn.microsoft.com/en-us/library/ee157980(v=exchg.80).aspx :
|
||||
@@ -636,6 +816,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
collectionId = [[(id)[theDocumentElement getElementsByTagName: @"CollectionId"] lastObject] textValue];
|
||||
realCollectionId = [collectionId realCollectionIdWithFolderType: &folderType];
|
||||
realCollectionId = [self globallyUniqueIDToIMAPFolderName: realCollectionId type: folderType];
|
||||
currentCollection = [self collectionFromId: realCollectionId type: folderType];
|
||||
|
||||
//
|
||||
@@ -710,6 +891,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
fileReference = [[[(id)[theDocumentElement getElementsByTagName: @"FileReference"] lastObject] textValue] stringByUnescapingURL];
|
||||
|
||||
realCollectionId = [fileReference realCollectionIdWithFolderType: &folderType];
|
||||
realCollectionId = [self globallyUniqueIDToIMAPFolderName: realCollectionId type: folderType];
|
||||
|
||||
if (folderType == ActiveSyncMailFolder)
|
||||
{
|
||||
@@ -803,6 +985,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
status = 1;
|
||||
|
||||
realCollectionId = [[[(id)[theDocumentElement getElementsByTagName: @"CollectionId"] lastObject] textValue] realCollectionIdWithFolderType: &folderType];
|
||||
realCollectionId = [self globallyUniqueIDToIMAPFolderName: realCollectionId type: folderType];
|
||||
userResponse = [[[(id)[theDocumentElement getElementsByTagName: @"UserResponse"] lastObject] textValue] intValue];
|
||||
requestId = [[(id)[theDocumentElement getElementsByTagName: @"RequestId"] lastObject] textValue];
|
||||
appointmentObject = nil;
|
||||
@@ -953,6 +1136,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
NSDictionary *response;
|
||||
NSString *v;
|
||||
|
||||
srcFolderId = [self globallyUniqueIDToIMAPFolderName: srcFolderId type: srcFolderType];
|
||||
dstFolderId = [self globallyUniqueIDToIMAPFolderName: dstFolderId type: dstFolderType];
|
||||
|
||||
currentCollection = [self collectionFromId: srcFolderId type: srcFolderType];
|
||||
|
||||
client = [[currentCollection imap4Connection] client];
|
||||
@@ -1496,6 +1682,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
folderId = [[(id)[theDocumentElement getElementsByTagName: @"FolderId"] lastObject] textValue];
|
||||
itemId = [[(id)[theDocumentElement getElementsByTagName: @"ItemId"] lastObject] textValue];
|
||||
realCollectionId = [folderId realCollectionIdWithFolderType: &folderType];
|
||||
realCollectionId = [self globallyUniqueIDToIMAPFolderName: realCollectionId type: folderType];
|
||||
|
||||
value = [theDocumentElement getElementsByTagName: @"ReplaceMime"];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user