if (StringUtils.empty(StringUtils.trim(line))) {
body = new StringBuilder();
} else {
int split = line.indexOf(':');
if (split < 0) {
throw new RenderException("illegal line: " + line);
}
String fieldName = line.substring(0, split).trim();
String fieldValue = line.substring(split + 1).trim();
if (!SUPPORTED_FIELDS.contains(fieldName)) {
throw new RenderException("unknown field: " + fieldName);
}
fieldValues.put(fieldName, fieldValue);
}
} else if (body.length() > 0 || !StringUtils.empty(StringUtils.trim(line))) {
body.append(line).append("\n");
}
}
required.removeAll(fieldValues.keySet());
if (required.size() > 0) {
throw new RenderException("missing fields: " + required);
}
if (body == null || body.length() == 0) {
throw new RenderException("empty body");
}
// remove trailing \n
body.setLength(body.length() - 1);
rendered.setSubject(fieldValues.get(FIELD_SUBJECT));