Skip to content

Commit

Permalink
MAILET-130 SetMailAttribute upgrade to new style
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaechler committed Sep 20, 2016
1 parent 9b1dd0b commit 12eb738
Showing 1 changed file with 13 additions and 32 deletions.
Expand Up @@ -21,17 +21,17 @@

package org.apache.james.transport.mailets;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import javax.mail.MessagingException;

import org.apache.mailet.Mail;
import org.apache.mailet.MailetException;
import org.apache.mailet.base.GenericMailet;

import com.google.common.collect.ImmutableMap;

/**
* <p>This mailet sets attributes on the Mail.</p>
*
Expand All @@ -43,52 +43,33 @@
* &lt;/mailet&gt;
* </code></pre>
*
* @version CVS $Revision$ $Date$
* @since 2.2.0
*/
public class SetMailAttribute extends GenericMailet {

private final HashMap<String, String> attributesToSet = new HashMap<String, String>(2);

private Set<Map.Entry<String, String>> entries;
private ImmutableMap<String, String> entries;

/**
* Return a string describing this mailet.
*
* @return a string describing this mailet
*/
@Override
public String getMailetInfo() {
return "Set Mail Attribute Mailet";
}

/**
* Initialize the mailet
*
* @throws MailetException if the processor parameter is missing
*/
public void init() throws MailetException
{
@Override
public void init() throws MailetException {
ImmutableMap.Builder<String, String> attributes = ImmutableMap.builder();
Iterator<String> iter = getInitParameterNames();
while (iter.hasNext()) {
String name = iter.next();
String value = getInitParameter (name);
attributesToSet.put (name,value);
String value = getInitParameter(name);
attributes.put(name, value);
}
entries = attributesToSet.entrySet();
entries = attributes.build();
}

/**
* Sets the configured attributes
*
* @param mail the mail to process
*
* @throws MessagingException in all cases
*/
@Override
public void service(Mail mail) throws MessagingException {
if (entries != null) {
for (Map.Entry<String, String> entry : entries) {
mail.setAttribute(entry.getKey(), entry.getValue());
}
for (Map.Entry<String, String> entry : entries.entrySet()) {
mail.setAttribute(entry.getKey(), entry.getValue());
}
}

Expand Down

0 comments on commit 12eb738

Please sign in to comment.