@Test public void bounceShouldWorkWhenProcessorSpecifiedAndNoExceptionMessage() throws Exception { RemoteDeliveryConfiguration configuration = new RemoteDeliveryConfiguration( FakeMailetConfig.builder() .setProperty(RemoteDeliveryConfiguration.HELO_NAME, HELLO_NAME) .setProperty(RemoteDeliveryConfiguration.BOUNCE_PROCESSOR, BOUNCE_PROCESSOR) .build(), mock(DomainList.class)); Bouncer testee = new Bouncer(configuration, mailetContext); Mail mail = FakeMail.builder().name("name").state(Mail.DEFAULT) .sender(MailAddressFixture.ANY_AT_JAMES) .build(); testee.bounce(mail, new MessagingException()); FakeMailContext.SentMail expected = FakeMailContext.sentMailBuilder() .sender(MailAddressFixture.ANY_AT_JAMES) .attribute(new Attribute(DELIVERY_ERROR, AttributeValue.of("null"))) .state(BOUNCE_PROCESSOR) .fromMailet() .build(); assertThat(mailetContext.getSentMails()).containsOnly(expected); assertThat(mailetContext.getBouncedMails()).isEmpty(); }
public void bounce(Mail mail, Exception ex) { if (!mail.hasSender()) { LOGGER.debug("Null Sender: no bounce will be generated for {}", mail.getName()); } else { if (configuration.getBounceProcessor() != null) { computeErrorCode(ex).ifPresent(mail::setAttribute); mail.setAttribute(new Attribute(DELIVERY_ERROR, AttributeValue.of(getErrorMsg(ex)))); try { mailetContext.sendMail(mail, configuration.getBounceProcessor()); } catch (MessagingException e) { LOGGER.warn("Exception re-inserting failed mail: ", e); } } else { bounceWithMailetContext(mail, ex); } } }
Bouncer { public void bounce(Mail mail, Exception ex) { if (!mail.hasSender()) { LOGGER.debug("Null Sender: no bounce will be generated for {}", mail.getName()); } else { if (configuration.getBounceProcessor() != null) { computeErrorCode(ex).ifPresent(mail::setAttribute); mail.setAttribute(new Attribute(DELIVERY_ERROR, AttributeValue.of(getErrorMsg(ex)))); try { mailetContext.sendMail(mail, configuration.getBounceProcessor()); } catch (MessagingException e) { LOGGER.warn("Exception re-inserting failed mail: ", e); } } else { bounceWithMailetContext(mail, ex); } } } }
Bouncer { public void bounce(Mail mail, Exception ex) { if (!mail.hasSender()) { LOGGER.debug("Null Sender: no bounce will be generated for {}", mail.getName()); } else { if (configuration.getBounceProcessor() != null) { computeErrorCode(ex).ifPresent(mail::setAttribute); mail.setAttribute(new Attribute(DELIVERY_ERROR, AttributeValue.of(getErrorMsg(ex)))); try { mailetContext.sendMail(mail, configuration.getBounceProcessor()); } catch (MessagingException e) { LOGGER.warn("Exception re-inserting failed mail: ", e); } } else { bounceWithMailetContext(mail, ex); } } } Bouncer(RemoteDeliveryConfiguration configuration, MailetContext mailetContext); }
Bouncer { public void bounce(Mail mail, Exception ex) { if (!mail.hasSender()) { LOGGER.debug("Null Sender: no bounce will be generated for {}", mail.getName()); } else { if (configuration.getBounceProcessor() != null) { computeErrorCode(ex).ifPresent(mail::setAttribute); mail.setAttribute(new Attribute(DELIVERY_ERROR, AttributeValue.of(getErrorMsg(ex)))); try { mailetContext.sendMail(mail, configuration.getBounceProcessor()); } catch (MessagingException e) { LOGGER.warn("Exception re-inserting failed mail: ", e); } } else { bounceWithMailetContext(mail, ex); } } } Bouncer(RemoteDeliveryConfiguration configuration, MailetContext mailetContext); void bounce(Mail mail, Exception ex); String explanationText(Mail mail, Exception ex); String getErrorMsg(Exception ex); String getNestedExceptionMessage(MessagingException me); }
Bouncer { public void bounce(Mail mail, Exception ex) { if (!mail.hasSender()) { LOGGER.debug("Null Sender: no bounce will be generated for {}", mail.getName()); } else { if (configuration.getBounceProcessor() != null) { computeErrorCode(ex).ifPresent(mail::setAttribute); mail.setAttribute(new Attribute(DELIVERY_ERROR, AttributeValue.of(getErrorMsg(ex)))); try { mailetContext.sendMail(mail, configuration.getBounceProcessor()); } catch (MessagingException e) { LOGGER.warn("Exception re-inserting failed mail: ", e); } } else { bounceWithMailetContext(mail, ex); } } } Bouncer(RemoteDeliveryConfiguration configuration, MailetContext mailetContext); void bounce(Mail mail, Exception ex); String explanationText(Mail mail, Exception ex); String getErrorMsg(Exception ex); String getNestedExceptionMessage(MessagingException me); static final AttributeName DELIVERY_ERROR; static final AttributeName DELIVERY_ERROR_CODE; static final AttributeName IS_DELIVERY_PERMANENT_ERROR; }