-
Notifications
You must be signed in to change notification settings - Fork 1
/
MailFetchToggle.m
58 lines (49 loc) · 1.63 KB
/
MailFetchToggle.m
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
//
// MailFetchToggle.m
// MailFetchToggle
//
// Created by Eiji Kato a.k.a. technolize
//
#import <Foundation/Foundation.h>
#if __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_2_2
#define PREF_FILE @"/var/mobile/Library/Preferences/com.apple.persistentconnection-mcc.plist"
#else
#define PREF_FILE @"/var/mobile/Library/Preferences/com.apple.persistentconnection.plist"
#endif
#define TMP_FILE @"/var/mobile/Library/SBSettings/Toggles/MailFetch/interval.plist"
BOOL isCapable() {
return YES;
}
BOOL isEnabled() {
NSDictionary *pref = [[NSDictionary alloc] initWithContentsOfFile:PREF_FILE];
BOOL flag = [[pref objectForKey:@"PCDefaultPollInterval"] boolValue];
[pref release];
return flag;
}
BOOL getStateFast() {
return isEnabled();
}
void setState(BOOL enable) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSMutableDictionary *pref = [NSMutableDictionary dictionaryWithContentsOfFile:PREF_FILE];
NSMutableDictionary *tmp;
NSNumber *interval;
if (enable) {
tmp = [NSMutableDictionary dictionaryWithContentsOfFile:TMP_FILE];
interval = [tmp objectForKey:@"interval"];
if (interval == nil || [interval intValue] < 900)
interval = [NSNumber numberWithInt:900];
}
else {
interval = [NSNumber numberWithInt:0];
tmp = [NSMutableDictionary dictionaryWithObject:[pref objectForKey:@"PCDefaultPollInterval"]
forKey:@"interval"];
[tmp writeToFile:TMP_FILE atomically:YES];
}
[pref setValue:interval forKey:@"PCDefaultPollInterval"];
[pref writeToFile:PREF_FILE atomically:YES];
[pool release];
}
float getDelayTime() {
return 0.5f;
}