Permalink
Browse files

Added implemented some attachment support and added some tests for it

  • Loading branch information...
1 parent 62b2380 commit a1f83aee8690106767cbf3e0ab8af9005bec6e34 Matt Ronge committed Aug 12, 2007
@@ -160,8 +160,9 @@
F81B88730A74AAD800143DF6 /* MailCore_Prefix.pch in Headers */ = {isa = PBXBuildFile; fileRef = F81B88710A74AAD800143DF6 /* MailCore_Prefix.pch */; };
F81E266A0C6ED35C00B3FBAC /* CTBareAttachment.h in Headers */ = {isa = PBXBuildFile; fileRef = F81E26680C6ED35C00B3FBAC /* CTBareAttachment.h */; };
F81E266B0C6ED35C00B3FBAC /* CTBareAttachment.m in Sources */ = {isa = PBXBuildFile; fileRef = F81E26690C6ED35C00B3FBAC /* CTBareAttachment.m */; };
- F81E266E0C6ED4E100B3FBAC /* CTCoreAttachment.h in Headers */ = {isa = PBXBuildFile; fileRef = F81E266C0C6ED4E100B3FBAC /* CTCoreAttachment.h */; };
+ F81E266E0C6ED4E100B3FBAC /* CTCoreAttachment.h in Headers */ = {isa = PBXBuildFile; fileRef = F81E266C0C6ED4E100B3FBAC /* CTCoreAttachment.h */; settings = {ATTRIBUTES = (Public, ); }; };
F81E266F0C6ED4E100B3FBAC /* CTCoreAttachment.m in Sources */ = {isa = PBXBuildFile; fileRef = F81E266D0C6ED4E100B3FBAC /* CTCoreAttachment.m */; };
+ F81E272F0C6EDC6A00B3FBAC /* CTCoreAttachmentTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F81E272E0C6EDC6A00B3FBAC /* CTCoreAttachmentTests.m */; };
F8245A6D0C041C8C005E08A8 /* CTMIMEFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = F8245A2F0C04089D005E08A8 /* CTMIMEFactory.h */; settings = {ATTRIBUTES = (Public, ); }; };
F8245A700C041C91005E08A8 /* CTMIMEFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = F8245A300C04089D005E08A8 /* CTMIMEFactory.m */; };
F8483E4109CE7B9000B80440 /* libssl.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = F8483E4009CE7B9000B80440 /* libssl.dylib */; };
@@ -382,6 +383,8 @@
F81E26690C6ED35C00B3FBAC /* CTBareAttachment.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CTBareAttachment.m; path = Source/CTBareAttachment.m; sourceTree = "<group>"; };
F81E266C0C6ED4E100B3FBAC /* CTCoreAttachment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CTCoreAttachment.h; path = Source/CTCoreAttachment.h; sourceTree = "<group>"; };
F81E266D0C6ED4E100B3FBAC /* CTCoreAttachment.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CTCoreAttachment.m; path = Source/CTCoreAttachment.m; sourceTree = "<group>"; };
+ F81E272D0C6EDC6A00B3FBAC /* CTCoreAttachmentTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CTCoreAttachmentTests.h; path = Tests/CTCoreAttachmentTests.h; sourceTree = "<group>"; };
+ F81E272E0C6EDC6A00B3FBAC /* CTCoreAttachmentTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CTCoreAttachmentTests.m; path = Tests/CTCoreAttachmentTests.m; sourceTree = "<group>"; };
F8245A2F0C04089D005E08A8 /* CTMIMEFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CTMIMEFactory.h; path = Source/CTMIMEFactory.h; sourceTree = "<group>"; };
F8245A300C04089D005E08A8 /* CTMIMEFactory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CTMIMEFactory.m; path = Source/CTMIMEFactory.m; sourceTree = "<group>"; };
F8483E4009CE7B9000B80440 /* libssl.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libssl.dylib; path = /usr/lib/libssl.dylib; sourceTree = "<absolute>"; };
@@ -729,6 +732,8 @@
F8EA76120C1141C1004F85D8 /* CTCoreAddressTests.m */,
72D117D00C5C181700FE2CB5 /* CTBareMessageTests.h */,
72D117D10C5C181700FE2CB5 /* CTBareMessageTests.m */,
+ F81E272D0C6EDC6A00B3FBAC /* CTCoreAttachmentTests.h */,
+ F81E272E0C6EDC6A00B3FBAC /* CTCoreAttachmentTests.m */,
);
name = Tests;
sourceTree = "<group>";
@@ -1075,6 +1080,7 @@
F81A8AED0C03FC58002F780A /* CTMIMETests.m in Sources */,
F8EA76130C1141C1004F85D8 /* CTCoreAddressTests.m in Sources */,
72D117D20C5C181700FE2CB5 /* CTBareMessageTests.m in Sources */,
+ F81E272F0C6EDC6A00B3FBAC /* CTCoreAttachmentTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -33,7 +33,9 @@
//TODO Document me
@interface CTBareAttachment : NSObject {
-
+ NSString *mFilename;
+ NSString *mContentType;
}
-
+@property(retain) NSString *filename;
+@property(retain) NSString *contentType;
@end
@@ -30,8 +30,15 @@
*/
#import "CTBareAttachment.h"
+#import "MailCoreTypes.h"
@implementation CTBareAttachment
+@synthesize filename=mFilename, contentType=mContentType;
+- (void)dealloc {
+ [mFilename release];
+ [mContentType release];
+ [super dealloc];
+}
@end
View
@@ -33,6 +33,7 @@
#import <Cocoa/Cocoa.h>
//TODO Document me
+//TODO Eventually CTCoreMessage should inherit from this
@interface CTBareMessage : NSObject {
NSString *mUid;
unsigned int mFlags;
View
@@ -30,10 +30,14 @@
*/
#import <Cocoa/Cocoa.h>
+#import "CTBareAttachment.h"
-
-@interface CTCoreAttachment : NSObject {
-
+@interface CTCoreAttachment : CTBareAttachment {
+ NSData *mData;
}
+@property(retain) NSData *data;
+- (id)initWithContentsOfFile:(NSString *)path;
+- (id)initWithData:(NSData *)data contentType:(NSString *)contentType
+ filename:(NSString *)filename;
@end
View
@@ -30,8 +30,50 @@
*/
#import "CTCoreAttachment.h"
+#import "MailCoreTypes.h"
@implementation CTCoreAttachment
+@synthesize data=mData;
+- (id)initWithContentsOfFile:(NSString *)path {
+ NSData *data = [NSData dataWithContentsOfFile:path];
+ NSString *filePathExt = [path pathExtension];
+
+ NSString *contentType = nil;
+ NSDictionary *contentTypes = [NSDictionary dictionaryWithContentsOfFile:CTContentTypesPath];
+ for (NSString *key in [contentTypes allKeys]) {
+ NSArray *fileExtensions = [contentTypes objectForKey:key];
+ for (NSString *ext in fileExtensions) {
+ if ([filePathExt isEqual:ext]) {
+ contentType = key;
+ break;
+ }
+ }
+ if (contentType != nil)
+ break;
+ }
+
+ // We couldn't find a content-type, set it to something generic
+ if (contentType == nil) {
+ contentType = @"application/octet-stream";
+ }
+
+ NSString *filename = [path lastPathComponent];
+ return [self initWithData:data contentType:contentType filename:filename];
+}
+
+- (id)initWithData:(NSData *)data contentType:(NSString *)contentType
+ filename:(NSString *)filename {
+ self = [super init];
+ if (self) {
+ self.data = data;
+ self.contentType = contentType;
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [mData release];
+}
@end
View
@@ -28,13 +28,15 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+
+#define DEST_CHARSET "iso-8859-1"
+#define CTContentTypesPath @"/System/Library/Frameworks/Foundation.framework/Resources/types.plist"
+
/* ========================= */
/* = List of Message Flags = */
/* ========================= */
-#define DEST_CHARSET "iso-8859-1"
-
//TODO Turn these into extern's, not defines
#define CTFlagNew MAIL_FLAG_NEW
View
Binary file not shown.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Binary file not shown.
@@ -0,0 +1,40 @@
+/*
+ * MailCore
+ *
+ * Copyright (C) 2007 - Matt Ronge
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the libEtPan! project nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#import <SenTestingKit/SenTestingKit.h>
+#import "CTCoreAttachment.h"
+#import "CTMIMETests.h"
+
+@interface CTCoreAttachmentTests : SenTestCase {
+
+}
+
+@end
@@ -0,0 +1,67 @@
+/*
+ * MailCore
+ *
+ * Copyright (C) 2007 - Matt Ronge
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the libEtPan! project nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#import "CTCoreAttachmentTests.h"
+
+
+@implementation CTCoreAttachmentTests
+- (void)testJPEG {
+ NSString *path = [NSString stringWithFormat:@"%@%@",filePrefix,@"TestData/DSC_6201.jpg"];
+ CTCoreAttachment *attach = [[CTCoreAttachment alloc] initWithContentsOfFile:path];
+ STAssertEqualObjects(@"image/jpeg", [attach contentType], @"The content-type should have been image/jpeg");
+ STAssertTrue([attach data] != nil, @"Data should not have been nil");
+ [attach release];
+}
+
+- (void)testPNG {
+ NSString *path = [NSString stringWithFormat:@"%@%@",filePrefix,@"TestData/DSC_6202.png"];
+ CTCoreAttachment *attach = [[CTCoreAttachment alloc] initWithContentsOfFile:path];
+ STAssertEqualObjects(@"image/png", [attach contentType], @"The content-type should have been image/png");
+ STAssertTrue([attach data] != nil, @"Data should not have been nil");
+ [attach release];
+}
+
+- (void)testTIFF {
+ NSString *path = [NSString stringWithFormat:@"%@%@",filePrefix,@"TestData/DSC_6193.tif"];
+ CTCoreAttachment *attach = [[CTCoreAttachment alloc] initWithContentsOfFile:path];
+ STAssertEqualObjects(@"image/tiff", [attach contentType], @"The content-type should have been image/TIFF");
+ STAssertTrue([attach data] != nil, @"Data should not have been nil");
+ [attach release];
+}
+
+- (void)testNEF {
+ NSString *path = [NSString stringWithFormat:@"%@%@",filePrefix,@"TestData/DSC_6204.NEF"];
+ CTCoreAttachment *attach = [[CTCoreAttachment alloc] initWithContentsOfFile:path];
+ STAssertEqualObjects(@"application/octet-stream", [attach contentType], @"The content-type should have been application/octet-stream");
+ STAssertTrue([attach data] != nil, @"Data should not have been nil");
+ [attach release];
+}
+@end
View
@@ -40,7 +40,7 @@
#import "CTMIME_SinglePart.h"
#import "CTMIME_TextPart.h"
-const NSString *filePrefix = @"/Users/local/Projects/MailCore/";
+const NSString *filePrefix = @"/Users/mronge/Projects/MailCore/";
@implementation CTMIMETests
- (void)testMIMETextPart {

0 comments on commit a1f83ae

Please sign in to comment.