use of org.simplejavamail.api.internal.smimesupport.model.PlainSmimeDetails in project simple-java-mail by bbottema.
the class MailerLiveTest method assertSendingEmail.
private Email assertSendingEmail(final EmailPopulatingBuilder originalEmailPopulatingBuilder, boolean compensateForDresscodeAttachmentNameOverrideErasure, boolean skipChecksDueToSmime, boolean async, final boolean sentDateWasFixed, final boolean dynamicImageEmbeddingWasUsed) throws MessagingException, ExecutionException, InterruptedException {
Email originalEmail = originalEmailPopulatingBuilder.buildEmail();
if (!async) {
mailer.sendMail(originalEmail);
} else {
verifyNonnullOrEmpty(mailer.sendMail(originalEmail, async)).get();
}
MimeMessageAndEnvelope receivedMimeMessage = smtpServerRule.getOnlyMessage();
assertThat(receivedMimeMessage.getMimeMessage().getMessageID()).isEqualTo(originalEmail.getId());
if (originalEmail.getBounceToRecipient() != null) {
assertThat(receivedMimeMessage.getEnvelopeSender()).isEqualTo(originalEmail.getBounceToRecipient().getAddress());
} else {
assertThat(receivedMimeMessage.getEnvelopeSender()).isEqualTo(originalEmail.getFromRecipient().getAddress());
}
Email receivedEmail = mimeMessageToEmail(receivedMimeMessage.getMimeMessage(), loadPkcs12KeyStore());
if (!sentDateWasFixed) {
GregorianCalendar receiveWindowStart = new GregorianCalendar();
receiveWindowStart.add(Calendar.SECOND, -10);
assertThat(receivedEmail.getSentDate()).isBetween(receiveWindowStart.getTime(), new Date());
} else {
assertThat(receivedEmail.getSentDate()).isEqualTo(originalEmailPopulatingBuilder.getSentDate());
}
// ID will always be generated when sending: if set to a specific value, just assume the generated one
if (originalEmailPopulatingBuilder.getId() == null) {
originalEmailPopulatingBuilder.fixingMessageId(receivedEmail.getId());
}
// sent-date will always be generated when sending: if not set to a specific value, just assume the generated one
if (originalEmailPopulatingBuilder.getSentDate() == null) {
originalEmailPopulatingBuilder.fixingSentDate(verifyNonnullOrEmpty(receivedEmail.getSentDate()));
}
// hack: it seems Wiser automatically defaults replyTo address to the From address if left empty
if (originalEmailPopulatingBuilder.getReplyToRecipient() == null) {
originalEmailPopulatingBuilder.withReplyTo(originalEmailPopulatingBuilder.getFromRecipient());
}
// received email will always have an id, so let's make sure we're able to compare to the original email object
if (originalEmailPopulatingBuilder.getHeaders().get("Message-ID") == null) {
originalEmailPopulatingBuilder.withHeader("Message-ID", originalEmail.getId());
}
// bounce recipient is not part of the Mimemessage, but the Envelope and is configured on the Session and is not received back on the MimeMessage
if (originalEmailPopulatingBuilder.getBounceToRecipient() != null) {
originalEmailPopulatingBuilder.clearBounceTo();
}
if (originalEmailPopulatingBuilder.getOriginalSmimeDetails() instanceof PlainSmimeDetails) {
// because the S/MIME module is loaded, the default PLAIN version gets replaced with the one from the module
((InternalEmailPopulatingBuilder) originalEmailPopulatingBuilder).withOriginalSmimeDetails(OriginalSmimeDetailsImpl.builder().build());
}
if (compensateForDresscodeAttachmentNameOverrideErasure) {
TestDataHelper.fixDresscodeAttachment(receivedEmail);
}
if (!skipChecksDueToSmime) {
// reading a signed mail is different from building a new one
assertThat(receivedEmail).isEqualTo(originalEmailPopulatingBuilder.buildEmail());
}
return receivedEmail;
}
Aggregations