From 8f24f1516fb1825ca0f9075955746a331944d5d4 Mon Sep 17 00:00:00 2001 From: Joel Date: Sun, 17 Jan 2021 12:37:14 +0100 Subject: [PATCH] Fix broken "download all attachments"-link Fixes #29 --- Fastmate.xcodeproj/project.pbxproj | 4 ++-- Fastmate/WebViewController.m | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Fastmate.xcodeproj/project.pbxproj b/Fastmate.xcodeproj/project.pbxproj index 4237327..2f8ed82 100644 --- a/Fastmate.xcodeproj/project.pbxproj +++ b/Fastmate.xcodeproj/project.pbxproj @@ -341,7 +341,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.13; - MARKETING_VERSION = 1.6.2; + MARKETING_VERSION = 1.6.3; PRODUCT_BUNDLE_IDENTIFIER = io.ekstrom.Fastmate; PRODUCT_NAME = "$(TARGET_NAME)"; }; @@ -364,7 +364,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.13; - MARKETING_VERSION = 1.6.2; + MARKETING_VERSION = 1.6.3; PRODUCT_BUNDLE_IDENTIFIER = io.ekstrom.Fastmate; PRODUCT_NAME = "$(TARGET_NAME)"; }; diff --git a/Fastmate/WebViewController.m b/Fastmate/WebViewController.m index e8de4dd..80cb999 100644 --- a/Fastmate/WebViewController.m +++ b/Fastmate/WebViewController.m @@ -65,11 +65,7 @@ - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigati decisionHandler(WKNavigationActionPolicyCancel); self.temporaryWebView = nil; } else if ([navigationAction.request.URL.host hasSuffix:@".fastmailusercontent.com"]) { - NSURLComponents *components = [NSURLComponents componentsWithURL:navigationAction.request.URL resolvingAgainstBaseURL:NO]; - BOOL shouldDownload = [components.queryItems indexOfObjectPassingTest:^BOOL(NSURLQueryItem *item, NSUInteger index, BOOL *stop) { - return [item.name isEqualToString:@"download"] && [item.value isEqualToString:@"1"]; - }] != NSNotFound; - if (shouldDownload) { + if ([self isDownloadRequest:navigationAction.request]) { [NSWorkspace.sharedWorkspace openURL:navigationAction.request.URL]; decisionHandler(WKNavigationActionPolicyCancel); } else { @@ -84,6 +80,18 @@ - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigati } } +/** + YES if request is to download a fastmail-hosted file + */ +- (BOOL)isDownloadRequest:(NSURLRequest *)request +{ + NSURLComponents *components = [NSURLComponents componentsWithURL:request.URL resolvingAgainstBaseURL:NO]; + BOOL hasDownloadQueryItem = [components.queryItems indexOfObjectPassingTest:^BOOL(NSURLQueryItem *item, NSUInteger index, BOOL *stop) { + return [item.name isEqualToString:@"download"] && [item.value isEqualToString:@"1"]; + }] != NSNotFound; + return hasDownloadQueryItem || [components.path hasPrefix:@"/jmap/download/"]; +} + - (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures { self.temporaryWebView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration]; self.temporaryWebView.navigationDelegate = self;