2010-10-01 20:54:30 +02: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
|
2010-10-18 14:57:31 +02:00
|
|
|
* the Free Software Foundation; either version 3, or (at your option)
|
2010-10-01 20:54:30 +02:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
|
|
|
|
2010-12-13 18:04:27 +01:00
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
|
|
|
|
2010-10-14 15:23:46 +02:00
|
|
|
#import <NGImap4/NGImap4EnvelopeAddress.h>
|
|
|
|
|
2010-12-30 15:37:07 +01:00
|
|
|
#import <Mailer/SOGoMailAccount.h>
|
2010-10-01 20:54:30 +02:00
|
|
|
#import <Mailer/SOGoMailFolder.h>
|
|
|
|
#import <Mailer/SOGoMailObject.h>
|
|
|
|
|
2010-10-14 18:39:52 +02:00
|
|
|
#import <SOGo/NSArray+Utilities.h>
|
|
|
|
|
2010-10-01 20:54:30 +02:00
|
|
|
#import "MAPIApplication.h"
|
|
|
|
#import "MAPIStoreAuthenticator.h"
|
2010-12-30 15:37:07 +01:00
|
|
|
#import "MAPIStoreMailFolderTable.h"
|
|
|
|
#import "MAPIStoreMailMessageTable.h"
|
2010-11-22 17:03:30 +01:00
|
|
|
#import "MAPIStoreMapping.h"
|
2010-11-22 17:12:41 +01:00
|
|
|
#import "MAPIStoreTypes.h"
|
2010-10-01 20:54:30 +02:00
|
|
|
#import "NSString+MAPIStore.h"
|
|
|
|
|
|
|
|
#import "MAPIStoreMailContext.h"
|
|
|
|
|
|
|
|
#undef DEBUG
|
|
|
|
#include <mapistore/mapistore.h>
|
2010-12-14 21:55:53 +01:00
|
|
|
|
2010-10-01 20:54:30 +02:00
|
|
|
@implementation MAPIStoreMailContext
|
|
|
|
|
2010-11-22 22:33:02 +01:00
|
|
|
+ (NSString *) MAPIModuleName
|
|
|
|
{
|
2010-12-30 15:37:07 +01:00
|
|
|
return @"inbox";
|
2010-11-22 22:33:02 +01:00
|
|
|
}
|
|
|
|
|
2010-11-22 17:03:30 +01:00
|
|
|
+ (void) registerFixedMappings: (MAPIStoreMapping *) mapping
|
|
|
|
{
|
2010-12-30 15:37:07 +01:00
|
|
|
[mapping registerURL: @"sogo://openchange:openchange@inbox/"
|
|
|
|
withID: 0x160001];
|
2010-11-22 17:03:30 +01:00
|
|
|
}
|
|
|
|
|
2010-10-01 20:54:30 +02:00
|
|
|
- (void) setupModuleFolder
|
|
|
|
{
|
2010-12-30 15:37:07 +01:00
|
|
|
SOGoUserFolder *userFolder;
|
|
|
|
SOGoMailAccounts *accountsFolder;
|
|
|
|
SOGoMailAccount *accountFolder;
|
|
|
|
SOGoFolder *currentContainer;
|
2010-10-01 22:35:29 +02:00
|
|
|
|
2010-11-18 23:29:01 +01:00
|
|
|
userFolder = [SOGoUserFolder objectWithName: [authenticator username]
|
|
|
|
inContainer: MAPIApp];
|
2010-12-01 17:34:41 +01:00
|
|
|
[parentFoldersBag addObject: userFolder];
|
2010-10-01 22:35:29 +02:00
|
|
|
[woContext setClientObject: userFolder];
|
|
|
|
|
|
|
|
accountsFolder = [userFolder lookupName: @"Mail"
|
|
|
|
inContext: woContext
|
|
|
|
acquire: NO];
|
2010-12-01 17:34:41 +01:00
|
|
|
[parentFoldersBag addObject: accountsFolder];
|
2010-10-01 22:35:29 +02:00
|
|
|
[woContext setClientObject: accountsFolder];
|
|
|
|
|
2010-12-30 15:37:07 +01:00
|
|
|
accountFolder = [accountsFolder lookupName: @"0"
|
|
|
|
inContext: woContext
|
|
|
|
acquire: NO];
|
|
|
|
[parentFoldersBag addObject: accountFolder];
|
|
|
|
[woContext setClientObject: accountFolder];
|
2010-10-01 20:54:30 +02:00
|
|
|
|
2010-12-30 15:37:07 +01:00
|
|
|
moduleFolder = [accountFolder inboxFolderInContext: nil];
|
|
|
|
[moduleFolder retain];
|
|
|
|
currentContainer = [moduleFolder container];
|
|
|
|
while (currentContainer != (SOGoFolder *) accountFolder)
|
2010-10-01 22:35:29 +02:00
|
|
|
{
|
2010-12-30 15:37:07 +01:00
|
|
|
[parentFoldersBag addObject: currentContainer];
|
|
|
|
currentContainer = [currentContainer container];
|
2010-10-01 22:35:29 +02:00
|
|
|
}
|
2010-11-22 22:33:02 +01:00
|
|
|
|
2010-12-30 15:37:07 +01:00
|
|
|
[self logWithFormat: @"moduleFolder: %@", moduleFolder];
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
2010-12-30 15:37:07 +01:00
|
|
|
- (Class) messageTableClass
|
2010-10-01 20:54:30 +02:00
|
|
|
{
|
2010-12-30 15:37:07 +01:00
|
|
|
return [MAPIStoreMailMessageTable class];
|
|
|
|
}
|
2010-10-01 22:35:29 +02:00
|
|
|
|
2010-12-30 15:37:07 +01:00
|
|
|
- (Class) folderTableClass
|
|
|
|
{
|
|
|
|
return [MAPIStoreMailFolderTable class];
|
2010-10-01 20:54:30 +02:00
|
|
|
}
|
|
|
|
|
2010-10-14 15:23:46 +02:00
|
|
|
- (int) openMessage: (struct mapistore_message *) msg
|
2010-12-30 15:37:07 +01:00
|
|
|
forKey: (NSString *) childKey
|
|
|
|
inTable: (MAPIStoreTable *) table
|
2010-10-14 15:23:46 +02:00
|
|
|
{
|
2010-12-30 15:37:07 +01:00
|
|
|
SOGoMailObject *child;
|
2010-10-14 15:23:46 +02:00
|
|
|
int rc;
|
|
|
|
struct SRowSet *recipients;
|
|
|
|
NSArray *to;
|
|
|
|
NSInteger count, max;
|
2010-10-14 17:23:01 +02:00
|
|
|
NGImap4EnvelopeAddress *currentAddress;
|
2010-10-14 15:23:46 +02:00
|
|
|
NSString *name;
|
|
|
|
|
2010-12-30 15:37:07 +01:00
|
|
|
rc = [super openMessage: msg forKey: childKey inTable: table];
|
|
|
|
|
|
|
|
if (rc == MAPI_E_SUCCESS && table == messageTable)
|
2010-10-14 15:23:46 +02:00
|
|
|
{
|
2010-12-30 15:37:07 +01:00
|
|
|
child = [[table folder] lookupName: childKey inContext: nil acquire: NO];
|
2010-10-14 15:23:46 +02:00
|
|
|
/* Retrieve recipients from the message */
|
|
|
|
to = [child toEnvelopeAddresses];
|
|
|
|
max = [to count];
|
|
|
|
recipients = talloc_zero (memCtx, struct SRowSet);
|
|
|
|
recipients->cRows = max;
|
|
|
|
recipients->aRow = talloc_array (recipients, struct SRow, max);
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
recipients->aRow[count].ulAdrEntryPad = 0;
|
|
|
|
recipients->aRow[count].cValues = 2;
|
|
|
|
recipients->aRow[count].lpProps = talloc_array (recipients->aRow,
|
|
|
|
struct SPropValue,
|
|
|
|
2);
|
2010-10-14 17:13:51 +02:00
|
|
|
|
2010-10-14 15:23:46 +02:00
|
|
|
// TODO (0x01 = primary recipient)
|
2010-10-14 17:13:51 +02:00
|
|
|
set_SPropValue_proptag (&(recipients->aRow[count].lpProps[0]),
|
|
|
|
PR_RECIPIENT_TYPE,
|
|
|
|
MAPILongValue (memCtx, 0x01));
|
|
|
|
|
2010-10-14 17:23:01 +02:00
|
|
|
currentAddress = [to objectAtIndex: count];
|
2010-10-14 17:23:19 +02:00
|
|
|
// name = [currentAddress personalName];
|
|
|
|
// if (![name length])
|
|
|
|
name = [currentAddress baseEMail];
|
2010-12-30 15:37:07 +01:00
|
|
|
if (!name)
|
|
|
|
name = @"";
|
2010-10-14 17:13:51 +02:00
|
|
|
set_SPropValue_proptag (&(recipients->aRow[count].lpProps[1]),
|
|
|
|
PR_DISPLAY_NAME,
|
|
|
|
[name asUnicodeInMemCtx: recipients->aRow[count].lpProps]);
|
2010-10-14 15:23:46 +02:00
|
|
|
}
|
|
|
|
msg->recipients = recipients;
|
2010-12-03 23:31:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2010-10-01 20:54:30 +02:00
|
|
|
@end
|