/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hu.nir.nmail.jsp.tld;

import java.io.IOException;
import javax.mail.Address;
import javax.mail.internet.MimeUtility;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;

/**
 *
 * @author attila
 */
public class DetectFrom extends SimpleTagSupport {
    private Address[] from;
    
    @Override
    public void doTag() throws IOException {
        JspWriter writer = getJspContext().getOut();
        
        if (from == null) {
            writer.print("");
            return;
        }
        
        StringBuffer fromLine = new StringBuffer("");
        int i = 0;
        for (Address address : from) {
            
            if (i == 0) {
                fromLine.append(address.toString());
            } else {
                fromLine.append(" ,"+address.toString());
            }
            i++;
        }
        
        String fromLineStr = fromLine.toString();
        fromLineStr = MimeUtility.decodeText(fromLineStr);
        
        writer.print(fromLineStr);
    }

    public Address[] getFrom() {
        return from;
    }

    public void setFrom(Address[] from) {
        this.from = from;
    }
    
}
