@Test void testService() throws MessagingException, IOException { Mailet mailet; FakeMailetConfig mci; MimeMessage message; Mail mail; mailet = new OnlyText(); mci = FakeMailetConfig.builder() .mailetName("Test") .build(); mailet.init(mci); message = new MimeMessage(Session.getDefaultInstance(new Properties())); message.setSubject("prova"); message.setText("Questa è una prova"); message.saveChanges(); mail = FakeMail.builder() .name("mail") .mimeMessage(message) .build(); mailet.service(mail); assertThat(mail.getMessage().getSubject()).isEqualTo("prova"); assertThat(mail.getMessage().getContent()).isEqualTo("Questa è una prova"); message = new MimeMessage(Session.getDefaultInstance(new Properties())); message.setSubject("prova"); MimeMultipart mp = new MimeMultipart(); MimeBodyPart bp = new MimeBodyPart(); bp.setText("Questo è un part interno1"); mp.addBodyPart(bp); bp = new MimeBodyPart(); bp.setText("Questo è un part interno2"); mp.addBodyPart(bp); bp = new MimeBodyPart(); MimeMessage message2 = new MimeMessage(Session .getDefaultInstance(new Properties())); bp.setContent(message2, "message/rfc822"); mp.addBodyPart(bp); message.setContent(mp); message.saveChanges(); mail = FakeMail.builder() .name("mail") .mimeMessage(message) .build(); mailet.service(mail); assertThat(mail.getMessage().getSubject()).isEqualTo("prova"); assertThat(mail.getMessage() .getContent()).isEqualTo("Questo è un part interno1"); message = new MimeMessage(Session.getDefaultInstance(new Properties())); message.setSubject("prova"); mp = new MimeMultipart(); bp = new MimeBodyPart(); bp.setText("Questo è un part interno1"); mp.addBodyPart(bp); bp = new MimeBodyPart(); bp.setText("Questo è un part interno2"); mp.addBodyPart(bp); bp = new MimeBodyPart(); message2 = new MimeMessage(Session.getDefaultInstance(new Properties())); bp.setContent(message2, "message/rfc822"); mp.addBodyPart(bp); MimeMultipart mpext = new MimeMultipart(); bp = new MimeBodyPart(); bp.setContent(mp); mpext.addBodyPart(bp); message.setContent(mpext); message.saveChanges(); mail = FakeMail.builder() .name("mail") .mimeMessage(message) .build(); mailet.service(mail); assertThat(mail.getMessage().getSubject()).isEqualTo("prova"); assertThat(mail.getMessage() .getContent()).isEqualTo("Questo è un part interno1"); message = new MimeMessage(Session.getDefaultInstance(new Properties())); message.setSubject("prova"); message.setContent("<p>Questa è una prova<br />di html</p>", "text/html"); message.saveChanges(); mail = FakeMail.builder() .name("mail") .mimeMessage(message) .build(); mailet.service(mail); assertThat(mail.getMessage().getSubject()).isEqualTo("prova"); assertThat(mail.getMessage() .getContent()).isEqualTo("Questa è una prova\ndi html\n"); assertThat(mail.getMessage().isMimeType("text/plain")).isTrue(); message = new MimeMessage(Session.getDefaultInstance(new Properties())); message.setSubject("prova"); mp = new MimeMultipart(); bp = new MimeBodyPart(); message2 = new MimeMessage(Session.getDefaultInstance(new Properties())); bp.setContent(message2, "message/rfc822"); mp.addBodyPart(bp); bp = new MimeBodyPart(); bp.setContent("<p>Questa è una prova<br />di html</p>", "text/html"); mp.addBodyPart(bp); message.setContent(mp); message.saveChanges(); mail = FakeMail.builder() .name("mail") .mimeMessage(message) .build(); mailet.service(mail); assertThat(mail.getMessage().getSubject()).isEqualTo("prova"); assertThat(mail.getMessage() .getContent()).isEqualTo("Questa è una prova\ndi html\n"); assertThat(mail.getMessage().isMimeType("text/plain")).isTrue(); }
@Override public void service(Mail mail) throws MailetException { try { Object content = mail.getMessage().getContent(); if (content instanceof Multipart) { Multipart mp = (Multipart) content; int found = -1; int htmlPart = -1; int stringPart = -1; int[] res = process(mail, (Multipart) content, found, htmlPart, stringPart); found = res[0]; htmlPart = res[1]; stringPart = res[2]; if (found < 0 && htmlPart != -1) { setContentFromPart(mail.getMessage(), mp.getBodyPart(htmlPart), html2Text((String) mp.getBodyPart(htmlPart).getContent()), true); found = 1; } if (found < 0 && stringPart != -1) { setContentFromPart(mail.getMessage(), mp.getBodyPart(htmlPart), null, false); found = 1; } if (found < 0 && optionsNotextProcessor != null) { mail.setState(optionsNotextProcessor); } } else if (!(content instanceof String) && optionsNotextProcessor != null) { mail.setState(optionsNotextProcessor); } else if (mail.getMessage().isMimeType("text/html")) { setContentFromPart(mail.getMessage(), mail.getMessage(), html2Text((String) mail.getMessage().getContent()), true); } } catch (IOException | MessagingException e) { throw new MailetException("Failed fetching text part", e); } }
OnlyText extends GenericMailet { @Override public void service(Mail mail) throws MailetException { try { Object content = mail.getMessage().getContent(); if (content instanceof Multipart) { Multipart mp = (Multipart) content; int found = -1; int htmlPart = -1; int stringPart = -1; int[] res = process(mail, (Multipart) content, found, htmlPart, stringPart); found = res[0]; htmlPart = res[1]; stringPart = res[2]; if (found < 0 && htmlPart != -1) { setContentFromPart(mail.getMessage(), mp.getBodyPart(htmlPart), html2Text((String) mp.getBodyPart(htmlPart).getContent()), true); found = 1; } if (found < 0 && stringPart != -1) { setContentFromPart(mail.getMessage(), mp.getBodyPart(htmlPart), null, false); found = 1; } if (found < 0 && optionsNotextProcessor != null) { mail.setState(optionsNotextProcessor); } } else if (!(content instanceof String) && optionsNotextProcessor != null) { mail.setState(optionsNotextProcessor); } else if (mail.getMessage().isMimeType("text/html")) { setContentFromPart(mail.getMessage(), mail.getMessage(), html2Text((String) mail.getMessage().getContent()), true); } } catch (IOException | MessagingException e) { throw new MailetException("Failed fetching text part", e); } } }
OnlyText extends GenericMailet { @Override public void service(Mail mail) throws MailetException { try { Object content = mail.getMessage().getContent(); if (content instanceof Multipart) { Multipart mp = (Multipart) content; int found = -1; int htmlPart = -1; int stringPart = -1; int[] res = process(mail, (Multipart) content, found, htmlPart, stringPart); found = res[0]; htmlPart = res[1]; stringPart = res[2]; if (found < 0 && htmlPart != -1) { setContentFromPart(mail.getMessage(), mp.getBodyPart(htmlPart), html2Text((String) mp.getBodyPart(htmlPart).getContent()), true); found = 1; } if (found < 0 && stringPart != -1) { setContentFromPart(mail.getMessage(), mp.getBodyPart(htmlPart), null, false); found = 1; } if (found < 0 && optionsNotextProcessor != null) { mail.setState(optionsNotextProcessor); } } else if (!(content instanceof String) && optionsNotextProcessor != null) { mail.setState(optionsNotextProcessor); } else if (mail.getMessage().isMimeType("text/html")) { setContentFromPart(mail.getMessage(), mail.getMessage(), html2Text((String) mail.getMessage().getContent()), true); } } catch (IOException | MessagingException e) { throw new MailetException("Failed fetching text part", e); } }  }
OnlyText extends GenericMailet { @Override public void service(Mail mail) throws MailetException { try { Object content = mail.getMessage().getContent(); if (content instanceof Multipart) { Multipart mp = (Multipart) content; int found = -1; int htmlPart = -1; int stringPart = -1; int[] res = process(mail, (Multipart) content, found, htmlPart, stringPart); found = res[0]; htmlPart = res[1]; stringPart = res[2]; if (found < 0 && htmlPart != -1) { setContentFromPart(mail.getMessage(), mp.getBodyPart(htmlPart), html2Text((String) mp.getBodyPart(htmlPart).getContent()), true); found = 1; } if (found < 0 && stringPart != -1) { setContentFromPart(mail.getMessage(), mp.getBodyPart(htmlPart), null, false); found = 1; } if (found < 0 && optionsNotextProcessor != null) { mail.setState(optionsNotextProcessor); } } else if (!(content instanceof String) && optionsNotextProcessor != null) { mail.setState(optionsNotextProcessor); } else if (mail.getMessage().isMimeType("text/html")) { setContentFromPart(mail.getMessage(), mail.getMessage(), html2Text((String) mail.getMessage().getContent()), true); } } catch (IOException | MessagingException e) { throw new MailetException("Failed fetching text part", e); } }  @Override String getMailetInfo(); @Override void init(); @Override void service(Mail mail); String html2Text(String html); String decodeEntities(String data); }
OnlyText extends GenericMailet { @Override public void service(Mail mail) throws MailetException { try { Object content = mail.getMessage().getContent(); if (content instanceof Multipart) { Multipart mp = (Multipart) content; int found = -1; int htmlPart = -1; int stringPart = -1; int[] res = process(mail, (Multipart) content, found, htmlPart, stringPart); found = res[0]; htmlPart = res[1]; stringPart = res[2]; if (found < 0 && htmlPart != -1) { setContentFromPart(mail.getMessage(), mp.getBodyPart(htmlPart), html2Text((String) mp.getBodyPart(htmlPart).getContent()), true); found = 1; } if (found < 0 && stringPart != -1) { setContentFromPart(mail.getMessage(), mp.getBodyPart(htmlPart), null, false); found = 1; } if (found < 0 && optionsNotextProcessor != null) { mail.setState(optionsNotextProcessor); } } else if (!(content instanceof String) && optionsNotextProcessor != null) { mail.setState(optionsNotextProcessor); } else if (mail.getMessage().isMimeType("text/html")) { setContentFromPart(mail.getMessage(), mail.getMessage(), html2Text((String) mail.getMessage().getContent()), true); } } catch (IOException | MessagingException e) { throw new MailetException("Failed fetching text part", e); } }  @Override String getMailetInfo(); @Override void init(); @Override void service(Mail mail); String html2Text(String html); String decodeEntities(String data);  }