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