Created
May 12, 2013 01:58
-
-
Save dinhvh/5562118 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 bf9f8cb..5530ef5 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 | |
@@ -27,6 +27,8 @@ | |
B12AAA3317322654003551C7 /* MCOCIDURLProtocol.mm in Sources */ = {isa = PBXBuildFile; fileRef = B12AAA2E17322654003551C7 /* MCOCIDURLProtocol.mm */; }; | |
B12AAA3417322654003551C7 /* MCOMessageView.mm in Sources */ = {isa = PBXBuildFile; fileRef = B12AAA3017322654003551C7 /* MCOMessageView.mm */; }; | |
B12AAA3517322654003551C7 /* MCTMsgViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B12AAA3217322654003551C7 /* MCTMsgViewController.m */; }; | |
+ C668E306173F009100A2BB47 /* ios-message.js in Resources */ = {isa = PBXBuildFile; fileRef = C668E304173EFD5200A2BB47 /* ios-message.js */; }; | |
+ C668E308173F291500A2BB47 /* ImageIO.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C668E307173F291500A2BB47 /* ImageIO.framework */; }; | |
/* End PBXBuildFile section */ | |
/* Begin PBXContainerItemProxy section */ | |
@@ -106,6 +108,8 @@ | |
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>"; }; | |
+ C668E304173EFD5200A2BB47 /* ios-message.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = "ios-message.js"; sourceTree = "<group>"; }; | |
+ C668E307173F291500A2BB47 /* ImageIO.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ImageIO.framework; path = System/Library/Frameworks/ImageIO.framework; sourceTree = SDKROOT; }; | |
/* End PBXFileReference section */ | |
/* Begin PBXFrameworksBuildPhase section */ | |
@@ -113,6 +117,7 @@ | |
isa = PBXFrameworksBuildPhase; | |
buildActionMask = 2147483647; | |
files = ( | |
+ C668E308173F291500A2BB47 /* ImageIO.framework in Frameworks */, | |
AB7BA446171389CC00104953 /* libMailCore-ios.a in Frameworks */, | |
AB9EAE40170374D900D750C7 /* Security.framework in Frameworks */, | |
AB9EAE06170368F000D750C7 /* UIKit.framework in Frameworks */, | |
@@ -151,6 +156,7 @@ | |
AB9EADF9170368F000D750C7 = { | |
isa = PBXGroup; | |
children = ( | |
+ C668E307173F291500A2BB47 /* ImageIO.framework */, | |
AB9EAE0B170368F000D750C7 /* iOS UI Test */, | |
AB9EAE04170368F000D750C7 /* Frameworks */, | |
AB9EAE03170368F000D750C7 /* Products */, | |
@@ -180,6 +186,7 @@ | |
AB9EAE0B170368F000D750C7 /* iOS UI Test */ = { | |
isa = PBXGroup; | |
children = ( | |
+ C668E2FF173EFD2F00A2BB47 /* resources */, | |
AB7BA4321713898B00104953 /* mailcore2.xcodeproj */, | |
AB9EAE11170368F000D750C7 /* main.mm */, | |
AB9EAE14170368F000D750C7 /* AppDelegate.h */, | |
@@ -215,6 +222,14 @@ | |
name = "Supporting Files"; | |
sourceTree = "<group>"; | |
}; | |
+ C668E2FF173EFD2F00A2BB47 /* resources */ = { | |
+ isa = PBXGroup; | |
+ children = ( | |
+ C668E304173EFD5200A2BB47 /* ios-message.js */, | |
+ ); | |
+ name = resources; | |
+ sourceTree = "<group>"; | |
+ }; | |
/* End PBXGroup section */ | |
/* Begin PBXNativeTarget section */ | |
@@ -313,6 +328,7 @@ | |
files = ( | |
AB9EAE10170368F000D750C7 /* InfoPlist.strings in Resources */, | |
AB9EAE18170368F000D750C7 /* Default.png in Resources */, | |
+ C668E306173F009100A2BB47 /* ios-message.js in Resources */, | |
AB9EAE1A170368F000D750C7 /* Default@2x.png in Resources */, | |
AB9EAE1C170368F000D750C7 /* Default-568h@2x.png in Resources */, | |
AB9EAE1F170368F000D750C7 /* MainStoryboard.storyboard in Resources */, | |
diff --git a/example/ios/iOS UI Test/iOS UI Test/MCOCIDURLProtocol.mm b/example/ios/iOS UI Test/iOS UI Test/MCOCIDURLProtocol.mm | |
index 6a6d0a0..029db88 100755 | |
--- a/example/ios/iOS UI Test/iOS UI Test/MCOCIDURLProtocol.mm | |
+++ b/example/ios/iOS UI Test/iOS UI Test/MCOCIDURLProtocol.mm | |
@@ -56,6 +56,7 @@ | |
{ | |
self = [super initWithRequest:request cachedResponse:cachedResponse client:client]; | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_downloaded:) name:MCOCIDURLProtocolDownloadedNotification object:nil]; | |
+ NSLog(@"%@", [request mainDocumentURL]); | |
return self; | |
} | |
@@ -82,6 +83,7 @@ | |
- (void) startLoading | |
{ | |
//NSLog(@"waiting for %p %@", self, [self _partUniqueID]); | |
+ NSLog(@"%@", [self request]); | |
if ([self _data] != NULL) { | |
[[self class] partDownloadedMessage:[self _message] partUniqueID:[self _partUniqueID] data:[self _data]]; | |
} | |
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 87e07b5..ad4e806 100755 | |
--- a/example/ios/iOS UI Test/iOS UI Test/MCOMessageView.mm | |
+++ b/example/ios/iOS UI Test/iOS UI Test/MCOMessageView.mm | |
@@ -21,6 +21,7 @@ | |
__weak id <MCOMessageViewDelegate> _delegate; | |
BOOL _prefetchIMAPImagesEnabled; | |
BOOL _prefetchIMAPAttachmentsEnabled; | |
+ int _frameLoadCount; | |
} | |
@synthesize folder = _folder; | |
@@ -90,7 +91,55 @@ | |
MCAssert(0); | |
} | |
} | |
- [_webView loadHTMLString:content baseURL:nil]; | |
+ | |
+ if (content == nil) { | |
+ NSString * urlString = [NSString stringWithFormat:@"file:///%p", self]; | |
+ [_webView loadHTMLString:@"" baseURL:/*[NSURL URLWithString:urlString]*/nil]; | |
+ return; | |
+ } | |
+ | |
+ NSMutableString * html = [NSMutableString string]; | |
+ NSURL * jsURL = [[NSBundle mainBundle] URLForResource:@"ios-message" 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]; | |
+} | |
+ | |
+- (void) _loadImages | |
+{ | |
+ NSString * result; | |
+ result = [_webView stringByEvaluatingJavaScriptFromString:@"findCIDImageURL()"]; | |
+ NSData * data = [result dataUsingEncoding:NSUTF8StringEncoding]; | |
+ NSArray * imagesURLStrings = [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL]; | |
+ | |
+ for(NSString * urlString in imagesURLStrings) { | |
+ MCOAbstractPart * part = nil; | |
+ NSURL * url; | |
+ | |
+ url = [NSURL URLWithString:urlString]; | |
+ if ([MCOCIDURLProtocol isCID:url]) { | |
+ part = [self _partForCIDURL:url]; | |
+ } | |
+ else if ([MCOCIDURLProtocol isXMailcoreImage:url]) { | |
+ NSString * specifier = [url resourceSpecifier]; | |
+ NSString * partUniqueID = specifier; | |
+ part = [self _partForUniqueID:partUniqueID]; | |
+ } | |
+ | |
+ 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:url]]; | |
+ [MCOCIDURLProtocol partDownloadedMessage:_message partUniqueID:partUniqueID data:previewData]; | |
+ }]; | |
+ } | |
+ [MCOCIDURLProtocol startLoadingWithMessage:_message | |
+ partUniqueID:partUniqueID | |
+ data:data | |
+ request:nil]; | |
+ } | |
} | |
- (MCOAbstractPart *) _partForCIDURL:(NSURL *)url | |
@@ -116,8 +165,8 @@ | |
return data; | |
} | |
-- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { | |
- | |
+- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType | |
+{ | |
NSURLRequest *responseRequest = [self webView:webView resource:nil willSendRequest:request redirectResponse:nil fromDataSource:nil]; | |
//NSLog(@"responseRequest:%@", responseRequest); | |
@@ -135,6 +184,11 @@ | |
{ | |
MCOAbstractPart * part = NULL; | |
+ if ([[[request URL] scheme] isEqualToString:@"x-mailcore-msgviewloaded"]) { | |
+ [self _loadImages]; | |
+ return request; | |
+ } | |
+ | |
if ([MCOCIDURLProtocol isCID:[request URL]]) { | |
part = [self _partForCIDURL:[request URL]]; | |
} | |
diff --git a/example/ios/iOS UI Test/iOS UI Test/MCTMsgViewController.m b/example/ios/iOS UI Test/iOS UI Test/MCTMsgViewController.m | |
index 6e3e8d5..1bd58d4 100755 | |
--- a/example/ios/iOS UI Test/iOS UI Test/MCTMsgViewController.m | |
+++ b/example/ios/iOS UI Test/iOS UI Test/MCTMsgViewController.m | |
@@ -9,6 +9,8 @@ | |
#import "MCTMsgViewController.h" | |
#import "MCOMessageView.h" | |
+#import <CoreGraphics/CoreGraphics.h> | |
+#import <ImageIO/ImageIO.h> | |
@interface MCTMsgViewController () <MCOMessageViewDelegate> | |
@@ -227,45 +229,45 @@ typedef void (^DownloadCallback)(NSError * error); | |
- (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; | |
+ 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; | |
+// return nil; | |
} | |
@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 0e4c848..ae78ce0 100644 | |
--- a/example/ios/iOS UI Test/iOS UI Test/MasterViewController.m | |
+++ b/example/ios/iOS UI Test/iOS UI Test/MasterViewController.m | |
@@ -126,6 +126,7 @@ | |
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { | |
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]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment