forked from SelfControlApp/selfcontrol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HostImporter.m
executable file
·100 lines (86 loc) · 4.13 KB
/
HostImporter.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//
// HostImporter.m
// SelfControl
//
// Created by Charlie Stigler on 2/16/09.
// Copyright 2009 Eyebeam.
// This file is part of SelfControl.
//
// SelfControl is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#import "HostImporter.h"
@implementation HostImporter
+ (NSArray*)incomingMailHostnamesFromMail {
NSMutableArray* hostnames = [NSMutableArray arrayWithCapacity: 10];
NSDictionary* defaults = [[NSUserDefaults standardUserDefaults] persistentDomainForName: @"com.apple.Mail"];
NSArray* incomingAccounts = [defaults objectForKey: @"MailAccounts"];
for(int i = 0; i < [incomingAccounts count]; i++) {
NSMutableString* hostname = [[[[incomingAccounts objectAtIndex: i] objectForKey: @"Hostname"] mutableCopy] autorelease];
// The LocalAccountName account has no hostname, so trying to add it would cause an error
if(hostname != nil) {
// If it has a defined port number, add it to the host to block for added
// block specificity, so only incoming mail is blocked.
if([[incomingAccounts objectAtIndex: i] objectForKey: @"PortNumber"] != nil) {
[hostname appendString: @":"];
[hostname appendString: [[incomingAccounts objectAtIndex: i] objectForKey: @"PortNumber"]];
// If it doesn't have a defined port number, we'll go through and choose
// the default port for the type of account it is.
} else if([[[incomingAccounts objectAtIndex: i] objectForKey: @"AccountType"] isEqual: @"POPAccount"]) {
if([[incomingAccounts objectAtIndex: i] objectForKey: @"SSLEnabled"]) {
[hostname appendString: @":"];
[hostname appendString: @"995"];
} else {
[hostname appendString: @":"];
[hostname appendString: @"110"];
}
} else if([[[incomingAccounts objectAtIndex: i] objectForKey: @"AccountType"] isEqual: @"IMAPAccount"]) {
if([[incomingAccounts objectAtIndex: i] objectForKey: @"SSLEnabled"]) {
[hostname appendString: @":"];
[hostname appendString: @"993"];
} else {
[hostname appendString: @":"];
[hostname appendString: @"143"];
}
}
[hostnames addObject: hostname];
}
}
return hostnames;
}
+ (NSArray*)outgoingMailHostnamesFromMail {
NSMutableArray* hostnames = [NSMutableArray arrayWithCapacity: 10];
NSDictionary* defaults = [[NSUserDefaults standardUserDefaults] persistentDomainForName: @"com.apple.Mail"];
NSArray* outgoingAccounts = [defaults objectForKey: @"DeliveryAccounts"];
for(int i = 0; i < [outgoingAccounts count]; i++) {
NSMutableString* hostname = [[[[outgoingAccounts objectAtIndex: i] objectForKey: @"Hostname"] mutableCopy] autorelease];
if(hostname != nil) {
if([[outgoingAccounts objectAtIndex: i] objectForKey: @"PortNumber"] != nil) {
[hostname appendString: @":"];
[hostname appendString: [[outgoingAccounts objectAtIndex: i] objectForKey: @"PortNumber"]];
// If it doesn't have a defined port number, we'll go through and choose
// the default port for the type of account it is.
} else {
[hostnames addObject: [hostname stringByAppendingString: @":25"]];
[hostnames addObject: [hostname stringByAppendingString: @":465"]];
[hostname appendString: @":587"];
}
[hostnames addObject: hostname];
}
}
return hostnames;
}
+ (NSArray*)incomingMailHostnamesFromThunderbird {
return [ThunderbirdPreferenceParser incomingHostnames];
}
+ (NSArray*)outgoingMailHostnamesFromThunderbird {
return [ThunderbirdPreferenceParser outgoingHostnames];
}
@end