Skip to content

Commit

Permalink
Fix broken "download all attachments"-link
Browse files Browse the repository at this point in the history
Fixes #29
  • Loading branch information
joelekstrom committed Jan 17, 2021
1 parent 3216b3e commit 8f24f15
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Fastmate.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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)";
};
Expand All @@ -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)";
};
Expand Down
18 changes: 13 additions & 5 deletions Fastmate/WebViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down

0 comments on commit 8f24f15

Please sign in to comment.