@Test void validTextCalendarShouldNotBeSanitized() throws Exception { FakeMail mail = FakeMail.builder() .name("mail") .mimeMessage( MimeMessageBuilder.mimeMessageBuilder() .setMultipartWithBodyParts( MimeMessageBuilder.bodyPartBuilder() .type("text/calendar") .data("Not empty") .addHeader("X-CUSTOM", "Because it is a valid ICS it should not be pushed in body"))) .build(); testee.service(mail); Object content = mail.getMessage().getContent(); assertThat(content).isInstanceOf(Multipart.class); Multipart multipart = (Multipart) content; assertThat(multipart.getCount()).isEqualTo(1); SharedByteArrayInputStream inputStream = (SharedByteArrayInputStream) multipart.getBodyPart(0).getContent(); assertThat(IOUtils.toString(inputStream, StandardCharsets.UTF_8)) .doesNotContain("X-CUSTOM"); }
@Override public void service(Mail mail) { try { MimeMessage mimeMessage = mail.getMessage(); if (mimeMessage.getContent() instanceof Multipart) { Multipart multipart = (Multipart) mimeMessage.getContent(); if (needsSanitizing(multipart)) { mimeMessage.setContent(sanitize(multipart)); mimeMessage.saveChanges(); } } } catch (Exception e) { LOGGER.warn("Could not sanitize {}", mail.getName(), e); } }
ICSSanitizer extends GenericMailet { @Override public void service(Mail mail) { try { MimeMessage mimeMessage = mail.getMessage(); if (mimeMessage.getContent() instanceof Multipart) { Multipart multipart = (Multipart) mimeMessage.getContent(); if (needsSanitizing(multipart)) { mimeMessage.setContent(sanitize(multipart)); mimeMessage.saveChanges(); } } } catch (Exception e) { LOGGER.warn("Could not sanitize {}", mail.getName(), e); } } }
ICSSanitizer extends GenericMailet { @Override public void service(Mail mail) { try { MimeMessage mimeMessage = mail.getMessage(); if (mimeMessage.getContent() instanceof Multipart) { Multipart multipart = (Multipart) mimeMessage.getContent(); if (needsSanitizing(multipart)) { mimeMessage.setContent(sanitize(multipart)); mimeMessage.saveChanges(); } } } catch (Exception e) { LOGGER.warn("Could not sanitize {}", mail.getName(), e); } }  }
ICSSanitizer extends GenericMailet { @Override public void service(Mail mail) { try { MimeMessage mimeMessage = mail.getMessage(); if (mimeMessage.getContent() instanceof Multipart) { Multipart multipart = (Multipart) mimeMessage.getContent(); if (needsSanitizing(multipart)) { mimeMessage.setContent(sanitize(multipart)); mimeMessage.saveChanges(); } } } catch (Exception e) { LOGGER.warn("Could not sanitize {}", mail.getName(), e); } }  @Override void service(Mail mail); }
ICSSanitizer extends GenericMailet { @Override public void service(Mail mail) { try { MimeMessage mimeMessage = mail.getMessage(); if (mimeMessage.getContent() instanceof Multipart) { Multipart multipart = (Multipart) mimeMessage.getContent(); if (needsSanitizing(multipart)) { mimeMessage.setContent(sanitize(multipart)); mimeMessage.saveChanges(); } } } catch (Exception e) { LOGGER.warn("Could not sanitize {}", mail.getName(), e); } }  @Override void service(Mail mail); static final String DEFAULT_FILENAME; }