View Javadoc

1   package com.ozacc.mail;
2   
3   import java.io.File;
4   import java.io.InputStream;
5   import java.io.UnsupportedEncodingException;
6   import java.net.URL;
7   import java.util.ArrayList;
8   import java.util.Collections;
9   import java.util.HashMap;
10  import java.util.Iterator;
11  import java.util.List;
12  import java.util.Map;
13  
14  import javax.activation.DataSource;
15  import javax.activation.FileDataSource;
16  import javax.activation.FileTypeMap;
17  import javax.activation.URLDataSource;
18  import javax.mail.internet.AddressException;
19  import javax.mail.internet.InternetAddress;
20  
21  import com.ozacc.mail.impl.ByteArrayDataSource;
22  import com.ozacc.mail.impl.Cp932;
23  
24  /***
25   * ¥á¡¼¥?¡£
26   * 
27   * @since 1.0
28   * @author Tomohiro Otsuka
29   * @version $Id: Mail.java,v 1.10 2004/09/18 00:38:54 otsuka Exp $
30   */
31  public class Mail {
32  
33  	/*** <code>ISO-2022-JP</code> */
34  	public static final String JIS_CHARSET = "ISO-2022-JP";
35  
36  	public static final String DOCTYPE_PUBLIC = "-//OZACC//DTD MAIL//EN";
37  
38  	public static final String DOCTYPE_SYSTEM = "http://www.ozacc.com/library/dtd/ozacc-mail.dtd";
39  
40  	private String charset = JIS_CHARSET;
41  
42  	private String text;
43  
44  	private InternetAddress from;
45  
46  	private String subject;
47  
48  	private List to;
49  
50  	private List cc;
51  
52  	private List bcc;
53  
54  	private InternetAddress returnPath;
55  
56  	private InternetAddress replyTo;
57  
58  	private String importance;
59  
60  	private Map xHeaders;
61  
62  	private String htmlText;
63  
64  	private List attachmentFiles;
65  
66  	/***
67  	 * ¥³¥ó¥¹¥È¥é¥¯¥¿¡£
68  	 */
69  	public Mail() {}
70  
71  	/***
72  	 * ¥³¥ó¥¹¥È¥é¥¯¥¿¡£
73  	 * °¸Àè¤äº¹½Ð¿Í¤Î̾Á°¤ò¥¨¥ó¥³¡¼¥É¤¹¤?»?¤Ë»ÈÍѤ¹¤?ʸ»ú¥³¡¼¥É¤ò»ØÄꤷ¤Þ¤¹¡£
74  	 * ¥Ç¥Õ¥©¥?¥È¤Ï<code>ISO-2022-JP</code>¤Ç¤¹¡£
75  	 * <p>
76  	 * Æ?Ëܸ?´Ä¶­¤ÇÍøÍѤ¹¤?¾?¹ç¤ÏÄ̾?Êѹ¹¤¹¤?ɬÍפϤ¢¤ê¤Þ¤»¤ó¡£
77  	 * 
78  	 * @param charset ¥¨¥ó¥³¡¼¥É¤Ë»ÈÍѤ¹¤?ʸ»ú¥³¡¼¥É
79  	 */
80  	public Mail(String charset) {
81  		this();
82  		this.charset = charset;
83  	}
84  
85  	/***
86  	 * ¥³¥Ô¡¼¥³¥ó¥¹¥È¥é¥¯¥¿¡£
87  	 * ¥·¥ã¥ú½¼¥³¥Ô¡¼(shallow copy)¤Ç¤¹¡£
88  	 * 
89  	 * @since 1.0.2
90  	 * 
91  	 * @param original ¥³¥Ô¡¼¸µ¤ÎMail¥¤¥ó¥¹¥¿¥ó¥¹
92  	 */
93  	public Mail(Mail original) {
94  		this.bcc = original.bcc;
95  		this.cc = original.cc;
96  		this.charset = original.charset;
97  		this.from = original.from;
98  		this.importance = original.importance;
99  		this.replyTo = original.replyTo;
100 		this.returnPath = original.returnPath;
101 		this.subject = original.subject;
102 		this.text = original.text;
103 		this.to = original.to;
104 		this.xHeaders = original.xHeaders;
105 		this.htmlText = original.htmlText;
106 		this.attachmentFiles = original.attachmentFiles;
107 	}
108 
109 	/***
110 	 * ¥¨¥ó¥³¡¼¥É¤Ë»ÈÍѤ¹¤?ʸ»ú¥³¡¼¥É¤òÊÖ¤·¤Þ¤¹¡£
111 	 * 
112 	 * @return ¥¨¥ó¥³¡¼¥É¤Ë»ÈÍѤ¹¤?ʸ»ú¥³¡¼¥É
113 	 */
114 	public String getCharset() {
115 		return charset;
116 	}
117 
118 	/***
119 	 * ¥á¡¼¥?¤Î½ÅÍ×ÅÙ¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£
120 	 * °ú¿ô¤Ç»ØÄ?²Äǽ¤ÊÃͤϡÖhigh¡×¡¢¡Önormal¡×¡¢¡Ölow¡×¤Î¤¤¤º¤?¤«¤Ç¤¹¡£
121 	 * 
122 	 * @param importance ¥á¡¼¥?¤Î½ÅÍ×ÅÙ¡£¡Öhigh¡×¡¢¡Önormal¡×¡¢¡Ölow¡×¤Î¤¤¤º¤?¤«¡£
123 	 * @throws IllegalArgumentException »ØÄ?²Äǽ¤ÊÃͰʳ°¤¬»ØÄꤵ¤?¤¿¾?¹?
124 	 * 
125 	 * @see Mail.Importance
126 	 */
127 	public void setImportance(String importance) throws IllegalArgumentException {
128 		if ("high".equals(importance) || "normal".equals(importance) || "low".equals(importance)) {
129 			this.importance = importance;
130 		} else {
131 			throw new IllegalArgumentException("'" + importance + "'¤Ï¡¢¥á¡¼¥?½ÅÍ×Å٤ˤϻØÄê¤Ç¤­¤Ê¤¤ÃͤǤ¹¡£");
132 		}
133 	}
134 
135 	/***
136 	 * ¥á¡¼¥?¤Î½ÅÍ×ÅÙ¤òÊÖ¤·¤Þ¤¹¡£
137 	 * ÃͤϡÖhigh¡×¡¢¡Önormal¡×¡¢¡Ölow¡×¤Î¤¤¤º¤?¤«¤Ç¤¹¡£
138 	 * 
139 	 * @return ¥á¡¼¥?¤Î½ÅÍ×ÅÙ¡£¡Öhigh¡×¡¢¡Önormal¡×¡¢¡Ölow¡×¤Î¤¤¤º¤?¤«¡£
140 	 */
141 	public String getImportance() {
142 		return importance;
143 	}
144 
145 	/***
146 	 * ¥á¡¼¥?¤ÎÁ÷¿®À襢¥É¥?¥¹¤òÄɲä·¤Þ¤¹¡£
147 	 * 
148 	 * @param address Á÷¿®À襢¥É¥?¥¹
149 	 */
150 	public void addTo(InternetAddress address) {
151 		if (to == null) {
152 			to = new ArrayList();
153 		}
154 		to.add(address);
155 	}
156 
157 	/***
158 	 * ¥á¡¼¥?¤ÎÁ÷¿®À襢¥É¥?¥¹¤òÄɲä·¤Þ¤¹¡£
159 	 * 
160 	 * @param email Á÷¿®À襢¥É¥?¥¹
161 	 * @throws IllegalArgumentException ÉÔÀµ¤Ê¥Õ¥©¡¼¥Þ¥Ã¥È¤Î¥¢¥É¥?¥¹¤¬»ØÄꤵ¤?¤¿¾?¹?
162 	 */
163 	public void addTo(String email) throws IllegalArgumentException {
164 		try {
165 			addTo(new InternetAddress(email));
166 		} catch (AddressException e) {
167 			throw new IllegalArgumentException(e.getMessage());
168 		}
169 	}
170 
171 	/***
172 	 * ¥á¡¼¥?¤ÎÁ÷¿®Àè̾¤È¥¢¥É¥?¥¹¤òÄɲä·¤Þ¤¹¡£
173 	 * ̾Á°¤ÏJIS_CHARSET¤Ç¥¨¥ó¥³¡¼¥É¤µ¤?¤Þ¤¹¡£
174 	 * 
175 	 * @param email Á÷¿®À襢¥É¥?¥¹
176 	 * @param name Á÷¿®Àè̾
177 	 * @throws IllegalArgumentException ÉÔÀµ¤Ê¥Õ¥©¡¼¥Þ¥Ã¥È¤Î¥¢¥É¥?¥¹¤¬»ØÄꤵ¤?¤¿¾?¹?
178 	 */
179 	public void addTo(String email, String name) throws IllegalArgumentException {
180 		if (charset.equals(JIS_CHARSET)) {
181 			name = Cp932.toJIS(name);
182 		}
183 		try {
184 			addTo(new InternetAddress(email, name, charset));
185 		} catch (UnsupportedEncodingException e) {
186 			throw new IllegalArgumentException(e.getMessage());
187 		}
188 	}
189 
190 	/***
191 	 * ¥á¡¼¥?¤ÎÁ÷¿®À襢¥É¥?¥¹¤ÎÇÛÎó¤òÊÖ¤·¤Þ¤¹¡£
192 	 * Á÷¿®À襢¥É¥?¥¹¤¬°?·?¤â¥»¥Ã¥È¤µ¤?¤Æ¤¤¤Ê¤¤¤È¤­¤Ï¶õ¤ÎÇÛÎó¤òÊÖ¤·¤Þ¤¹¡£
193 	 * 
194 	 * @return Á÷¿®À襢¥É¥?¥¹¤ÎÇÛÎ?
195 	 */
196 	public InternetAddress[] getTo() {
197 		if (to == null) {
198 			return new InternetAddress[0];
199 		}
200 		return (InternetAddress[])to.toArray(new InternetAddress[to.size()]);
201 	}
202 
203 	/***
204 	 * CC¥¢¥É¥?¥¹¤òÄɲä·¤Þ¤¹¡£
205 	 * 
206 	 * @param address CC¤Î¥¢¥É¥?¥¹
207 	 */
208 	public void addCc(InternetAddress address) {
209 		if (cc == null) {
210 			cc = new ArrayList();
211 		}
212 		cc.add(address);
213 	}
214 
215 	/***
216 	 * CC¥¢¥É¥?¥¹¤òÄɲä·¤Þ¤¹¡£
217 	 * 
218 	 * @param email CC¤Î¥¢¥É¥?¥¹
219 	 * @throws IllegalArgumentException ÉÔÀµ¤Ê¥Õ¥©¡¼¥Þ¥Ã¥È¤Î¥¢¥É¥?¥¹¤¬»ØÄꤵ¤?¤¿¾?¹?
220 	 */
221 	public void addCc(String email) throws IllegalArgumentException {
222 		try {
223 			addCc(new InternetAddress(email));
224 		} catch (AddressException e) {
225 			throw new IllegalArgumentException(e.getMessage());
226 		}
227 	}
228 
229 	/***
230 	 * CC¤Î°¸Ì¾¤È¥¢¥É¥?¥¹¤òÄɲä·¤Þ¤¹¡£
231 	 * ̾Á°¤ÏJIS_CHARSET¤Ç¥¨¥ó¥³¡¼¥É¤µ¤?¤Þ¤¹¡£
232 	 * 
233 	 * @param email CC¤Î¥¢¥É¥?¥¹
234 	 * @param name CC¤Î°¸Ì¾
235 	 * @throws IllegalArgumentException ÉÔÀµ¤Ê¥Õ¥©¡¼¥Þ¥Ã¥È¤Î¥¢¥É¥?¥¹¤¬»ØÄꤵ¤?¤¿¾?¹?
236 	 */
237 	public void addCc(String email, String name) throws IllegalArgumentException {
238 		if (charset.equals(JIS_CHARSET)) {
239 			name = Cp932.toJIS(name);
240 		}
241 		try {
242 			addCc(new InternetAddress(email, name, charset));
243 		} catch (UnsupportedEncodingException e) {
244 			throw new IllegalArgumentException(e.getMessage());
245 		}
246 	}
247 
248 	/***
249 	 * ¥á¡¼¥?¤ÎCC¥¢¥É¥?¥¹ÇÛÎó¤òÊÖ¤·¤Þ¤¹¡£
250 	 * CC¥¢¥É¥?¥¹¤¬°?·?¤â¥»¥Ã¥È¤µ¤?¤Æ¤¤¤Ê¤¤¤È¤­¤Ï¶õ¤ÎÇÛÎó¤òÊÖ¤·¤Þ¤¹¡£
251 	 * 
252 	 * @return CC¥¢¥É¥?¥¹¤ÎÇÛÎ?
253 	 */
254 	public InternetAddress[] getCc() {
255 		if (cc == null) {
256 			return new InternetAddress[0];
257 		}
258 		return (InternetAddress[])cc.toArray(new InternetAddress[cc.size()]);
259 	}
260 
261 	/***
262 	 * BCC¥¢¥É¥?¥¹¤òÄɲä·¤Þ¤¹¡£
263 	 * 
264 	 * @param address BCC¤Î¥¢¥É¥?¥¹
265 	 */
266 	public void addBcc(InternetAddress address) {
267 		if (bcc == null) {
268 			bcc = new ArrayList();
269 		}
270 		bcc.add(address);
271 	}
272 
273 	/***
274 	 * BCC¥¢¥É¥?¥¹¤òÄɲä·¤Þ¤¹¡£
275 	 * 
276 	 * @param email BCC¤Î¥¢¥É¥?¥¹
277 	 * @throws IllegalArgumentException ÉÔÀµ¤Ê¥Õ¥©¡¼¥Þ¥Ã¥È¤Î¥¢¥É¥?¥¹¤¬»ØÄꤵ¤?¤¿¾?¹?
278 	 */
279 	public void addBcc(String email) throws IllegalArgumentException {
280 		try {
281 			addBcc(new InternetAddress(email));
282 		} catch (AddressException e) {
283 			throw new IllegalArgumentException(e.getMessage());
284 		}
285 	}
286 
287 	/***
288 	 * ¥á¡¼¥?¤ÎBCC¥¢¥É¥?¥¹¤ÎÇÛÎó¤òÊÖ¤·¤Þ¤¹¡£
289 	 * BCC¥¢¥É¥?¥¹¤¬°?·?¤â¥»¥Ã¥È¤µ¤?¤Æ¤¤¤Ê¤¤¤È¤­¤Ï¶õ¤ÎÇÛÎó¤òÊÖ¤·¤Þ¤¹¡£
290 	 * 
291 	 * @return BCC¥¢¥É¥?¥¹¤ÎÇÛÎ?
292 	 */
293 	public InternetAddress[] getBcc() {
294 		if (bcc == null) {
295 			return new InternetAddress[0];
296 		}
297 		return (InternetAddress[])bcc.toArray(new InternetAddress[bcc.size()]);
298 	}
299 
300 	/***
301 	 * ¥á¡¼¥?¤Îº¹½Ð¿Í¥¢¥É¥?¥¹¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£
302 	 * 
303 	 * @param address º¹½Ð¿Í¥¢¥É¥?¥¹
304 	 */
305 	public void setFrom(InternetAddress address) {
306 		from = address;
307 	}
308 
309 	/***
310 	 * ¥á¡¼¥?¤Îº¹½Ð¿Í¥¢¥É¥?¥¹¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£
311 	 * 
312 	 * @param email º¹½Ð¿Í¥¢¥É¥?¥¹
313 	 * @throws IllegalArgumentException ÉÔÀµ¤Ê¥Õ¥©¡¼¥Þ¥Ã¥È¤Î¥¢¥É¥?¥¹¤¬»ØÄꤵ¤?¤¿¾?¹?
314 	 */
315 	public void setFrom(String email) throws IllegalArgumentException {
316 		try {
317 			setFrom(new InternetAddress(email));
318 		} catch (AddressException e) {
319 			throw new IllegalArgumentException(e.getMessage());
320 		}
321 	}
322 
323 	/***
324 	 * ¥á¡¼¥?¤Îº¹½Ð¿Í̾¤È¥¢¥É¥?¥¹¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£
325 	 * ̾Á°¤ÏJIS_CHARSET¤Ç¥¨¥ó¥³¡¼¥É¤µ¤?¤Þ¤¹¡£
326 	 * 
327 	 * @param email º¹½Ð¿Í¥¢¥É¥?¥¹
328 	 * @param name º¹½Ð¿Í̾
329 	 * @throws IllegalArgumentException ÉÔÀµ¤Ê¥Õ¥©¡¼¥Þ¥Ã¥È¤Î¥¢¥É¥?¥¹¤¬»ØÄꤵ¤?¤¿¾?¹?
330 	 */
331 	public void setFrom(String email, String name) throws IllegalArgumentException {
332 		if (charset.equals(JIS_CHARSET)) {
333 			name = Cp932.toJIS(name);
334 		}
335 		try {
336 			setFrom(new InternetAddress(email, name, charset));
337 		} catch (UnsupportedEncodingException e) {
338 			throw new IllegalArgumentException(e.getMessage());
339 		}
340 	}
341 
342 	/***
343 	 * ¥á¡¼¥?¤Îº¹½Ð¿Í¥¢¥É¥?¥¹¤òÊÖ¤·¤Þ¤¹¡£¥»¥Ã¥È¤µ¤?¤Æ¤¤¤Ê¤¤¾?¹ç¤Ïnull¤òÊÖ¤·¤Þ¤¹¡£
344 	 * 
345 	 * @return ¥á¡¼¥?¤Îº¹½Ð¿Í¥¢¥É¥?¥¹
346 	 */
347 	public InternetAddress getFrom() {
348 		return from;
349 	}
350 
351 	/***
352 	 * Return-Path¥¢¥É¥?¥¹¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£
353 	 * 
354 	 * @param address Return-Path¥¢¥É¥?¥¹
355 	 */
356 	public void setReturnPath(InternetAddress address) {
357 		returnPath = address;
358 	}
359 
360 	/***
361 	 * Return-Path¥¢¥É¥?¥¹¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£
362 	 * 
363 	 * @param email Return-Path¥¢¥É¥?¥¹
364 	 * @throws IllegalArgumentException ÉÔÀµ¤Ê¥Õ¥©¡¼¥Þ¥Ã¥È¤Î¥¢¥É¥?¥¹¤¬»ØÄꤵ¤?¤¿¾?¹?
365 	 */
366 	public void setReturnPath(String email) throws IllegalArgumentException {
367 		try {
368 			setReturnPath(new InternetAddress(email));
369 		} catch (AddressException e) {
370 			throw new IllegalArgumentException(e.getMessage());
371 		}
372 	}
373 
374 	/***
375 	 * Return-Path¥¢¥É¥?¥¹¤òÊÖ¤·¤Þ¤¹¡£
376 	 * 
377 	 * @return Return-Path¥¢¥É¥?¥¹
378 	 */
379 	public InternetAddress getReturnPath() {
380 		return returnPath;
381 	}
382 
383 	/***
384 	 * ÊÖ¿®À襢¥É¥?¥¹¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£
385 	 * 
386 	 * @param address ÊÖ¿®À襢¥É¥?¥¹
387 	 */
388 	public void setReplyTo(InternetAddress address) {
389 		replyTo = address;
390 	}
391 
392 	/***
393 	 * ÊÖ¿®À襢¥É¥?¥¹¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£
394 	 * 
395 	 * @param email ÊÖ¿®À襢¥É¥?¥¹
396 	 * @throws IllegalArgumentException ÉÔÀµ¤Ê¥Õ¥©¡¼¥Þ¥Ã¥È¤Î¥¢¥É¥?¥¹¤¬»ØÄꤵ¤?¤¿¾?¹?
397 	 */
398 	public void setReplyTo(String email) throws IllegalArgumentException {
399 		try {
400 			setReplyTo(new InternetAddress(email));
401 		} catch (AddressException e) {
402 			throw new IllegalArgumentException(e.getMessage());
403 		}
404 	}
405 
406 	/***
407 	 * ¥á¡¼¥?¤ÎÊÖ¿®À襢¥É¥?¥¹¤òÊÖ¤·¤Þ¤¹¡£¥»¥Ã¥È¤µ¤?¤Æ¤¤¤Ê¤¤¾?¹ç¤Ïnull¤òÊÖ¤·¤Þ¤¹¡£
408 	 * 
409 	 * @return ÊÖ¿®À襢¥É¥?¥¹
410 	 */
411 	public InternetAddress getReplyTo() {
412 		return replyTo;
413 	}
414 
415 	/***
416 	 * ¥á¡¼¥?¤Î·?̾¤òÊÖ¤·¤Þ¤¹¡£¥»¥Ã¥È¤µ¤?¤Æ¤¤¤Ê¤¤¾?¹ç¤Ï¶õʸ»úÎó¤òÊÖ¤·¤Þ¤¹¡£
417 	 * 
418 	 * @return ¥á¡¼¥?¤Î·?̾
419 	 */
420 	public String getSubject() {
421 		if (subject == null) {
422 			return "";
423 		}
424 		return subject;
425 	}
426 
427 	/***
428 	 * ¥á¡¼¥?¤Î·?̾¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£
429 	 * 
430 	 * @param subject ¥á¡¼¥?¤Î·?̾
431 	 */
432 	public void setSubject(String subject) {
433 		this.subject = subject;
434 	}
435 
436 	/***
437 	 * ¥á¡¼¥?ËÜʸ¤òÊÖ¤·¤Þ¤¹¡£
438 	 * ËÜʸ¥»¥Ã¥È¤µ¤?¤Æ¤¤¤Ê¤¤¾?¹ç¤Ï¶õʸ»úÎó¤òÊÖ¤·¤Þ¤¹¡£
439 	 * 
440 	 * @return ¥á¡¼¥?ËÜʸ
441 	 */
442 	public String getText() {
443 		if (text == null) {
444 			return "";
445 		}
446 		return text;
447 	}
448 
449 	/***
450 	 * ¥á¡¼¥?ËÜʸ¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£
451 	 * 
452 	 * @param text ¥á¡¼¥?ËÜʸ
453 	 */
454 	public void setText(String text) {
455 		this.text = text;
456 	}
457 
458 	/***
459 	 * ¥á¡¼¥?¥Ø¥Ã¥À¤ËǤ°Õ¤Î¥Ø¥Ã¥À¤òÄɲä·¤Þ¤¹¡£
460 	 * Ǥ°Õ¥Ø¥Ã¥À¤Ï¡ÖX-key: value¡×¤Î¥Õ¥©¡¼¥Þ¥Ã¥È¤Ç¥á¡¼¥?¥Ø¥Ã¥À¤ËÁȤ߹?¤Þ¤?¤Þ¤¹¡£
461 	 *  
462 	 * @param key Ǥ°Õ¥Ø¥Ã¥À̾¡£Æ¬¤¬"X-"¤Ç»Ï¤Þ¤Ã¤Æ¤¤¤Ê¤±¤?¤Ð¡¢¼«Æ°Åª¤ËÉÕÍ¿¤µ¤?¤Þ¤¹¡£
463 	 * @param value Ǥ°Õ¥Ø¥Ã¥À¤ÎÃÍ
464 	 */
465 	public void addXHeader(String key, String value) {
466 		if (xHeaders == null) {
467 			xHeaders = new HashMap();
468 		}
469 		if (key.startsWith("X-")) {
470 			xHeaders.put(key, value);
471 		} else {
472 			xHeaders.put("X-" + key, value);
473 		}
474 	}
475 
476 	/***
477 	 * ¥á¡¼¥?¤ÎǤ°Õ¥Ø¥Ã¥À̾¤ÈÃͤÎMap¥¤¥ó¥¹¥¿¥ó¥¹¤òÊÖ¤·¤Þ¤¹¡£
478 	 * Ǥ°Õ¥Ø¥Ã¥À¤¬°?·?¤â¥»¥Ã¥È¤µ¤?¤Æ¤¤¤Ê¤¤¤È¤­¤Ïnull¤òÊÖ¤·¤Þ¤¹¡£
479 	 * <p>
480 	 * ¤³¤ÎMap¥¤¥ó¥¹¥¿¥ó¥¹¤Ø¤Î½¤Àµ¤Ï¤Ç¤­¤Þ¤»¤ó¡£(unmodifiableMap¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£)
481 	 * 
482 	 * @return ¥á¡¼¥?¤ÎǤ°Õ¥Ø¥Ã¥À̾¤ÈÃͤÎMap¥¤¥ó¥¹¥¿¥ó¥¹¡£¤Þ¤¿¤Ïnull¡£
483 	 */
484 	public Map getXHeaders() {
485 		if (xHeaders == null) {
486 			return null;
487 		}
488 		return Collections.unmodifiableMap(xHeaders);
489 	}
490 
491 	/***
492 	 * ¥á¡¼¥?ÆâÍÆ¤ò½ÐÎϤ·¤Þ¤¹¡£<br>
493 	 * ¥á¡¼¥?¤Î¥½¡¼¥¹¤Ë»÷¤¿¥Õ¥©¡¼¥Þ¥Ã¥È¤Ç½ÐÎϤµ¤?¤Þ¤¹¡£
494 	 * 
495 	 * @see java.lang.Object#toString()
496 	 */
497 	public String toString() {
498 		StringBuffer buf = new StringBuffer(1000);
499 		buf.append("Mail\n");
500 		buf.append("Return-Path: ").append(returnPath).append("\n");
501 		buf.append("From: ").append(from != null ? from.toUnicodeString() : null).append("\n");
502 		buf.append("To: ").append(arrayToCommaDelimitedString(to)).append("\n");
503 		buf.append("Cc: ").append(arrayToCommaDelimitedString(cc)).append("\n");
504 		buf.append("Bcc: ").append(arrayToCommaDelimitedString(bcc)).append("\n");
505 		buf.append("Subject: ").append(subject).append("\n");
506 
507 		if (xHeaders != null) {
508 			for (Iterator itr = xHeaders.keySet().iterator(); itr.hasNext();) {
509 				String header = (String)itr.next();
510 				String value = (String)xHeaders.get(header);
511 				buf.append(header).append(": ").append(value).append("\n");
512 			}
513 		}
514 
515 		buf.append("\n");
516 		buf.append(text);
517 
518 		if (htmlText != null) {
519 			buf.append("\n\n-----\n\n");
520 			buf.append(htmlText);
521 		}
522 
523 		return buf.toString();
524 	}
525 
526 	/***
527 	 * @param list
528 	 * @return 
529 	 */
530 	private String arrayToCommaDelimitedString(List list) {
531 		if (list == null) {
532 			return "null";
533 		} else {
534 			StringBuffer sb = new StringBuffer();
535 			for (int i = 0, num = list.size(); i < num; i++) {
536 				if (i > 0) {
537 					sb.append(", ");
538 				}
539 				sb.append(((InternetAddress)list.get(i)).toUnicodeString());
540 			}
541 			return sb.toString();
542 		}
543 	}
544 
545 	/***
546 	 * ¥»¥Ã¥È¤µ¤?¤Æ¤¤¤?Á÷¿®À襢¥É¥?¥¹(To¥¢¥É¥?¥¹)¤òÁ´¤Æ¥¯¥?¥¢¤·¤Þ¤¹¡£
547 	 *
548 	 * @since 1.0.2
549 	 */
550 	public void clearTo() {
551 		to = null;
552 	}
553 
554 	/***
555 	 * ¥»¥Ã¥È¤µ¤?¤Æ¤¤¤?CC¥¢¥É¥?¥¹¤òÁ´¤Æ¥¯¥?¥¢¤·¤Þ¤¹¡£
556 	 *
557 	 * @since 1.0.2
558 	 */
559 	public void clearCc() {
560 		cc = null;
561 	}
562 
563 	/***
564 	 * ¥»¥Ã¥È¤µ¤?¤Æ¤¤¤?BCC¥¢¥É¥?¥¹¤òÁ´¤Æ¥¯¥?¥¢¤·¤Þ¤¹¡£
565 	 *
566 	 * @since 1.0.2
567 	 */
568 	public void clearBcc() {
569 		bcc = null;
570 	}
571 
572 	/***
573 	 * HTML¤ÎËÜʸ¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£
574 	 * 
575 	 * @since 1.1
576 	 * 
577 	 * @param htmlText HTML¤ÎËÜʸ
578 	 */
579 	public void setHtmlText(String htmlText) {
580 		this.htmlText = htmlText;
581 	}
582 
583 	/***
584 	 * HTML¤ÎËÜʸ¤òÊÖ¤·¤Þ¤¹¡£
585 	 * 
586 	 * @since 1.1
587 	 * 
588 	 * @return HTML¤ÎËÜʸ¡£¤Þ¤¿¤Ïnull¡£
589 	 */
590 	public String getHtmlText() {
591 		return htmlText;
592 	}
593 
594 	/***
595 	 * »ØÄꤵ¤?¤¿¥Õ¥¡¥¤¥?¤òźÉÕ¤·¤Þ¤¹¡£
596 	 * źÉÕ¥Õ¥¡¥¤¥?̾¤Ë¤Ï¡¢»ØÄꤵ¤?¤¿¥Õ¥¡¥¤¥?¤Î̾Á°¤¬»ÈÍѤµ¤?¤Þ¤¹¡£
597 	 * ¤³¤Î¥Õ¥¡¥¤¥?¤Î̾Á°¤ÏŬÀڤʳÈÄ¥»Ò¤¬ÉÕ¤±¤é¤?¤Æ¤¤¤?ɬÍפ¬¤¢¤ê¤Þ¤¹¡£
598 	 * 
599 	 * @since 1.1
600 	 * 
601 	 * @param file źÉÕ¥Õ¥¡¥¤¥?
602 	 */
603 	public void addFile(File file) {
604 		if (attachmentFiles == null) {
605 			initAttachmentFiles();
606 		}
607 		addFile(file, file.getName());
608 	}
609 
610 	/***
611 	 * »ØÄꤵ¤?¤¿¥Õ¥¡¥¤¥?¤òźÉÕ¤·¤Þ¤¹¡£
612 	 * »ØÄꤹ¤?¥Õ¥¡¥¤¥?̾¤Ë¤ÏŬÀڤʳÈÄ¥»Ò¤¬ÉÕ¤±¤é¤?¤Æ¤¤¤?ɬÍפ¬¤¢¤ê¤Þ¤¹¡£
613 	 * 
614 	 * @since 1.1
615 	 * 
616 	 * @param file źÉÕ¥Õ¥¡¥¤¥?
617 	 * @param fileName ¥Õ¥¡¥¤¥?̾
618 	 */
619 	public void addFile(File file, String fileName) {
620 		if (attachmentFiles == null) {
621 			initAttachmentFiles();
622 		}
623 		attachmentFiles.add(new AttachmentFile(fileName, file));
624 	}
625 
626 	/***
627 	 * »ØÄꤵ¤?¤¿URL¤Î¥Õ¥¡¥¤¥?¤òźÉÕ¤·¤Þ¤¹¡£
628 	 * »ØÄꤹ¤?¥Õ¥¡¥¤¥?̾¤Ë¤ÏŬÀڤʳÈÄ¥»Ò¤¬ÉÕ¤±¤é¤?¤Æ¤¤¤?ɬÍפ¬¤¢¤ê¤Þ¤¹¡£
629 	 * 
630 	 * @since 1.1
631 	 * 
632 	 * @param url źÉÕ¥Õ¥¡¥¤¥?
633 	 * @param fileName ¥Õ¥¡¥¤¥?̾
634 	 */
635 	public void addFile(URL url, String fileName) {
636 		if (attachmentFiles == null) {
637 			initAttachmentFiles();
638 		}
639 		attachmentFiles.add(new AttachmentFile(fileName, url));
640 	}
641 
642 	/***
643 	 * »ØÄꤵ¤?¤¿InputStream¤ò¥Õ¥¡¥¤¥?¤È¤·¤ÆÅºÉÕ¤·¤Þ¤¹¡£
644 	 * »ØÄꤹ¤?¥Õ¥¡¥¤¥?̾¤Ë¤ÏŬÀڤʳÈÄ¥»Ò¤¬ÉÕ¤±¤é¤?¤Æ¤¤¤?ɬÍפ¬¤¢¤ê¤Þ¤¹¡£
645 	 * 
646 	 * @since 1.1
647 	 * 
648 	 * @param is źÉÕ¥Õ¥¡¥¤¥?¤òÀ¸À®¤¹¤?InputStream
649 	 * @param fileName ¥Õ¥¡¥¤¥?̾
650 	 */
651 	public void addFile(InputStream is, String fileName) {
652 		if (attachmentFiles == null) {
653 			initAttachmentFiles();
654 		}
655 		attachmentFiles.add(new AttachmentFile(fileName, is));
656 	}
657 
658 	/***
659 	 * attachmentFiles¥×¥úÁѥƥ£¤ò½é´?²½¡£
660 	 */
661 	private void initAttachmentFiles() {
662 		attachmentFiles = new ArrayList();
663 	}
664 
665 	/***
666 	 * źÉÕ¥Õ¥¡¥¤¥?¤ÎÇÛÎó¤òÊÖ¤·¤Þ¤¹¡£
667 	 * źÉÕ¥Õ¥¡¥¤¥?¤¬¥»¥Ã¥È¤µ¤?¤Æ¤¤¤Ê¤¤¾?¹ç¤Ï¡¢¶õ¤ÎÇÛÎó¤òÊÖ¤·¤Þ¤¹¡£
668 	 * 
669 	 * @since 1.1
670 	 * 
671 	 * @return źÉÕ¥Õ¥¡¥¤¥?¤ÎÇÛÎ󡣤ޤ¿¤Ï¶õ¤ÎÇÛÎó¡£
672 	 */
673 	public AttachmentFile[] getAttachmentFiles() {
674 		if (attachmentFiles == null) {
675 			return new AttachmentFile[0];
676 		}
677 		return (AttachmentFile[])attachmentFiles
678 				.toArray(new AttachmentFile[attachmentFiles.size()]);
679 	}
680 
681 	/***
682 	 * HTML¤ÎËÜʸ¤¬¥»¥Ã¥È¤µ¤?¤Æ¤¤¤?¤«¤É¤¦¤«È½Äꤷ¤Þ¤¹¡£
683 	 * 
684 	 * @since 1.1
685 	 * 
686 	 * @return HTML¤ÎËÜʸ¤¬¥»¥Ã¥È¤µ¤?¤Æ¤¤¤?¾?¹? true
687 	 */
688 	public boolean isHtmlMail() {
689 		return (htmlText != null);
690 	}
691 
692 	/***
693 	 * ¥Õ¥¡¥¤¥?¤¬ÅºÉÕ¤µ¤?¤Æ¤¤¤?¤«¤É¤¦¤«È½Äꤷ¤Þ¤¹¡£
694 	 * 
695 	 * @since 1.1
696 	 * 
697 	 * @return ¥Õ¥¡¥¤¥?¤¬ÅºÉÕ¤µ¤?¤Æ¤¤¤?¾?¹? true
698 	 */
699 	public boolean isFileAttached() {
700 		return attachmentFiles != null && attachmentFiles.size() > 0;
701 	}
702 
703 	/***
704 	 * ¥Þ¥?¥Á¥Ñ¡¼¥È¡¦¥á¡¼¥?¤«¤É¤¦¤«È½Äꤷ¤Þ¤¹¡£<br>
705 	 * HTMLËÜʸ¤¬¥»¥Ã¥È¤µ¤?¤Æ¤¤¤?¤«¡¢¥Õ¥¡¥¤¥?¤¬ÅºÉÕ¤µ¤?¤Æ¤¤¤?¾?¹ç¤Ë true ¤¬ÊÖ¤µ¤?¤Þ¤¹¡£
706 	 * <p>
707 	 * Ã?: ¤³¤³¤ÇȽÄꤵ¤?¤?¥Þ¥?¥Á¥Ñ¡¼¥È¤Ï¡¢¸·Ì©¤Ê°ÕÌ£¤Ç¤Î¥Þ¥?¥Á¥Ñ¡¼¥È¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡£
708 	 * 
709 	 * @since 1.1
710 	 * 
711 	 * @return ¥Þ¥?¥Á¥Ñ¡¼¥È¡¦¥á¡¼¥?¤Î¾?¹? true
712 	 */
713 	public boolean isMultipartMail() {
714 		return isHtmlMail() || isFileAttached();
715 	}
716 
717 	/***
718 	 * ¥»¥Ã¥È¤µ¤?¤Æ¤¤¤?źÉÕ¥Õ¥¡¥¤¥?¤òÁ´¤Æ¥¯¥?¥¢¤·¤Þ¤¹¡£
719 	 * 
720 	 * @since 1.1
721 	 */
722 	public void clearFile() {
723 		initAttachmentFiles();
724 	}
725 
726 	/***
727 	 * źÉÕ¥Õ¥¡¥¤¥?¡£
728 	 * 
729 	 * @since 1.1
730 	 * @author Tomohiro Otsuka
731 	 * @version $Id: Mail.java,v 1.10 2004/09/18 00:38:54 otsuka Exp $
732 	 */
733 	public class AttachmentFile {
734 
735 		private String name;
736 
737 		private File file;
738 
739 		private InputStream is;
740 
741 		private URL url;
742 
743 		/***
744 		 * ¥Õ¥¡¥¤¥?̾¤È¥Õ¥¡¥¤¥?¤ò»ØÄꤷ¤Æ¡¢¤³¤Î¥¯¥é¥¹¤Î¥¤¥ó¥¿¥ó¥¹¤òÀ¸À®¤·¤Þ¤¹¡£
745 		 * ¥Õ¥¡¥¤¥?̾¤Ë¤ÏŬÀڤʳÈÄ¥»Ò¤¬ÉÕ¤±¤é¤?¤Æ¤¤¤?ɬÍפ¬¤¢¤ê¤Þ¤¹¡£
746 		 * 
747 		 * @param name ¥á¡¼¥?¤Ëɽ¼¨¤¹¤?¥Õ¥¡¥¤¥?̾
748 		 * @param file źÉÕ¥Õ¥¡¥¤¥?
749 		 */
750 		public AttachmentFile(String name, File file) {
751 			this.name = name;
752 			this.file = file;
753 		}
754 
755 		/***
756 		 * ¥Õ¥¡¥¤¥?̾¤ÈInputStream¤ò»ØÄꤷ¤Æ¡¢¤³¤Î¥¯¥é¥¹¤Î¥¤¥ó¥¿¥ó¥¹¤òÀ¸À®¤·¤Þ¤¹¡£
757 		 * ¥Õ¥¡¥¤¥?̾¤Ë¤ÏŬÀڤʳÈÄ¥»Ò¤¬ÉÕ¤±¤é¤?¤Æ¤¤¤?ɬÍפ¬¤¢¤ê¤Þ¤¹¡£
758 		 * 
759 		 * @param name ¥á¡¼¥?¤Ëɽ¼¨¤¹¤?¥Õ¥¡¥¤¥?̾
760 		 * @param is źÉÕ¥Õ¥¡¥¤¥?¤òÀ¸À®¤¹¤?InputStream
761 		 */
762 		public AttachmentFile(String name, InputStream is) {
763 			this.name = name;
764 			this.is = is;
765 		}
766 
767 		/***
768 		 * ¥Õ¥¡¥¤¥?̾¤È¥Õ¥¡¥¤¥?¥úÁ±¡¼¥·¥ç¥ó¤ÎURL¤ò»ØÄꤷ¤Æ¡¢¤³¤Î¥¯¥é¥¹¤Î¥¤¥ó¥¿¥ó¥¹¤òÀ¸À®¤·¤Þ¤¹¡£
769 		 * ¥Õ¥¡¥¤¥?̾¤Ë¤ÏŬÀڤʳÈÄ¥»Ò¤¬ÉÕ¤±¤é¤?¤Æ¤¤¤?ɬÍפ¬¤¢¤ê¤Þ¤¹¡£
770 		 * 
771 		 * @param name ¥á¡¼¥?¤Ëɽ¼¨¤¹¤?¥Õ¥¡¥¤¥?̾
772 		 * @param url źÉÕ¥Õ¥¡¥¤¥?¤Î¥úÁ±¡¼¥·¥ç¥óURL
773 		 */
774 		public AttachmentFile(String name, URL url) {
775 			this.name = name;
776 			this.url = url;
777 		}
778 
779 		/***
780 		 * źÉÕ¥Õ¥¡¥¤¥?¤ÎDataSource¥¤¥ó¥¹¥¿¥ó¥¹¤òÀ¸À®¤·¤ÆÊÖ¤·¤Þ¤¹¡£
781 		 * 
782 		 * @return źÉÕ¥Õ¥¡¥¤¥?¤ÎDataSource¥¤¥ó¥¹¥¿¥ó¥¹
783 		 */
784 		public DataSource getDataSource() {
785 			if (file != null) {
786 				return new FileDataSource(file);
787 			}
788 
789 			if (url != null) {
790 				return new URLDataSource(url);
791 			}
792 
793 			// InputStream¤«¤éDataSource¤òÀ¸À®
794 			String contentType = FileTypeMap.getDefaultFileTypeMap().getContentType(name);
795 			return new ByteArrayDataSource(is, contentType);
796 		}
797 
798 		/***
799 		 * źÉÕ¥Õ¥¡¥¤¥?̾¤òÊÖ¤·¤Þ¤¹¡£
800 		 * 
801 		 * @return źÉÕ¥Õ¥¡¥¤¥?̾
802 		 */
803 		public String getName() {
804 			return name;
805 		}
806 
807 		/***
808 		 * @return ¥»¥Ã¥È¤µ¤?¤¿¥Õ¥¡¥¤¥?¡£¤Þ¤¿¤Ïnull¡£
809 		 */
810 		public File getFile() {
811 			return file;
812 		}
813 
814 		/***
815 		 * @return ¥»¥Ã¥È¤µ¤?¤¿InputStream¡£¤Þ¤¿¤Ïnull¡£
816 		 */
817 		public InputStream getInputStream() {
818 			return is;
819 		}
820 
821 		/***
822 		 * @return ¥»¥Ã¥È¤µ¤?¤¿URL¡£¤Þ¤¿¤Ïnull¡£
823 		 */
824 		public URL getUrl() {
825 			return url;
826 		}
827 	}
828 
829 	/***
830 	 * ¥á¡¼¥?¤Î½ÅÍ×ÅÙ¡£Ä?¿ô¤Î¤ß¤òÄ?µÁ¡£
831 	 * 
832 	 * @author Tomohiro Otsuka
833 	 * @version $Id: Mail.java,v 1.10 2004/09/18 00:38:54 otsuka Exp $
834 	 */
835 	public static class Importance {
836 
837 		/*** ½ÅÍ×ÅÙ¡Ö¹â¡× */
838 		public static final String HIGH = "high";
839 
840 		/*** ½ÅÍ×ÅÙ¡ÖÃæ¡× */
841 		public static final String NORMAL = "normal";
842 
843 		/*** ½ÅÍ×ÅÙ¡ÖÄã¡× */
844 		public static final String LOW = "low";
845 
846 	}
847 }