Skip to content

Commit 0e0b8a9

Browse files
committed
#114: - Added reset methods to clear fields in builder
- Resolved all static analyses issues (reported by IntelliJ) - Made Email immutable and all the fields final (excpet ID, which is updated during sending email)
1 parent ef94279 commit 0e0b8a9

File tree

9 files changed

+773
-521
lines changed

9 files changed

+773
-521
lines changed

src/main/java/org/simplejavamail/email/Email.java

Lines changed: 125 additions & 316 deletions
Large diffs are not rendered by default.

src/main/java/org/simplejavamail/email/EmailBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ public static final class EmailBuilderInstance {
161161
*
162162
* @see #replyingTo(MimeMessage, boolean, String)
163163
*/
164+
@SuppressWarnings("JavaDoc")
164165
static final String DEFAULT_QUOTING_MARKUP = "<blockquote style=\"color: gray; border-left: 1px solid #4f4f4f; padding-left: " +
165166
"1cm\">%s</blockquote>";
166167

src/main/java/org/simplejavamail/email/EmailPopulatingBuilder.java

Lines changed: 616 additions & 165 deletions
Large diffs are not rendered by default.

src/main/java/org/simplejavamail/mailer/config/TransportStrategy.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,6 @@ public String propertyNameSSLTrust() {
168168
return "mail.smtp.ssl.trust";
169169
}
170170

171-
/**
172-
* @return {@link #opportunisticTLS}
173-
*/
174-
@Override
175-
@Nullable
176-
public Boolean getOpportunisticTLS() {
177-
return opportunisticTLS;
178-
}
179-
180171
/**
181172
* Sets {@link #opportunisticTLS}. Setting <code>null</code> will revert to property value if available or default to {@value
182173
* DEFAULT_OPPORTUNISTIC_TLS}
@@ -465,11 +456,10 @@ public Properties generateProperties() {
465456
public abstract String propertyNameTimeout();
466457

467458
/**
468-
* @see TransportStrategy#SMTP#getOpportunisticTLS()
469-
*/
470-
@Nullable public Boolean getOpportunisticTLS() { return false; }
471-
/**
472-
* @see TransportStrategy#SMTP#setOpportunisticTLS(Boolean)
459+
* Refer to {@link #SMTP}.opportunisticTLS for details. Defaults to {@code false} for all other transport strategies.
460+
* <hr>
461+
* Determines whether TLS should be attempted for SMTP plain protocol (optional if offered by the SMTP server). Setting this flag to false causes
462+
* the {@link TransportStrategy#SMTP} to revert back to the legacy behavior.
473463
*/
474464
public void setOpportunisticTLS(@Nullable final Boolean opportunisticTLS) {}
475465

src/main/java/org/simplejavamail/mailer/internal/mailsender/MailSender.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ private void sendMailClosure(@Nonnull final Session session, @Nonnull final Emai
278278

279279
logSession(session);
280280
message.saveChanges(); // some headers and id's will be set for this specific message
281-
email.setId(message.getMessageID());
281+
//noinspection deprecation
282+
email.internalSetId(message.getMessageID());
282283

283284
try {
284285
synchronized (this) {

src/main/java/org/simplejavamail/mailer/internal/socks/socks5client/KeyStoreInfo.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@
77
@SuppressWarnings("SameParameterValue")
88
public class KeyStoreInfo {
99

10-
private String keyStorePath;
11-
private String password;
10+
private final String keyStorePath;
11+
private final String password;
1212
private String type = "JKS";
1313

14-
public KeyStoreInfo() {
15-
}
14+
// public KeyStoreInfo() {
15+
// }
1616

1717
public KeyStoreInfo(final String keyStorePath, final String password, final String type) {
1818
this.keyStorePath = MiscUtil.checkNotNull(keyStorePath, "Argument [keyStorePath] may not be null");
1919
this.password = MiscUtil.checkNotNull(password, "Argument [password] may not be null");
2020
this.type = MiscUtil.checkNotNull(type, "Argument [type] may not be null");
2121
}
2222

23-
public KeyStoreInfo(final String keyStorePath, final String password) {
24-
this(keyStorePath, password, "JKS");
25-
}
23+
// public KeyStoreInfo(final String keyStorePath, final String password) {
24+
// this(keyStorePath, password, "JKS");
25+
// }
2626

2727
public String getKeyStorePath() {
2828
return keyStorePath;

src/main/java/org/simplejavamail/mailer/internal/socks/socks5client/Socks5.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ public class Socks5 {
2727

2828
private boolean alwaysResolveAddressLocally = false;
2929

30-
public Socks5(final InetSocketAddress socketAddress, final String username, final String password) {
31-
this(socketAddress);
32-
setCredentials(new ProxyCredentials(username, password));
33-
}
34-
35-
public Socks5(final String host, final int port)
36-
throws UnknownHostException {
37-
this(InetAddress.getByName(host), port);
38-
}
30+
// public Socks5(final InetSocketAddress socketAddress, final String username, final String password) {
31+
// this(socketAddress);
32+
// setCredentials(new ProxyCredentials(username, password));
33+
// }
34+
//
35+
// public Socks5(final String host, final int port)
36+
// throws UnknownHostException {
37+
// this(InetAddress.getByName(host), port);
38+
// }
3939

4040
Socks5(final InetAddress inetAddress, final int port) {
4141
this(new InetSocketAddress(inetAddress, port));
@@ -52,12 +52,12 @@ private Socks5(final Socks5 chainProxy, final InetSocketAddress socketAddress) {
5252
this.setChainProxy(chainProxy);
5353
}
5454

55-
public Socks5(final String host, final int port, final ProxyCredentials credentials)
56-
throws UnknownHostException {
57-
this.inetAddress = InetAddress.getByName(host);
58-
this.port = port;
59-
this.credentials = credentials;
60-
}
55+
// public Socks5(final String host, final int port, final ProxyCredentials credentials)
56+
// throws UnknownHostException {
57+
// this.inetAddress = InetAddress.getByName(host);
58+
// this.port = port;
59+
// this.credentials = credentials;
60+
// }
6161

6262
public void buildConnection()
6363
throws IOException {

src/test/java/org/simplejavamail/mailer/MailerLiveTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ private Email assertSendingEmail(final EmailPopulatingBuilder originalEmailPopul
122122
}
123123
// bounce recipient is not part of the Mimemessage, but the Envelope and is configured on the Session, so just ignore this
124124
if (originalEmailPopulatingBuilder.getBounceToRecipient() != null) {
125-
receivedEmail.setBounceToRecipient(originalEmailPopulatingBuilder.getBounceToRecipient());
125+
originalEmailPopulatingBuilder.clearBounceTo();
126126
}
127127
assertThat(receivedEmail).isEqualTo(originalEmailPopulatingBuilder.buildEmail());
128128
return receivedEmail;

src/test/java/org/simplejavamail/mailer/MailerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,12 @@ public void testParser()
278278
final EmailPopulatingBuilder emailPopulatingBuilderNormal = EmailHelper.createDummyEmailBuilder(true, false, false);
279279

280280
// let's try producing and then consuming a MimeMessage ->
281+
// (bounce recipient is not part of the Mimemessage, but the Envelope and is configured on the Session, so just ignore this)
282+
emailPopulatingBuilderNormal.clearBounceTo();
281283
Email emailNormal = emailPopulatingBuilderNormal.buildEmail();
282284
final MimeMessage mimeMessage = EmailConverter.emailToMimeMessage(emailNormal);
283285
final Email emailFromMimeMessage = EmailConverter.mimeMessageToEmail(mimeMessage);
284286

285-
// bounce recipient is not part of the Mimemessage, but the Envelope and is configured on the Session, so just ignore this
286-
emailFromMimeMessage.setBounceToRecipient(emailPopulatingBuilderNormal.getBounceToRecipient());
287287

288288
assertThat(emailFromMimeMessage).isEqualTo(emailNormal);
289289
}

0 commit comments

Comments
 (0)