private void reprocess(MailRepository repository, Mail mail) { try { targetProcessor.ifPresent(mail::setState); mailQueue.enQueue(mail); repository.remove(mail); } catch (Exception e) { throw new RuntimeException("Error encountered while reprocessing mail " + mail.getName(), e); } } }
MailQueueItem queueItem = queue.deQueue(); Mail mail = queueItem.getMail(); if (logger.isDebugEnabled()) {
@Override public void sendMail(Mail mail, String state, long delay, TimeUnit unit) throws MessagingException { mail.setAttribute(Mail.SENT_BY_MAILET, "true"); mail.setState(state); rootMailQueue.enQueue(mail, delay, unit); }
queueItem = queue.deQueue(); workerService.execute(() -> { TimeMetric timeMetric = metricFactory.timer(SPOOL_PROCESSING);
@Override public void sendMail(Mail mail, String state) throws MessagingException { mail.setAttribute(Mail.SENT_BY_MAILET, "true"); mail.setState(state); rootMailQueue.enQueue(mail); }
@Test public void remoteDeliveryShouldStart() throws Exception { when(mailQueue.deQueue()).thenAnswer(invocation -> { countDownLatch.countDown(); Thread.sleep(TimeUnit.SECONDS.toMillis(20)); return null; }); remoteDelivery.init(FakeMailetConfig.builder() .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") .setProperty(RemoteDeliveryConfiguration.OUTGOING, QUEUE_NAME) .setProperty(RemoteDeliveryConfiguration.HELO_NAME, "Hello_name") .build()); countDownLatch.await(); verify(mailQueue).deQueue(); }
private void serviceSingleServer(Mail mail, String originalName, Map.Entry<Domain, Collection<MailAddress>> entry) { if (configuration.isDebug()) { LOGGER.debug("Sending mail to {} on host {}", entry.getValue(), entry.getKey()); } mail.setRecipients(entry.getValue()); mail.setName(originalName + NAME_JUNCTION + entry.getKey().name()); try { queue.enQueue(mail); } catch (MailQueueException e) { LOGGER.error("Unable to queue mail {} for recipients {}", mail.getName(), mail.getRecipients(), e); } }
MailQueue.MailQueueItem queueItem = queue.deQueue(); timeMetric = metricFactory.timer(REMOTE_DELIVERY_TRIAL); Mail mail = queueItem.getMail();
private void serviceWithGateway(Mail mail) { if (configuration.isDebug()) { LOGGER.debug("Sending mail to {} via {}", mail.getRecipients(), configuration.getGatewayServer()); } try { queue.enQueue(mail); } catch (MailQueueException e) { LOGGER.error("Unable to queue mail {} for recipients {}", mail.getName(), mail.getRecipients(), e); } }
@Test public void sendShouldPositionJMAPRelatedMetadata() throws Exception { FakeMail mail = FakeMail.builder() .name(NAME) .build(); mailSpool.send(mail, new MailMetadata(MESSAGE_ID, USERNAME)); MailQueueItem actual = myQueue.deQueue(); assertThat(actual.getMail().getAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE)) .isEqualTo(USERNAME); assertThat(actual.getMail().getAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE)) .isEqualTo(MESSAGE_ID.serialize()); }
queue.enQueue(mail); Collection<MailAddress> theRecipients = mail.getRecipients(); String recipientString = "";
@Test public void sendShouldEnQueueTheMail() throws Exception { FakeMail mail = FakeMail.builder() .name(NAME) .build(); mailSpool.send(mail, new MailMetadata(MESSAGE_ID, USERNAME)); MailQueueItem actual = myQueue.deQueue(); assertThat(actual.getMail().getName()).isEqualTo(NAME); }
private void reAttemptDelivery(Mail mail, int retries) throws MailQueue.MailQueueException { LOGGER.debug("Storing message {} into outgoing after {} retries", mail.getName(), retries); DeliveryRetriesHelper.incrementRetries(mail); mail.setLastUpdated(dateSupplier.get()); // Something happened that will delay delivery. Store it back in the retry repository. long delay = getNextDelay(DeliveryRetriesHelper.retrieveRetries(mail)); if (configuration.isUsePriority()) { // Use lowest priority for retries. See JAMES-1311 mail.setAttribute(MailPrioritySupport.MAIL_PRIORITY, MailPrioritySupport.LOW_PRIORITY); } queue.enQueue(mail, delay, TimeUnit.MILLISECONDS); }
public void send(Mail mail, MailMetadata metadata) throws MailQueueException { mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, metadata.getMessageId().serialize()); mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, metadata.getUsername()); queue.enQueue(mail); } }
@Test public void bounceShouldEnqueueEmailWithRootState() throws Exception { MailImpl mail = new MailImpl(); mail.setSender(mailAddress); mail.setRecipients(ImmutableList.of(mailAddress)); mail.setMessage(MimeMessageUtil.defaultMimeMessage()); testee.bounce(mail, "message"); ArgumentCaptor<Mail> mailArgumentCaptor = ArgumentCaptor.forClass(Mail.class); verify(spoolMailQueue).enQueue(mailArgumentCaptor.capture()); verifyNoMoreInteractions(spoolMailQueue); assertThat(mailArgumentCaptor.getValue().getState()).isEqualTo(Mail.DEFAULT); }
@Test public void sendMailShouldEnqueueEmailWithRootState() throws Exception { MailImpl mail = new MailImpl(); mail.setSender(mailAddress); mail.setRecipients(ImmutableList.of(mailAddress)); mail.setMessage(MimeMessageUtil.defaultMimeMessage()); testee.sendMail(mail); ArgumentCaptor<Mail> mailArgumentCaptor = ArgumentCaptor.forClass(Mail.class); verify(spoolMailQueue).enQueue(mailArgumentCaptor.capture()); verifyNoMoreInteractions(spoolMailQueue); assertThat(mailArgumentCaptor.getValue().getState()).isEqualTo(Mail.DEFAULT); }
@Test public void sendMailShouldEnqueueEmailWithOtherStateWhenSpecified() throws Exception { MailImpl mail = new MailImpl(); mail.setSender(mailAddress); mail.setRecipients(ImmutableList.of(mailAddress)); mail.setMessage(MimeMessageUtil.defaultMimeMessage()); String other = "other"; testee.sendMail(mail, other); ArgumentCaptor<Mail> mailArgumentCaptor = ArgumentCaptor.forClass(Mail.class); verify(spoolMailQueue).enQueue(mailArgumentCaptor.capture()); verifyNoMoreInteractions(spoolMailQueue); assertThat(mailArgumentCaptor.getValue().getState()).isEqualTo(other); }
@Test public void sendMailForMessageShouldEnqueueEmailWithRootState() throws Exception { MimeMessage message = MimeMessageBuilder.mimeMessageBuilder() .addFrom(mailAddress.asString()) .addToRecipient(mailAddress.asString()) .setText("Simple text") .build(); testee.sendMail(message); ArgumentCaptor<Mail> mailArgumentCaptor = ArgumentCaptor.forClass(Mail.class); verify(spoolMailQueue).enQueue(mailArgumentCaptor.capture()); verifyNoMoreInteractions(spoolMailQueue); assertThat(mailArgumentCaptor.getValue().getState()).isEqualTo(Mail.DEFAULT); }
@Test public void sendMailShouldEnqueueEmailWithRootStateAndDelayWhenSpecified() throws Exception { MailImpl mail = new MailImpl(); mail.setSender(mailAddress); mail.setRecipients(ImmutableList.of(mailAddress)); mail.setMessage(MimeMessageUtil.defaultMimeMessage()); testee.sendMail(mail, 5, TimeUnit.MINUTES); ArgumentCaptor<Mail> mailArgumentCaptor = ArgumentCaptor.forClass(Mail.class); ArgumentCaptor<Long> delayArgumentCaptor = ArgumentCaptor.forClass(Long.class); ArgumentCaptor<TimeUnit> timeUnitArgumentCaptor = ArgumentCaptor.forClass(TimeUnit.class); verify(spoolMailQueue).enQueue(mailArgumentCaptor.capture(), delayArgumentCaptor.capture(), timeUnitArgumentCaptor.capture()); verifyNoMoreInteractions(spoolMailQueue); softly.assertThat(mailArgumentCaptor.getValue().getState()).isEqualTo(Mail.DEFAULT); softly.assertThat(delayArgumentCaptor.getValue()).isEqualTo(5L); softly.assertThat(timeUnitArgumentCaptor.getValue()).isEqualTo(TimeUnit.MINUTES); }
@Test public void sendMailShouldEnqueueEmailWithOtherStateAndDelayWhenSpecified() throws Exception { MailImpl mail = new MailImpl(); mail.setSender(mailAddress); mail.setRecipients(ImmutableList.of(mailAddress)); mail.setMessage(MimeMessageUtil.defaultMimeMessage()); String other = "other"; testee.sendMail(mail, other, 5, TimeUnit.MINUTES); ArgumentCaptor<Mail> mailArgumentCaptor = ArgumentCaptor.forClass(Mail.class); ArgumentCaptor<Long> delayArgumentCaptor = ArgumentCaptor.forClass(Long.class); ArgumentCaptor<TimeUnit> timeUnitArgumentCaptor = ArgumentCaptor.forClass(TimeUnit.class); verify(spoolMailQueue).enQueue(mailArgumentCaptor.capture(), delayArgumentCaptor.capture(), timeUnitArgumentCaptor.capture()); verifyNoMoreInteractions(spoolMailQueue); softly.assertThat(mailArgumentCaptor.getValue().getState()).isEqualTo(other); softly.assertThat(delayArgumentCaptor.getValue()).isEqualTo(5L); softly.assertThat(timeUnitArgumentCaptor.getValue()).isEqualTo(TimeUnit.MINUTES); }