1   package com.atlassian.mail.server;
2   
3   import com.atlassian.mail.MailException;
4   
5   import javax.annotation.Nullable;
6   import javax.mail.Authenticator;
7   import javax.mail.Session;
8   import java.util.List;
9   import java.util.Map;
10  import java.util.Properties;
11  
12  /**
13   * This class allows MailServers to be created, updated and deleted.
14   *
15   * It also allows MailServers to be retrieved by id and name.
16   */
17  public interface MailServerManager
18  {
19      String[] SERVER_TYPES = new String[]{"pop", "smtp"};
20  
21  	@Nullable
22      MailServer getMailServer(Long id) throws MailException;
23  
24  	@Nullable
25      MailServer getMailServer(String name) throws MailException;
26  
27      Long create(MailServer mailServer) throws MailException;
28  
29      void update(MailServer mailServer) throws MailException;
30  
31      void delete(Long mailServerId) throws MailException;
32  
33      List<String> getServerNames() throws MailException;
34  
35      /**
36       * Gets a list of all the configured SMTP mail servers.
37       * @return A list of all the configured SMTP mail servers.
38       */
39      List<SMTPMailServer> getSmtpMailServers();
40  
41      /**
42       * Gets a list of all the configured POP mail servers.
43       * @return A list of all the configured POP mail servers.
44       */
45      List<PopMailServer> getPopMailServers();
46  
47      @Nullable
48  	SMTPMailServer getDefaultSMTPMailServer();
49  
50      /**
51       * Whether a &quot;default&quot; SMTP Mail Server has been defined.
52       * @return true if a &quot;default&quot; SMTP Mail Server has been defined; otherwise, false.
53       */
54      boolean isDefaultSMTPMailServerDefined();
55  
56  	@Nullable
57      PopMailServer getDefaultPopMailServer();
58  
59      Session getSession(Properties props, @Nullable Authenticator auth) throws MailException;
60  
61      void init(Map params);
62  
63  	/**
64  	 * Implementations of this interface are supposed to call registered here MailServerConfigurationHandler
65  	 * immediately after they construct MailServer objects.
66  	 *
67  	 * You can use it to further customise MailServer objects managed by this manager - e.g. initialize MailServer
68  	 * fields basing on application specific needs.
69  	 * This method is used to make up for lack of dependency injection while constructing MailServerManager implementation
70  	 * by {@link com.atlassian.mail.config.ConfigLoader#ConfigLoader(String)}
71  	 *
72  	 * @param mailServerConfigurationHandler callback called upon creation of MailServer objects
73  	 */
74  	void setMailServerConfigurationHandler(@Nullable MailServerConfigurationHandler mailServerConfigurationHandler);
75  }