-
Notifications
You must be signed in to change notification settings - Fork 8
/
mailhandlers_main.m
43 lines (37 loc) · 1.18 KB
/
mailhandlers_main.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
#import <AppKit/AppKit.h>
static NSString * const kRelativeWebmailerPath = @"PreferencePanes/Webmailer.prefPane/Contents/Resources/Webmailer.app";
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSEnumerator *libraryEnum = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSAllDomainsMask, YES) objectEnumerator];
NSString *nextPath;
while ((nextPath = [[libraryEnum nextObject] stringByAppendingPathComponent:kRelativeWebmailerPath]))
{
if ([fileManager fileExistsAtPath:nextPath])
break;
}
OSStatus returnCode;
if (nextPath != nil)
{
returnCode = LSRegisterURL((CFURLRef) [[[NSURL alloc] initFileURLWithPath:nextPath] autorelease], NO);
if (returnCode != 0)
{
if ([[NSWorkspace sharedWorkspace] launchApplication:nextPath])
returnCode = 0;
else
{
NSBeep();
NSLog(@"Unable to add Webmailer as a mail handler. Please e-mail [email protected] with this error code: %d", returnCode);
}
}
}
else
{
NSBeep();
NSLog(@"Webmailer does not seem to be installed on your system.");
returnCode = -1;
}
[pool release];
return returnCode;
}