private List<MailAddress> allOrSender(Mail mail, InternetAddress[] addresses) throws AddressException { if (addresses != null) { return MailAddressUtils.from(addresses); } else { return mail.getMaybeSender().asList(); } }
private List<MailAddress> getSenderAsList(Mail originalMail) { MaybeSender reversePath = originalMail.getMaybeSender(); if (getInitParameters().isDebug()) { LOGGER.debug("Processing a bounce request for a message with a reverse path. The bounce will be sent to {}", reversePath.asString()); } return reversePath.asList(); }
@Test void asListShouldReturnEmptyWhenNullSender() { assertThat(MaybeSender.nullSender().asList()) .isEmpty(); }
@Test void asListShouldReturnEmptyWhenNullSender() { assertThat(MaybeSender.nullSender().asList()) .isEmpty(); }
@Test void asListShouldReturnWrappedValue() { assertThat(MaybeSender.of(mailAddress).asList()) .contains(mailAddress); }
/** * Generates a bounce mail that is a bounce of the original message. * * @param bounceText the text to be prepended to the message to describe the bounce * condition * @return the bounce mail * @throws MessagingException if the bounce mail could not be created */ private MailImpl rawBounce(Mail mail, String bounceText) throws MessagingException { Preconditions.checkArgument(mail.hasSender(), "Mail should have a sender"); // This sends a message to the james component that is a bounce of the sent message MimeMessage original = mail.getMessage(); MimeMessage reply = (MimeMessage) original.reply(false); reply.setSubject("Re: " + original.getSubject()); reply.setSentDate(new Date()); Collection<MailAddress> recipients = mail.getMaybeSender().asList(); MailAddress sender = mail.getMaybeSender().get(); reply.setRecipient(Message.RecipientType.TO, new InternetAddress(mail.getMaybeSender().asString())); reply.setFrom(new InternetAddress(mail.getRecipients().iterator().next().toString())); reply.setText(bounceText); reply.setHeader(RFC2822Headers.MESSAGE_ID, "replyTo-" + mail.getName()); return new MailImpl("replyTo-" + mail.getName(), sender, recipients, reply); }
@Test void asListShouldReturnWrappedValue() { assertThat(MaybeSender.of(mailAddress).asList()) .contains(mailAddress); }
@Override public void service(Mail mail) throws MessagingException { // Sanity checks if (!mail.hasSender()) { LOGGER.error("Sender is null"); return; } if (!getMailetContext().isLocalServer(mail.getMaybeSender().get().getDomain())) { LOGGER.error("Sender not local"); return; } // Update the Session for the current mail and execute SettableSession session = new SettableSession(); if (mail.getAttribute(Mail.SMTP_AUTH_USER_ATTRIBUTE_NAME) != null) { session.setState(Session.State.AUTHENTICATED); } else { session.setState(Session.State.UNAUTHENTICATED); } session.setUser(mail.getMaybeSender().get().asString()); getMailetContext().sendMail( mail.getRecipients().iterator().next(), mail.getMaybeSender().asList(), transcoder.execute(session, mail.getMessage())); mail.setState(Mail.GHOST); // And tidy up clearCaches(); }