From 9a680a53a499cf29a66c05154f83c415acc3ba8f Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 31 Jul 2014 13:12:57 +0200 Subject: [PATCH] =?utf8?q?Only=20add=20mail=20parts=20if=20they=E2=80=99re?= =?utf8?q?=20necessary.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../rhynodge/actions/EmailAction.java | 26 +++++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/pterodactylus/rhynodge/actions/EmailAction.java b/src/main/java/net/pterodactylus/rhynodge/actions/EmailAction.java index 0a0aca7..b781f4d 100644 --- a/src/main/java/net/pterodactylus/rhynodge/actions/EmailAction.java +++ b/src/main/java/net/pterodactylus/rhynodge/actions/EmailAction.java @@ -101,12 +101,8 @@ public class EmailAction implements Action { /* create text and html parts. */ MimeMultipart multipart = new MimeMultipart(); multipart.setSubType("alternative"); - MimeBodyPart textPart = new MimeBodyPart(); - textPart.setContent(output.text("text/plain", -1), "text/plain;charset=utf-8"); - MimeBodyPart htmlPart = new MimeBodyPart(); - htmlPart.setContent(output.text("text/html", -1), "text/html;charset=utf-8"); - multipart.addBodyPart(textPart); - multipart.addBodyPart(htmlPart); + addPlainTextPart(output, multipart); + addHtmlPart(output, multipart); message.setContent(multipart); transport.connect(); @@ -116,4 +112,22 @@ public class EmailAction implements Action { } } + private void addPlainTextPart(Output output, MimeMultipart multipart) throws MessagingException { + if (output.text("text/plain", -1) == null) { + return; + } + MimeBodyPart textPart = new MimeBodyPart(); + textPart.setContent(output.text("text/plain", -1), "text/plain;charset=utf-8"); + multipart.addBodyPart(textPart); + } + + private void addHtmlPart(Output output, MimeMultipart multipart) throws MessagingException { + if (output.text("text/html", -1) == null) { + return; + } + MimeBodyPart htmlPart = new MimeBodyPart(); + htmlPart.setContent(output.text("text/html", -1), "text/html;charset=utf-8"); + multipart.addBodyPart(htmlPart); + } + } -- 2.7.4