View Javadoc

1   package com.ozacc.mail.fetch.impl;
2   
3   import com.ozacc.mail.MailException;
4   import com.ozacc.mail.fetch.FetchMail;
5   import com.ozacc.mail.fetch.ReceivedMail;
6   
7   /***
8    * <code>FetchMail</code>インターフェースの実装クラス。
9    * <p>
10   * <code>FetchMailProImpl</code>クラスに処理を委譲しています。
11   * 
12   * @since 1.2
13   * @see FetchMailProImpl
14   * 
15   * @author Tomohiro Otsuka
16   * @version $Id: FetchMailImpl.java,v 1.1.2.4 2004/10/27 19:42:41 otsuka Exp $
17   */
18  public class FetchMailImpl implements FetchMail {
19  
20  	//private FetchMailProImpl fetchMailProImpl;
21  	/*** デフォルトのSMTPサーバ。「localhost」 */
22  	public static final String DEFAULT_HOST = "localhost";
23  
24  	/*** デフォルトのプロトコル。「pop3」 */
25  	public static final String DEFAULT_PROTOCOL = "pop3";
26  
27  	/***
28  	 * デフォルトのポート。「-1」<br>
29  	 * -1はプロトコルに応じた適切なポートを設定する特別な値。
30  	 */
31  	public static final int DEFAULT_PORT = -1;
32  
33  	private static final String INBOX_NAME = "INBOX";
34  
35  	private String host = DEFAULT_HOST;
36  
37  	private String protocol = DEFAULT_PROTOCOL;
38  
39  	private int port = DEFAULT_PORT;
40  
41  	private String username;
42  
43  	private String password;
44  
45  	/***
46  	 * コンストラクタ。
47  	 */
48  	public FetchMailImpl() {}
49  
50  	/***
51  	 * @see com.ozacc.mail.fetch.FetchMail#getMails()
52  	 */
53  	public ReceivedMail[] getMails() throws MailException {
54  		return getMails(false);
55  	}
56  
57  	/***
58  	 * @see com.ozacc.mail.fetch.FetchMail#getMails(boolean)
59  	 */
60  	public ReceivedMail[] getMails(boolean delete) throws MailException {
61  		FetchMailProImpl fetchMailProImpl = createFetchMailProImpl();
62  		fetchMailProImpl.connect();
63  		try {
64  			ReceivedMail[] mails = fetchMailProImpl.getMails(delete);
65  			return mails;
66  		} finally {
67  			fetchMailProImpl.disconnect();
68  		}
69  	}
70  
71  	/***
72  	 * サーバ情報をセットしたFetchMailProImplインスタンスを生成します。
73  	 * 
74  	 * @return サーバ情報をセットしたFetchMailProImplインスタンス
75  	 */
76  	private FetchMailProImpl createFetchMailProImpl() {
77  		FetchMailProImpl fmp = new FetchMailProImpl();
78  		fmp.setHost(host);
79  		fmp.setPort(port);
80  		fmp.setProtocol(protocol);
81  		fmp.setUsername(username);
82  		fmp.setPassword(password);
83  		return fmp;
84  	}
85  
86  	/***
87  	 * @param host 
88  	 */
89  	public void setHost(String host) {
90  		this.host = host;
91  	}
92  
93  	/***
94  	 * @param password 
95  	 */
96  	public void setPassword(String password) {
97  		this.password = password;
98  	}
99  
100 	/***
101 	 * @param port 
102 	 */
103 	public void setPort(int port) {
104 		this.port = port;
105 	}
106 
107 	/***
108 	 * メール受信に使用するプロトコロルをセットします。
109 	 * 現在サポートされているプロトコルは、「pop3」と「imap」の二つです。
110 	 * デフォルトは「pop3」です。
111 	 * <p>
112 	 * POP3サーバへの認証をAPOPで行いたい場合は、プロトコル名ではありませんが、
113 	 * 「apop」を指定してください。APOP認証を使用するには、JavaMail 1.3.2以降が必要です。
114 	 * 
115 	 * @param protocol プロトコル
116 	 */
117 	public void setProtocol(String protocol) {
118 		this.protocol = protocol;
119 	}
120 
121 	/***
122 	 * @param username 
123 	 */
124 	public void setUsername(String username) {
125 		this.username = username;
126 	}
127 
128 	/***
129 	 * @return Returns the host.
130 	 */
131 	public String getHost() {
132 		return host;
133 	}
134 
135 	/***
136 	 * @return Returns the password.
137 	 */
138 	public String getPassword() {
139 		return password;
140 	}
141 
142 	/***
143 	 * @return Returns the port.
144 	 */
145 	public int getPort() {
146 		return port;
147 	}
148 
149 	/***
150 	 * @return Returns the protocol.
151 	 */
152 	public String getProtocol() {
153 		return protocol;
154 	}
155 
156 	/***
157 	 * @return Returns the username.
158 	 */
159 	public String getUsername() {
160 		return username;
161 	}
162 }