| 1 |
|
package com.ozacc.mail.mock; |
| 2 |
|
|
| 3 |
|
import java.util.ArrayList; |
| 4 |
|
import java.util.List; |
| 5 |
|
|
| 6 |
|
import org.apache.commons.logging.Log; |
| 7 |
|
import org.apache.commons.logging.LogFactory; |
| 8 |
|
|
| 9 |
|
import com.ozacc.mail.MailException; |
| 10 |
|
import com.ozacc.mail.fetch.FetchMail; |
| 11 |
|
import com.ozacc.mail.fetch.ReceivedMail; |
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
1 |
public class MockFetchMail implements FetchMail { |
| 22 |
|
|
| 23 |
1 |
private static Log log = LogFactory.getLog(MockFetchMail.class); |
| 24 |
|
|
| 25 |
|
|
| 26 |
|
public static final String DEFAULT_HOST = "localhost"; |
| 27 |
|
|
| 28 |
|
|
| 29 |
|
public static final String DEFAULT_PROTOCOL = "pop3"; |
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
public static final int DEFAULT_PORT = -1; |
| 36 |
|
|
| 37 |
|
private static final String INBOX_NAME = "INBOX"; |
| 38 |
|
|
| 39 |
1 |
private String host = DEFAULT_HOST; |
| 40 |
|
|
| 41 |
1 |
private String protocol = DEFAULT_PROTOCOL; |
| 42 |
|
|
| 43 |
1 |
private int port = DEFAULT_PORT; |
| 44 |
|
|
| 45 |
|
private String username; |
| 46 |
|
|
| 47 |
|
private String password; |
| 48 |
|
|
| 49 |
|
private List receivedMails; |
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
public MockFetchMail() { |
| 55 |
1 |
super(); |
| 56 |
1 |
receivedMails = new ArrayList(); |
| 57 |
1 |
} |
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
|
| 63 |
|
|
| 64 |
|
|
| 65 |
|
public void setupGetMails(ReceivedMail mail) { |
| 66 |
1 |
receivedMails.add(mail); |
| 67 |
1 |
} |
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
public void setupGetMails(ReceivedMail[] mails) { |
| 76 |
0 |
for (int i = 0; i < mails.length; i++) { |
| 77 |
0 |
ReceivedMail mail = mails[i]; |
| 78 |
0 |
setupGetMails(mail); |
| 79 |
|
} |
| 80 |
0 |
} |
| 81 |
|
|
| 82 |
|
|
| 83 |
|
|
| 84 |
|
|
| 85 |
|
public ReceivedMail[] getMails() throws MailException { |
| 86 |
1 |
log.debug(protocol.toUpperCase() + "¥µ¡¼¥Ð[" + host + "]¤ËÀܳ¤·¤?¥Õ¥ê¡£"); |
| 87 |
1 |
log.debug(protocol.toUpperCase() + "¥µ¡¼¥Ð[" + host + "]¤ËÀܳ¤·¤¿¥Õ¥ê¡£"); |
| 88 |
|
|
| 89 |
1 |
if (receivedMails.size() > 0) { |
| 90 |
1 |
log.debug(receivedMails.size() + "Ä̤Υ᡼¥?¤ò¼õ¿®¤¹¤?¥Õ¥ê¡£"); |
| 91 |
|
} else { |
| 92 |
0 |
log.debug("¼õ¿®¤¹¤?¥Õ¥ê¤ò¤¹¤?¥á¡¼¥?¤Ï¤¢¤ê¤Þ¤»¤ó¡£"); |
| 93 |
|
} |
| 94 |
|
try { |
| 95 |
1 |
return (ReceivedMail[])receivedMails.toArray(new ReceivedMail[receivedMails.size()]); |
| 96 |
0 |
} finally { |
| 97 |
1 |
log.debug(protocol.toUpperCase() + "¥µ¡¼¥Ð[" + host + "]¤È¤ÎÀܳ¤òÀÚÃǤ¹¤?¥Õ¥ê¡£"); |
| 98 |
1 |
log.debug(protocol.toUpperCase() + "¥µ¡¼¥Ð[" + host + "]¤È¤ÎÀܳ¤òÀÚÃǤ·¤¿¥Õ¥ê¡£"); |
| 99 |
1 |
} |
| 100 |
|
} |
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| 104 |
|
|
| 105 |
|
public ReceivedMail[] getMails(boolean delete) throws MailException { |
| 106 |
0 |
ReceivedMail[] result = getMails(); |
| 107 |
0 |
if (delete) { |
| 108 |
0 |
receivedMails.clear(); |
| 109 |
|
} |
| 110 |
0 |
return result; |
| 111 |
|
} |
| 112 |
|
|
| 113 |
|
|
| 114 |
|
|
| 115 |
|
|
| 116 |
|
public String getHost() { |
| 117 |
0 |
return host; |
| 118 |
|
} |
| 119 |
|
|
| 120 |
|
|
| 121 |
|
|
| 122 |
|
|
| 123 |
|
public void setHost(String host) { |
| 124 |
0 |
this.host = host; |
| 125 |
0 |
} |
| 126 |
|
|
| 127 |
|
|
| 128 |
|
|
| 129 |
|
|
| 130 |
|
public String getPassword() { |
| 131 |
0 |
return password; |
| 132 |
|
} |
| 133 |
|
|
| 134 |
|
|
| 135 |
|
|
| 136 |
|
|
| 137 |
|
public void setPassword(String password) { |
| 138 |
0 |
this.password = password; |
| 139 |
0 |
} |
| 140 |
|
|
| 141 |
|
|
| 142 |
|
|
| 143 |
|
|
| 144 |
|
public int getPort() { |
| 145 |
0 |
return port; |
| 146 |
|
} |
| 147 |
|
|
| 148 |
|
|
| 149 |
|
|
| 150 |
|
|
| 151 |
|
public void setPort(int port) { |
| 152 |
0 |
this.port = port; |
| 153 |
0 |
} |
| 154 |
|
|
| 155 |
|
|
| 156 |
|
|
| 157 |
|
|
| 158 |
|
public String getProtocol() { |
| 159 |
0 |
return protocol; |
| 160 |
|
} |
| 161 |
|
|
| 162 |
|
|
| 163 |
|
|
| 164 |
|
|
| 165 |
|
public void setProtocol(String protocol) { |
| 166 |
0 |
this.protocol = protocol; |
| 167 |
0 |
} |
| 168 |
|
|
| 169 |
|
|
| 170 |
|
|
| 171 |
|
|
| 172 |
|
public String getUsername() { |
| 173 |
0 |
return username; |
| 174 |
|
} |
| 175 |
|
|
| 176 |
|
|
| 177 |
|
|
| 178 |
|
|
| 179 |
|
public void setUsername(String username) { |
| 180 |
0 |
this.username = username; |
| 181 |
0 |
} |
| 182 |
|
} |