1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.icegreen.greenmail.util;
20
21 import com.icegreen.greenmail.Managers;
22 import com.icegreen.greenmail.imap.ImapServer;
23 import com.icegreen.greenmail.pop3.Pop3Server;
24 import com.icegreen.greenmail.server.AbstractServer;
25 import com.icegreen.greenmail.smtp.InterruptableSmtpServer;
26 import java.util.HashMap;
27 import java.util.Map;
28
29 public class InterruptableGreenMail extends GreenMail {
30
31 public InterruptableGreenMail(final ServerSetup[] config) {
32 super(config);
33 }
34
35 @Override
36 protected Map<String, AbstractServer> createServices(final ServerSetup[] config, final Managers mgr) {
37 Map<String, AbstractServer> srvc = new HashMap<>();
38 for (ServerSetup setup : config) {
39 if (srvc.containsKey(setup.getProtocol())) {
40 throw new IllegalArgumentException("Server '" + setup.getProtocol()
41 + "' was found at least twice in the array");
42 }
43 final String protocol = setup.getProtocol();
44 if (protocol.startsWith(ServerSetup.PROTOCOL_SMTP)) {
45 srvc.put(protocol, new InterruptableSmtpServer(setup, mgr));
46 } else if (protocol.startsWith(ServerSetup.PROTOCOL_POP3)) {
47 srvc.put(protocol, new Pop3Server(setup, mgr));
48 } else if (protocol.startsWith(ServerSetup.PROTOCOL_IMAP)) {
49 srvc.put(protocol, new ImapServer(setup, mgr));
50 }
51 }
52 return srvc;
53 }
54 }