Skip to content

Commit

Permalink
#105: renamed the TransportStrategy enums
Browse files Browse the repository at this point in the history
  • Loading branch information
bbottema committed Nov 5, 2017
1 parent 8f0359f commit 787aac2
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 35 deletions.
10 changes: 5 additions & 5 deletions src/main/java/org/simplejavamail/mailer/Mailer.java
Expand Up @@ -135,7 +135,7 @@ public Mailer(final Session session, final ProxyConfig proxyConfig) {
* No-arg constructor that only works with properly populated config file ("simplejavamail.properties") on the classpath.
* <p>
* Delegates to {@link #Mailer(ServerConfig, TransportStrategy, ProxyConfig)} and populates as much as possible from the config file (smtp server
* details, proxy details, transport strategy) and otherwise defaults to {@link TransportStrategy#SMTP_PLAIN} and skipping proxy.
* details, proxy details, transport strategy) and otherwise defaults to {@link TransportStrategy#SMTP} and skipping proxy.
*
* @see #Mailer(ServerConfig, TransportStrategy, ProxyConfig)
*/
Expand All @@ -145,7 +145,7 @@ public Mailer() {

/**
* Delegates to {@link #Mailer(ServerConfig, TransportStrategy, ProxyConfig)} and populates as much as possible from the config file (proxy details,
* transport strategy) and otherwise defaults to {@link TransportStrategy#SMTP_PLAIN} and skipping proxy.
* transport strategy) and otherwise defaults to {@link TransportStrategy#SMTP} and skipping proxy.
*
* @param host The address URL of the SMTP server to be used.
* @param port The port of the SMTP server.
Expand All @@ -159,7 +159,7 @@ public Mailer(final String host, final Integer port, final String username, fina

/**
* Delegates to {@link #Mailer(ServerConfig, TransportStrategy, ProxyConfig)} and populates as much as possible from the config file (proxy details,
* transport strategy) and otherwise defaults to {@link TransportStrategy#SMTP_PLAIN} and skipping proxy.
* transport strategy) and otherwise defaults to {@link TransportStrategy#SMTP} and skipping proxy.
*
* @param serverConfig Remote SMTP server details.
* @see #Mailer(ServerConfig, TransportStrategy, ProxyConfig)
Expand Down Expand Up @@ -197,7 +197,7 @@ public Mailer(final ServerConfig serverConfig, final TransportStrategy transport

/**
* Delegates to {@link #Mailer(ServerConfig, TransportStrategy, ProxyConfig)} and tries to populates transport strategy from config file and otherwise
* defaults to {@link TransportStrategy#SMTP_PLAIN}.
* defaults to {@link TransportStrategy#SMTP}.
*
* @param serverConfig Remote SMTP server details.
* @param proxyConfig Remote proxy server details, if the connection should be run through a SOCKS proxy.
Expand All @@ -218,7 +218,7 @@ public Mailer(final ServerConfig serverConfig, final ProxyConfig proxyConfig) {
* @param proxyConfig Remote proxy server details, if the connection should be run through a SOCKS proxy.
*/
public Mailer(final ServerConfig serverConfig, final TransportStrategy transportStrategy, final ProxyConfig proxyConfig) {
final TransportStrategy effectiveTransportStrategy = valueOrProperty(transportStrategy, TRANSPORT_STRATEGY, TransportStrategy.SMTP_PLAIN);
final TransportStrategy effectiveTransportStrategy = valueOrProperty(transportStrategy, TRANSPORT_STRATEGY, TransportStrategy.SMTP);
final Session session = createMailSession(serverConfig, effectiveTransportStrategy);
this.mailSender = new MailSender(session, proxyConfig, effectiveTransportStrategy);
this.emailAddressCriteria = null;
Expand Down
Expand Up @@ -27,7 +27,7 @@ public enum TransportStrategy {
* untrusted certificate authority; or 4) by presenting a certificate that was issued by a valid certificate
* authority to a domain other than the mail server's.
* <p>
* For proper mail transport encryption, see {@link TransportStrategy#SMTP_SSL} or
* For proper mail transport encryption, see {@link TransportStrategy#SMTPS} or
* {@link TransportStrategy#SMTP_TLS}.
* <p>
* Implementation notes:
Expand All @@ -40,9 +40,9 @@ public enum TransportStrategy {
* <li>Certificate identity checks are disabled by setting {@code mail.smtp.ssl.checkserveridentity} to {@code false}.</li>
* </ul>
*/
SMTP_PLAIN {
SMTP {
/**
* @see TransportStrategy#SMTP_PLAIN
* @see TransportStrategy#SMTP
*/
@Override
public Properties generateProperties() {
Expand Down Expand Up @@ -169,9 +169,9 @@ public String propertyNameSSLTrust() {
* </li>
* </ul>
*/
SMTP_SSL {
SMTPS {
/**
* @see TransportStrategy#SMTP_SSL
* @see TransportStrategy#SMTPS
*/
@Override
public Properties generateProperties() {
Expand Down
Expand Up @@ -159,7 +159,7 @@ private static AnonymousSocks5Server configureSessionWithProxy(final ProxyConfig
if (!effectiveProxyConfig.requiresProxy()) {
LOGGER.debug("No proxy set, skipping proxy.");
} else {
if (transportStrategy == TransportStrategy.SMTP_SSL) {
if (transportStrategy == TransportStrategy.SMTPS) {
throw new MailSenderException(MailSenderException.INVALID_PROXY_SLL_COMBINATION);
}
final Properties sessionProperties = session.getProperties();
Expand Down
6 changes: 3 additions & 3 deletions src/main/webapp/src/app/components/features/features.html
Expand Up @@ -280,8 +280,8 @@ <h2>Sending with SSL and TLS</h2>
<div class="side">
<pre><code>Email email = new Email();

new Mailer(..., TransportStrategy.SMTP_PLAIN, ...); // default if omitted
new Mailer(..., TransportStrategy.SMTP_SSL, ...);
new Mailer(..., TransportStrategy.SMTP, ...); // default if omitted
new Mailer(..., TransportStrategy.SMTPS, ...);
new Mailer(..., TransportStrategy.SMTP_TLS, ...);
</code></pre>
</div>
Expand All @@ -307,7 +307,7 @@ <h3>SSL and TLS with Google mail</h3>
<div class="side">
<pre><code>new Mailer("smtp.gmail.com", 25, "your user", "your password", TransportStrategy.SMTP_TLS).sendMail(email);
new Mailer("smtp.gmail.com", 587, "your user", "your password", TransportStrategy.SMTP_TLS).sendMail(email);
new Mailer("smtp.gmail.com", 465, "your user", "your password", TransportStrategy.SMTP_SSL).sendMail(email);
new Mailer("smtp.gmail.com", 465, "your user", "your password", TransportStrategy.SMTPS).sendMail(email);
</code></pre>
</div>
</section>
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/demo/MailTestApp.java
Expand Up @@ -68,7 +68,7 @@ private static void sendMail(final Email email) {
// ProxyConfig proxyconfig = new ProxyConfig("localhost", 1030);
sendMail(serverConfigSMTP, TransportStrategy.SMTP_TLS, email);
sendMail(serverConfigTLS, TransportStrategy.SMTP_TLS, email);
sendMail(serverConfigSSL, TransportStrategy.SMTP_SSL, email);
sendMail(serverConfigSSL, TransportStrategy.SMTPS, email);
}

private static void sendMail(ServerConfig serverConfigSMTP, TransportStrategy smtpTls, Email email) {
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/simplejavamail/mailer/MailerTest.java
Expand Up @@ -23,7 +23,7 @@
import static javax.xml.bind.DatatypeConverter.parseBase64Binary;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
import static org.simplejavamail.mailer.config.TransportStrategy.SMTP_SSL;
import static org.simplejavamail.mailer.config.TransportStrategy.SMTPS;
import static org.simplejavamail.mailer.config.TransportStrategy.SMTP_TLS;

@SuppressWarnings("unused")
Expand Down Expand Up @@ -173,7 +173,7 @@ public void createMailSession_MaximumConstructor_WithConfig()
@Test
public void createMailSession_MaximumConstructor_WithConfig_TLS()
throws Exception {
Mailer mailer = createFullyConfiguredMailer(false, "overridden ", SMTP_SSL);
Mailer mailer = createFullyConfiguredMailer(false, "overridden ", SMTPS);

Session session = mailer.getSession();

Expand Down
Expand Up @@ -12,8 +12,8 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.simplejavamail.mailer.config.TransportStrategy.SMTP_PLAIN;
import static org.simplejavamail.mailer.config.TransportStrategy.SMTP_SSL;
import static org.simplejavamail.mailer.config.TransportStrategy.SMTP;
import static org.simplejavamail.mailer.config.TransportStrategy.SMTPS;

public class MailSenderTest {

Expand Down Expand Up @@ -48,18 +48,18 @@ public void call() throws Throwable {

@Test
public void trustAllHosts_PLAIN() {
MailSender mailSender = new MailSender(session, null, SMTP_PLAIN);
MailSender mailSender = new MailSender(session, null, SMTP);
mailSender.trustAllHosts(true);
assertThat(session.getProperties().getProperty("mail.smtp.ssl.trust")).isEqualTo("*");
mailSender.trustAllHosts(false);
assertThat(session.getProperties().getProperty("mail.smtp.ssl.trust")).isNull();
}

@Test
public void trustAllHosts_SSL() {
public void trustAllHosts_SMTPS() {
ProxyConfig proxyBypassingMock = mock(ProxyConfig.class);
when(proxyBypassingMock.requiresProxy()).thenReturn(false);
MailSender mailSender = new MailSender(session, proxyBypassingMock, SMTP_SSL);
MailSender mailSender = new MailSender(session, proxyBypassingMock, SMTPS);
mailSender.trustAllHosts(true);
assertThat(session.getProperties().getProperty("mail.smtps.ssl.trust")).isEqualTo("*");
mailSender.trustAllHosts(false);
Expand All @@ -68,7 +68,7 @@ public void trustAllHosts_SSL() {

@Test
public void trustHosts() {
MailSender mailSender = new MailSender(session, null, SMTP_PLAIN);
MailSender mailSender = new MailSender(session, null, SMTP);
mailSender.trustHosts();
assertThat(session.getProperties().getProperty("mail.smtp.ssl.trust")).isNull();
mailSender.trustHosts("a");
Expand Down
22 changes: 11 additions & 11 deletions src/test/java/org/simplejavamail/util/ConfigLoaderTest.java
Expand Up @@ -13,7 +13,7 @@
import java.util.Properties;

import static org.assertj.core.api.Assertions.assertThat;
import static org.simplejavamail.mailer.config.TransportStrategy.SMTP_SSL;
import static org.simplejavamail.mailer.config.TransportStrategy.SMTPS;
import static org.simplejavamail.util.ConfigLoader.Property.DEFAULT_BCC_ADDRESS;
import static org.simplejavamail.util.ConfigLoader.Property.DEFAULT_BCC_NAME;
import static org.simplejavamail.util.ConfigLoader.Property.DEFAULT_CC_ADDRESS;
Expand Down Expand Up @@ -157,7 +157,7 @@ public void parsePropertyValue() {
assertThat(ConfigLoader.parsePropertyValue("true")).isEqualTo(true);
assertThat(ConfigLoader.parsePropertyValue("yes")).isEqualTo(true);
assertThat(ConfigLoader.parsePropertyValue("yesno")).isEqualTo("yesno");
assertThat(ConfigLoader.parsePropertyValue("SMTP_PLAIN")).isEqualTo(TransportStrategy.SMTP_PLAIN);
assertThat(ConfigLoader.parsePropertyValue("SMTP")).isEqualTo(TransportStrategy.SMTP);
assertThat(ConfigLoader.parsePropertyValue("SMTP_TLS")).isEqualTo(TransportStrategy.SMTP_TLS);
}

Expand All @@ -166,7 +166,7 @@ public void loadPropertiesFromFileClassPath()
throws Exception {
ConfigLoader.loadProperties("simplejavamail.properties", false);
assertThat(ConfigLoader.getProperty(JAVAXMAIL_DEBUG)).isEqualTo(true);
assertThat(ConfigLoader.getProperty(TRANSPORT_STRATEGY)).isSameAs(SMTP_SSL);
assertThat(ConfigLoader.getProperty(TRANSPORT_STRATEGY)).isSameAs(SMTPS);
assertThat(ConfigLoader.getProperty(SMTP_HOST)).isEqualTo("smtp.default.com");
assertThat(ConfigLoader.getProperty(SMTP_PORT)).isEqualTo(25);
assertThat(ConfigLoader.getProperty(SMTP_USERNAME)).isEqualTo("username");
Expand All @@ -193,7 +193,7 @@ public void loadPropertiesFromFileClassPath()
public void loadPropertiesAddingMode()
throws Exception {
String s1 = "simplejavamail.javaxmail.debug=true\n"
+ "simplejavamail.transportstrategy=SMTP_SSL";
+ "simplejavamail.transportstrategy=SMTPS";
String s2 = "simplejavamail.defaults.to.name=To Default\n"
+ "simplejavamail.defaults.to.address=to@default.com";

Expand All @@ -202,7 +202,7 @@ public void loadPropertiesAddingMode()

// some checks from the config file
assertThat(ConfigLoader.getProperty(JAVAXMAIL_DEBUG)).isEqualTo(true);
assertThat(ConfigLoader.getProperty(TRANSPORT_STRATEGY)).isEqualTo(TransportStrategy.SMTP_SSL);
assertThat(ConfigLoader.getProperty(TRANSPORT_STRATEGY)).isEqualTo(TransportStrategy.SMTPS);
// now check if the extra properties were added
assertThat(ConfigLoader.getProperty(DEFAULT_TO_NAME)).isEqualTo("To Default");
assertThat(ConfigLoader.getProperty(DEFAULT_TO_ADDRESS)).isEqualTo("to@default.com");
Expand All @@ -213,15 +213,15 @@ public void loadPropertiesFromInputStream()
throws IOException {

String s = "simplejavamail.javaxmail.debug=true\n"
+ "simplejavamail.transportstrategy=SMTP_SSL\n"
+ "simplejavamail.transportstrategy=SMTPS\n"
+ "simplejavamail.smtp.host=smtp.default.com\n"
+ "simplejavamail.smtp.port=25\n"
+ "simplejavamail.smtp.username=username\n"
+ "simplejavamail.smtp.password=password\n";

ConfigLoader.loadProperties(new ByteArrayInputStream(s.getBytes()), false);
assertThat(ConfigLoader.getProperty(JAVAXMAIL_DEBUG)).isEqualTo(true);
assertThat(ConfigLoader.getProperty(TRANSPORT_STRATEGY)).isSameAs(SMTP_SSL);
assertThat(ConfigLoader.getProperty(TRANSPORT_STRATEGY)).isSameAs(SMTPS);
assertThat(ConfigLoader.getProperty(SMTP_HOST)).isEqualTo("smtp.default.com");
assertThat(ConfigLoader.getProperty(SMTP_PORT)).isEqualTo(25);
assertThat(ConfigLoader.getProperty(SMTP_USERNAME)).isEqualTo("username");
Expand All @@ -233,15 +233,15 @@ public void loadPropertiesFromProperties()
throws IOException {
Properties source = new Properties();
source.put("simplejavamail.javaxmail.debug", "true");
source.put("simplejavamail.transportstrategy", "SMTP_SSL");
source.put("simplejavamail.transportstrategy", "SMTPS");
source.put("simplejavamail.smtp.host", "smtp.default.com");
source.put("simplejavamail.smtp.port", "25");
source.put("simplejavamail.smtp.username", "username");
source.put("simplejavamail.smtp.password", "password");

ConfigLoader.loadProperties(source, false);
assertThat(ConfigLoader.getProperty(JAVAXMAIL_DEBUG)).isEqualTo(true);
assertThat(ConfigLoader.getProperty(TRANSPORT_STRATEGY)).isSameAs(SMTP_SSL);
assertThat(ConfigLoader.getProperty(TRANSPORT_STRATEGY)).isSameAs(SMTPS);
assertThat(ConfigLoader.getProperty(SMTP_HOST)).isEqualTo("smtp.default.com");
assertThat(ConfigLoader.getProperty(SMTP_PORT)).isEqualTo(25);
assertThat(ConfigLoader.getProperty(SMTP_USERNAME)).isEqualTo("username");
Expand All @@ -253,15 +253,15 @@ public void loadPropertiesFromObjectProperties()
throws IOException {
Properties source = new Properties();
source.put("simplejavamail.javaxmail.debug", true);
source.put("simplejavamail.transportstrategy", TransportStrategy.SMTP_SSL);
source.put("simplejavamail.transportstrategy", TransportStrategy.SMTPS);
source.put("simplejavamail.smtp.host", "smtp.default.com");
source.put("simplejavamail.smtp.port", 25);
source.put("simplejavamail.smtp.username", "username");
source.put("simplejavamail.smtp.password", "password");

ConfigLoader.loadProperties(source, false);
assertThat(ConfigLoader.getProperty(JAVAXMAIL_DEBUG)).isEqualTo(true);
assertThat(ConfigLoader.getProperty(TRANSPORT_STRATEGY)).isSameAs(SMTP_SSL);
assertThat(ConfigLoader.getProperty(TRANSPORT_STRATEGY)).isSameAs(SMTPS);
assertThat(ConfigLoader.getProperty(SMTP_HOST)).isEqualTo("smtp.default.com");
assertThat(ConfigLoader.getProperty(SMTP_PORT)).isEqualTo(25);
assertThat(ConfigLoader.getProperty(SMTP_USERNAME)).isEqualTo("username");
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/simplejavamail.properties
@@ -1,5 +1,5 @@
simplejavamail.javaxmail.debug=true
simplejavamail.transportstrategy=SMTP_SSL
simplejavamail.transportstrategy=SMTPS
simplejavamail.smtp.host=smtp.default.com
simplejavamail.smtp.port=25
simplejavamail.smtp.username=username
Expand Down

0 comments on commit 787aac2

Please sign in to comment.