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 * メールの受信とMailetの起動を行うクラス。 12 * 13 * @since 1.2 14 * @author Tomohiro Otsuka 15 * @version $Id: MailetRunner.java,v 1.1.2.5 2005/04/19 14:51:55 otsuka Exp $ 16 */ 17 public class MailetRunner { 18 19 private List mailetWrapperList; 20 21 private FetchMailPro fetchMailPro; 22 23 /*** 24 * コンストラクタ。 25 */ 26 public MailetRunner() { 27 mailetWrapperList = new ArrayList(); 28 } 29 30 /*** 31 * メール受信とMailetの起動を行います。 32 */ 33 public void run() { 34 fetchMailPro.connect(); 35 try { 36 int count = fetchMailPro.getMailCount(); 37 for (int i = 1; i <= count; i++) { 38 ReceivedMail mail = fetchMailPro.getMail(i); 39 processMail(mail); 40 } 41 } finally { 42 fetchMailPro.disconnect(); 43 } 44 } 45 46 /*** 47 * 指定された受信メールに対してMailetを適用します。 48 * 49 * @param mail MailetWrapperに渡す受信メール 50 */ 51 private void processMail(ReceivedMail mail) { 52 for (Iterator itr = mailetWrapperList.iterator(); itr.hasNext();) { 53 MailetWrapper mailetWrapper = (MailetWrapper)itr.next(); 54 mailetWrapper.execute(mail); 55 } 56 } 57 58 /*** 59 * メールの受信に使用するFetchMailProインターフェースの実装インスタンスをセットします。 60 * 61 * @param fetchMailPro FetchMailProインターフェースの実装インスタンス 62 */ 63 public void setFetchMailPro(FetchMailPro fetchMailPro) { 64 this.fetchMailPro = fetchMailPro; 65 } 66 67 /*** 68 * 実行するMailetのMailetWrapperリストをセットします。 69 * 70 * @param mailetWrapperList 実行するMailetのMailetWrapperリスト 71 */ 72 public void setMailetWrapperList(List mailetWrapperList) { 73 this.mailetWrapperList = mailetWrapperList; 74 } 75 }