Header can be empty
When converting a mimeMessage to Email abject I get the following stack trace.
java.lang.IllegalArgumentException: value is required
at org.simplejavamail.internal.util.Preconditions.checkNonEmptyArgument(Preconditions.java:15)
at org.simplejavamail.email.EmailPopulatingBuilder.withHeader(EmailPopulatingBuilder.java:1194)
at org.simplejavamail.email.EmailPopulatingBuilder.withHeaders(EmailPopulatingBuilder.java:1178)
at org.simplejavamail.converter.EmailConverter.buildEmailFromMimeMessage(EmailConverter.java:255)
at org.simplejavamail.converter.EmailConverter.mimeMessageToEmailBuilder(EmailConverter.java:64)
at org.simplejavamail.converter.EmailConverter.mimeMessageToEmail(EmailConverter.java:55)
One of the headers is in the MimeMessage is an empty string, I found this related issue: https://github.com/bbottema/simple-java-mail/issues/109
It seems to be the same problem, but in a different case when converting from a mimeMessage.
See (in EmailPopulatingBuilder.java)
public EmailPopulatingBuilder withHeader(@Nonnull String name, @Nonnull Object value) {
Preconditions.checkNonEmptyArgument(name, "name");
Preconditions.checkNonEmptyArgument(value, "value");
this.headers.put(name, String.valueOf(value));
return this;
}
Should be
public EmailPopulatingBuilder withHeader(@Nonnull final String name, @Nullable final Object value) {
checkNonEmptyArgument(name, "name");
//checkNonEmptyArgument(value, "value");
headers.put(name, value != null ? String.valueOf(value) : "");
return this;
}
Hi @mcix, this issue should already be solved (#109) in 5.0.0.rc1-SNAPSHOT. Is it possible for you to update to this? You'll need the Nexus snapshots repo.
Hi @bbottema , yes I did try the 5.0.0.rc1-SNAPSHOT version using the nexus snapshot repo, but that did not solve the problem. The fix in https://github.com/bbottema/simple-java-mail/issues/109 was fixed in src/main/java/org/simplejavamail/email/Email.java, the issue I am referring to is in src/main/java/org/simplejavamail/email/EmailPopulatingBuilder.java
I published a new release candidate, 5.0.0.rc2-SNAPSHOT, please try with that.
Thanks! Tested with 5.0.0.rc2-SNAPSHOT, works 👍