2011-02-25 17:41:53 +01:00
|
|
|
/* MAPIStoreMailContext.m - this file is part of SOGo
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Inverse inc.
|
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-01-31 13:54:36 +01:00
|
|
|
#import <Foundation/NSArray.h>
|
2012-01-30 22:42:03 +01:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2011-02-25 17:41:53 +01:00
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
|
2012-01-29 20:55:21 +01:00
|
|
|
#import <Mailer/SOGoMailAccount.h>
|
|
|
|
#import <Mailer/SOGoMailFolder.h>
|
|
|
|
|
2011-02-25 17:41:53 +01:00
|
|
|
#import "MAPIStoreMailFolder.h"
|
2012-01-29 20:55:21 +01:00
|
|
|
#import "MAPIStoreUserContext.h"
|
2012-01-26 20:54:36 +01:00
|
|
|
#import "NSString+MAPIStore.h"
|
2011-02-25 17:41:53 +01:00
|
|
|
|
2012-02-03 16:05:55 +01:00
|
|
|
#import <SOGo/NSString+Utilities.h>
|
2011-02-25 17:41:53 +01:00
|
|
|
#import "MAPIStoreMailContext.h"
|
|
|
|
|
2012-01-29 20:55:21 +01:00
|
|
|
#include <dlinklist.h>
|
2012-01-26 20:54:36 +01:00
|
|
|
#undef DEBUG
|
|
|
|
#include <mapistore/mapistore.h>
|
|
|
|
|
2012-01-29 20:55:21 +01:00
|
|
|
static Class MAPIStoreMailFolderK;
|
2011-02-25 17:41:53 +01:00
|
|
|
|
2012-01-29 20:55:21 +01:00
|
|
|
@implementation MAPIStoreMailContext
|
2011-02-25 17:41:53 +01:00
|
|
|
|
2012-01-29 20:55:21 +01:00
|
|
|
+ (void) initialize
|
2012-01-26 20:54:36 +01:00
|
|
|
{
|
2012-01-29 20:55:21 +01:00
|
|
|
MAPIStoreMailFolderK = [MAPIStoreMailFolder class];
|
2012-01-26 20:54:36 +01:00
|
|
|
}
|
|
|
|
|
2011-02-25 17:41:53 +01:00
|
|
|
+ (NSString *) MAPIModuleName
|
|
|
|
{
|
2012-01-29 20:55:21 +01:00
|
|
|
return @"mail";
|
2011-02-25 17:41:53 +01:00
|
|
|
}
|
|
|
|
|
2012-02-03 16:05:55 +01:00
|
|
|
+ (enum mapistore_context_role) MAPIContextRole
|
|
|
|
{
|
|
|
|
return MAPISTORE_MAIL_ROLE;
|
|
|
|
}
|
|
|
|
|
2012-01-26 20:54:36 +01:00
|
|
|
+ (struct mapistore_contexts_list *) listContextsForUser: (NSString *) userName
|
2012-01-29 20:55:21 +01:00
|
|
|
withTDBIndexing: (struct tdb_wrap *) indexingTdb
|
2012-01-26 20:54:36 +01:00
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
|
|
|
{
|
2012-01-31 13:54:36 +01:00
|
|
|
struct mapistore_contexts_list *firstContext = NULL, *context;
|
|
|
|
NSString *urlBase, *stringData, *currentName, *inboxName, *draftsName, *sentName, *trashName;
|
|
|
|
NSMutableArray *secondaryFolders;
|
2012-01-29 20:55:21 +01:00
|
|
|
enum mapistore_context_role role[] = {MAPISTORE_MAIL_ROLE,
|
|
|
|
MAPISTORE_DRAFTS_ROLE,
|
2012-01-31 13:54:36 +01:00
|
|
|
MAPISTORE_SENTITEMS_ROLE};
|
|
|
|
NSString *folderName[3];
|
|
|
|
NSUInteger count, max;
|
2012-01-29 20:55:21 +01:00
|
|
|
SOGoMailAccount *accountFolder;
|
|
|
|
MAPIStoreUserContext *userContext;
|
|
|
|
WOContext *woContext;
|
2012-01-26 20:54:36 +01:00
|
|
|
|
2012-01-29 20:55:21 +01:00
|
|
|
userContext = [MAPIStoreUserContext userContextWithUsername: userName
|
|
|
|
andTDBIndexing: indexingTdb];
|
2012-01-30 22:42:03 +01:00
|
|
|
accountFolder = [[userContext rootFolders] objectForKey: @"mail"];
|
2012-01-29 20:55:21 +01:00
|
|
|
woContext = [userContext woContext];
|
2012-01-31 13:54:36 +01:00
|
|
|
|
|
|
|
inboxName = @"folderINBOX";
|
|
|
|
folderName[0] = inboxName;
|
|
|
|
|
|
|
|
draftsName = [NSString stringWithFormat: @"folder%@",
|
|
|
|
[accountFolder draftsFolderNameInContext: woContext]];
|
|
|
|
folderName[1] = draftsName;
|
|
|
|
sentName = [NSString stringWithFormat: @"folder%@",
|
|
|
|
[accountFolder sentFolderNameInContext: woContext]];
|
|
|
|
folderName[2] = sentName;
|
|
|
|
trashName = [NSString stringWithFormat: @"folder%@",
|
|
|
|
[accountFolder trashFolderNameInContext: woContext]];
|
2011-02-25 17:41:53 +01:00
|
|
|
|
2012-01-29 20:55:21 +01:00
|
|
|
urlBase = [NSString stringWithFormat: @"sogo://%@:%@@mail/", userName, userName];
|
2011-02-25 17:41:53 +01:00
|
|
|
|
2012-01-31 13:54:36 +01:00
|
|
|
for (count = 0; count < 3; count++)
|
2012-01-29 20:55:21 +01:00
|
|
|
{
|
|
|
|
context = talloc_zero (memCtx, struct mapistore_contexts_list);
|
|
|
|
stringData = [NSString stringWithFormat: @"%@%@", urlBase,
|
|
|
|
folderName[count]];
|
|
|
|
context->url = [stringData asUnicodeInMemCtx: context];
|
|
|
|
/* remove "folder" prefix */
|
2012-02-03 16:05:55 +01:00
|
|
|
stringData = [[folderName[count] substringFromIndex: 6] fromCSSIdentifier];
|
2012-01-29 20:55:21 +01:00
|
|
|
context->name = [stringData asUnicodeInMemCtx: context];
|
|
|
|
context->main_folder = true;
|
|
|
|
context->role = role[count];
|
|
|
|
context->tag = "tag";
|
|
|
|
DLIST_ADD_END (firstContext, context, void);
|
|
|
|
}
|
2011-02-25 17:41:53 +01:00
|
|
|
|
2012-01-31 13:54:36 +01:00
|
|
|
secondaryFolders = [[accountFolder toManyRelationshipKeysWithNamespaces: NO]
|
|
|
|
mutableCopy];
|
|
|
|
[secondaryFolders autorelease];
|
|
|
|
[secondaryFolders removeObject: inboxName];
|
|
|
|
[secondaryFolders removeObject: draftsName];
|
|
|
|
[secondaryFolders removeObject: draftsName];
|
|
|
|
[secondaryFolders removeObject: sentName];
|
|
|
|
[secondaryFolders removeObject: trashName];
|
|
|
|
max = [secondaryFolders count];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
context = talloc_zero (memCtx, struct mapistore_contexts_list);
|
|
|
|
currentName = [secondaryFolders objectAtIndex: count];
|
|
|
|
stringData = [NSString stringWithFormat: @"%@%@", urlBase, currentName];
|
|
|
|
context->url = [stringData asUnicodeInMemCtx: context];
|
2012-02-03 16:05:55 +01:00
|
|
|
stringData = [[currentName substringFromIndex: 6] fromCSSIdentifier];
|
2012-01-31 13:54:36 +01:00
|
|
|
context->name = [stringData asUnicodeInMemCtx: context];
|
|
|
|
context->main_folder = false;
|
|
|
|
context->role = MAPISTORE_MAIL_ROLE;
|
|
|
|
context->tag = "tag";
|
|
|
|
DLIST_ADD_END (firstContext, context, void);
|
|
|
|
}
|
|
|
|
|
2012-01-29 20:55:21 +01:00
|
|
|
return firstContext;
|
2012-01-26 20:54:36 +01:00
|
|
|
}
|
|
|
|
|
2012-02-03 16:05:55 +01:00
|
|
|
+ (NSString *)
|
|
|
|
createRootSecondaryFolderWithFID: (uint64_t) fid
|
|
|
|
andName: (NSString *) newFolderName
|
|
|
|
forUser: (NSString *) userName
|
|
|
|
withTDBIndexing: (struct tdb_wrap *) indexingTdb
|
|
|
|
{
|
|
|
|
NSString *mapistoreURI, *folderName;
|
|
|
|
MAPIStoreUserContext *userContext;
|
|
|
|
SOGoMailAccount *accountFolder;
|
|
|
|
SOGoMailFolder *newFolder;
|
|
|
|
|
|
|
|
userContext = [MAPIStoreUserContext userContextWithUsername: userName
|
|
|
|
andTDBIndexing: indexingTdb];
|
|
|
|
accountFolder = [[userContext rootFolders] objectForKey: @"mail"];
|
|
|
|
folderName = [NSString stringWithFormat: @"folder%@",
|
|
|
|
[newFolderName asCSSIdentifier]];
|
|
|
|
newFolder = [SOGoMailFolder objectWithName: folderName
|
|
|
|
inContainer: accountFolder];
|
|
|
|
if ([newFolder create])
|
|
|
|
mapistoreURI = [NSString stringWithFormat: @"sogo://%@:%@@mail/%@/",
|
|
|
|
userName, userName, folderName];
|
|
|
|
else
|
|
|
|
mapistoreURI = nil;
|
|
|
|
|
|
|
|
return mapistoreURI;
|
|
|
|
}
|
|
|
|
|
2012-01-29 20:55:21 +01:00
|
|
|
- (Class) MAPIStoreFolderClass
|
2011-02-25 17:41:53 +01:00
|
|
|
{
|
2012-01-29 20:55:21 +01:00
|
|
|
return MAPIStoreMailFolderK;
|
2011-02-25 17:41:53 +01:00
|
|
|
}
|
|
|
|
|
2012-01-29 20:55:21 +01:00
|
|
|
- (id) rootSOGoFolder
|
2011-02-25 17:41:53 +01:00
|
|
|
{
|
2012-01-30 22:42:03 +01:00
|
|
|
return [[userContext rootFolders] objectForKey: @"mail"];
|
2011-02-25 17:41:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2012-01-31 13:54:36 +01:00
|
|
|
@implementation MAPIStoreOutboxContext
|
2011-02-25 17:41:53 +01:00
|
|
|
|
|
|
|
+ (NSString *) MAPIModuleName
|
|
|
|
{
|
2012-01-31 13:54:36 +01:00
|
|
|
return @"outbox";
|
2011-02-25 17:41:53 +01:00
|
|
|
}
|
2011-08-15 17:53:16 +02:00
|
|
|
|
2012-01-31 13:54:36 +01:00
|
|
|
+ (struct mapistore_contexts_list *) listContextsForUser: (NSString *) userName
|
|
|
|
withTDBIndexing: (struct tdb_wrap *) indexingTdb
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2012-01-26 20:54:36 +01:00
|
|
|
{
|
2012-01-31 13:54:36 +01:00
|
|
|
struct mapistore_contexts_list *context;
|
|
|
|
NSString *url, *folderName;
|
|
|
|
SOGoMailAccount *accountFolder;
|
|
|
|
MAPIStoreUserContext *userContext;
|
|
|
|
WOContext *woContext;
|
|
|
|
|
|
|
|
userContext = [MAPIStoreUserContext userContextWithUsername: userName
|
|
|
|
andTDBIndexing: indexingTdb];
|
|
|
|
accountFolder = [[userContext rootFolders] objectForKey: @"mail"];
|
|
|
|
woContext = [userContext woContext];
|
|
|
|
folderName = [NSString stringWithFormat: @"folder%@",
|
|
|
|
[accountFolder draftsFolderNameInContext: woContext]];
|
|
|
|
url = [NSString stringWithFormat: @"sogo://%@:%@@outbox/%@", userName,
|
|
|
|
userName, folderName];
|
|
|
|
|
|
|
|
context = talloc_zero (memCtx, struct mapistore_contexts_list);
|
|
|
|
context->url = [url asUnicodeInMemCtx: context];
|
|
|
|
/* TODO: use a localized version of this display name */
|
|
|
|
context->name = [@"Outbox" asUnicodeInMemCtx: context];
|
|
|
|
context->main_folder = true;
|
|
|
|
context->role = MAPISTORE_OUTBOX_ROLE;
|
|
|
|
context->tag = "tag";
|
|
|
|
context->prev = context;
|
|
|
|
|
|
|
|
return context;
|
2012-01-26 20:54:36 +01:00
|
|
|
}
|
|
|
|
|
2011-02-25 17:41:53 +01:00
|
|
|
@end
|