From d63c4e2334ff90ceaca273f6a1925855630e265e Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Thu, 24 Feb 2011 20:34:10 +0000 Subject: [PATCH] Monotone-Parent: af2ea31f45eb560c291dfec4c44ae6e1ad120ccb Monotone-Revision: d54b0a4d8b7cb99ddb2be62efc4a25eece49e483 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2011-02-24T20:34:10 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 3 + OpenChange/MAPIStoreAttachment.h | 38 ++++++ OpenChange/MAPIStoreAttachment.m | 47 +++++++ OpenChange/MAPIStoreDraftsAttachment.h | 31 +++++ OpenChange/MAPIStoreDraftsAttachment.m | 27 ++++ OpenChange/MAPIStoreMailAttachment.h | 39 ++++++ OpenChange/MAPIStoreMailAttachment.m | 177 +++++++++++++++++++++++++ 7 files changed, 362 insertions(+) create mode 100644 OpenChange/MAPIStoreAttachment.h create mode 100644 OpenChange/MAPIStoreAttachment.m create mode 100644 OpenChange/MAPIStoreDraftsAttachment.h create mode 100644 OpenChange/MAPIStoreDraftsAttachment.m create mode 100644 OpenChange/MAPIStoreMailAttachment.h create mode 100644 OpenChange/MAPIStoreMailAttachment.m diff --git a/ChangeLog b/ChangeLog index ca17501cf..4b6a7c83c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2011-02-24 Wolfgang Sourdeau + * OpenChange/MAPIStoreAttachment.m: new super class, derived from + MAPIStoreObject and used for MAPI attachment objects. + * OpenChange/MAPIStoreFolder.m: new super class used as wrapper around SOGoFolder objects, by decoupling the code previously found in the SOGo*Context classes and which implement basic and uniform diff --git a/OpenChange/MAPIStoreAttachment.h b/OpenChange/MAPIStoreAttachment.h new file mode 100644 index 000000000..ea8146815 --- /dev/null +++ b/OpenChange/MAPIStoreAttachment.h @@ -0,0 +1,38 @@ +/* MAPIStoreAttachment.h - this file is part of SOGo + * + * Copyright (C) 2011 Inverse inc + * + * Author: Wolfgang Sourdeau + * + * 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 2, 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. + */ + +#ifndef MAPISTOREATTACHMENT_H +#define MAPISTOREATTACHMENT_H + +#import "MAPIStoreObject.h" + +@interface MAPIStoreAttachment : MAPIStoreObject +{ + uint32_t aid; +} + +- (void) setAID: (uint32_t) newAID; +- (uint32_t) AID; + +@end + +#endif /* MAPISTOREATTACHMENT_H */ diff --git a/OpenChange/MAPIStoreAttachment.m b/OpenChange/MAPIStoreAttachment.m new file mode 100644 index 000000000..a5ecfa348 --- /dev/null +++ b/OpenChange/MAPIStoreAttachment.m @@ -0,0 +1,47 @@ +/* MAPIStoreAttachment.m - this file is part of $PROJECT_NAME_HERE$ + * + * Copyright (C) 2011 Inverse inc + * + * Author: Wolfgang Sourdeau + * + * 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 2, 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. + */ + +#import "MAPIStoreAttachment.h" + +#include +#include +#include + +@implementation MAPIStoreAttachment + +- (void) setAID: (uint32_t) newAID +{ + aid = newAID; +} + +- (uint32_t) AID +{ + return aid; +} + +- (int) getProperty: (void **) data + withTag: (enum MAPITAGS) propTag +{ + return MAPISTORE_ERR_NOT_FOUND; +} + +@end diff --git a/OpenChange/MAPIStoreDraftsAttachment.h b/OpenChange/MAPIStoreDraftsAttachment.h new file mode 100644 index 000000000..89ba7d105 --- /dev/null +++ b/OpenChange/MAPIStoreDraftsAttachment.h @@ -0,0 +1,31 @@ +/* MAPIStoreDraftsAttachment.h - this file is part of SOGo + * + * Copyright (C) 2011 Inverse inc + * + * Author: Wolfgang Sourdeau + * + * 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 2, 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. + */ + +#ifndef MAPISTOREDRAFTSATTACHMENT_H +#define MAPISTOREDRAFTSATTACHMENT_H + +#import "MAPIStoreAttachment.h" + +@interface MAPIStoreDraftsAttachment : MAPIStoreAttachment +@end + +#endif /* MAPISTOREDRAFTSATTACHMENT_H */ diff --git a/OpenChange/MAPIStoreDraftsAttachment.m b/OpenChange/MAPIStoreDraftsAttachment.m new file mode 100644 index 000000000..5945e1622 --- /dev/null +++ b/OpenChange/MAPIStoreDraftsAttachment.m @@ -0,0 +1,27 @@ +/* MAPIStoreDraftsAttachment.m - this file is part of SOGo + * + * Copyright (C) 2011 Inverse inc + * + * Author: Wolfgang Sourdeau + * + * 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 2, 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. + */ + +#import "MAPIStoreDraftsAttachment.h" + +@implementation MAPIStoreDraftsAttachment + +@end diff --git a/OpenChange/MAPIStoreMailAttachment.h b/OpenChange/MAPIStoreMailAttachment.h new file mode 100644 index 000000000..5fded594c --- /dev/null +++ b/OpenChange/MAPIStoreMailAttachment.h @@ -0,0 +1,39 @@ +/* MAPIStoreMailAttachment.h - this file is part of SOGo + * + * Copyright (C) 2011 Inverse inc + * + * Author: Wolfgang Sourdeau + * + * 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 2, 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. + */ + +#ifndef MAPISTOREMAILATTACHMENT_H +#define MAPISTOREMAILATTACHMENT_H + +#import "MAPIStoreAttachment.h" + +@class NSDictionary; + +@interface MAPIStoreMailAttachment : MAPIStoreAttachment +{ + NSDictionary *bodyInfo; +} + +- (void) setBodyInfo: (NSDictionary *) newBodyInfo; + +@end + +#endif /* MAPISTOREMAILATTACHMENT_H */ diff --git a/OpenChange/MAPIStoreMailAttachment.m b/OpenChange/MAPIStoreMailAttachment.m new file mode 100644 index 000000000..0f0106c8a --- /dev/null +++ b/OpenChange/MAPIStoreMailAttachment.m @@ -0,0 +1,177 @@ +/* MAPIStoreMailAttachment.m - this file is part of SOGo + * + * Copyright (C) 2011 Inverse inc + * + * Author: Wolfgang Sourdeau + * + * 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 2, 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. + */ + +#import +#import +#import +#import +#import +#import +#import +#import +#import + +#import "MAPIStoreTypes.h" +#import "MAPIStoreMailMessage.h" +#import "NSCalendarDate+MAPIStore.h" +#import "NSData+MAPIStore.h" +#import "NSString+MAPIStore.h" + +#import "MAPIStoreMailAttachment.h" + +#undef DEBUG +#include +#include +#include +#include + +@implementation MAPIStoreMailAttachment + +- (id) init +{ + if ((self = [super init])) + { + bodyInfo = nil; + } + + return self; +} + +- (void) dealloc +{ + [bodyInfo release]; + [super dealloc]; +} + +- (void) setBodyInfo: (NSDictionary *) newBodyInfo +{ + ASSIGN (bodyInfo, newBodyInfo); +} + +- (int) getProperty: (void **) data + withTag: (enum MAPITAGS) propTag +{ + static char tagBytes[] = {0x2a, 0x86, 0x48, 0x86, 0xf7, 0x14, 0x03, 0x0a, + 0x04}; /* MIME */ + static char recordBytes[] = {0xd9, 0xd8, 0x11, 0xa3, 0xe2, 0x90, 0x18, 0x41, + 0x9e, 0x04, 0x58, 0x46, 0x9d, 0x6d, 0x1b, 0x68}; + uint32_t longValue; + NSString *stringValue; + NSCalendarDate *date; + NSDictionary *parameters; + int rc; + + rc = MAPISTORE_SUCCESS; + switch (propTag) + { + case PR_MID: + *data = MAPILongLongValue (memCtx, [container objectId]); + break; + case PR_ATTACH_NUM: + *data = MAPILongValue (memCtx, aid); + break; + case PR_ATTACH_METHOD: + *data = MAPILongValue (memCtx, 1); + break; + case PR_ATTACH_TAG: + *data = [[NSData dataWithBytes: tagBytes length: 9] + asShortBinaryInMemCtx: memCtx]; + break; + case PR_ATTACH_SIZE: + longValue = [[bodyInfo objectForKey: @"size"] longValue]; + *data = MAPILongValue (memCtx, longValue); + break; + + case PR_RENDERING_POSITION: + *data = MAPILongValue (memCtx, 0xffffffff); + break; + + case PR_RECORD_KEY: + *data = [[NSData dataWithBytes: recordBytes length: 16] + asShortBinaryInMemCtx: memCtx]; + break; + + // PR_RECORD_KEY (0xFF90102) D9 D8 11 A3 E2 90 18 41 9E 04 58 46 9D 6D 1B 68 + + case PR_ATTACH_LONG_FILENAME_UNICODE: + case PR_ATTACH_FILENAME_UNICODE: + stringValue = [[bodyInfo objectForKey: @"parameterList"] + objectForKey: @"name"]; + if (!stringValue) + { + parameters = [[bodyInfo objectForKey: @"disposition"] + objectForKey: @"parameterList"]; + stringValue = [parameters objectForKey: @"filename"]; + } + + if (propTag == PR_ATTACH_FILENAME_UNICODE) + { + NSString *baseName, *ext; + + baseName = [stringValue stringByDeletingPathExtension]; + if ([baseName length] > 8) + baseName = [baseName substringToIndex: 8]; + + ext = [stringValue pathExtension]; + if ([ext length] > 3) + ext = [ext substringToIndex: 3]; + stringValue = [NSString stringWithFormat: @"%@.%@", baseName, ext]; + } + + *data = [stringValue asUnicodeInMemCtx: memCtx]; + break; + + case PR_DISPLAY_NAME_UNICODE: /* TODO: check if description ? */ + stringValue = [bodyInfo objectForKey: @"description"]; + *data = [stringValue asUnicodeInMemCtx: memCtx]; + break; + + case PR_ATTACH_CONTENT_ID_UNICODE: + stringValue = [bodyInfo objectForKey: @"bodyId"]; + *data = [stringValue asUnicodeInMemCtx: memCtx]; + break; + + case PR_ATTACH_MIME_TAG_UNICODE: + stringValue = [NSString stringWithFormat: @"%@/%@", + [bodyInfo objectForKey: @"type"], + [bodyInfo objectForKey: @"subtype"]]; + *data = [[stringValue lowercaseString] asUnicodeInMemCtx: memCtx]; + break; + + case PR_CREATION_TIME: + case PR_LAST_MODIFICATION_TIME: + date = [[container sogoObject] date]; + *data = [date asFileTimeInMemCtx: memCtx]; + break; + + case PR_ATTACH_DATA_BIN: + *data = [[sogoObject fetchBLOB] asShortBinaryInMemCtx: memCtx]; + break; + + default: + rc = [super getProperty: data withTag: propTag]; + } + + return rc; +} + +@end