Skip to content

Commit

Permalink
MAILET-115 getRecipients should return a list
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Duprat authored and chibenwa committed Jan 11, 2017
1 parent d6b0899 commit d010021
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 26 deletions.
Expand Up @@ -19,7 +19,6 @@


package org.apache.james.transport.mailets; package org.apache.james.transport.mailets;


import java.util.Collection;
import java.util.List; import java.util.List;


import javax.mail.MessagingException; import javax.mail.MessagingException;
Expand Down Expand Up @@ -138,7 +137,7 @@ protected String getMessage(Mail originalMail) throws MessagingException {
} }


@Override @Override
protected Collection<MailAddress> getRecipients() { protected List<MailAddress> getRecipients() {
return RECIPIENTS; return RECIPIENTS;
} }


Expand Down
Expand Up @@ -21,10 +21,8 @@


import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.regex.Pattern; import java.util.regex.Pattern;


import javax.mail.MessagingException; import javax.mail.MessagingException;
Expand All @@ -49,7 +47,6 @@
import org.apache.mailet.base.mail.MimeMultipartReport; import org.apache.mailet.base.mail.MimeMultipartReport;


import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;


/** /**
* <p> * <p>
Expand Down Expand Up @@ -94,7 +91,7 @@
public class DSNBounce extends AbstractRedirect { public class DSNBounce extends AbstractRedirect {


private static final String[] CONFIGURABLE_PARAMETERS = new String[]{ "debug", "passThrough", "messageString", "attachment", "sender", "prefix" }; private static final String[] CONFIGURABLE_PARAMETERS = new String[]{ "debug", "passThrough", "messageString", "attachment", "sender", "prefix" };
private static final Set<MailAddress> RECIPIENT_MAIL_ADDRESSES = ImmutableSet.of(SpecialAddress.REVERSE_PATH); private static final List<MailAddress> RECIPIENT_MAIL_ADDRESSES = ImmutableList.of(SpecialAddress.REVERSE_PATH);
private static final InternetAddress[] TO_INTERNET_ADDRESSES = new InternetAddress[] { SpecialAddress.REVERSE_PATH.toInternetAddress() }; private static final InternetAddress[] TO_INTERNET_ADDRESSES = new InternetAddress[] { SpecialAddress.REVERSE_PATH.toInternetAddress() };


private static final String LOCALHOST = "127.0.0.1"; private static final String LOCALHOST = "127.0.0.1";
Expand Down Expand Up @@ -132,7 +129,7 @@ protected String getMessage(Mail originalMail) throws MessagingException {
} }


@Override @Override
protected Collection<MailAddress> getRecipients() { protected List<MailAddress> getRecipients() {
return RECIPIENT_MAIL_ADDRESSES; return RECIPIENT_MAIL_ADDRESSES;
} }


Expand Down
Expand Up @@ -19,7 +19,6 @@


package org.apache.james.transport.mailets; package org.apache.james.transport.mailets;


import java.util.Collection;
import java.util.List; import java.util.List;


import javax.mail.MessagingException; import javax.mail.MessagingException;
Expand Down Expand Up @@ -111,7 +110,7 @@ protected String getMessage(Mail originalMail) throws MessagingException {
} }


@Override @Override
protected Collection<MailAddress> getRecipients() throws MessagingException { protected List<MailAddress> getRecipients() throws MessagingException {
ImmutableList.Builder<MailAddress> builder = ImmutableList.builder(); ImmutableList.Builder<MailAddress> builder = ImmutableList.builder();
for (InternetAddress address : extractAddresses(getForwardTo())) { for (InternetAddress address : extractAddresses(getForwardTo())) {
builder.add(toMailAddress(address)); builder.add(toMailAddress(address));
Expand Down
Expand Up @@ -19,7 +19,6 @@


package org.apache.james.transport.mailets; package org.apache.james.transport.mailets;


import java.util.Collection;
import java.util.List; import java.util.List;


import javax.mail.MessagingException; import javax.mail.MessagingException;
Expand All @@ -38,7 +37,6 @@


import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;


/** /**
* <p> * <p>
Expand Down Expand Up @@ -147,8 +145,8 @@ protected String getMessage(Mail originalMail) throws MessagingException {
} }


@Override @Override
protected Collection<MailAddress> getRecipients() { protected List<MailAddress> getRecipients() {
return ImmutableSet.of(getMailetContext().getPostmaster()); return ImmutableList.of(getMailetContext().getPostmaster());
} }


@Override @Override
Expand Down
Expand Up @@ -19,9 +19,7 @@


package org.apache.james.transport.mailets; package org.apache.james.transport.mailets;


import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Set;


import javax.mail.MessagingException; import javax.mail.MessagingException;
import javax.mail.internet.InternetAddress; import javax.mail.internet.InternetAddress;
Expand All @@ -39,7 +37,6 @@


import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;


/** /**
* <p> * <p>
Expand Down Expand Up @@ -116,7 +113,7 @@ public class NotifySender extends AbstractRedirect {


private static final String[] CONFIGURABLE_PARAMETERS = new String[]{ private static final String[] CONFIGURABLE_PARAMETERS = new String[]{
"debug", "passThrough", "fakeDomainCheck", "inline", "attachment", "message", "notice", "sender", "sendingAddress", "prefix", "attachError", "to" }; "debug", "passThrough", "fakeDomainCheck", "inline", "attachment", "message", "notice", "sender", "sendingAddress", "prefix", "attachError", "to" };
private static final Set<MailAddress> RECIPIENT_MAIL_ADDRESSES = ImmutableSet.of(SpecialAddress.SENDER); private static final List<MailAddress> RECIPIENT_MAIL_ADDRESSES = ImmutableList.of(SpecialAddress.SENDER);
private static final List<String> ALLOWED_SPECIALS = ImmutableList.of("sender", "unaltered", "from"); private static final List<String> ALLOWED_SPECIALS = ImmutableList.of("sender", "unaltered", "from");


private Optional<String> to = Optional.absent(); private Optional<String> to = Optional.absent();
Expand Down Expand Up @@ -148,7 +145,7 @@ protected String getMessage(Mail originalMail) throws MessagingException {
} }


@Override @Override
protected Collection<MailAddress> getRecipients() { protected List<MailAddress> getRecipients() {
return RECIPIENT_MAIL_ADDRESSES; return RECIPIENT_MAIL_ADDRESSES;
} }


Expand Down
Expand Up @@ -19,7 +19,6 @@


package org.apache.james.transport.mailets; package org.apache.james.transport.mailets;


import java.util.Collection;
import java.util.List; import java.util.List;


import javax.mail.MessagingException; import javax.mail.MessagingException;
Expand Down Expand Up @@ -318,7 +317,7 @@ protected String getMessage(Mail originalMail) throws MessagingException {
} }


@Override @Override
protected Collection<MailAddress> getRecipients() throws MessagingException { protected List<MailAddress> getRecipients() throws MessagingException {
String recipientsOrTo = getRecipientsOrTo(); String recipientsOrTo = getRecipientsOrTo();
if (recipientsOrTo == null) { if (recipientsOrTo == null) {
return null; return null;
Expand Down
Expand Up @@ -187,7 +187,7 @@ public void setDNSService(DNSService dns) {
* <code>SpecialAddress.RECIPIENTS</code> or <code>null</code> if * <code>SpecialAddress.RECIPIENTS</code> or <code>null</code> if
* missing * missing
*/ */
protected Collection<MailAddress> getRecipients() throws MessagingException { protected List<MailAddress> getRecipients() throws MessagingException {
ImmutableList.Builder<MailAddress> builder = ImmutableList.builder(); ImmutableList.Builder<MailAddress> builder = ImmutableList.builder();
List<MailAddress> mailAddresses = AddressExtractor.withContext(getMailetContext()) List<MailAddress> mailAddresses = AddressExtractor.withContext(getMailetContext())
.allowedSpecials(ImmutableList.of("postmaster", "sender", "from", "replyTo", "reversePath", "unaltered", "recipients", "to", "null")) .allowedSpecials(ImmutableList.of("postmaster", "sender", "from", "replyTo", "reversePath", "unaltered", "recipients", "to", "null"))
Expand All @@ -204,8 +204,8 @@ protected Collection<MailAddress> getRecipients() throws MessagingException {
* *
* @return {@link #replaceMailAddresses} on {@link #getRecipients()}, * @return {@link #replaceMailAddresses} on {@link #getRecipients()},
*/ */
protected Collection<MailAddress> getRecipients(Mail originalMail) throws MessagingException { protected List<MailAddress> getRecipients(Mail originalMail) throws MessagingException {
Collection<MailAddress> recipients = getRecipients(); List<MailAddress> recipients = getRecipients();
if (recipients != null) { if (recipients != null) {
if (containsOnlyUnalteredOrRecipients(recipients)) { if (containsOnlyUnalteredOrRecipients(recipients)) {
return null; return null;
Expand Down
Expand Up @@ -18,7 +18,7 @@
****************************************************************/ ****************************************************************/
package org.apache.james.transport.util; package org.apache.james.transport.util;


import java.util.Collection; import java.util.List;
import java.util.Set; import java.util.Set;


import javax.mail.MessagingException; import javax.mail.MessagingException;
Expand All @@ -31,6 +31,7 @@
import org.apache.mailet.MailAddress; import org.apache.mailet.MailAddress;
import org.apache.mailet.base.GenericMailet; import org.apache.mailet.base.GenericMailet;


import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;


public class SpecialAddressesUtils { public class SpecialAddressesUtils {
Expand Down Expand Up @@ -64,8 +65,8 @@ public SpecialAddressesUtils(GenericMailet genericMailet) {
* <code>SpecialAddress.UNALTERED</code> are ignored.<br> * <code>SpecialAddress.UNALTERED</code> are ignored.<br>
* Any other address is not replaced. * Any other address is not replaced.
*/ */
public Collection<MailAddress> replaceSpecialAddresses(Mail mailWithReplacementAddresses, Collection<MailAddress> mailAddresses) { public List<MailAddress> replaceSpecialAddresses(Mail mailWithReplacementAddresses, List<MailAddress> mailAddresses) {
ImmutableSet.Builder<MailAddress> builder = ImmutableSet.builder(); ImmutableList.Builder<MailAddress> builder = ImmutableList.builder();
for (MailAddress mailAddress : mailAddresses) { for (MailAddress mailAddress : mailAddresses) {
if (!SpecialAddress.isSpecialAddress(mailAddress)) { if (!SpecialAddress.isSpecialAddress(mailAddress)) {
builder.add(mailAddress); builder.add(mailAddress);
Expand Down

0 comments on commit d010021

Please sign in to comment.