use of org.ambraproject.wombat.model.EmailMessage in project wombat by PLOS.
the class FeedbackController method receiveFeedback.
@RequestMapping(name = "feedbackPost", value = "/feedback", method = RequestMethod.POST)
public String receiveFeedback(HttpServletRequest request, HttpServletResponse response, Model model, @SiteParam Site site, @RequestParam("fromEmailAddress") String fromEmailAddress, @RequestParam("note") String note, @RequestParam("subject") String subject, @RequestParam("name") String name, @RequestParam("userId") String userId, @RequestParam(value = "authorPhone", required = false) String authorPhone, @RequestParam(value = "authorAffiliation", required = false) String authorAffiliation) throws IOException, MessagingException {
validateFeedbackConfig(site);
// Fill input parameters into model. (These can be used in two ways: in the generated email if all input is valid,
// or in the form in case we need to display validation errors.)
model.addAttribute("fromEmailAddress", fromEmailAddress);
model.addAttribute("note", note);
model.addAttribute("name", name);
model.addAttribute("subject", subject);
Set<String> errors = validateInput(fromEmailAddress, note, subject, name);
if (applyValidation(response, model, errors)) {
return serveFeedbackPage(model, site);
}
if (subject.isEmpty()) {
model.addAttribute("subject", getFeedbackConfig(site).get("defaultSubject"));
}
model.addAttribute("id", userId);
model.addAttribute("userInfo", formatUserInfo(request));
if (honeypotService.checkHoneypot(request, authorPhone, authorAffiliation)) {
return site + "/ftl/feedback/success";
}
Multipart content = freemarkerMailService.createContent(site, "feedback", model);
String destinationAddress = (String) getFeedbackConfig(site).get("destination");
EmailMessage message = EmailMessage.builder().addToEmailAddress(EmailMessage.createAddress(null, destinationAddress)).setSenderAddress(EmailMessage.createAddress(name, fromEmailAddress)).setSubject(subject).setContent(content).setEncoding(freeMarkerConfig.getConfiguration().getDefaultEncoding()).build();
message.send(javaMailSender);
return site + "/ftl/feedback/success";
}
use of org.ambraproject.wombat.model.EmailMessage in project wombat by PLOS.
the class ArticleController method emailArticle.
/**
* @param model data passed in from the view
* @param site current site
* @return path to the template
* @throws IOException
*/
@RequestMapping(name = "emailPost", value = "/article/email", method = RequestMethod.POST)
public String emailArticle(HttpServletRequest request, HttpServletResponse response, Model model, @SiteParam Site site, RequestedDoiVersion articleId, @RequestParam("articleUri") String articleUri, @RequestParam("emailToAddresses") String emailToAddresses, @RequestParam("emailFrom") String emailFrom, @RequestParam("senderName") String senderName, @RequestParam("note") String note, @RequestParam(value = "authorPhone", required = false) String authorPhone, @RequestParam(value = "authorAffiliation", required = false) String authorAffiliation) throws IOException, MessagingException {
requireNonemptyParameter(articleUri);
model.addAttribute("emailToAddresses", emailToAddresses);
model.addAttribute("emailFrom", emailFrom);
model.addAttribute("senderName", senderName);
model.addAttribute("note", note);
model.addAttribute("articleUri", articleUri);
List<InternetAddress> toAddresses = Splitter.on(CharMatcher.anyOf("\n\r")).omitEmptyStrings().splitToList(emailToAddresses).stream().map(email -> EmailMessage.createAddress(null, /*name*/
email)).collect(Collectors.toList());
Set<String> errors = validateEmailArticleInput(toAddresses, emailFrom, senderName);
if (applyValidation(response, model, errors)) {
return renderEmailThisArticle(request, model, site, articleId);
}
Map<String, ?> articleMetadata = articleMetadataFactory.get(site, articleId).validateVisibility("emailPost").getIngestionMetadata();
String title = articleMetadata.get("title").toString();
model.addAttribute("article", articleMetadata);
model.addAttribute("journalName", site.getJournalName());
if (honeypotService.checkHoneypot(request, authorPhone, authorAffiliation)) {
response.setStatus(HttpStatus.CREATED.value());
return site + "/ftl/article/emailSuccess";
}
Multipart content = freemarkerMailService.createContent(site, "emailThisArticle", model);
EmailMessage message = EmailMessage.builder().addToEmailAddresses(toAddresses).setSenderAddress(EmailMessage.createAddress(senderName, emailFrom)).setSubject("An Article from " + site.getJournalName() + ": " + title).setContent(content).setEncoding(freeMarkerConfig.getConfiguration().getDefaultEncoding()).build();
message.send(javaMailSender);
response.setStatus(HttpStatus.CREATED.value());
return site + "/ftl/article/emailSuccess";
}
Aggregations