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.5 2005/01/18 16:42:00 otsuka Exp $
17 */
18 public class FetchMailImpl implements FetchMail {
19
20
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 * メールサーバのホスト名、またはIPアドレスをセットします。
88 * デフォルトは localhost です。
89 *
90 * @param host メールサーバのホスト名、またはIPアドレス
91 */
92 public void setHost(String host) {
93 this.host = host;
94 }
95
96 /***
97 * メールサーバの認証パスワード名をセットします。
98 *
99 * @param password メールサーバの認証パスワード
100 */
101 public void setPassword(String password) {
102 this.password = password;
103 }
104
105 /***
106 * メール受信に使用するポート番号をセットします。
107 * プロトコルに応じたポート番号が自動的に使用されますので、通常ここでポート番号をセットする必要はありません。
108 *
109 * @param port ポート番号
110 */
111 public void setPort(int port) {
112 this.port = port;
113 }
114
115 /***
116 * メール受信に使用するプロトコロルをセットします。
117 * 現在サポートされているプロトコルは、「pop3」と「imap」の二つです。
118 * デフォルトは「pop3」です。
119 * <p>
120 * POP3サーバへの認証をAPOPで行いたい場合は、プロトコル名ではありませんが、
121 * 「apop」を指定してください。APOP認証を使用するには、JavaMail 1.3.2以降が必要です。
122 *
123 * @param protocol プロトコル
124 */
125 public void setProtocol(String protocol) {
126 this.protocol = protocol;
127 }
128
129 /***
130 * メールサーバの認証ユーザ名をセットします。
131 *
132 * @param username メールサーバの認証ユーザ名
133 */
134 public void setUsername(String username) {
135 this.username = username;
136 }
137
138 /***
139 * メールサーバのホスト名、またはIPアドレスを返します。
140 *
141 * @return メールサーバのホスト名、またはIPアドレス
142 */
143 public String getHost() {
144 return host;
145 }
146
147 /***
148 * メールサーバの認証パスワードを返します。
149 *
150 * @return メールサーバの認証パスワード
151 */
152 public String getPassword() {
153 return password;
154 }
155
156 /***
157 * @return ポート番号
158 */
159 public int getPort() {
160 return port;
161 }
162
163 /***
164 * メール受信に使用するプロトコロルをセットします。
165 *
166 * @return プロトコル
167 */
168 public String getProtocol() {
169 return protocol;
170 }
171
172 /***
173 * メールサーバの認証ユーザ名を返します。
174 *
175 * @return メールサーバの認証ユーザ名
176 */
177 public String getUsername() {
178 return username;
179 }
180 }