001package votorola.g.mail; // Copyright 2008, Michael Allan.  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE.
002
003import java.io.*;
004import votorola.g.lang.*;
005
006
007/** Mail transfer service (transport), via Simple Mail Transfer Protocol (SMTP).
008  *
009  *     @see com.sun.mail.smtp.SMTPTransport
010  *     @see ConstructionContext
011  */
012public final class SMTPTransportX
013{
014
015
016    private SMTPTransportX() {}
017
018
019
020   // ====================================================================================
021
022
023    /** A context for configuring access to an SMTP transfer server.
024      */
025    public static @ThreadSafe class ConstructionContext
026    {
027
028
029        /** Constructs a ConstructionContext.
030          *
031          *     @param startupConfigurationFile
032          *       per {@linkplain #startupConfigurationFile() startupConfigurationFile}()
033          */
034        public ConstructionContext( File startupConfigurationFile )
035        {
036            this.startupConfigurationFile = startupConfigurationFile;
037        }
038
039
040
041       // --------------------------------------------------------------------------------
042
043
044        /** The file from which this construction context was generated.
045          */
046        public File startupConfigurationFile() { return startupConfigurationFile; }
047
048
049            private final File startupConfigurationFile;
050
051
052
053        /** Returns the authentication method for access to the server;
054          * or null, if no authentication is required.
055          *
056          *     @see #setAuthenticationMethodSimple(String,String)
057          */
058        public SimpleAuthentication getAuthenticationMethod() { return authenticationMethod; }
059
060
061            private SimpleAuthentication authenticationMethod;
062
063
064            /** Sets the authentication method to simple name/password (not yet tested).
065              *
066              *     @see #getAuthenticationMethod()
067              */
068                @ThreadRestricted("constructor")
069            public void setAuthenticationMethodSimple( String name, String password )
070            {
071                authenticationMethod = new SimpleAuthentication( name, password );
072            }
073
074
075
076        /** Returns the encryption method for communication with the server ("ssl");
077          * or null, if no encryption is used.
078          *
079          *     @see #setEncryptionMethodSSL()
080          */
081        public String getEncryptionMethod() { return encryptionMethod; }
082
083
084            private String encryptionMethod;
085
086
087            /** Sets the encryption method to Secure Sockets Layer (not yet tested).
088              *
089              *     @see #getEncryptionMethod()
090              */
091                @ThreadRestricted("constructor")
092            public void setEncryptionMethodSSL() { encryptionMethod = "ssl"; }
093
094
095
096        /** Returns the name of the transfer server.  For example "localhost", or
097          * "smtp.somewhere.net".
098          *
099          *     @see #setServerName(String)
100          */
101        public String getServerName() { return serverName; }
102
103
104            private String serverName = "localhost";
105
106
107            /** Sets the name of the transfer server.  The default value is "localhost".
108              *
109              *     @see #getServerName()
110              */
111                @ThreadRestricted("constructor")
112            public void setServerName( String serverName ) { this.serverName = serverName; }
113
114
115
116        /** Returns the communication port of the transfer server.
117          *
118          *     @see #setServerPort(int)
119          */
120        public int getServerPort() { return serverPort; }
121
122
123            private int serverPort = 25;
124
125
126            /** Sets the port of the PostgreSQL transfer server.
127              * The default value is 25.
128              *
129              *     @see #getServerPort()
130              */
131                @ThreadRestricted("constructor")
132            public void setServerPort( int serverPort ) { this.serverPort = serverPort; }
133
134
135
136    }
137
138
139
140   // ====================================================================================
141
142
143    /** Simple authentication for server access.
144      */
145    public static final class SimpleAuthentication
146    {
147
148        private SimpleAuthentication( String name, String password )
149        {
150            this.name = name;
151            this.password = password;
152        }
153
154
155        public String password() { return password; }
156
157
158            private final String password;
159
160
161        public String name() { return name; }
162
163
164            private final String name;
165
166
167    }
168
169
170
171}