Skip to content

Commit 6d95974

Browse files
committed
#331: coalesce empty strings to null, to trigger the right authentication behavior from CLI
1 parent dfba897 commit 6d95974

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Diff for: modules/core-module/src/main/java/org/simplejavamail/internal/util/MiscUtil.java

+5
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ public static <T> boolean valueNullOrEmpty(final @Nullable T value) {
7171
(value instanceof byte[] && ((byte[]) value).length == 0);
7272
}
7373

74+
@Nullable
75+
public static <T> T emptyAsNull(final @Nullable T value) {
76+
return valueNullOrEmpty(value) ? null : value;
77+
}
78+
7479
public static String buildLogStringForSOCKSCommunication(final byte[] bytes, final boolean isReceived) {
7580
final StringBuilder debugMsg = new StringBuilder();
7681
debugMsg.append(isReceived ? "Received: " : "Sent: ");

Diff for: modules/simple-java-mail/src/main/java/org/simplejavamail/mailer/internal/MailerRegularBuilderImpl.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static org.simplejavamail.config.ConfigLoader.Property.TRANSPORT_STRATEGY;
2020
import static org.simplejavamail.config.ConfigLoader.hasProperty;
2121
import static org.simplejavamail.internal.util.MiscUtil.checkArgumentNotEmpty;
22+
import static org.simplejavamail.internal.util.MiscUtil.emptyAsNull;
2223
import static org.simplejavamail.internal.util.Preconditions.verifyNonnullOrEmpty;
2324

2425
/**
@@ -109,8 +110,8 @@ public MailerRegularBuilderImpl withTransportStrategy(@NotNull final TransportSt
109110
public MailerRegularBuilderImpl withSMTPServer(@Nullable final String host, @Nullable final Integer port, @Nullable final String username, @Nullable final String password) {
110111
return withSMTPServerHost(host)
111112
.withSMTPServerPort(port)
112-
.withSMTPServerUsername(username)
113-
.withSMTPServerPassword(password);
113+
.withSMTPServerUsername(emptyAsNull(username))
114+
.withSMTPServerPassword(emptyAsNull(password));
114115
}
115116

116117
/**

0 commit comments

Comments
 (0)