MAILET-122 Improve UserIs code quality
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/b936cf56 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/b936cf56 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/b936cf56 Branch: refs/heads/master Commit: b936cf56015f9b80782ddd482f26b98f09317063 Parents: cb0650f Author: Benoit Tellier <[email protected]> Authored: Fri Oct 7 11:02:56 2016 +0200 Committer: Benoit Tellier <[email protected]> Committed: Mon Oct 10 11:35:59 2016 +0200 ---------------------------------------------------------------------- .../apache/james/transport/matchers/UserIs.java | 34 ++++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/b936cf56/mailet/standard/src/main/java/org/apache/james/transport/matchers/UserIs.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/main/java/org/apache/james/transport/matchers/UserIs.java b/mailet/standard/src/main/java/org/apache/james/transport/matchers/UserIs.java index a8f7727..2dd81aa 100644 --- a/mailet/standard/src/main/java/org/apache/james/transport/matchers/UserIs.java +++ b/mailet/standard/src/main/java/org/apache/james/transport/matchers/UserIs.java @@ -17,39 +17,39 @@ * under the License. * ****************************************************************/ - - package org.apache.james.transport.matchers; import org.apache.mailet.base.GenericRecipientMatcher; import org.apache.mailet.MailAddress; +import java.util.Set; import java.util.StringTokenizer; import java.util.Vector; +import javax.mail.MessagingException; + +import com.google.common.base.Splitter; +import com.google.common.base.Strings; +import com.google.common.collect.ImmutableSet; + /** * Matches mail where the user is contained in a configurable list. * @version 1.0.0, 24/04/1999 */ public class UserIs extends GenericRecipientMatcher { - Vector<String> users = null; - - /* - * (non-Javadoc) - * @see org.apache.mailet.base.GenericMatcher#init() - */ - public void init() { - StringTokenizer st = new StringTokenizer(getCondition(), ", ", false); - users = new Vector<String>(); - while (st.hasMoreTokens()) { - users.add(st.nextToken()); + + Set<String> users; + + public void init() throws MessagingException { + if (Strings.isNullOrEmpty(getCondition())) { + throw new MessagingException("UserIs should have a condition composed of a list of local parts of mail addresses"); + } + users = ImmutableSet.copyOf(Splitter.on(", ").split(getCondition())); + if (users.size() < 1) { + throw new MessagingException("UserIs should have at least a user specified"); } } - /* - * (non-Javadoc) - * @see org.apache.mailet.base.GenericRecipientMatcher#matchRecipient(org.apache.mailet.MailAddress) - */ public boolean matchRecipient(MailAddress recipient) { return users.contains(recipient.getLocalPart()); } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
