View Javadoc

    1   package com.ozacc.mail.mailet;
    2
    3   import java.util.ArrayList;
    4   import java.util.Iterator;
    5   import java.util.List;
    6
    7   import com.ozacc.mail.fetch.FetchMailPro;
    8   import com.ozacc.mail.fetch.ReceivedMail;
    9
    10  /***
    11   *
    12   * @author Tomohiro Otsuka
    13   * @version $Id: MailetRunner.java,v 1.1.2.2 2005/01/18 07:22:20 otsuka Exp $
    14   */
    15  public class MailetRunner {
    16
    17  	private List mailetWrapperList;
    18
    19  	private FetchMailPro fetchMailPro;
    20
    21  	/***
    22  	 * コンストラクタ。
    23  	 */
    24  	public MailetRunner() {
    25  		mailetWrapperList = new ArrayList();
    26  	}
    27
    28  	public void run() {
    29  		fetchMailPro.connect();
    30  		try {
    31  			int count = fetchMailPro.getMailCount();
    32  			for (int i = 1; i <= count; i++) {
    33  				ReceivedMail mail = fetchMailPro.getMail(i);
    34  				processMail(mail);
    35  			}
    36  		} finally {
    37  			if (fetchMailPro.isConnected()) {
    38  				fetchMailPro.disconnect();
    39  			}
    40  		}
    41  	}
    42
    43  	/***
    44  	 * 指定された受信メールに対してMailetを適用します。
    45  	 *
    46  	 * @param mail MailetUnitに渡す受信メール
    47  	 */
    48  	private void processMail(ReceivedMail mail) {
    49  		for (Iterator itr = mailetWrapperList.iterator(); itr.hasNext();) {
    50  			MailetWrapper mailetUnit = (MailetWrapper)itr.next();
    51  			mailetUnit.execute(mail);
    52  		}
    53  	}
    54
    55  	/***
    56  	 * @param fetchMailPro The fetchMailPro to set.
    57  	 */
    58  	public void setFetchMailPro(FetchMailPro fetchMailPro) {
    59  		this.fetchMailPro = fetchMailPro;
    60  	}
    61
    62  	/***
    63  	 * @param mailetWrapperList
    64  	 */
    65  	public void setMailetWrapperList(List mailetWrapperList) {
    66  		this.mailetWrapperList = mailetWrapperList;
    67  	}
    68  }