mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-03-22 14:52:44 +00:00
Monotone-Parent: 8433690e83501187848cc751a754f1f1fdf2d8c5
Monotone-Revision: 8387e16ec4baa1ac1d8fd5958d3681e5bcf43e92 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2011-11-09T15:02:04 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
#import <Foundation/NSArray.h>
|
||||
#import <Foundation/NSBundle.h>
|
||||
#import <Foundation/NSData.h>
|
||||
#import <Foundation/NSDictionary.h>
|
||||
#import <Foundation/NSString.h>
|
||||
@@ -42,6 +43,8 @@
|
||||
|
||||
#import "MAPIStoreMessage.h"
|
||||
|
||||
#include <unrtf.h>
|
||||
|
||||
#undef DEBUG
|
||||
#include <stdbool.h>
|
||||
#include <gen_ndr/exchange.h>
|
||||
@@ -49,6 +52,8 @@
|
||||
#include <mapistore/mapistore_errors.h>
|
||||
#include <mapistore/mapistore_nameid.h>
|
||||
|
||||
static NSString *resourcesDir = nil;
|
||||
|
||||
NSData *
|
||||
MAPIStoreInternalEntryId (NSString *username)
|
||||
{
|
||||
@@ -147,6 +152,64 @@ MAPIStoreExternalEntryId (NSString *cn, NSString *email)
|
||||
return entryId;
|
||||
}
|
||||
|
||||
/* rtf conversion via unrtf */
|
||||
static int
|
||||
unrtf_data_output (void *data, const char *str, size_t str_len)
|
||||
{
|
||||
NSMutableData *rtfData = data;
|
||||
|
||||
[rtfData appendBytes: str length: str_len];
|
||||
|
||||
return str_len;
|
||||
}
|
||||
|
||||
static NSData *
|
||||
uncompressRTF (NSData *compressedRTF)
|
||||
{
|
||||
NSData *rtfData = nil;
|
||||
DATA_BLOB *rtf;
|
||||
TALLOC_CTX *mem_ctx;
|
||||
|
||||
mem_ctx = talloc_zero (NULL, TALLOC_CTX);
|
||||
rtf = talloc_zero (mem_ctx, DATA_BLOB);
|
||||
|
||||
if (uncompress_rtf (mem_ctx,
|
||||
(uint8_t *) [compressedRTF bytes], [compressedRTF length],
|
||||
rtf)
|
||||
== MAPI_E_SUCCESS)
|
||||
rtfData = [NSData dataWithBytes: rtf->data length: rtf->length];
|
||||
|
||||
talloc_free (mem_ctx);
|
||||
|
||||
return rtfData;
|
||||
}
|
||||
|
||||
static NSData *
|
||||
rtf2html (NSData *compressedRTF)
|
||||
{
|
||||
NSData *rtf;
|
||||
NSMutableData *html = nil;
|
||||
int rc;
|
||||
struct unRTFOptions unrtfOptions;
|
||||
|
||||
rtf = uncompressRTF (compressedRTF);
|
||||
if (rtf)
|
||||
{
|
||||
html = [NSMutableData data];
|
||||
memset (&unrtfOptions, 0, sizeof (struct unRTFOptions));
|
||||
unrtf_set_output_device (&unrtfOptions, unrtf_data_output, html);
|
||||
unrtfOptions.config_directory = [resourcesDir UTF8String];
|
||||
unrtfOptions.output_format = "html";
|
||||
unrtfOptions.nopict_mode = YES;
|
||||
rc = unrtf_convert_from_string (&unrtfOptions,
|
||||
[rtf bytes], [rtf length]);
|
||||
if (!rc)
|
||||
html = nil;
|
||||
}
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
@interface SOGoObject (MAPIStoreProtocol)
|
||||
|
||||
- (NSString *) davEntityTag;
|
||||
@@ -156,6 +219,15 @@ MAPIStoreExternalEntryId (NSString *cn, NSString *email)
|
||||
|
||||
@implementation MAPIStoreMessage
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
if (!resourcesDir)
|
||||
{
|
||||
resourcesDir = [[NSBundle bundleForClass: self] resourcePath];
|
||||
[resourcesDir retain];
|
||||
}
|
||||
}
|
||||
|
||||
- (id) init
|
||||
{
|
||||
if ((self = [super init]))
|
||||
@@ -304,6 +376,38 @@ MAPIStoreExternalEntryId (NSString *cn, NSString *email)
|
||||
return MAPISTORE_SUCCESS;
|
||||
}
|
||||
|
||||
- (void) addProperties: (NSDictionary *) newNewProperties
|
||||
{
|
||||
NSData *htmlData, *rtfData;
|
||||
static NSNumber *htmlKey = nil, *rtfKey = nil;
|
||||
|
||||
[super addProperties: newNewProperties];
|
||||
|
||||
if (!htmlKey)
|
||||
{
|
||||
htmlKey = MAPIPropertyKey (PR_HTML);
|
||||
[htmlKey retain];
|
||||
}
|
||||
|
||||
if (!rtfKey)
|
||||
{
|
||||
rtfKey = MAPIPropertyKey (PR_RTF_COMPRESSED);
|
||||
[rtfKey retain];
|
||||
}
|
||||
|
||||
if (![properties objectForKey: htmlKey])
|
||||
{
|
||||
rtfData = [properties objectForKey: rtfKey];
|
||||
if (rtfData)
|
||||
{
|
||||
htmlData = rtf2html (rtfData);
|
||||
[properties setObject: htmlData forKey: htmlKey];
|
||||
[properties removeObjectForKey: rtfKey];
|
||||
[properties removeObjectForKey: MAPIPropertyKey (PR_RTF_IN_SYNC)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (MAPIStoreAttachment *) createAttachment
|
||||
{
|
||||
MAPIStoreAttachment *newAttachment;
|
||||
|
||||
Reference in New Issue
Block a user