From ae9a7f0d0b9626e66f877191465ee38ad9b93039 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 6 Jul 2017 22:31:48 +0200 Subject: [PATCH] Lesser method calls in another method call + lesser parameter = better style ... ;-) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../jmailee/model/delivery/BaseMailer.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/org/mxchange/jmailee/model/delivery/BaseMailer.java b/src/org/mxchange/jmailee/model/delivery/BaseMailer.java index 843bada..2e677f7 100644 --- a/src/org/mxchange/jmailee/model/delivery/BaseMailer.java +++ b/src/org/mxchange/jmailee/model/delivery/BaseMailer.java @@ -20,7 +20,6 @@ import java.io.StringWriter; import java.text.MessageFormat; import java.util.Date; import java.util.Properties; -import javax.mail.Address; import javax.mail.MessagingException; import javax.mail.Session; import javax.mail.Transport; @@ -128,14 +127,14 @@ public abstract class BaseMailer implements DeliverableEmail { *

* @param emailAddress Email address for recipient * @param subjectLine Subject line - * @param body Body part + * @param writer Body part * @param mailSession Corresponding mail session to use *

* @throws MessagingException If something happened on message delivery */ - private void sendMail (final Address emailAddress, final String subjectLine, final String body, final Session mailSession) throws MessagingException { + private void sendMail (final WrapableEmailDelivery emailWrapper, final StringWriter writer, final Session mailSession) throws MessagingException { // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendMail: emailAddress={0},subjectLine={1},body={2},mailSession={3} - CALLED!", emailAddress, subjectLine, body, mailSession)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendMail: emailWrapper={0},body={1},mailSession={2} - CALLED!", emailWrapper, writer, mailSession)); //NOI18N // Are the additional properties set? if (null == this.properties) { @@ -147,10 +146,10 @@ public abstract class BaseMailer implements DeliverableEmail { MimeMessage message = new MimeMessage(mailSession); // Set subject, recipients and body - message.setSubject(subjectLine); - message.setRecipients(javax.mail.Message.RecipientType.TO, InternetAddress.parse(emailAddress.toString(), true)); + message.setSubject(emailWrapper.getSubjectLine()); + message.setRecipients(javax.mail.Message.RecipientType.TO, InternetAddress.parse(emailWrapper.getRecipient().toString(), true)); message.setSentDate(new Date()); - message.setText(body); + message.setText(writer.toString()); message.setHeader("MIME-Version", "1.0"); //NOI18N message.setHeader("Content-Type", "text/plain; charset=UTF-8"); //NOI18N message.setHeader("Content-Transfer-Encoding", "8bit"); //NOI18N @@ -175,6 +174,9 @@ public abstract class BaseMailer implements DeliverableEmail { // Directly send email Transport.send(message); + + // Trace message + this.getLoggerBeanLocal().logTrace("init: EXIT!"); //NOI18N } /** @@ -234,7 +236,10 @@ public abstract class BaseMailer implements DeliverableEmail { template.merge(context, writer); // Get all out and send it - this.sendMail(emailWrapper.getRecipient(), emailWrapper.getSubjectLine(), writer.toString(), mailSession); + this.sendMail(emailWrapper, writer, mailSession); + + // Trace message + this.getLoggerBeanLocal().logTrace("init: EXIT!"); //NOI18N } } -- 2.39.5