-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTweak.x
63 lines (56 loc) · 1.84 KB
/
Tweak.x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#import "MailAccount.h"
static NSObject *lock;
static NSDictionary *settings;
static void toggle(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
@synchronized (lock) {
settings = nil;
}
}
static NSArray *addresses_for_account(NSString *identifier) {
@synchronized (lock) {
if (!settings) {
static dispatch_once_t once;
dispatch_once(&once, ^{
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, &toggle, CFSTR("net.joedj.gmailsender"), NULL, 0);
});
settings = [NSDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/net.joedj.gmailsender.plist"] ?: @{};
}
return [settings[identifier] componentsSeparatedByString:@" "] ?: @[];
}
}
static NSArray *merge_addresses(MailAccount *account, NSArray *realAddresses) {
NSArray *fromAddresses = addresses_for_account(account.identifier);
if (fromAddresses.count) {
NSMutableArray *newAddresses = [[NSMutableArray alloc] init];
NSMutableSet *seenAddresses = [[NSMutableSet alloc] init];
for (NSString *address in [fromAddresses arrayByAddingObjectsFromArray:realAddresses]) {
if (address.length && ![seenAddresses containsObject:address]) {
[newAddresses addObject:address];
[seenAddresses addObject:address];
}
}
return newAddresses;
}
return realAddresses;
}
@interface GmailAccount: MailAccount
@end
%group IMAP
%hook GmailAccount
- (NSArray *)emailAddresses {
return merge_addresses(self, %orig);
}
%end
%end
%hook MailAccount
+ (void)initialize {
if (self == %c(GmailAccount)) {
%init(IMAP);
}
%orig;
}
%end
%ctor {
lock = [[NSObject alloc] init];
%init;
}