Search in sources :

Example 1 with TextContentRenderer

use of org.commonmark.renderer.text.TextContentRenderer in project lavagna by digitalfondue.

the class MailTicketService method sendEmail.

private void sendEmail(String to, String name, Card createdCard, Board board, ProjectMailTicketConfig config, ProjectMailTicket ticketConfig) {
    String cardId = board.getShortName() + "-" + createdCard.getSequence();
    String subjectTemplate = "" + (ticketConfig.getNotificationOverride() ? ticketConfig.getSubject() : config.getSubject());
    String bodyTemplate = "" + (ticketConfig.getNotificationOverride() ? ticketConfig.getBody() : config.getBody());
    String subject = subjectTemplate.replaceAll("\\{\\{card}}", cardId);
    String body = bodyTemplate.replaceAll("\\{\\{card}}", cardId).replaceAll("\\{\\{name}}", name != null ? name : to);
    Parser parser = Parser.builder().build();
    Node document = parser.parse(body);
    HtmlRenderer htmlRenderer = HtmlRenderer.builder().build();
    TextContentRenderer textRendered = TextContentRenderer.builder().build();
    String htmlText = htmlRenderer.render(document);
    String plainText = textRendered.render(document);
    ProjectMailTicketConfigData configData = config.getConfig();
    MailConfig mailConfig = new MailConfig(configData.getOutboundServer(), configData.getOutboundPort(), configData.getOutboundProtocol(), configData.getOutboundUser(), configData.getOutboundPassword(), ticketConfig.getSendByAlias() ? ticketConfig.getAlias() : configData.getOutboundAddress(), configData.getOutboundProperties());
    mailConfig.send(to, subject, plainText, htmlText);
}
Also used : Node(org.commonmark.node.Node) TextContentRenderer(org.commonmark.renderer.text.TextContentRenderer) HtmlRenderer(org.commonmark.renderer.html.HtmlRenderer) Parser(org.commonmark.parser.Parser)

Aggregations

Node (org.commonmark.node.Node)1 Parser (org.commonmark.parser.Parser)1 HtmlRenderer (org.commonmark.renderer.html.HtmlRenderer)1 TextContentRenderer (org.commonmark.renderer.text.TextContentRenderer)1