1 | |
package com.nilhcem.fakesmtp.model; |
2 | |
|
3 | |
import java.util.HashMap; |
4 | |
import java.util.List; |
5 | |
import java.util.Map; |
6 | |
import com.nilhcem.fakesmtp.core.I18n; |
7 | |
import com.nilhcem.fakesmtp.core.exception.BindPortException; |
8 | |
import com.nilhcem.fakesmtp.core.exception.InvalidPortException; |
9 | |
import com.nilhcem.fakesmtp.core.exception.OutOfRangePortException; |
10 | |
import com.nilhcem.fakesmtp.server.SMTPServerHandler; |
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | 1 | public enum UIModel { |
24 | 1 | INSTANCE; |
25 | |
|
26 | 1 | private boolean started = false; |
27 | |
private String portStr; |
28 | 1 | private int nbMessageReceived = 0; |
29 | 1 | private String savePath = I18n.INSTANCE.get("emails.default.dir"); |
30 | 1 | private final Map<Integer, String> listMailsMap = new HashMap<Integer, String>(); |
31 | |
private List<String> relayDomains; |
32 | |
|
33 | 1 | UIModel() { |
34 | 1 | } |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
public void toggleButton() throws BindPortException, OutOfRangePortException, InvalidPortException { |
48 | 3 | if (started) { |
49 | |
|
50 | |
} else { |
51 | |
int port; |
52 | |
|
53 | |
try { |
54 | 2 | port = Integer.parseInt(portStr); |
55 | 1 | } catch (NumberFormatException e) { |
56 | 1 | throw new InvalidPortException(e); |
57 | 1 | } |
58 | 1 | SMTPServerHandler.INSTANCE.startServer(port, null); |
59 | |
} |
60 | 2 | started = !started; |
61 | 2 | } |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
public boolean isStarted() { |
69 | 3 | return started; |
70 | |
} |
71 | |
|
72 | |
public void setPort(String port) { |
73 | 2 | this.portStr = port; |
74 | 2 | } |
75 | |
|
76 | |
public int getNbMessageReceived() { |
77 | 1 | return nbMessageReceived; |
78 | |
} |
79 | |
|
80 | |
public void setNbMessageReceived(int nbMessageReceived) { |
81 | 0 | this.nbMessageReceived = nbMessageReceived; |
82 | 0 | } |
83 | |
|
84 | |
public String getSavePath() { |
85 | 1 | return savePath; |
86 | |
} |
87 | |
|
88 | |
public void setSavePath(String savePath) { |
89 | 0 | this.savePath = savePath; |
90 | 0 | } |
91 | |
|
92 | |
public Map<Integer, String> getListMailsMap() { |
93 | 2 | return listMailsMap; |
94 | |
} |
95 | |
|
96 | |
public List<String> getRelayDomains() { |
97 | 1 | return relayDomains; |
98 | |
} |
99 | |
|
100 | |
public void setRelayDomains(List<String> relayDomains) { |
101 | 0 | this.relayDomains = relayDomains; |
102 | 0 | } |
103 | |
} |