Skip to content

Commit

Permalink
#193: Added default SOCKS proxy port in the mailer builder
Browse files Browse the repository at this point in the history
  • Loading branch information
bbottema committed Apr 4, 2019
1 parent 0ca64f0 commit fa81e72
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public interface MailerGenericBuilder<T extends MailerGenericBuilder<?>> {
* Can be overridden from a config file or through System variable.
*/
int DEFAULT_POOL_SIZE = 10;
/**
* Default port is <code>{@value}</code>.
*/
int DEFAULT_PROXY_PORT = 1080;
/**
* The temporary intermediary SOCKS5 relay server bridge is a server that sits in between JavaMail and the remote proxy.
* Default port is <code>{@value}</code>.
Expand Down Expand Up @@ -82,10 +86,9 @@ public interface MailerGenericBuilder<T extends MailerGenericBuilder<?>> {
/**
* Sets the proxy port, which will override any default that might have been set (through properties file or programmatically).
* <p>
* Proxy port is required if a proxyHost has been configured.
* Defaults to {@value DEFAULT_PROXY_PORT} if no custom default property was configured.
*/
@Cli.ExcludeApi(reason = "API is a subset of a more details API")
// TODO take default port from transport strategy
T withProxyPort(@Nullable Integer proxyPort);

/**
Expand All @@ -110,6 +113,7 @@ public interface MailerGenericBuilder<T extends MailerGenericBuilder<?>> {
* Relevant only when using username authentication with a proxy.
* <p>
* Overrides the default for the intermediary SOCKS5 relay server bridge, which is a server that sits in between JavaMail and the remote proxy.
* <p>
* Defaults to {@value DEFAULT_PROXY_BRIDGE_PORT} if no custom default property was configured.
*
* @param proxyBridgePort The port to use for the proxy bridging server.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static org.simplejavamail.internal.util.Preconditions.assumeNonNull;
import static org.simplejavamail.config.ConfigLoader.Property.PROXY_HOST;
import static org.simplejavamail.config.ConfigLoader.Property.PROXY_PASSWORD;
import static org.simplejavamail.config.ConfigLoader.Property.PROXY_PORT;
import static org.simplejavamail.config.ConfigLoader.Property.PROXY_USERNAME;
import static org.simplejavamail.config.ConfigLoader.hasProperty;

Expand Down Expand Up @@ -114,23 +113,21 @@ public abstract class MailerGenericBuilderImpl<T extends MailerGenericBuilderImp
*/
MailerGenericBuilderImpl() {
if (hasProperty(PROXY_HOST)) {
withProxyHost(ConfigLoader.getStringProperty(PROXY_HOST));
}
if (hasProperty(PROXY_PORT)) {
withProxyPort(ConfigLoader.getIntegerProperty(PROXY_PORT));
this.proxyHost = ConfigLoader.getStringProperty(PROXY_HOST);
}
if (hasProperty(PROXY_USERNAME)) {
withProxyUsername(ConfigLoader.getStringProperty(PROXY_USERNAME));
this.proxyUsername = ConfigLoader.getStringProperty(PROXY_USERNAME);
}
if (hasProperty(PROXY_PASSWORD)) {
withProxyPassword(ConfigLoader.getStringProperty(PROXY_PASSWORD));
this.proxyPassword = ConfigLoader.getStringProperty(PROXY_PASSWORD);
}

this.proxyBridgePort = assumeNonNull(ConfigLoader.valueOrPropertyAsInteger(null, Property.PROXY_SOCKS5BRIDGE_PORT, DEFAULT_PROXY_BRIDGE_PORT));
this.debugLogging = assumeNonNull(ConfigLoader.valueOrPropertyAsBoolean(null, Property.JAVAXMAIL_DEBUG, DEFAULT_JAVAXMAIL_DEBUG));
this.sessionTimeout = assumeNonNull(ConfigLoader.valueOrPropertyAsInteger(null, Property.DEFAULT_SESSION_TIMEOUT_MILLIS, DEFAULT_SESSION_TIMEOUT_MILLIS));
this.threadPoolSize = assumeNonNull(ConfigLoader.valueOrPropertyAsInteger(null, Property.DEFAULT_POOL_SIZE, DEFAULT_POOL_SIZE));
this.transportModeLoggingOnly = assumeNonNull(ConfigLoader.valueOrPropertyAsBoolean(null, Property.TRANSPORT_MODE_LOGGING_ONLY, DEFAULT_TRANSPORT_MODE_LOGGING_ONLY));

this.proxyPort = assumeNonNull(ConfigLoader.valueOrPropertyAsInteger(null, Property.PROXY_PORT, DEFAULT_PROXY_PORT));
this.proxyBridgePort = assumeNonNull(ConfigLoader.valueOrPropertyAsInteger(null, Property.PROXY_SOCKS5BRIDGE_PORT, DEFAULT_PROXY_BRIDGE_PORT));
this.debugLogging = assumeNonNull(ConfigLoader.valueOrPropertyAsBoolean(null, Property.JAVAXMAIL_DEBUG, DEFAULT_JAVAXMAIL_DEBUG));
this.sessionTimeout = assumeNonNull(ConfigLoader.valueOrPropertyAsInteger(null, Property.DEFAULT_SESSION_TIMEOUT_MILLIS, DEFAULT_SESSION_TIMEOUT_MILLIS));
this.threadPoolSize = assumeNonNull(ConfigLoader.valueOrPropertyAsInteger(null, Property.DEFAULT_POOL_SIZE, DEFAULT_POOL_SIZE));
this.transportModeLoggingOnly = assumeNonNull(ConfigLoader.valueOrPropertyAsBoolean(null, Property.TRANSPORT_MODE_LOGGING_ONLY, DEFAULT_TRANSPORT_MODE_LOGGING_ONLY));

this.emailAddressCriteria = EmailAddressCriteria.RFC_COMPLIANT.clone();
this.trustAllSSLHost = true;
Expand Down Expand Up @@ -212,7 +209,6 @@ public T withProxyHost(@Nullable final String proxyHost) {
* @see MailerGenericBuilder#withProxyPort(Integer)
*/
@Override
// TODO take default port from transport strategy
public T withProxyPort(@Nullable final Integer proxyPort) {
this.proxyPort = proxyPort;
return (T) this;
Expand Down

0 comments on commit fa81e72

Please sign in to comment.