2011-05-31 07:04:46 +02:00
|
|
|
/* MAPIStoreFallbackContext.m - this file is part of SOGo
|
|
|
|
*
|
2014-05-14 03:06:59 +02:00
|
|
|
* Copyright (C) 2011-2014 Inverse inc.
|
2011-05-31 07:04:46 +02:00
|
|
|
*
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2016-02-17 16:09:18 +01:00
|
|
|
#import <Foundation/NSArray.h>
|
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
#import <Foundation/NSURL.h>
|
2011-05-31 07:04:46 +02:00
|
|
|
|
2016-02-17 16:09:18 +01:00
|
|
|
#import "MAPIStoreUserContext.h"
|
2012-01-30 21:20:02 +01:00
|
|
|
#import "NSString+MAPIStore.h"
|
2016-02-17 16:09:18 +01:00
|
|
|
#import <SOGo/SOGoCacheGCSFolder.h>
|
2011-05-31 07:04:46 +02:00
|
|
|
|
2016-02-17 16:09:18 +01:00
|
|
|
#import "MAPIStoreFallbackContext.h"
|
2012-02-03 16:05:55 +01:00
|
|
|
|
2012-01-26 20:56:56 +01:00
|
|
|
#undef DEBUG
|
2016-02-17 16:09:18 +01:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <dlinklist.h>
|
|
|
|
#include <mapistore/mapistore.h>
|
2012-01-26 20:56:56 +01:00
|
|
|
|
2011-05-31 07:04:46 +02:00
|
|
|
@implementation MAPIStoreFallbackContext
|
|
|
|
|
|
|
|
+ (NSString *) MAPIModuleName
|
|
|
|
{
|
|
|
|
return @"fallback";
|
|
|
|
}
|
|
|
|
|
2012-02-03 16:05:55 +01:00
|
|
|
+ (enum mapistore_context_role) MAPIContextRole
|
|
|
|
{
|
|
|
|
return MAPISTORE_MAIL_ROLE;
|
|
|
|
}
|
|
|
|
|
2012-01-26 20:56:56 +01:00
|
|
|
+ (struct mapistore_contexts_list *) listContextsForUser: (NSString *) userName
|
2013-11-08 17:02:50 +01:00
|
|
|
withIndexing: (struct indexing_context *) indexing
|
2012-01-26 20:56:56 +01:00
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
|
|
|
{
|
2012-01-30 21:20:02 +01:00
|
|
|
struct mapistore_contexts_list *firstContext = NULL, *context;
|
2014-05-14 03:06:59 +02:00
|
|
|
SOGoCacheGCSFolder *root;
|
2012-01-30 21:20:02 +01:00
|
|
|
NSArray *names;
|
|
|
|
NSUInteger count, max;
|
|
|
|
NSString *baseURL, *url, *name;
|
2012-06-29 19:59:38 +02:00
|
|
|
MAPIStoreUserContext *userContext;
|
2012-01-26 20:56:56 +01:00
|
|
|
|
2015-01-19 19:04:06 +01:00
|
|
|
baseURL = [NSString stringWithFormat: @"sogo://%@@fallback/",
|
|
|
|
[userName stringByReplacingOccurrencesOfString: @"@"
|
|
|
|
withString: @"%40"]];
|
|
|
|
|
2012-01-30 21:20:02 +01:00
|
|
|
|
|
|
|
context = talloc_zero (memCtx, struct mapistore_contexts_list);
|
|
|
|
context->url = [baseURL asUnicodeInMemCtx: context];
|
2012-01-26 20:56:56 +01:00
|
|
|
context->name = "Fallback";
|
|
|
|
context->main_folder = true;
|
|
|
|
context->role = MAPISTORE_FALLBACK_ROLE;
|
|
|
|
context->tag = "tag";
|
|
|
|
|
2012-01-30 21:20:02 +01:00
|
|
|
DLIST_ADD_END (firstContext, context, void);
|
|
|
|
|
|
|
|
/* Maybe emsmdbp_provisioning should be fixed in order to only take the uri
|
|
|
|
returned above to avoid deleting its entries... */
|
2014-05-14 03:06:59 +02:00
|
|
|
root = [SOGoCacheGCSFolder objectWithName: [self MAPIModuleName]
|
2012-06-29 19:59:38 +02:00
|
|
|
inContainer: nil];
|
|
|
|
[root setOwner: userName];
|
|
|
|
userContext = [MAPIStoreUserContext userContextWithUsername: userName
|
2013-11-08 17:02:50 +01:00
|
|
|
andTDBIndexing: indexing];
|
2012-06-29 19:59:38 +02:00
|
|
|
[userContext ensureFolderTableExists];
|
|
|
|
[root setTableUrl: [userContext folderTableURL]];
|
2012-01-30 21:20:02 +01:00
|
|
|
names = [root toManyRelationshipKeys];
|
|
|
|
max = [names count];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
name = [names objectAtIndex: count];
|
|
|
|
url = [NSString stringWithFormat: @"%@%@/", baseURL, name];
|
|
|
|
context = talloc_zero (memCtx, struct mapistore_contexts_list);
|
|
|
|
context->url = [url asUnicodeInMemCtx: context];
|
|
|
|
context->name = [name asUnicodeInMemCtx: context];
|
|
|
|
context->main_folder = false;
|
|
|
|
context->role = MAPISTORE_FALLBACK_ROLE;
|
|
|
|
context->tag = "tag";
|
|
|
|
DLIST_ADD_END (firstContext, context, void);
|
|
|
|
}
|
|
|
|
|
|
|
|
return firstContext;
|
2012-01-26 20:56:56 +01:00
|
|
|
}
|
|
|
|
|
2012-02-03 16:05:55 +01:00
|
|
|
+ (NSString *)
|
|
|
|
createRootSecondaryFolderWithFID: (uint64_t) fid
|
|
|
|
andName: (NSString *) folderName
|
|
|
|
forUser: (NSString *) userName
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat: @"sogo://%@@fallback/0x%.16"PRIx64"/",
|
2015-01-19 19:04:06 +01:00
|
|
|
[userName stringByReplacingOccurrencesOfString: @"@"
|
|
|
|
withString: @"%40"],
|
|
|
|
(unsigned long long) fid];
|
|
|
|
|
2012-02-03 16:05:55 +01:00
|
|
|
}
|
|
|
|
|
2011-05-31 07:04:46 +02:00
|
|
|
@end
|