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