@Test public void multipleRecipientShouldGenerateNotifications() throws MessagingException { String secondUserName = "default@any.com"; MailAddress secondRecipient = new MailAddress(secondUserName); AccountId secondAccountId = AccountId.fromString(secondUserName); FakeMail mail = FakeMail.builder() .name("name") .fileName("spamMail.eml") .recipients(originalRecipient, secondRecipient) .sender(originalSender) .build(); when(vacationRepository.retrieveVacation(AccountId.fromString(USERNAME))) .thenReturn(Mono.just(VACATION)); when(vacationRepository.retrieveVacation(secondAccountId)) .thenReturn(Mono.just(VACATION)); when(zonedDateTimeProvider.get()).thenReturn(DATE_TIME_2017); when(automaticallySentMailDetector.isAutomaticallySent(mail)).thenReturn(false); when(notificationRegistry.isRegistered(ACCOUNT_ID, RecipientId.fromMailAddress(originalSender))) .thenReturn(Mono.just(false)); when(notificationRegistry.isRegistered(secondAccountId, RecipientId.fromMailAddress(originalSender))) .thenReturn(Mono.just(false)); when(notificationRegistry.register(any(), any(), any())) .thenReturn(Mono.empty()); testee.service(mail); verify(mailetContext).sendMail(eq(originalRecipient), eq(ImmutableList.of(originalSender)), any()); verify(mailetContext).sendMail(eq(secondRecipient), eq(ImmutableList.of(originalSender)), any()); verifyNoMoreInteractions(mailetContext); }
@Override public void service(Mail mail) { try { if (!mail.hasSender()) { return; } if (! automaticallySentMailDetector.isAutomaticallySent(mail)) { ZonedDateTime processingDate = zonedDateTimeProvider.get(); mail.getRecipients() .forEach(mailAddress -> manageVacation(mailAddress, mail, processingDate)); } } catch (Throwable e) { LOGGER.warn("Can not process vacation for one or more recipients in {}", mail.getRecipients(), e); } }
VacationMailet extends GenericMailet { @Override public void service(Mail mail) { try { if (!mail.hasSender()) { return; } if (! automaticallySentMailDetector.isAutomaticallySent(mail)) { ZonedDateTime processingDate = zonedDateTimeProvider.get(); mail.getRecipients() .forEach(mailAddress -> manageVacation(mailAddress, mail, processingDate)); } } catch (Throwable e) { LOGGER.warn("Can not process vacation for one or more recipients in {}", mail.getRecipients(), e); } } }
VacationMailet extends GenericMailet { @Override public void service(Mail mail) { try { if (!mail.hasSender()) { return; } if (! automaticallySentMailDetector.isAutomaticallySent(mail)) { ZonedDateTime processingDate = zonedDateTimeProvider.get(); mail.getRecipients() .forEach(mailAddress -> manageVacation(mailAddress, mail, processingDate)); } } catch (Throwable e) { LOGGER.warn("Can not process vacation for one or more recipients in {}", mail.getRecipients(), e); } } @Inject  VacationMailet(VacationRepository vacationRepository, ZonedDateTimeProvider zonedDateTimeProvider,
                          AutomaticallySentMailDetector automaticallySentMailDetector, NotificationRegistry notificationRegistry,
                          MimeMessageBodyGenerator mimeMessageBodyGenerator); }
VacationMailet extends GenericMailet { @Override public void service(Mail mail) { try { if (!mail.hasSender()) { return; } if (! automaticallySentMailDetector.isAutomaticallySent(mail)) { ZonedDateTime processingDate = zonedDateTimeProvider.get(); mail.getRecipients() .forEach(mailAddress -> manageVacation(mailAddress, mail, processingDate)); } } catch (Throwable e) { LOGGER.warn("Can not process vacation for one or more recipients in {}", mail.getRecipients(), e); } } @Inject  VacationMailet(VacationRepository vacationRepository, ZonedDateTimeProvider zonedDateTimeProvider,
                          AutomaticallySentMailDetector automaticallySentMailDetector, NotificationRegistry notificationRegistry,
                          MimeMessageBodyGenerator mimeMessageBodyGenerator); @Override void service(Mail mail); }
VacationMailet extends GenericMailet { @Override public void service(Mail mail) { try { if (!mail.hasSender()) { return; } if (! automaticallySentMailDetector.isAutomaticallySent(mail)) { ZonedDateTime processingDate = zonedDateTimeProvider.get(); mail.getRecipients() .forEach(mailAddress -> manageVacation(mailAddress, mail, processingDate)); } } catch (Throwable e) { LOGGER.warn("Can not process vacation for one or more recipients in {}", mail.getRecipients(), e); } } @Inject  VacationMailet(VacationRepository vacationRepository, ZonedDateTimeProvider zonedDateTimeProvider,
                          AutomaticallySentMailDetector automaticallySentMailDetector, NotificationRegistry notificationRegistry,
                          MimeMessageBodyGenerator mimeMessageBodyGenerator); @Override void service(Mail mail);  }