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.3 2005/01/23 06:47:01 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 if (fetchMailPro.isConnected()) {
43 fetchMailPro.disconnect();
44 }
45 }
46 }
47
48 /***
49 * 指定された受信メールに対してMailetを適用します。
50 *
51 * @param mail MailetUnitに渡す受信メール
52 */
53 private void processMail(ReceivedMail mail) {
54 for (Iterator itr = mailetWrapperList.iterator(); itr.hasNext();) {
55 MailetWrapper mailetWrapper = (MailetWrapper)itr.next();
56 mailetWrapper.execute(mail);
57 }
58 }
59
60 /***
61 * メールの受信に使用するFetchMailProインターフェースの実装インスタンスをセットします。
62 *
63 * @param fetchMailPro FetchMailProインターフェースの実装インスタンス
64 */
65 public void setFetchMailPro(FetchMailPro fetchMailPro) {
66 this.fetchMailPro = fetchMailPro;
67 }
68
69 /***
70 * 実行するMailetのMailetWrapperリストをセットします。
71 *
72 * @param mailetWrapperList 実行するMailetのMailetWrapperリスト
73 */
74 public void setMailetWrapperList(List mailetWrapperList) {
75 this.mailetWrapperList = mailetWrapperList;
76 }
77 }