* @param errors StringBuilder for the error messages
* @param warnings StringBuilder for the warnings
* @param locale The users local
*/
public static void appendErrorsAndWarnings(MailerResult mailerResult, StringBuilder errors, StringBuilder warnings, Locale locale) {
Translator trans = new PackageTranslator(Util.getPackageName(MailerResult.class), locale);
int returnCode = mailerResult.getReturnCode();
List<Identity> failedIdentites = mailerResult.getFailedIdentites();
// first the severe errors
if (returnCode == MailerResult.SEND_GENERAL_ERROR) {
errors.append("<p>").append(trans.translate("mailhelper.error.send.general")).append("</p>");
} else if (returnCode == MailerResult.SENDER_ADDRESS_ERROR) {
errors.append("<p>").append(trans.translate("mailhelper.error.sender.address")).append("</p>");
} else if (returnCode == MailerResult.RECIPIENT_ADDRESS_ERROR) {
errors.append("<p>").append(trans.translate("mailhelper.error.recipient.address")).append("</p>");
} else if (returnCode == MailerResult.TEMPLATE_GENERAL_ERROR) {
errors.append("<p>").append(trans.translate("mailhelper.error.template.general")).append("</p>");
} else if (returnCode == MailerResult.TEMPLATE_PARSE_ERROR) {
errors.append("<p>").append(trans.translate("mailhelper.error.template.parse")).append("</p>");
} else if (returnCode == MailerResult.ATTACHMENT_INVALID) {
errors.append("<p>").append(trans.translate("mailhelper.error.attachment")).append("</p>");
} else {
// mail could be send, but maybe not to all the users (e.g. invalid mail
// adresses or a temporary problem)
if (failedIdentites != null && failedIdentites.size() > 0) {
warnings.append("<p>").append(trans.translate("mailhelper.error.failedusers"));
warnings.append("<ul>");
for (Identity identity : failedIdentites) {
User user = identity.getUser();
warnings.append("<li>");
warnings.append(trans.translate("mailhelper.error.failedusers.user", new String[] { user.getProperty(UserConstants.FIRSTNAME, null), user.getProperty(UserConstants.LASTNAME, null),
user.getProperty(UserConstants.EMAIL, null), identity.getName() }));
warnings.append("</li>");
}
warnings.append("</ul></p>");
}