]>
Commit | Line | Data |
---|---|---|
1 | /* Cydia - iPhone UIKit Front-End for Debian APT | |
2 | * Copyright (C) 2008-2014 Jay Freeman (saurik) | |
3 | */ | |
4 | ||
5 | /* GNU General Public License, Version 3 {{{ */ | |
6 | /* | |
7 | * Cydia is free software: you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published | |
9 | * by the Free Software Foundation, either version 3 of the License, | |
10 | * or (at your option) any later version. | |
11 | * | |
12 | * Cydia is distributed in the hope that it will be useful, but | |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with Cydia. If not, see <http://www.gnu.org/licenses/>. | |
19 | **/ | |
20 | /* }}} */ | |
21 | ||
22 | #include "CyteKit/MFMailComposeViewController-MailToURL.h" | |
23 | ||
24 | #include <objc/runtime.h> | |
25 | #include <dlfcn.h> | |
26 | ||
27 | static void $MFMailComposeViewController$setMailToURL$(MFMailComposeViewController *self, SEL _cmd, NSURL *url) { | |
28 | NSString *scheme([url scheme]); | |
29 | ||
30 | if (scheme == nil || ![[scheme lowercaseString] isEqualToString:@"mailto"]) | |
31 | [NSException raise:NSInvalidArgumentException format:@"-[MFMailComposeViewController setMailToURL:] - non-mailto: URL"]; | |
32 | ||
33 | NSString *href([url absoluteString]); | |
34 | NSRange question([href rangeOfString:@"?"]); | |
35 | ||
36 | NSMutableArray *to([NSMutableArray arrayWithCapacity:1]); | |
37 | ||
38 | NSString *target, *query; | |
39 | if (question.location == NSNotFound) { | |
40 | target = [href substringFromIndex:7]; | |
41 | query = nil; | |
42 | } else { | |
43 | target = [href substringWithRange:NSMakeRange(7, question.location - 7)]; | |
44 | query = [href substringFromIndex:(question.location + 1)]; | |
45 | } | |
46 | ||
47 | if ([target length] != 0) | |
48 | [to addObject:target]; | |
49 | ||
50 | if (query != nil && [query length] != 0) { | |
51 | NSMutableArray *cc([NSMutableArray arrayWithCapacity:1]); | |
52 | NSMutableArray *bcc([NSMutableArray arrayWithCapacity:1]); | |
53 | ||
54 | for (NSString *assign in [query componentsSeparatedByString:@"&"]) { | |
55 | NSRange equal([assign rangeOfString:@"="]); | |
56 | if (equal.location == NSNotFound) | |
57 | continue; | |
58 | ||
59 | NSString *name([assign substringToIndex:equal.location]); | |
60 | NSString *value([assign substringFromIndex:(equal.location + 1)]); | |
61 | value = [value stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; | |
62 | ||
63 | if (false); | |
64 | else if ([name isEqualToString:@"attachment"]) { | |
65 | if (NSData *data = [NSData dataWithContentsOfFile:value]) | |
66 | [self addAttachmentData:data mimeType:@"application/octet-stream" fileName:[value lastPathComponent]]; | |
67 | } else if ([name isEqualToString:@"bcc"]) | |
68 | [bcc addObject:value]; | |
69 | else if ([name isEqualToString:@"body"]) | |
70 | [self setMessageBody:value isHTML:NO]; | |
71 | else if ([name isEqualToString:@"cc"]) | |
72 | [cc addObject:value]; | |
73 | else if ([name isEqualToString:@"subject"]) | |
74 | [self setSubject:value]; | |
75 | else if ([name isEqualToString:@"to"]) | |
76 | [to addObject:value]; | |
77 | } | |
78 | ||
79 | [self setCcRecipients:cc]; | |
80 | [self setBccRecipients:bcc]; | |
81 | } | |
82 | ||
83 | [self setToRecipients:to]; | |
84 | } | |
85 | ||
86 | __attribute__((__constructor__)) static void MFMailComposeViewController_CyteMailToURL() { | |
87 | dlopen("/System/Library/Frameworks/MessageUI.framework/MessageUI", RTLD_GLOBAL | RTLD_LAZY); | |
88 | if (Class MFMailComposeViewController = objc_getClass("MFMailComposeViewController")) | |
89 | class_addMethod(MFMailComposeViewController, @selector(setMailToURL:), (IMP) $MFMailComposeViewController$setMailToURL$, "v12@0:4@8"); | |
90 | } |