View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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  }