1 package com.ozacc.mail.mock;
\r
3 import java.util.ArrayList;
\r
4 import java.util.List;
\r
6 import javax.mail.internet.MimeMessage;
\r
8 import org.apache.commons.logging.Log;
\r
9 import org.apache.commons.logging.LogFactory;
\r
11 import com.ozacc.mail.MailException;
\r
12 import com.ozacc.mail.NotConnectedException;
\r
13 import com.ozacc.mail.fetch.FetchMailPro;
\r
14 import com.ozacc.mail.fetch.ReceivedMail;
\r
17 * FetchMailProImplクラスのMock。
\r
20 * @author Tomohiro Otsuka
\r
21 * @version $Id: MockFetchMailPro.java,v 1.1.2.2 2005/04/10 05:22:34 otsuka Exp $
\r
23 public class MockFetchMailPro implements FetchMailPro {
\r
25 private static Log log = LogFactory.getLog(MockFetchMailPro.class);
\r
27 /** デフォルトのSMTPサーバ。「localhost」 */
\r
28 public static final String DEFAULT_HOST = "localhost";
\r
30 /** デフォルトのプロトコル。「pop3」 */
\r
31 public static final String DEFAULT_PROTOCOL = "pop3";
\r
34 * デフォルトのポート。「-1」<br>
\r
35 * -1はプロトコルに応じた適切なポートを設定する特別な値。
\r
37 public static final int DEFAULT_PORT = -1;
\r
39 private static final String INBOX_NAME = "INBOX";
\r
41 private String host = DEFAULT_HOST;
\r
43 private String protocol = DEFAULT_PROTOCOL;
\r
45 private int port = DEFAULT_PORT;
\r
47 private String username;
\r
49 private String password;
\r
51 private boolean javaMailLogEnabled;
\r
53 private boolean connected = false;
\r
55 private List receivedMails;
\r
60 public MockFetchMailPro() {
\r
62 receivedMails = new ArrayList();
\r
66 * @see com.ozacc.mail.fetch.FetchMailPro#connect()
\r
68 public synchronized void connect() throws MailException {
\r
69 if (isConnected()) {
\r
70 log.warn("既にサーバ[" + host + "]に接続されています。再接続するには先に接続を切断する必要があります。");
\r
74 log.debug(protocol.toUpperCase() + "サーバ[" + host + "]に接続するフリ。");
\r
76 log.info(protocol.toUpperCase() + "サーバ[" + host + "]に接続したフリ。");
\r
80 * @see com.ozacc.mail.fetch.FetchMailPro#disconnect()
\r
82 public synchronized void disconnect() throws MailException {
\r
83 if (isConnected()) {
\r
84 log.debug(protocol.toUpperCase() + "サーバ[" + host + "]との接続を切断するフリ。");
\r
86 log.debug(protocol.toUpperCase() + "サーバ[" + host + "]との接続を切断したフリ。");
\r
91 * <code>MockFetchMailPro</code>の<code>getMails()</code>メソッドが返す
\r
92 * <code>ReceivedMail</code>インスタンスをセットします。
\r
94 * @param mail <code>getMails()</code>メソッドが返す<code>ReceivedMail</code>インスタンス
\r
96 public void setupGetMails(ReceivedMail mail) {
\r
97 receivedMails.add(mail);
\r
101 * <code>MockFetchMailPro</code>の<code>getMails()</code>メソッドが返す
\r
102 * <code>ReceivedMail</code>インスタンスをセットします。
\r
104 * @param mails <code>getMails()</code>メソッドが返す<code>ReceivedMail</code>インスタンス配列
\r
106 public void setupGetMails(ReceivedMail[] mails) {
\r
107 for (int i = 0; i < mails.length; i++) {
\r
108 ReceivedMail mail = mails[i];
\r
109 setupGetMails(mail);
\r
114 * @see com.ozacc.mail.fetch.FetchMailPro#getMailCount()
\r
116 public int getMailCount() throws MailException {
\r
117 return receivedMails.size();
\r
121 * @see com.ozacc.mail.fetch.FetchMailPro#getMail(int)
\r
123 public synchronized ReceivedMail getMail(int num) throws MailException {
\r
124 return getMail(num, false);
\r
128 * @see com.ozacc.mail.fetch.FetchMailPro#getMail(int, boolean)
\r
130 public synchronized ReceivedMail getMail(int num, boolean delete) throws MailException {
\r
131 if (isConnected()) {
\r
133 return (ReceivedMail)receivedMails.remove(num - 1);
\r
135 return (ReceivedMail)receivedMails.get(num - 1);
\r
138 throw new NotConnectedException(protocol.toUpperCase() + "サーバ[" + host + "]に接続されていません。");
\r
143 * @see com.ozacc.mail.fetch.FetchMailPro#getMails(boolean)
\r
145 public synchronized ReceivedMail[] getMails(boolean delete) throws MailException {
\r
146 if (isConnected()) {
\r
147 ReceivedMail[] results = (ReceivedMail[])receivedMails
\r
148 .toArray(new ReceivedMail[receivedMails.size()]);
\r
150 receivedMails.clear();
\r
154 throw new NotConnectedException(protocol.toUpperCase() + "サーバ[" + host + "]に接続されていません。");
\r
159 * @see com.ozacc.mail.fetch.FetchMailPro#getMessage(int)
\r
161 public MimeMessage getMessage(int num) throws MailException {
\r
162 throw new UnsupportedOperationException("申し訳ございません。MockFetchMailProでは、このメソッドをサポートしていません。");
\r
166 * @see com.ozacc.mail.fetch.FetchMailPro#getMessages(boolean)
\r
168 public MimeMessage[] getMessages(boolean delete) throws MailException {
\r
169 throw new UnsupportedOperationException("申し訳ございません。MockFetchMailProでは、このメソッドをサポートしていません。");
\r
173 * @see com.ozacc.mail.fetch.FetchMailPro#changeFolder(java.lang.String)
\r
175 public synchronized void changeFolder(String folderName) throws MailException {
\r
176 if (!isConnected()) {
\r
177 log.warn("メールサーバに接続されていません。");
\r
181 log.debug("メッセージフォルダ[" + folderName + "]をオープンするフリ。");
\r
182 log.debug("メッセージフォルダ[" + folderName + "]をオープンしたフリ。");
\r
186 * @see com.ozacc.mail.fetch.FetchMailPro#isConnected()
\r
188 public boolean isConnected() {
\r
193 * @return Returns the host.
\r
195 public String getHost() {
\r
200 * @param host The host to set.
\r
202 public void setHost(String host) {
\r
207 * @return Returns the javaMailLogEnabled.
\r
209 public boolean isJavaMailLogEnabled() {
\r
210 return javaMailLogEnabled;
\r
214 * @param javaMailLogEnabled The javaMailLogEnabled to set.
\r
216 public void setJavaMailLogEnabled(boolean javaMailLogEnabled) {
\r
217 this.javaMailLogEnabled = javaMailLogEnabled;
\r
221 * @return Returns the password.
\r
223 public String getPassword() {
\r
228 * @param password The password to set.
\r
230 public void setPassword(String password) {
\r
231 this.password = password;
\r
235 * @return Returns the port.
\r
237 public int getPort() {
\r
242 * @param port The port to set.
\r
244 public void setPort(int port) {
\r
249 * @return Returns the protocol.
\r
251 public String getProtocol() {
\r
256 * @param protocol The protocol to set.
\r
258 public void setProtocol(String protocol) {
\r
259 this.protocol = protocol;
\r
263 * @return Returns the username.
\r
265 public String getUsername() {
\r
270 * @param username The username to set.
\r
272 public void setUsername(String username) {
\r
273 this.username = username;
\r