1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package davmail.service;
20
21 import davmail.BundleMessage;
22 import davmail.DavGateway;
23 import davmail.Settings;
24 import davmail.ui.tray.DavGatewayTray;
25 import org.boris.winrun4j.AbstractService;
26
27
28
29
30 public class DavService extends AbstractService {
31
32 private final Object LOCK = new Object();
33
34
35
36
37
38
39
40 @Override
41 public int serviceRequest(int control) {
42 switch (control) {
43 case SERVICE_CONTROL_STOP:
44 case SERVICE_CONTROL_SHUTDOWN:
45 DavGatewayTray.debug(new BundleMessage("LOG_STOPPING_DAVMAIL"));
46 DavGateway.stop();
47 synchronized (LOCK) {
48 LOCK.notifyAll();
49 }
50 }
51 return 0;
52 }
53
54
55
56
57
58
59
60 public int serviceMain(String[] args) {
61 if (args.length >= 1) {
62 Settings.setConfigFilePath(args[0]);
63 }
64
65 Settings.load();
66 if (!Settings.getBooleanProperty("davmail.server")) {
67 Settings.setProperty("davmail.server", "true");
68 Settings.updateLoggingConfig();
69 }
70
71 DavGateway.start();
72 DavGatewayTray.debug(new BundleMessage("LOG_DAVMAIL_STARTED"));
73
74 synchronized (LOCK) {
75 try {
76 LOCK.wait();
77 } catch (InterruptedException e) {
78 DavGatewayTray.debug(new BundleMessage("LOG_GATEWAY_INTERRUPTED"));
79 Thread.currentThread().interrupt();
80 }
81 }
82
83 return 0;
84 }
85 }