@Test public void bounceShouldCustomizeSendFailedExceptionByDefault() throws Exception { RemoteDeliveryConfiguration configuration = new RemoteDeliveryConfiguration( DEFAULT_REMOTE_DELIVERY_CONFIG, mock(DomainList.class)); Bouncer testee = new Bouncer(configuration, mailetContext); Mail mail = FakeMail.builder().name("name").state(Mail.DEFAULT) .sender(MailAddressFixture.ANY_AT_JAMES) .build(); String exceptionMessage = "Error from remote server"; testee.bounce(mail, new MessagingException("Exception message", new SendFailedException(exceptionMessage))); FakeMailContext.BouncedMail expected = new FakeMailContext.BouncedMail(FakeMailContext.fromMail(mail), "Hi. This is the James mail server at " + HELLO_NAME + ".\n" + "I'm afraid I wasn't able to deliver your message to the following addresses.\n" + "This is a permanent error; I've given up. Sorry it didn't work out. Below\n" + "I include the list of recipients and the reason why I was unable to deliver\n" + "your message.\n" + "\n" + "Remote mail server told me: " + exceptionMessage + "\n\n", Optional.empty()); assertThat(mailetContext.getSentMails()).isEmpty(); assertThat(mailetContext.getBouncedMails()).containsOnly(expected); }
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; }