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