001/*
002 * acme4j - Java ACME client
003 *
004 * Copyright (C) 2021 Richard "Shred" Körber
005 *   http://acme4j.shredzone.org
006 *
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
013 */
014package org.shredzone.acme4j.smime.email;
015
016import jakarta.mail.Message;
017import jakarta.mail.MessagingException;
018
019/**
020 * A generator for the response body to be set to the {@link Message}.
021 * <p>
022 * This generator can be used to design the body of the outgoing response email. However,
023 * note that the response email is evaluated by a machine and usually not read by humans,
024 * so the design should be kept simple, and <em>must</em> be conformous to RFC-8823.
025 * <p>
026 * The {@code responseBody} must be a part of the response email body, otherwise the
027 * validation will fail.
028 * <p>
029 * A minimal implementation is:
030 * <pre>
031 * response.setContent(responseBody, RESPONSE_BODY_TYPE);
032 * </pre>
033 *
034 * @see <a href="https://datatracker.ietf.org/doc/html/rfc8823">RFC 8823</a>
035 * @since 2.12
036 */
037@FunctionalInterface
038public interface ResponseBodyGenerator {
039
040    /**
041     * The content-type of the response body: {@value #RESPONSE_BODY_TYPE}
042     */
043    String RESPONSE_BODY_TYPE = "text/plain";
044
045    /**
046     * Sets the content of the {@link Message}.
047     *
048     * @param response
049     *         {@link Message} to set the body content.
050     * @param responseBody
051     *         The response body that <em>must</em> be part of the email response, and
052     *         <em>must</em> use {@value #RESPONSE_BODY_TYPE} content type.
053     */
054    void setContent(Message response, String responseBody) throws MessagingException;
055
056}