%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
com.ozacc.mail.impl.SendMailImpl$MimeMessageWrapper |
|
|
1 | package com.ozacc.mail.impl; |
|
2 | ||
3 | import java.io.UnsupportedEncodingException; |
|
4 | import java.util.Date; |
|
5 | import java.util.Properties; |
|
6 | ||
7 | import javax.mail.AuthenticationFailedException; |
|
8 | import javax.mail.MessagingException; |
|
9 | import javax.mail.Session; |
|
10 | import javax.mail.Transport; |
|
11 | import javax.mail.internet.InternetAddress; |
|
12 | import javax.mail.internet.MimeMessage; |
|
13 | ||
14 | import org.apache.commons.logging.Log; |
|
15 | import org.apache.commons.logging.LogFactory; |
|
16 | ||
17 | import com.ozacc.mail.Mail; |
|
18 | import com.ozacc.mail.MailAuthenticationException; |
|
19 | import com.ozacc.mail.MailBuildException; |
|
20 | import com.ozacc.mail.MailException; |
|
21 | import com.ozacc.mail.MailSendException; |
|
22 | import com.ozacc.mail.SendMail; |
|
23 | ||
24 | /** |
|
25 | * SendMail¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤Î¼ÂÁõ¥¯¥é¥¹¡£ |
|
26 | * |
|
27 | * @since 1.0 |
|
28 | * @author Tomohiro Otsuka |
|
29 | * @version $Id: SendMailImpl.java,v 1.7.2.3 2005/01/29 23:09:36 otsuka Exp $ |
|
30 | */ |
|
31 | public class SendMailImpl implements SendMail { |
|
32 | ||
33 | private static Log log = LogFactory.getLog(SendMailImpl.class); |
|
34 | ||
35 | /** ¥Ç¥Õ¥©¥?¥È¤Î¥×¥úÁÈ¥³¥?¡£¡Ösmtp¡× */ |
|
36 | public static final String DEFAULT_PROTOCOL = "smtp"; |
|
37 | ||
38 | /** |
|
39 | * ¥Ç¥Õ¥©¥?¥È¤Î¥Ý¡¼¥È¡£¡Ö-1¡×<br> |
|
40 | * -1¤Ï¥×¥úÁÈ¥³¥?¤Ë±?¤¸¤¿Å¬Àڤʥݡ¼¥È¤òÀßÄꤹ¤?ÆÃÊ̤ÊÃÍ¡£ |
|
41 | * */ |
|
42 | public static final int DEFAULT_PORT = -1; |
|
43 | ||
44 | /** ¥Ç¥Õ¥©¥?¥È¤ÎSMTP¥µ¡¼¥Ð¡£¡Ölocalhost¡× */ |
|
45 | public static final String DEFAULT_HOST = "localhost"; |
|
46 | ||
47 | /** ISO-2022-JP */ |
|
48 | public static final String JIS_CHARSET = "ISO-2022-JP"; |
|
49 | ||
50 | private static final String RETURN_PATH_KEY = "mail.smtp.from"; |
|
51 | ||
52 | /** Àܳ¥¿¥¤¥à¥¢¥¦¥È */ |
|
53 | private static final int DEFAULT_CONNECTION_TIMEOUT = 5000; |
|
54 | ||
55 | /** ÆÉ¹?¥¿¥¤¥à¥¢¥¦¥È */ |
|
56 | private static final int DEFAULT_READ_TIMEOUT = 5000; |
|
57 | ||
58 | private String protocol = DEFAULT_PROTOCOL; |
|
59 | ||
60 | private String host = DEFAULT_HOST; |
|
61 | ||
62 | private int port = DEFAULT_PORT; |
|
63 | ||
64 | private String username; |
|
65 | ||
66 | private String password; |
|
67 | ||
68 | private String charset = JIS_CHARSET; |
|
69 | ||
70 | private String returnPath; |
|
71 | ||
72 | private String messageId; |
|
73 | ||
74 | private int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT; |
|
75 | ||
76 | private int readTimeout = DEFAULT_READ_TIMEOUT; |
|
77 | ||
78 | /** |
|
79 | * ¥³¥ó¥¹¥È¥é¥¯¥¿¡£ |
|
80 | */ |
|
81 | public SendMailImpl() {} |
|
82 | ||
83 | /** |
|
84 | * ¥³¥ó¥¹¥È¥é¥¯¥¿¡£»ÈÍѤ¹¤?SMTP¥µ¡¼¥Ð¤ò»ØÄꤷ¤Þ¤¹¡£ |
|
85 | * |
|
86 | * @param host SMTP¥µ¡¼¥Ð¤Î¥Û¥¹¥È̾¡¢¤Þ¤¿¤ÏIP¥¢¥É¥?¥¹ |
|
87 | */ |
|
88 | public SendMailImpl(String host) { |
|
89 | this(); |
|
90 | setHost(host); |
|
91 | } |
|
92 | ||
93 | /** |
|
94 | * @see com.ozacc.mail.SendMail#send(com.ozacc.mail.Mail) |
|
95 | */ |
|
96 | public void send(Mail mail) throws MailException { |
|
97 | send(new Mail[] { mail }); |
|
98 | } |
|
99 | ||
100 | /** |
|
101 | * @see com.ozacc.mail.SendMail#send(com.ozacc.mail.Mail[]) |
|
102 | */ |
|
103 | public void send(Mail[] mails) throws MailException { |
|
104 | MimeMessageWrapper[] mmws = new MimeMessageWrapper[mails.length]; |
|
105 | Session session = Session.getInstance(new Properties()); |
|
106 | for (int i = 0; i < mails.length; i++) { |
|
107 | Mail mail = mails[i]; |
|
108 | ||
109 | // MimeMessage¤òÀ¸À® |
|
110 | MimeMessage message = createMimeMessage(session); |
|
111 | MimeMessageBuilder builder = new MimeMessageBuilder(message); |
|
112 | try { |
|
113 | builder.buildMimeMessage(mail); |
|
114 | } catch (UnsupportedEncodingException e) { |
|
115 | throw new MailBuildException("¥µ¥Ý¡¼¥È¤µ¤?¤Æ¤¤¤Ê¤¤Ê¸»ú¥³¡¼¥É¤¬»ØÄꤵ¤?¤Þ¤·¤¿¡£", e); |
|
116 | } catch (MessagingException e) { |
|
117 | throw new MailBuildException("MimeMessage¤ÎÀ¸À®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£", e); |
|
118 | } |
|
119 | ||
120 | // Return-Path¤ò¼èÆÀ |
|
121 | String returnPath; |
|
122 | if (mail.getReturnPath() != null) { |
|
123 | returnPath = mail.getReturnPath().getAddress(); |
|
124 | } else { |
|
125 | returnPath = this.returnPath; |
|
126 | } |
|
127 | ||
128 | mmws[i] = new MimeMessageWrapper(message, returnPath, mail.getEnvelopeTo()); |
|
129 | } |
|
130 | processSend(mmws); |
|
131 | } |
|
132 | ||
133 | /** |
|
134 | * @see com.ozacc.mail.SendMail#send(javax.mail.internet.MimeMessage) |
|
135 | */ |
|
136 | public void send(MimeMessage message) throws MailException { |
|
137 | send(new MimeMessage[] { message }); |
|
138 | } |
|
139 | ||
140 | /** |
|
141 | * @see com.ozacc.mail.SendMail#send(javax.mail.internet.MimeMessage[]) |
|
142 | */ |
|
143 | public void send(MimeMessage[] messages) throws MailException { |
|
144 | MimeMessageWrapper[] mmws = new MimeMessageWrapper[messages.length]; |
|
145 | for (int i = 0; i < messages.length; i++) { |
|
146 | mmws[i] = new MimeMessageWrapper(messages[i], returnPath); |
|
147 | } |
|
148 | processSend(mmws); |
|
149 | } |
|
150 | ||
151 | private void processSend(MimeMessageWrapper[] mmws) throws MailException { |
|
152 | ||
153 | Properties prop = new Properties(); |
|
154 | // ¥¿¥¤¥à¥¢¥¦¥È¤ÎÀßÄ? |
|
155 | prop.put("mail.smtp.connectiontimeout", String.valueOf(connectionTimeout)); |
|
156 | prop.put("mail.smtp.timeout", String.valueOf(readTimeout)); |
|
157 | Session session = Session.getInstance(prop); |
|
158 | ||
159 | Transport transport = null; |
|
160 | try { |
|
161 | // SMTP¥µ¡¼¥Ð¤ËÀܳ |
|
162 | log.debug("SMTP¥µ¡¼¥Ð[" + host + "]¤ËÀܳ¤·¤Þ¤¹¡£"); |
|
163 | transport = session.getTransport(protocol); |
|
164 | transport.connect(host, port, username, password); |
|
165 | log.debug("SMTP¥µ¡¼¥Ð[" + host + "]¤ËÀܳ¤·¤Þ¤·¤¿¡£"); |
|
166 | ||
167 | for (int i = 0; i < mmws.length; i++) { |
|
168 | MimeMessage mimeMessage = mmws[i].getMimeMessage(); |
|
169 | // Return-Path¤ò¥»¥Ã¥È |
|
170 | String returnPath = mmws[i].getReturnPath(); |
|
171 | if (returnPath != null) { |
|
172 | session.getProperties().put(RETURN_PATH_KEY, returnPath); |
|
173 | log.debug("Return-Path[" + returnPath + "]¤òÀßÄꤷ¤Þ¤·¤¿¡£"); |
|
174 | } |
|
175 | // Á÷¿®Æ?»?¤ò¥»¥Ã¥È |
|
176 | mimeMessage.setSentDate(new Date()); |
|
177 | mimeMessage.saveChanges(); |
|
178 | ||
179 | // Á÷¿® |
|
180 | log.debug("¥á¡¼¥?¤òÁ÷¿®¤·¤Þ¤¹¡£"); |
|
181 | if (mmws[i].hasEnvelopeTo()) { |
|
182 | log.debug("¥á¡¼¥?¤Ïenvelope-to¥¢¥É¥?¥¹¤ËÁ÷¿®¤µ¤?¤Þ¤¹¡£"); |
|
183 | transport.sendMessage(mimeMessage, mmws[i].getEnvelopeTo()); |
|
184 | } else { |
|
185 | transport.sendMessage(mimeMessage, mimeMessage.getAllRecipients()); |
|
186 | } |
|
187 | log.debug("¥á¡¼¥?¤òÁ÷¿®¤·¤Þ¤·¤¿¡£"); |
|
188 | ||
189 | // Return-Path¤ò²ò½? |
|
190 | if (returnPath != null) { |
|
191 | session.getProperties().remove(RETURN_PATH_KEY); |
|
192 | log.debug("Return-PathÀßÄê¤ò¥¯¥?¥¢¤·¤Þ¤·¤¿¡£"); |
|
193 | } |
|
194 | } |
|
195 | } catch (AuthenticationFailedException ex) { |
|
196 | log.error("SMTP¥µ¡¼¥Ð[" + host + "]¤Ø¤ÎÀܳǧ¾Ú¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£", ex); |
|
197 | throw new MailAuthenticationException(ex); |
|
198 | } catch (MessagingException ex) { |
|
199 | log.error("¥á¡¼¥?¤ÎÁ÷¿®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£", ex); |
|
200 | throw new MailSendException("¥á¡¼¥?¤ÎÁ÷¿®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£", ex); |
|
201 | } finally { |
|
202 | if (transport != null && transport.isConnected()) { |
|
203 | log.debug("SMTP¥µ¡¼¥Ð[" + host + "]¤È¤ÎÀܳ¤òÀÚÃǤ·¤Þ¤¹¡£"); |
|
204 | try { |
|
205 | // SMTP¥µ¡¼¥Ð¤È¤ÎÀܳ¤òÀÚÃÇ |
|
206 | transport.close(); |
|
207 | } catch (MessagingException e) { |
|
208 | log.error("SMTP¥µ¡¼¥Ð[" + host + "]¤È¤ÎÀܳÀÚÃǤ˼ºÇÔ¤·¤Þ¤·¤¿¡£", e); |
|
209 | throw new MailException("SMTP¥µ¡¼¥Ð[" + host + "]¤È¤ÎÀܳÀÚÃǤ˼ºÇÔ¤·¤Þ¤·¤¿¡£"); |
|
210 | } |
|
211 | log.debug("SMTP¥µ¡¼¥Ð[" + host + "]¤È¤ÎÀܳ¤òÀÚÃǤ·¤Þ¤·¤¿¡£"); |
|
212 | } |
|
213 | } |
|
214 | } |
|
215 | ||
216 | /** |
|
217 | * ¿·¤·¤¤MimeMessage¥ª¥Ö¥¸¥§¥¯¥È¤òÀ¸À®¤·¤Þ¤¹¡£<br> |
|
218 | * messageId¥×¥úÁѥƥ£¤¬¥»¥Ã¥È¤µ¤?¤Æ¤¤¤?¾?¹ç¡¢OMLMimeMessage¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤òÀ¸À®¤·¤Þ¤¹¡£ |
|
219 | * |
|
220 | * @return ¿·¤·¤¤MimeMessage¥ª¥Ö¥¸¥§¥¯¥È |
|
221 | */ |
|
222 | private MimeMessage createMimeMessage(Session session) { |
|
223 | if (isMessageIdCustomized()) { |
|
224 | return new OMLMimeMessage(session, messageId); |
|
225 | } |
|
226 | return new MimeMessage(session); |
|
227 | } |
|
228 | ||
229 | /** |
|
230 | * Message-Id¥Ø¥Ã¥À¤Î¥É¥á¥¤¥óÉôʬ¤òÆÈ¼«¤Ë¥»¥Ã¥È¤·¤Æ¤¤¤?¤«¤É¤¦¤«È½Äꤷ¤Þ¤¹¡£ |
|
231 | * |
|
232 | * @return Message-Id¥Ø¥Ã¥À¤Î¥É¥á¥¤¥óÉôʬ¤òÆÈ¼«¤Ë¥»¥Ã¥È¤·¤Æ¤¤¤?¾?¹? true |
|
233 | */ |
|
234 | private boolean isMessageIdCustomized() { |
|
235 | return messageId != null; |
|
236 | } |
|
237 | ||
238 | /** |
|
239 | * ¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°¤Ë»ÈÍѤ¹¤?ʸ»ú¥³¡¼¥É¤òÊÖ¤·¤Þ¤¹¡£ |
|
240 | * |
|
241 | * @return ¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°¤Ë»ÈÍѤ¹¤?ʸ»ú¥³¡¼¥É |
|
242 | */ |
|
243 | public String getCharset() { |
|
244 | return charset; |
|
245 | } |
|
246 | ||
247 | /** |
|
248 | * ¥á¡¼¥?¤Î·?̾¤äËÜʸ¤Î¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°¤Ë»ÈÍѤ¹¤?ʸ»ú¥³¡¼¥É¤ò»ØÄꤷ¤Þ¤¹¡£ |
|
249 | * ¥Ç¥Õ¥©¥?¥È¤Ï<code>ISO-2022-JP</code>¤Ç¤¹¡£ |
|
250 | * <p> |
|
251 | * Æ?Ëܸ?´Ä¶¤ÇÍøÍѤ¹¤?¾?¹ç¤ÏÄ̾?Êѹ¹¤¹¤?ɬÍפϤ¢¤ê¤Þ¤»¤ó¡£ |
|
252 | * |
|
253 | * @param charset ¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°¤Ë»ÈÍѤ¹¤?ʸ»ú¥³¡¼¥É |
|
254 | */ |
|
255 | public void setCharset(String charset) { |
|
256 | this.charset = charset; |
|
257 | } |
|
258 | ||
259 | /** |
|
260 | * ¥»¥Ã¥È¤µ¤?¤¿SMTP¥µ¡¼¥Ð¤Î¥Û¥¹¥È̾¡¢¤Þ¤¿¤ÏIP¥¢¥É¥?¥¹¤òÊÖ¤·¤Þ¤¹¡£ |
|
261 | * |
|
262 | * @return SMTP¥µ¡¼¥Ð¤Î¥Û¥¹¥È̾¡¢¤Þ¤¿¤ÏIP¥¢¥É¥?¥¹ |
|
263 | */ |
|
264 | public String getHost() { |
|
265 | return host; |
|
266 | } |
|
267 | ||
268 | /** |
|
269 | * SMTP¥µ¡¼¥Ð¤Î¥Û¥¹¥È̾¡¢¤Þ¤¿¤ÏIP¥¢¥É¥?¥¹¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£ |
|
270 | * ¥Ç¥Õ¥©¥?¥È¤Ï localhost ¤Ç¤¹¡£ |
|
271 | * |
|
272 | * @param host SMTP¥µ¡¼¥Ð¤Î¥Û¥¹¥È̾¡¢¤Þ¤¿¤ÏIP¥¢¥É¥?¥¹ |
|
273 | */ |
|
274 | public void setHost(String host) { |
|
275 | this.host = host; |
|
276 | } |
|
277 | ||
278 | /** |
|
279 | * @return SMTP¥µ¡¼¥Ðǧ¾Ú¥Ñ¥¹¥?¡¼¥É |
|
280 | */ |
|
281 | public String getPassword() { |
|
282 | return password; |
|
283 | } |
|
284 | ||
285 | /** |
|
286 | * SMTP¥µ¡¼¥Ð¤ÎÀܳǧ¾Ú¤¬É¬Íפʾ?¹ç¤Ë¥Ñ¥¹¥?¡¼¥É¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£ |
|
287 | * |
|
288 | * @param password SMTP¥µ¡¼¥Ðǧ¾Ú¥Ñ¥¹¥?¡¼¥É |
|
289 | */ |
|
290 | public void setPassword(String password) { |
|
291 | this.password = password; |
|
292 | } |
|
293 | ||
294 | /** |
|
295 | * @return SMTP¥µ¡¼¥Ð¤Î¥Ý¡¼¥ÈÈÖ¹? |
|
296 | */ |
|
297 | public int getPort() { |
|
298 | return port; |
|
299 | } |
|
300 | ||
301 | /** |
|
302 | * SMTP¥µ¡¼¥Ð¤Î¥Ý¡¼¥ÈÈÖ¹æ¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£ |
|
303 | * |
|
304 | * @param port SMTP¥µ¡¼¥Ð¤Î¥Ý¡¼¥ÈÈÖ¹? |
|
305 | */ |
|
306 | public void setPort(int port) { |
|
307 | this.port = port; |
|
308 | } |
|
309 | ||
310 | /** |
|
311 | * ¥×¥úÁÈ¥³¥?¤òÊÖ¤·¤Þ¤¹¡£ |
|
312 | * |
|
313 | * @return ¥×¥úÁÈ¥³¥? |
|
314 | */ |
|
315 | public String getProtocol() { |
|
316 | return protocol; |
|
317 | } |
|
318 | ||
319 | /** |
|
320 | * ¥×¥úÁÈ¥³¥?¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£¥Ç¥Õ¥©¥?¥È¤Ï¡Ösmtp¡×¡£ |
|
321 | * |
|
322 | * @param protocol ¥×¥úÁÈ¥³¥? |
|
323 | */ |
|
324 | public void setProtocol(String protocol) { |
|
325 | this.protocol = protocol; |
|
326 | } |
|
327 | ||
328 | /** |
|
329 | * @return Return-Path¥¢¥É¥?¥¹ |
|
330 | */ |
|
331 | public String getReturnPath() { |
|
332 | return class="keyword">returnPath; |
|
333 | } |
|
334 | ||
335 | /** |
|
336 | * Return-Path¥¢¥É¥?¥¹¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£ |
|
337 | * <p> |
|
338 | * Á÷¿®¤¹¤?Mail¥¤¥ó¥¹¥¿¥ó¥¹¤Ë»ØÄꤵ¤?¤¿From¥¢¥É¥?¥¹°Ê³°¤Î¥¢¥É¥?¥¹¤òReturn-Path¤È¤·¤¿¤¤¾?¹ç¤Ë»ÈÍѤ·¤Þ¤¹¡£ |
|
339 | * ¤³¤³¤Ç¥»¥Ã¥È¤µ¤?¤¿Return-Path¤è¤ê¡¢Mail¥¤¥ó¥¹¥¿¥ó¥¹¤Ë¥»¥Ã¥È¤µ¤?¤¿Return-Path¤¬Í¥À褵¤?¤Þ¤¹¡£ |
|
340 | * |
|
341 | * @param returnPath Return-Path¥¢¥É¥?¥¹ |
|
342 | */ |
|
343 | public void setReturnPath(String returnPath) { |
|
344 | this.returnPath = returnPath; |
|
345 | } |
|
346 | ||
347 | /** |
|
348 | * @return SMTP¥µ¡¼¥Ðǧ¾Ú¥æ¡¼¥¶Ì¾ |
|
349 | */ |
|
350 | public String getUsername() { |
|
351 | return username; |
|
352 | } |
|
353 | ||
354 | /** |
|
355 | * SMTP¥µ¡¼¥Ð¤ÎÀܳǧ¾Ú¤¬É¬Íפʾ?¹ç¤Ë¥æ¡¼¥¶Ì¾¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£ |
|
356 | * |
|
357 | * @param username SMTP¥µ¡¼¥Ðǧ¾Ú¥æ¡¼¥¶Ì¾ |
|
358 | */ |
|
359 | public void setUsername(String username) { |
|
360 | this.username = username; |
|
361 | } |
|
362 | ||
363 | /** |
|
364 | * SMTP¥µ¡¼¥Ð¤È¤ÎÀܳ¥¿¥¤¥à¥¢¥¦¥È¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£ |
|
365 | * ñ°Ì¤Ï¥ß¥?Éᣥǥե©¥?¥È¤Ï5,000¥ß¥?ÉÃ(5ÉÃ)¤Ç¤¹¡£ |
|
366 | * <p> |
|
367 | * -1¤ò»ØÄꤹ¤?¤È̵¸ÂÂç¤Ë¤Ê¤ê¤Þ¤¹¤¬¡¢¤ªÁ¦¤á¤·¤Þ¤»¤ó¡£ |
|
368 | * |
|
369 | * @since 1.1.4 |
|
370 | * @param connectionTimeout SMTP¥µ¡¼¥Ð¤È¤ÎÀܳ¥¿¥¤¥à¥¢¥¦¥È |
|
371 | */ |
|
372 | public void setConnectionTimeout(int connectionTimeout) { |
|
373 | this.connectionTimeout = connectionTimeout; |
|
374 | } |
|
375 | ||
376 | /** |
|
377 | * SMTP¥µ¡¼¥Ð¤Ø¤ÎÁ÷¿®»?¤Î¥¿¥¤¥à¥¢¥¦¥È¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£ |
|
378 | * ñ°Ì¤Ï¥ß¥?Éᣥǥե©¥?¥È¤Ï5,000¥ß¥?ÉÃ(5ÉÃ)¤Ç¤¹¡£<br> |
|
379 | * Á÷¿®»?¤Ë¥¿¥¤¥à¥¢¥¦¥È¤¹¤?¤È¡¢<code>com.ozacc.mail.MailSendException</code>¤¬¥¹¥ú½¼¤µ¤?¤Þ¤¹¡£ |
|
380 | * <p> |
|
381 | * -1¤ò»ØÄꤹ¤?¤È̵¸ÂÂç¤Ë¤Ê¤ê¤Þ¤¹¤¬¡¢¤ªÁ¦¤á¤·¤Þ¤»¤ó¡£ |
|
382 | * |
|
383 | * @since 1.1.4 |
|
384 | * @param readTimeout SMTP¥µ¡¼¥Ð¤Ø¤ÎÁ÷¼õ¿®»?¤Î¥¿¥¤¥à¥¢¥¦¥È |
|
385 | */ |
|
386 | public void setReadTimeout(int readTimeout) { |
|
387 | this.readTimeout = readTimeout; |
|
388 | } |
|
389 | ||
390 | /** |
|
391 | * À¸À®¤µ¤?¤?MimeMessage¤ËÉÕ¤±¤é¤?¤?Message-Id¥Ø¥Ã¥À¤Î¥É¥á¥¤¥óÉôʬ¤ò»ØÄꤷ¤Þ¤¹¡£<br> |
|
392 | * »ØÄꤵ¤?¤Ê¤¤¾?¹?(null¤ä¶õʸ»úÎó¤Î¾?¹?)¤Ï¡¢JavaMail¤¬Message-Id¥Ø¥Ã¥À¤òÀ¸À®¤·¤Þ¤¹¡£ |
|
393 | * JavaMail¤¬À¸À®¤¹¤?¡ÖJavaMail.¼Â¹Ô¥æ¡¼¥¶Ì¾@¥Û¥¹¥È̾¡×¤ÎMessage-Id¤òÈò¤±¤¿¤¤¾?¹ç¤Ë¡¢¤³¤Î¥á¥½¥Ã¥É¤ò»ÈÍѤ·¤Þ¤¹¡£ |
|
394 | * <p> |
|
395 | * messageId¥×¥úÁѥƥ£¤¬¥»¥Ã¥È¤µ¤?¤Æ¤¤¤?¾?¹ç¡¢Mail¤«¤éÀ¸À®¤µ¤?¤?MimeMessage¤ÎMessage-Id¤Ë¤Ï |
|
396 | * <code>¥¿¥¤¥à¥¹¥¿¥ó¥× + ¥é¥ó¥À¥à¤ËÀ¸À®¤µ¤?¤?16·å¤Î¿ôÃÍ + ¤³¤³¤Ç¥»¥Ã¥È¤µ¤?¤¿ÃÍ</code> |
|
397 | * ¤¬»ÈÍѤµ¤?¤Þ¤¹¡£ |
|
398 | * <p> |
|
399 | * À¸À®¤µ¤?¤?Message-Id¤ÎÎã¡£ (¼ÂºÝ¤Î¿ôÃÍÉôʬ¤ÏÁ÷¿®¥á¡¼¥?Ëè¤ËÊѤ?¤ê¤Þ¤¹)<ul> |
|
400 | * <li>messageId¤Ë'example.com'¤ò»ØÄꤷ¤¿¾?¹ç¡¦¡¦¡¦1095714924963.5619528074501343@example.com</li> |
|
401 | * <li>messageId¤Ë'@example.com'¤ò»ØÄꤷ¤¿¾?¹ç¡¦¡¦¡¦1095714924963.5619528074501343@example.com (¾å¤ÈƱ¤¸)</li> |
|
402 | * <li>messageId¤Ë'OML@example.com'¤ò»ØÄꤷ¤¿¾?¹ç¡¦¡¦¡¦1095714924963.5619528074501343.OML@example.com</li> |
|
403 | * <li>messageId¤Ë'.OML@example.com'¤ò»ØÄꤷ¤¿¾?¹ç¡¦¡¦¡¦1095714924963.5619528074501343.OML@example.com (¾å¤ÈƱ¤¸)</li> |
|
404 | * </ul> |
|
405 | * <p> |
|
406 | * <strong>Ã?:</strong> ¤³¤ÎMessage-Id¤Ï<code>send(Mail)</code>¤«<code>send(Mail[])</code>¥á¥½¥Ã¥É¤¬¸Æ¤Ó¤À¤?¤¿»?¤Ë¤Î¤ß͸ú¤Ç¤¹¡£MimeMessage¤òľÀÜÁ÷¿®¤¹¤?¾?¹ç¤Ë¤ÏŬÍѤµ¤?¤Þ¤»¤ó¡£ |
|
407 | * |
|
408 | * @param messageId ¥á¡¼¥?¤ËÉÕ¤±¤é¤?¤?Message-Id¥Ø¥Ã¥À¤Î¥É¥á¥¤¥óÉôʬ |
|
409 | * @throws IllegalArgumentException @¤òÊ£¿ô´Þ¤ó¤Àʸ»úÎó¤ò»ØÄꤷ¤¿¾?¹? |
|
410 | */ |
|
411 | public void setMessageId(String messageId) { |
|
412 | if (messageId == null || messageId.length() < 1) { |
|
413 | return; |
|
414 | } |
|
415 | ||
416 | String[] parts = messageId.split("@"); |
|
417 | if (parts.length > 2) { |
|
418 | throw new IllegalArgumentException("messageId¥×¥úÁѥƥ£¤Ë'@'¤òÊ£¿ô´Þ¤à¤³¤È¤Ï¤Ç¤¤Þ¤»¤ó¡£[" + messageId |
|
419 | + "]"); |
|
420 | } |
|
421 | ||
422 | this.messageId = messageId; |
|
423 | } |
|
424 | ||
425 | /** |
|
426 | * MimeMessage¥¤¥ó¥¹¥¿¥ó¥¹¤È¡¢¤½¤Î¥á¡¼¥?¤ËÂб?¤¹¤?Return-Path¡¢envelope-to¥¢¥É¥?¥¹¤ò¥é¥Ã¥×¤¹¤?¥¯¥é¥¹¡£ |
|
427 | * |
|
428 | * @author Tomohiro Otsuka |
|
429 | * @version $Id: SendMailImpl.java,v 1.7.2.3 2005/01/29 23:09:36 otsuka Exp $ |
|
430 | */ |
|
431 | private static class MimeMessageWrapper { |
|
432 | ||
433 | private MimeMessage mimeMessage; |
|
434 | ||
435 | private String returnPath; |
|
436 | ||
437 | private InternetAddress[] envelopeTo; |
|
438 | ||
439 | 0 | public MimeMessageWrapper(MimeMessage mimeMessage, String returnPath) { |
440 | 0 | this.mimeMessage = mimeMessage; |
441 | 0 | this.returnPath = returnPath; |
442 | 0 | } |
443 | ||
444 | 3 | public MimeMessageWrapper(MimeMessage mimeMessage, String returnPath, |
445 | InternetAddress[] envelopeTo) { |
|
446 | 3 | this.mimeMessage = mimeMessage; |
447 | 3 | this.returnPath = returnPath; |
448 | 3 | this.envelopeTo = envelopeTo; |
449 | 3 | } |
450 | ||
451 | public MimeMessage getMimeMessage() { |
|
452 | 3 | return mimeMessage; |
453 | } |
|
454 | ||
455 | public String getReturnPath() { |
|
456 | 3 | return class="keyword">returnPath; |
457 | } |
|
458 | ||
459 | public boolean hasEnvelopeTo() { |
|
460 | 3 | return envelopeTo.length > 0; |
461 | } |
|
462 | ||
463 | public InternetAddress[] getEnvelopeTo() { |
|
464 | 0 | return envelopeTo; |
465 | } |
|
466 | } |
|
467 | ||
468 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |