1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.icegreen.greenmail.smtp;
20
21 import com.icegreen.greenmail.Managers;
22 import com.icegreen.greenmail.server.ProtocolHandler;
23 import com.icegreen.greenmail.util.ServerSetup;
24 import java.io.IOException;
25 import java.net.Socket;
26
27 public class InterruptableSmtpServer extends SmtpServer {
28
29 private boolean rejectRequests = false;
30
31 public InterruptableSmtpServer(final ServerSetup setup, final Managers managers) {
32 super(setup, managers);
33 }
34
35 @Override
36 protected ProtocolHandler createProtocolHandler(final Socket clientSocket) {
37 synchronized (this) {
38 if (rejectRequests) {
39 try {
40 clientSocket.close();
41 } catch (IOException e) {
42
43 }
44 }
45
46 return super.createProtocolHandler(clientSocket);
47 }
48 }
49
50 public void setRejectRequests(final boolean rejectRequests) {
51 this.rejectRequests = rejectRequests;
52 }
53 }