From a5dd9d33e7ef2acffbf8a7e3c1fc5e32767b377c Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 5 Jan 2018 12:33:33 +0300 Subject: email: html formatting --- juick-api/src/main/java/com/juick/api/EmailManager.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'juick-api/src/main/java/com') diff --git a/juick-api/src/main/java/com/juick/api/EmailManager.java b/juick-api/src/main/java/com/juick/api/EmailManager.java index d906b8a5..af66466f 100644 --- a/juick-api/src/main/java/com/juick/api/EmailManager.java +++ b/juick-api/src/main/java/com/juick/api/EmailManager.java @@ -6,6 +6,7 @@ import com.juick.service.EmailService; import com.juick.service.MessagesService; import com.juick.service.SubscriptionService; import com.juick.service.UserService; +import com.juick.util.MessageUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -82,10 +83,12 @@ public class EmailManager implements ApplicationListener { StringUtils.isNotEmpty(msg.getText()) ? formatPost(msg) : "", formatUrl(msg)); MimeBodyPart textBodyPart = new MimeBodyPart(); textBodyPart.setContent(plainText, "text/plain; charset=UTF-8"); + boolean isCode = msg.getTags().stream().anyMatch(t -> t.getName().equals("code")); String htmlText = String.format("%s

--
You are receiving this because you are subscribed to this user " + ", discussion or tag. Reply to this email directly or view it on Juick." + "
Configure or disable notifications", - StringUtils.isNotEmpty(msg.getText()) ? formatPost(msg) : "", formatUrl(msg), + StringUtils.isNotEmpty(msg.getText()) ? isCode ? MessageUtils.formatMessageCode(msg.getText()) + : MessageUtils.formatMessage(msg.getText()) : "", formatUrl(msg), userService.getHashByUID(userService.getUserByEmail(email).getUid())); MimeBodyPart htmlBodyPart = new MimeBodyPart(); htmlBodyPart.setContent(htmlText, "text/html; charset=UTF-8"); @@ -93,7 +96,8 @@ public class EmailManager implements ApplicationListener { multipart.addBodyPart(textBodyPart); multipart.addBodyPart(htmlBodyPart); message.setContent(multipart); - message.setHeader("List-Unsubscribe", String.format("https://juick.com/settings?hash=%s", userService.getHashByUID(userService.getUserByEmail(email).getUid()))); + message.setHeader("List-Unsubscribe", String.format("https://juick.com/settings?hash=%s", + userService.getHashByUID(userService.getUserByEmail(email).getUid()))); message.saveChanges(); transport.connect(); transport.sendMessage(message, message.getAllRecipients()); -- cgit v1.2.3