2011-08-12 17:02:01 +02:00
|
|
|
/* MAPIStoreAttachment.m - this file is part of SOGo
|
2011-02-24 21:34:10 +01:00
|
|
|
*
|
2012-08-17 21:04:57 +02:00
|
|
|
* Copyright (C) 2011-2012 Inverse inc
|
2011-02-24 21:34:10 +01:00
|
|
|
*
|
|
|
|
* 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
|
2011-08-12 17:02:01 +02:00
|
|
|
* the Free Software Foundation; either version 3, or (at your option)
|
2011-02-24 21:34:10 +01: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.
|
|
|
|
*/
|
|
|
|
|
2011-04-01 00:05:33 +02:00
|
|
|
#import <Foundation/NSData.h>
|
|
|
|
|
2011-02-24 21:34:10 +01:00
|
|
|
#import "MAPIStoreAttachment.h"
|
2012-06-01 17:15:30 +02:00
|
|
|
#import "MAPIStoreEmbeddedMessage.h"
|
2011-06-04 01:53:30 +02:00
|
|
|
#import "MAPIStoreContext.h"
|
2011-04-01 00:05:33 +02:00
|
|
|
#import "MAPIStoreMapping.h"
|
|
|
|
#import "MAPIStoreMessage.h"
|
|
|
|
#import "MAPIStoreTypes.h"
|
2012-08-06 21:20:07 +02:00
|
|
|
#import "NSObject+MAPIStore.h"
|
2011-02-24 21:34:10 +01:00
|
|
|
|
2011-04-01 00:05:33 +02:00
|
|
|
#undef DEBUG
|
2011-02-24 21:34:10 +01:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <gen_ndr/exchange.h>
|
2011-04-01 00:05:33 +02:00
|
|
|
#include <mapistore/mapistore.h>
|
2011-02-24 21:34:10 +01:00
|
|
|
#include <mapistore/mapistore_errors.h>
|
|
|
|
|
|
|
|
@implementation MAPIStoreAttachment
|
|
|
|
|
|
|
|
- (void) setAID: (uint32_t) newAID
|
|
|
|
{
|
|
|
|
aid = newAID;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (uint32_t) AID
|
|
|
|
{
|
|
|
|
return aid;
|
|
|
|
}
|
|
|
|
|
2011-04-01 00:05:33 +02:00
|
|
|
- (NSString *) nameInContainer
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat: @"%d", aid];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSData *) mimeAttachTag
|
|
|
|
{
|
|
|
|
static NSData *mimeAttachTag = nil;
|
|
|
|
char tagBytes[] = {0x2a, 0x86, 0x48, 0x86, 0xf7, 0x14, 0x03, 0x0a, 0x04};
|
|
|
|
|
|
|
|
if (!mimeAttachTag)
|
|
|
|
{
|
|
|
|
mimeAttachTag = [NSData dataWithBytes: tagBytes length: 9];
|
|
|
|
[mimeAttachTag retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return mimeAttachTag;
|
|
|
|
}
|
|
|
|
|
2012-03-02 21:44:24 +01:00
|
|
|
- (int) getPidTagMid: (void **) data
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-02-24 21:34:10 +01:00
|
|
|
{
|
2011-10-25 19:36:51 +02:00
|
|
|
*data = MAPILongLongValue (memCtx, [container objectId]);
|
2011-04-01 00:05:33 +02:00
|
|
|
|
2011-10-25 19:36:51 +02:00
|
|
|
return MAPISTORE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2012-03-02 21:44:24 +01:00
|
|
|
- (int) getPidTagAttachNumber: (void **) data
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-10-25 19:36:51 +02:00
|
|
|
{
|
|
|
|
*data = MAPILongValue (memCtx, aid);
|
|
|
|
|
|
|
|
return MAPISTORE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2012-03-02 21:44:24 +01:00
|
|
|
- (int) getPidTagRenderingPosition: (void **) data
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-10-25 19:36:51 +02:00
|
|
|
{
|
|
|
|
*data = MAPILongValue (memCtx, 0xffffffff);
|
2011-04-01 00:05:33 +02:00
|
|
|
|
2011-10-25 19:36:51 +02:00
|
|
|
return MAPISTORE_SUCCESS;
|
2011-04-01 00:05:33 +02:00
|
|
|
}
|
|
|
|
|
2012-08-06 21:20:07 +02:00
|
|
|
- (int) getPidTagAccessLevel: (void **) data
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
|
|
|
{
|
|
|
|
return [self getLongZero: data inMemCtx: memCtx];
|
|
|
|
}
|
|
|
|
|
2012-06-01 17:15:30 +02:00
|
|
|
- (int) openEmbeddedMessage: (MAPIStoreEmbeddedMessage **) messagePtr
|
2011-04-01 00:05:33 +02:00
|
|
|
withMID: (uint64_t *) mid
|
2011-07-13 23:41:58 +02:00
|
|
|
withMAPIStoreMsg: (struct mapistore_message **) mapistoreMsgPtr
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-04-01 00:05:33 +02:00
|
|
|
{
|
2012-06-01 17:15:30 +02:00
|
|
|
MAPIStoreEmbeddedMessage *attMessage;
|
2011-07-13 23:41:58 +02:00
|
|
|
struct mapistore_message *mapistoreMsg;
|
|
|
|
|
|
|
|
mapistoreMsg = talloc_zero (memCtx, struct mapistore_message);
|
2011-04-01 00:05:33 +02:00
|
|
|
|
2012-07-20 17:21:11 +02:00
|
|
|
attMessage = [self openEmbeddedMessage];
|
|
|
|
if (attMessage)
|
2011-04-01 00:05:33 +02:00
|
|
|
{
|
2012-09-19 17:57:53 +02:00
|
|
|
*mid = [attMessage objectId];
|
2012-07-20 17:21:11 +02:00
|
|
|
*messagePtr = attMessage;
|
|
|
|
*mapistoreMsgPtr = mapistoreMsg;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (attMessage ? MAPISTORE_SUCCESS : MAPISTORE_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) createEmbeddedMessage: (MAPIStoreEmbeddedMessage **) messagePtr
|
|
|
|
withMAPIStoreMsg: (struct mapistore_message **) mapistoreMsgPtr
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
|
|
|
{
|
|
|
|
MAPIStoreEmbeddedMessage *attMessage;
|
|
|
|
struct mapistore_message *mapistoreMsg;
|
|
|
|
|
|
|
|
mapistoreMsg = talloc_zero (memCtx, struct mapistore_message);
|
|
|
|
attMessage = [self createEmbeddedMessage];
|
|
|
|
if (attMessage)
|
|
|
|
{
|
|
|
|
*messagePtr = attMessage;
|
|
|
|
*mapistoreMsgPtr = mapistoreMsg;
|
2011-04-01 00:05:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return (attMessage ? MAPISTORE_SUCCESS : MAPISTORE_ERROR);
|
|
|
|
}
|
|
|
|
|
2011-10-27 18:01:51 +02:00
|
|
|
- (NSDate *) creationTime
|
|
|
|
{
|
|
|
|
return [container creationTime];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDate *) lastModificationTime
|
|
|
|
{
|
|
|
|
return [container lastModificationTime];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (uint64_t) objectVersion
|
|
|
|
{
|
|
|
|
/* attachments have no version number */
|
|
|
|
return ULLONG_MAX;
|
|
|
|
}
|
|
|
|
|
2012-12-03 15:18:17 +01:00
|
|
|
- (void) copyToAttachment: (MAPIStoreAttachment *) newAttachment inMemCtx: (TALLOC_CTX *) memCtx
|
2012-08-15 03:02:08 +02:00
|
|
|
{
|
|
|
|
void *attachMethod;
|
|
|
|
enum mapistore_error error;
|
|
|
|
MAPIStoreEmbeddedMessage *embeddedMessage, *newEmbeddedMessage;
|
|
|
|
|
2012-12-03 15:18:17 +01:00
|
|
|
[self copyPropertiesToObject: newAttachment inMemCtx: memCtx];
|
2012-08-15 03:02:08 +02:00
|
|
|
|
|
|
|
attachMethod = NULL;
|
|
|
|
error = [self getProperty: &attachMethod
|
|
|
|
withTag: PidTagAttachMethod
|
|
|
|
inMemCtx: NULL];
|
|
|
|
if (error == MAPISTORE_SUCCESS && attachMethod)
|
|
|
|
{
|
|
|
|
if (*(uint32_t *) attachMethod == afEmbeddedMessage)
|
|
|
|
{
|
|
|
|
embeddedMessage = [self openEmbeddedMessage];
|
|
|
|
newEmbeddedMessage = [newAttachment createEmbeddedMessage];
|
2012-12-03 15:18:17 +01:00
|
|
|
[embeddedMessage copyToMessage: newEmbeddedMessage inMemCtx: memCtx];
|
2012-08-15 03:02:08 +02:00
|
|
|
}
|
|
|
|
talloc_free (attachMethod);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-01 00:05:33 +02:00
|
|
|
/* subclasses */
|
2012-06-01 17:15:30 +02:00
|
|
|
- (MAPIStoreEmbeddedMessage *) openEmbeddedMessage
|
2011-04-01 00:05:33 +02:00
|
|
|
{
|
2011-07-21 21:03:17 +02:00
|
|
|
// [self subclassResponsibility: _cmd];
|
2011-04-01 00:05:33 +02:00
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2012-06-01 17:15:30 +02:00
|
|
|
- (MAPIStoreEmbeddedMessage *) createEmbeddedMessage
|
2011-04-01 00:05:33 +02:00
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
|
|
|
return nil;
|
2011-02-24 21:34:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|