aboutsummaryrefslogtreecommitdiffhomepage
path: root/example
diff options
context:
space:
mode:
authorGravatar DINH Viêt Hoà <dinh.viet.hoa@gmail.com>2013-05-14 09:29:05 -0700
committerGravatar DINH Viêt Hoà <dinh.viet.hoa@gmail.com>2013-05-14 09:29:05 -0700
commite79638a917ee19546adcce763104d82193254ad0 (patch)
treea0c86d49c871b0b85386709126f138a795bcd09b /example
parent6c42bb1d834c71658ec65f1dff3ef8abf51b1ec7 (diff)
parent65553c63e7d4c69743a7917e9958987acc01061b (diff)
Merge pull request #47 from MailCore/cid-images
Implement the ability to load cid and x-mailcore-images in the iOS demo
Diffstat (limited to 'example')
-rw-r--r--example/ios/iOS UI Test/iOS UI Test.xcodeproj/project.pbxproj26
-rwxr-xr-xexample/ios/iOS UI Test/iOS UI Test/MCOCIDURLProtocol.h31
-rwxr-xr-xexample/ios/iOS UI Test/iOS UI Test/MCOCIDURLProtocol.mm145
-rwxr-xr-xexample/ios/iOS UI Test/iOS UI Test/MCOMessageView.mm159
-rw-r--r--example/ios/iOS UI Test/iOS UI Test/MCOMessageViewScript.js30
-rwxr-xr-xexample/ios/iOS UI Test/iOS UI Test/MCTMsgViewController.mm (renamed from example/ios/iOS UI Test/iOS UI Test/MCTMsgViewController.m)103
-rw-r--r--example/ios/iOS UI Test/iOS UI Test/MasterViewController.m27
7 files changed, 210 insertions, 311 deletions
diff --git a/example/ios/iOS UI Test/iOS UI Test.xcodeproj/project.pbxproj b/example/ios/iOS UI Test/iOS UI Test.xcodeproj/project.pbxproj
index bf9f8cbb..a4e6718f 100644
--- a/example/ios/iOS UI Test/iOS UI Test.xcodeproj/project.pbxproj
+++ b/example/ios/iOS UI Test/iOS UI Test.xcodeproj/project.pbxproj
@@ -24,9 +24,11 @@
AB9EAE3617036FD700D750C7 /* SettingsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AB9EAE3417036FD600D750C7 /* SettingsViewController.m */; };
AB9EAE3717036FD700D750C7 /* SettingsViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = AB9EAE3517036FD700D750C7 /* SettingsViewController.xib */; };
AB9EAE40170374D900D750C7 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB9EAE3F170374D900D750C7 /* Security.framework */; };
- B12AAA3317322654003551C7 /* MCOCIDURLProtocol.mm in Sources */ = {isa = PBXBuildFile; fileRef = B12AAA2E17322654003551C7 /* MCOCIDURLProtocol.mm */; };
+ ABE40268173F0151007F1FB3 /* MCOMessageViewScript.js in Sources */ = {isa = PBXBuildFile; fileRef = ABE40267173F0151007F1FB3 /* MCOMessageViewScript.js */; };
+ ABE40269173F0282007F1FB3 /* MCOMessageViewScript.js in Resources */ = {isa = PBXBuildFile; fileRef = ABE40267173F0151007F1FB3 /* MCOMessageViewScript.js */; };
+ ABE4026B173F3FCE007F1FB3 /* ImageIO.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ABE4026A173F3FCE007F1FB3 /* ImageIO.framework */; };
B12AAA3417322654003551C7 /* MCOMessageView.mm in Sources */ = {isa = PBXBuildFile; fileRef = B12AAA3017322654003551C7 /* MCOMessageView.mm */; };
- B12AAA3517322654003551C7 /* MCTMsgViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B12AAA3217322654003551C7 /* MCTMsgViewController.m */; };
+ B12AAA3517322654003551C7 /* MCTMsgViewController.mm in Sources */ = {isa = PBXBuildFile; fileRef = B12AAA3217322654003551C7 /* MCTMsgViewController.mm */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -100,12 +102,12 @@
AB9EAE3417036FD600D750C7 /* SettingsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SettingsViewController.m; sourceTree = "<group>"; };
AB9EAE3517036FD700D750C7 /* SettingsViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = SettingsViewController.xib; sourceTree = "<group>"; };
AB9EAE3F170374D900D750C7 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; };
- B12AAA2D17322654003551C7 /* MCOCIDURLProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCOCIDURLProtocol.h; sourceTree = "<group>"; };
- B12AAA2E17322654003551C7 /* MCOCIDURLProtocol.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MCOCIDURLProtocol.mm; sourceTree = "<group>"; };
+ ABE40267173F0151007F1FB3 /* MCOMessageViewScript.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = MCOMessageViewScript.js; sourceTree = "<group>"; };
+ ABE4026A173F3FCE007F1FB3 /* ImageIO.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ImageIO.framework; path = System/Library/Frameworks/ImageIO.framework; sourceTree = SDKROOT; };
B12AAA2F17322654003551C7 /* MCOMessageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCOMessageView.h; sourceTree = "<group>"; };
B12AAA3017322654003551C7 /* MCOMessageView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MCOMessageView.mm; sourceTree = "<group>"; };
B12AAA3117322654003551C7 /* MCTMsgViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCTMsgViewController.h; sourceTree = "<group>"; };
- B12AAA3217322654003551C7 /* MCTMsgViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MCTMsgViewController.m; sourceTree = "<group>"; };
+ B12AAA3217322654003551C7 /* MCTMsgViewController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MCTMsgViewController.mm; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -114,6 +116,7 @@
buildActionMask = 2147483647;
files = (
AB7BA446171389CC00104953 /* libMailCore-ios.a in Frameworks */,
+ ABE4026B173F3FCE007F1FB3 /* ImageIO.framework in Frameworks */,
AB9EAE40170374D900D750C7 /* Security.framework in Frameworks */,
AB9EAE06170368F000D750C7 /* UIKit.framework in Frameworks */,
AB9EAE08170368F000D750C7 /* Foundation.framework in Frameworks */,
@@ -168,6 +171,7 @@
AB9EAE04170368F000D750C7 /* Frameworks */ = {
isa = PBXGroup;
children = (
+ ABE4026A173F3FCE007F1FB3 /* ImageIO.framework */,
AB7BA4471713913F00104953 /* CFNetwork.framework */,
AB9EAE3F170374D900D750C7 /* Security.framework */,
AB9EAE05170368F000D750C7 /* UIKit.framework */,
@@ -187,16 +191,15 @@
AB9EAE1D170368F000D750C7 /* MainStoryboard.storyboard */,
AB9EAE20170368F000D750C7 /* MasterViewController.h */,
AB9EAE21170368F000D750C7 /* MasterViewController.m */,
- B12AAA2D17322654003551C7 /* MCOCIDURLProtocol.h */,
- B12AAA2E17322654003551C7 /* MCOCIDURLProtocol.mm */,
B12AAA2F17322654003551C7 /* MCOMessageView.h */,
B12AAA3017322654003551C7 /* MCOMessageView.mm */,
+ ABE40267173F0151007F1FB3 /* MCOMessageViewScript.js */,
B12AAA3117322654003551C7 /* MCTMsgViewController.h */,
- B12AAA3217322654003551C7 /* MCTMsgViewController.m */,
- AB9EAE0C170368F000D750C7 /* Supporting Files */,
+ B12AAA3217322654003551C7 /* MCTMsgViewController.mm */,
AB9EAE3317036FD600D750C7 /* SettingsViewController.h */,
AB9EAE3417036FD600D750C7 /* SettingsViewController.m */,
AB9EAE3517036FD700D750C7 /* SettingsViewController.xib */,
+ AB9EAE0C170368F000D750C7 /* Supporting Files */,
AB665BC917134336007F2151 /* common */,
);
path = "iOS UI Test";
@@ -311,6 +314,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ ABE40269173F0282007F1FB3 /* MCOMessageViewScript.js in Resources */,
AB9EAE10170368F000D750C7 /* InfoPlist.strings in Resources */,
AB9EAE18170368F000D750C7 /* Default.png in Resources */,
AB9EAE1A170368F000D750C7 /* Default@2x.png in Resources */,
@@ -332,9 +336,9 @@
AB9EAE22170368F000D750C7 /* MasterViewController.m in Sources */,
AB9EAE3617036FD700D750C7 /* SettingsViewController.m in Sources */,
AB665BCD17134336007F2151 /* FXKeychain.m in Sources */,
- B12AAA3317322654003551C7 /* MCOCIDURLProtocol.mm in Sources */,
B12AAA3417322654003551C7 /* MCOMessageView.mm in Sources */,
- B12AAA3517322654003551C7 /* MCTMsgViewController.m in Sources */,
+ B12AAA3517322654003551C7 /* MCTMsgViewController.mm in Sources */,
+ ABE40268173F0151007F1FB3 /* MCOMessageViewScript.js in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/example/ios/iOS UI Test/iOS UI Test/MCOCIDURLProtocol.h b/example/ios/iOS UI Test/iOS UI Test/MCOCIDURLProtocol.h
deleted file mode 100755
index ac4b0f2b..00000000
--- a/example/ios/iOS UI Test/iOS UI Test/MCOCIDURLProtocol.h
+++ /dev/null
@@ -1,31 +0,0 @@
-//
-// MCTCIDURLProtocol.h
-// testUI
-//
-// Created by DINH Viêt Hoà on 1/22/13.
-// Copyright (c) 2013 MailCore. All rights reserved.
-//
-
-#import <Foundation/Foundation.h>
-
-#include <MailCore/MailCore.h>
-
-@interface MCOCIDURLProtocol : NSURLProtocol
-
-+ (void) registerProtocol;
-
-+ (BOOL) isCID:(NSURL *)url;
-+ (BOOL) isXMailcoreImage:(NSURL *)url;
-
-#ifdef __cplusplus
-+ (void) startLoadingWithMessage:(MCOAbstractMessage *)message
- partUniqueID:(NSString *)partUniqueID
- data:(NSData *)data
- request:(NSMutableURLRequest *)request;
-
-+ (void) partDownloadedMessage:(MCOAbstractMessage *)message
- partUniqueID:(NSString *)partUniqueID
- data:(NSData *)data;
-#endif
-
-@end
diff --git a/example/ios/iOS UI Test/iOS UI Test/MCOCIDURLProtocol.mm b/example/ios/iOS UI Test/iOS UI Test/MCOCIDURLProtocol.mm
deleted file mode 100755
index 6a6d0a03..00000000
--- a/example/ios/iOS UI Test/iOS UI Test/MCOCIDURLProtocol.mm
+++ /dev/null
@@ -1,145 +0,0 @@
-//
-// MCTCIDURLProtocol.m
-// testUI
-//
-// Created by DINH Viêt Hoà on 1/22/13.
-// Copyright (c) 2013 MailCore. All rights reserved.
-//
-
-#import "MCOCIDURLProtocol.h"
-
-#import "MCOMessageView.h"
-
-#define MCOCIDURLProtocolDownloadedNotification @"MCOCIDURLProtocolDownloadedNotification"
-
-@implementation MCOCIDURLProtocol
-
-+ (void) registerProtocol
-{
- static dispatch_once_t onceToken = 0;
- dispatch_once(&onceToken, ^{
- [NSURLProtocol registerClass:[MCOCIDURLProtocol class]];
- });
-}
-
-+ (BOOL) canInitWithRequest:(NSURLRequest *)theRequest
-{
- if ([self isCID:[theRequest URL]])
- return YES;
- if ([self isXMailcoreImage:[theRequest URL]])
- return YES;
- return NO;
-}
-
-+ (BOOL) isCID:(NSURL *)url
-{
- NSString *theScheme = [url scheme];
- if ([theScheme caseInsensitiveCompare:@"cid"] == NSOrderedSame)
- return YES;
- return NO;
-}
-
-+ (BOOL) isXMailcoreImage:(NSURL *)url
-{
- NSString *theScheme = [url scheme];
- if ([theScheme caseInsensitiveCompare:@"x-mailcore-image"] == NSOrderedSame)
- return YES;
- return NO;
-}
-
-+ (NSURLRequest *) canonicalRequestForRequest:(NSURLRequest *)request
-{
- return request;
-}
-
-- (id) initWithRequest:(NSURLRequest *)request cachedResponse:(NSCachedURLResponse *)cachedResponse client:(id < NSURLProtocolClient >)client
-{
- self = [super initWithRequest:request cachedResponse:cachedResponse client:client];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_downloaded:) name:MCOCIDURLProtocolDownloadedNotification object:nil];
- return self;
-}
-
-- (void) dealloc
-{
- [[NSNotificationCenter defaultCenter] removeObserver:self];
-}
-
-- (NSString *) _partUniqueID
-{
- return [NSURLProtocol propertyForKey:@"PartUniqueID" inRequest:[self request]];
-}
-
-- (NSData *) _data
-{
- return [NSURLProtocol propertyForKey:@"Data" inRequest:[self request]];
-}
-
-- (MCOAbstractMessage *) _message
-{
- return (MCOAbstractMessage *) [NSURLProtocol propertyForKey:@"Message" inRequest:[self request]];
-}
-
-- (void) startLoading
-{
- //NSLog(@"waiting for %p %@", self, [self _partUniqueID]);
- if ([self _data] != NULL) {
- [[self class] partDownloadedMessage:[self _message] partUniqueID:[self _partUniqueID] data:[self _data]];
- }
-}
-
-- (void) _downloaded:(NSNotification *)notification
-{
- NSDictionary * userInfo = [notification userInfo];
-
- //NSLog(@"downloaded?");
- NSString * notifPartID = [userInfo objectForKey:@"PartUniqueID"];
- MCOAbstractMessage * notifMessage = [userInfo objectForKey:@"Message"];
- if (notifMessage != [self _message]) {
- return;
- }
- if (![[self _partUniqueID] isEqualToString:notifPartID]) {
- return;
- }
-
- //NSLog(@"downloaded2 %p %@", self, notifPartID);
-
- NSData * data = [userInfo objectForKey:@"Data"];
- NSURLResponse * response = [[NSURLResponse alloc] initWithURL:[[self request] URL] MIMEType:@"application/data"
- expectedContentLength:[data length] textEncodingName:nil];
- [[self client] URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
- [[self client] URLProtocol:self didLoadData:data];
- [[self client] URLProtocolDidFinishLoading:self];
-}
-
-- (void) stopLoading
-{
-}
-
-+ (void) startLoadingWithMessage:(MCOAbstractMessage *)message
- partUniqueID:(NSString *)partUniqueID
- data:(NSData *)data
- request:(NSMutableURLRequest *)request
-{
- [NSURLProtocol setProperty:message
- forKey:@"Message" inRequest:request];
- if (data != NULL) {
- [NSURLProtocol setProperty:data forKey:@"Data" inRequest:request];
- }
- [NSURLProtocol setProperty:partUniqueID forKey:@"PartUniqueID" inRequest:request];
-}
-
-+ (void) partDownloadedMessage:(MCOAbstractMessage *)message
- partUniqueID:(NSString *)partUniqueID
- data:(NSData *)data
-{
- NSMutableDictionary * userInfo = [[NSMutableDictionary alloc] init];
- [userInfo setObject:message forKey:@"Message"];
- [userInfo setObject:partUniqueID forKey:@"PartUniqueID"];
- if (data != NULL) {
- [userInfo setObject:data forKey:@"Data"];
- }
- [[NSNotificationCenter defaultCenter] postNotificationName:MCOCIDURLProtocolDownloadedNotification object:nil userInfo:userInfo];
- //NSLog(@"downloaded %p %@", self, partUniqueID);
-}
-
-@end
diff --git a/example/ios/iOS UI Test/iOS UI Test/MCOMessageView.mm b/example/ios/iOS UI Test/iOS UI Test/MCOMessageView.mm
index 87e07b57..c39ee1af 100755
--- a/example/ios/iOS UI Test/iOS UI Test/MCOMessageView.mm
+++ b/example/ios/iOS UI Test/iOS UI Test/MCOMessageView.mm
@@ -8,8 +8,6 @@
#import "MCOMessageView.h"
-#import "MCOCIDURLProtocol.h"
-
@interface MCOMessageView () <MCOHTMLRendererIMAPDelegate>
@end
@@ -28,11 +26,6 @@
@synthesize prefetchIMAPImagesEnabled = _prefetchIMAPImagesEnabled;
@synthesize prefetchIMAPAttachmentsEnabled = _prefetchIMAPAttachmentsEnabled;
-+ (void) initialize
-{
- [MCOCIDURLProtocol registerProtocol];
-}
-
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
@@ -89,8 +82,99 @@
content = nil;
MCAssert(0);
}
- }
- [_webView loadHTMLString:content baseURL:nil];
+ }
+ if (content == nil) {
+ [_webView loadHTMLString:@"" baseURL:nil];
+ return;
+ }
+
+ NSMutableString * html = [NSMutableString string];
+ NSURL * jsURL = [[NSBundle mainBundle] URLForResource:@"MCOMessageViewScript" withExtension:@"js"];
+ [html appendFormat:@"<html><head><script src=\"%@\"></script></head><body'>%@</body><iframe src='x-mailcore-msgviewloaded:' style='width: 0px; height: 0px; border: none;'></iframe></html>",
+ [jsURL absoluteString], content];
+ [_webView loadHTMLString:html baseURL:nil];
+}
+
+- (BOOL) _isCID:(NSURL *)url
+{
+ NSString *theScheme = [url scheme];
+ if ([theScheme caseInsensitiveCompare:@"cid"] == NSOrderedSame)
+ return YES;
+ return NO;
+}
+
+- (BOOL) _isXMailcoreImage:(NSURL *)url
+{
+ NSString *theScheme = [url scheme];
+ if ([theScheme caseInsensitiveCompare:@"x-mailcore-image"] == NSOrderedSame)
+ return YES;
+ return NO;
+}
+
+- (void) _loadImages
+{
+ NSString * result = [_webView stringByEvaluatingJavaScriptFromString:@"findCIDImageURL()"];
+ NSData * data = [result dataUsingEncoding:NSUTF8StringEncoding];
+ NSError *error = nil;
+ NSArray * imagesURLStrings = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
+
+ for(NSString * urlString in imagesURLStrings) {
+ MCOAbstractPart * part = nil;
+ NSURL * url;
+
+ url = [NSURL URLWithString:urlString];
+ if ([self _isCID:url]) {
+ part = [self _partForCIDURL:url];
+ }
+ else if ([self _isXMailcoreImage:url]) {
+ NSString * specifier = [url resourceSpecifier];
+ NSString * partUniqueID = specifier;
+ part = [self _partForUniqueID:partUniqueID];
+ }
+
+ if (part == nil)
+ continue;
+
+ NSString * partUniqueID = [part uniqueID];
+ NSData * data = [[self delegate] MCOMessageView:self dataForPartWithUniqueID:partUniqueID];
+
+ void (^replaceImages)(NSError *error) = ^(NSError *error) {
+ NSData * downloadedData = [[self delegate] MCOMessageView:self dataForPartWithUniqueID:partUniqueID];
+ NSData * previewData = [[self delegate] MCOMessageView:self previewForData:downloadedData isHTMLInlineImage:[self _isCID:url]];
+ NSString * filename = [NSString stringWithFormat:@"%lu", (unsigned long)urlString.hash];
+ NSURL * cacheURL = [self _cacheJPEGImageData:previewData withFilename:filename];
+
+ NSDictionary * args = @{ @"URLKey": urlString, @"LocalPathKey": cacheURL.absoluteString };
+ NSString * jsonString = [self _jsonEscapedStringFromDictionary:args];
+
+ NSString * replaceScript = [NSString stringWithFormat:@"replaceImageSrc(\"%@\")", jsonString];
+ [_webView stringByEvaluatingJavaScriptFromString:replaceScript];
+ };
+
+ if (data == nil) {
+ [[self delegate] MCOMessageView:self fetchDataForPartWithUniqueID:partUniqueID downloadedFinished:^(NSError * error) {
+ replaceImages(error);
+ }];
+ } else {
+ replaceImages(nil);
+ }
+ }
+}
+
+- (NSString *) _jsonEscapedStringFromDictionary:(NSDictionary *)dictionary
+{
+ NSData * json = [NSJSONSerialization dataWithJSONObject:dictionary options:0 error:nil];
+ NSString * jsonString = [[NSString alloc] initWithData:json encoding:NSUTF8StringEncoding];
+ jsonString = [jsonString stringByReplacingOccurrencesOfString:@"\\" withString:@"\\\\"];
+ jsonString = [jsonString stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
+ return jsonString;
+}
+
+- (NSURL *) _cacheJPEGImageData:(NSData *)imageData withFilename:(NSString *)filename
+{
+ NSString * path = [[NSTemporaryDirectory() stringByAppendingPathComponent:filename] stringByAppendingPathExtension:@"jpg"];
+ [imageData writeToFile:path atomically:YES];
+ return [NSURL fileURLWithPath:path];
}
- (MCOAbstractPart *) _partForCIDURL:(NSURL *)url
@@ -120,68 +204,21 @@
NSURLRequest *responseRequest = [self webView:webView resource:nil willSendRequest:request redirectResponse:nil fromDataSource:nil];
- //NSLog(@"responseRequest:%@", responseRequest);
-
if(responseRequest == request) {
return YES;
} else {
[webView loadRequest:responseRequest];
return NO;
}
-
}
- (NSURLRequest *)webView:(UIWebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(id)dataSource
-{
- MCOAbstractPart * part = NULL;
-
- if ([MCOCIDURLProtocol isCID:[request URL]]) {
- part = [self _partForCIDURL:[request URL]];
- }
- else if ([MCOCIDURLProtocol isXMailcoreImage:[ request URL]]) {
- NSString * specifier = [[request URL] resourceSpecifier];
- NSString * partUniqueID = specifier;
- part = [self _partForUniqueID:partUniqueID];
- }
-
- if (part != NULL) {
- if ([_message isKindOfClass:[MCOIMAPMessage class]]) {
- NSMutableURLRequest * mutableRequest = [request mutableCopy];
- NSString * partUniqueID = [part uniqueID];
- NSData * data = [[self delegate] MCOMessageView:self dataForPartWithUniqueID:partUniqueID];
- if (data == NULL) {
- [[self delegate] MCOMessageView:self fetchDataForPartWithUniqueID:partUniqueID downloadedFinished:^(NSError * error) {
- NSData * downloadedData = [[self delegate] MCOMessageView:self dataForPartWithUniqueID:partUniqueID];
- NSData * previewData = [[self delegate] MCOMessageView:self previewForData:downloadedData isHTMLInlineImage:[MCOCIDURLProtocol isCID:[request URL]]];
- [MCOCIDURLProtocol partDownloadedMessage:_message partUniqueID:partUniqueID data:previewData];
- }];
- }
- [MCOCIDURLProtocol startLoadingWithMessage:_message
- partUniqueID:partUniqueID
- data:data
- request:mutableRequest];
-
- return mutableRequest;
- }
- else if ([_message isKindOfClass:[MCOMessageParser class]]) {
- NSMutableURLRequest * mutableRequest = [request mutableCopy];
- NSString * partUniqueID = [part uniqueID];
- NSData * data = [(MCOAttachment *) part data];
- NSData * previewData = [[self delegate] MCOMessageView:self previewForData:data isHTMLInlineImage:[MCOCIDURLProtocol isCID:[request URL]]];
- [MCOCIDURLProtocol startLoadingWithMessage:_message
- partUniqueID:partUniqueID
- data:previewData
- request:mutableRequest];
-
- return mutableRequest;
- }
- else {
- return request;
- }
- }
- else {
- return request;
+{
+ if ([[[request URL] scheme] isEqualToString:@"x-mailcore-msgviewloaded"]) {
+ [self _loadImages];
}
+
+ return request;
}
- (BOOL) MCOAbstractMessage:(MCOAbstractMessage *)msg canPreviewPart:(MCOAbstractPart *)part
diff --git a/example/ios/iOS UI Test/iOS UI Test/MCOMessageViewScript.js b/example/ios/iOS UI Test/iOS UI Test/MCOMessageViewScript.js
new file mode 100644
index 00000000..1078b04b
--- /dev/null
+++ b/example/ios/iOS UI Test/iOS UI Test/MCOMessageViewScript.js
@@ -0,0 +1,30 @@
+
+var imageElements = function() {
+ var imageNodes = document.getElementsByTagName('img');
+ return [].slice.call(imageNodes);
+}
+
+var findCIDImageURL = function() {
+ var images = imageElements();
+
+ var imgLinks = [];
+ for (var i = 0; i < images.length; i++) {
+ var url = images[i].getAttribute('src');
+ if (url.indexOf('cid:') == 0 || url.indexOf('x-mailcore-image:') == 0)
+ imgLinks.push(url);
+ }
+ return JSON.stringify(imgLinks);
+}
+
+var replaceImageSrc = function(jsonString) {
+ var parsedJson = JSON.parse(jsonString);
+ var images = imageElements();
+
+ for (var i = 0; i < images.length; i++) {
+ var url = images[i].getAttribute('src');
+ if (url.indexOf(parsedJson.URLKey) == 0) {
+ images[i].setAttribute('src', parsedJson.LocalPathKey);
+ break;
+ }
+ }
+}
diff --git a/example/ios/iOS UI Test/iOS UI Test/MCTMsgViewController.m b/example/ios/iOS UI Test/iOS UI Test/MCTMsgViewController.mm
index 6e3e8d52..b60e91c7 100755
--- a/example/ios/iOS UI Test/iOS UI Test/MCTMsgViewController.m
+++ b/example/ios/iOS UI Test/iOS UI Test/MCTMsgViewController.mm
@@ -7,7 +7,8 @@
//
#import "MCTMsgViewController.h"
-
+#import <CoreGraphics/CoreGraphics.h>
+#import <ImageIO/ImageIO.h>
#import "MCOMessageView.h"
@interface MCTMsgViewController () <MCOMessageViewDelegate>
@@ -68,7 +69,7 @@
- (void) setMessage:(MCOIMAPMessage *)message
{
- NSLog(@"set message : %@", message);
+ MCLog("set message : %s", message.description.UTF8String);
for(MCOOperation * op in _ops) {
[op cancel];
}
@@ -87,7 +88,7 @@
- (MCOIMAPFetchContentOperation *) _fetchIMAPPartWithUniqueID:(NSString *)partUniqueID folder:(NSString *)folder
{
- NSLog(@"%@ is missing, fetching", partUniqueID);
+ MCLog("%s is missing, fetching", partUniqueID.description.UTF8String);
if ([_pending containsObject:partUniqueID]) {
return NULL;
@@ -110,7 +111,7 @@
[_ops removeObject:op];
[_storage setObject:data forKey:partUniqueID];
[_pending removeObject:partUniqueID];
- NSLog(@"downloaded %@", partUniqueID);
+ MCLog("downloaded %s", partUniqueID.description.UTF8String);
[self _callbackForPartUniqueID:partUniqueID error:nil];
}];
@@ -124,11 +125,9 @@ typedef void (^DownloadCallback)(NSError * error);
{
NSArray * blocks;
blocks = [_callbacks objectForKey:partUniqueID];
- NSLog(@"%@", blocks);
for(DownloadCallback block in blocks) {
block(error);
}
- NSLog(@"done: %@", blocks);
}
- (NSString *) MCOMessageView_templateForAttachment:(MCOMessageView *)view
@@ -189,8 +188,14 @@ typedef void (^DownloadCallback)(NSError * error);
- (NSData *) MCOMessageView:(MCOMessageView *)view dataForPartWithUniqueID:(NSString *)partUniqueID
{
- NSData * data = [_storage objectForKey:partUniqueID];
- return data;
+ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"FetchFullMessageEnabled"]) {
+ MCOAttachment * attachment = (MCOAttachment *) [[_messageView message] partForUniqueID:partUniqueID];
+ return [attachment data];
+ }
+ else {
+ NSData * data = [_storage objectForKey:partUniqueID];
+ return data;
+ }
}
- (void) MCOMessageView:(MCOMessageView *)view fetchDataForPartWithUniqueID:(NSString *)partUniqueID
@@ -198,7 +203,7 @@ typedef void (^DownloadCallback)(NSError * error);
{
MCOIMAPFetchContentOperation * op = [self _fetchIMAPPartWithUniqueID:partUniqueID folder:_folder];
[op setProgress:^(unsigned int current, unsigned int maximum) {
- NSLog(@"progress content: %u/%u", current, maximum);
+ MCLog("progress content: %u/%u", current, maximum);
}];
[_ops addObject:op];
if (downloadFinished != NULL) {
@@ -225,47 +230,45 @@ typedef void (^DownloadCallback)(NSError * error);
#define IMAGE_PREVIEW_HEIGHT 300
#define IMAGE_PREVIEW_WIDTH 500
-- (NSData *) _convertToJPEGData:(NSData *)data
-{
-// CGImageRef imageSource;
-// CGImageRef thumbnail;
-// NSMutableDictionary * info;
-// int width;
-// int height;
-// float quality;
-//
-// width = IMAGE_PREVIEW_WIDTH;
-// height = IMAGE_PREVIEW_HEIGHT;
-// quality = 1.0;
-//
-// imageSource = CGImageSourceCreateWithData((__bridge CFDataRef) data, NULL);
-// if (imageSource == NULL)
-// return nil;
-//
-// info = [[NSMutableDictionary alloc] init];
-// [info setObject:(id) kCFBooleanTrue forKey:(id) kCGImageSourceCreateThumbnailWithTransform];
-// [info setObject:(id) kCFBooleanTrue forKey:(id) kCGImageSourceCreateThumbnailFromImageAlways];
-// [info setObject:(id) [NSNumber numberWithFloat:(float) IMAGE_PREVIEW_WIDTH] forKey:(id) kCGImageSourceThumbnailMaxPixelSize];
-// thumbnail = CGImageSourceCreateThumbnailAtIndex(imageSource, 0, (CFDictionaryRef) info);
-// [info release];
-//
-// CGImageDestinationRef destination;
-// NSMutableData * destData = [NSMutableData data];
-//
-// destination = CGImageDestinationCreateWithData((CFMutableDataRef) destData,
-// (CFStringRef) @"public.jpeg",
-// 1, NULL);
-//
-// CGImageDestinationAddImage(destination, thumbnail, NULL);
-// CGImageDestinationFinalize(destination);
-//
-// CFRelease(destination);
-//
-// CFRelease(thumbnail);
-// CFRelease(imageSource);
-//
-// return destData;
- return nil;
+- (NSData *) _convertToJPEGData:(NSData *)data {
+ CGImageSourceRef imageSource;
+ CGImageRef thumbnail;
+ NSMutableDictionary * info;
+ int width;
+ int height;
+ float quality;
+
+ width = IMAGE_PREVIEW_WIDTH;
+ height = IMAGE_PREVIEW_HEIGHT;
+ quality = 1.0;
+
+ imageSource = CGImageSourceCreateWithData((__bridge CFDataRef) data, NULL);
+ if (imageSource == NULL)
+ return nil;
+
+ info = [[NSMutableDictionary alloc] init];
+ [info setObject:(id) kCFBooleanTrue forKey:(id) kCGImageSourceCreateThumbnailWithTransform];
+ [info setObject:(id) kCFBooleanTrue forKey:(id) kCGImageSourceCreateThumbnailFromImageAlways];
+ [info setObject:(id) [NSNumber numberWithFloat:(float) IMAGE_PREVIEW_WIDTH] forKey:(id) kCGImageSourceThumbnailMaxPixelSize];
+ thumbnail = CGImageSourceCreateThumbnailAtIndex(imageSource, 0, (__bridge CFDictionaryRef) info);
+ //[info release];
+
+ CGImageDestinationRef destination;
+ NSMutableData * destData = [NSMutableData data];
+
+ destination = CGImageDestinationCreateWithData((__bridge CFMutableDataRef) destData,
+ + (CFStringRef) @"public.jpeg",
+ + 1, NULL);
+
+ CGImageDestinationAddImage(destination, thumbnail, NULL);
+ CGImageDestinationFinalize(destination);
+
+ CFRelease(destination);
+
+ CFRelease(thumbnail);
+ CFRelease(imageSource);
+
+ return destData;
}
@end
diff --git a/example/ios/iOS UI Test/iOS UI Test/MasterViewController.m b/example/ios/iOS UI Test/iOS UI Test/MasterViewController.m
index 493c8e5b..c9866ff8 100644
--- a/example/ios/iOS UI Test/iOS UI Test/MasterViewController.m
+++ b/example/ios/iOS UI Test/iOS UI Test/MasterViewController.m
@@ -22,7 +22,7 @@
@implementation MasterViewController
- (void)viewDidLoad {
- [super viewDidLoad];
+ [super viewDidLoad];
[[NSUserDefaults standardUserDefaults] registerDefaults:@{ HostnameKey: @"imap.gmail.com" }];
@@ -64,9 +64,9 @@
- (void)loadEmails {
MCOIMAPMessagesRequestKind requestKind = (MCOIMAPMessagesRequestKind)
- (MCOIMAPMessagesRequestKindHeaders | MCOIMAPMessagesRequestKindStructure |
- MCOIMAPMessagesRequestKindInternalDate | MCOIMAPMessagesRequestKindHeaderSubject |
- MCOIMAPMessagesRequestKindFlags);
+ (MCOIMAPMessagesRequestKindHeaders | MCOIMAPMessagesRequestKindStructure |
+ MCOIMAPMessagesRequestKindInternalDate | MCOIMAPMessagesRequestKindHeaderSubject |
+ MCOIMAPMessagesRequestKindFlags);
self.imapMessagesFetchOp = [self.imapSession fetchMessagesByUIDOperationWithFolder:@"INBOX"
requestKind:requestKind
uids:[MCOIndexSet indexSetWithRange:MCORangeMake(1, UINT64_MAX)]];
@@ -80,13 +80,13 @@
NSLog(@"fetched all messages.");
NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"header.date" ascending:NO];
- strongSelf.messages = [messages sortedArrayUsingDescriptors:@[sort]];//[NSArray arrayWithArray:messages];
+ strongSelf.messages = [messages sortedArrayUsingDescriptors:@[sort]];
[strongSelf.tableView reloadData];
}];
}
- (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
+ [super didReceiveMemoryWarning];
NSLog(@"%s",__PRETTY_FUNCTION__);
}
@@ -101,12 +101,12 @@
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
MCOIMAPMessage *message = self.messages[indexPath.row];
cell.textLabel.text = message.header.subject;
- return cell;
+ return cell;
}
- (void)showSettingsViewController:(id)sender {
@@ -133,11 +133,12 @@
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- MCOIMAPMessage *msg = self.messages[indexPath.row];
- MCTMsgViewController *vc = [[MCTMsgViewController alloc] init];
- vc.message = msg;
- vc.session = self.imapSession;
- [self.navigationController pushViewController:vc animated:YES];
+ MCOIMAPMessage *msg = self.messages[indexPath.row];
+ MCTMsgViewController *vc = [[MCTMsgViewController alloc] init];
+ vc.folder = @"INBOX";
+ vc.message = msg;
+ vc.session = self.imapSession;
+ [self.navigationController pushViewController:vc animated:YES];
}
@end