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