View Javadoc

1   package com.ozacc.mail;
2   
3   import java.io.UnsupportedEncodingException;
4   import java.util.ArrayList;
5   import java.util.Collections;
6   import java.util.HashMap;
7   import java.util.Iterator;
8   import java.util.List;
9   import java.util.Map;
10  
11  import javax.mail.internet.AddressException;
12  import javax.mail.internet.InternetAddress;
13  
14  import com.ozacc.mail.impl.Cp932;
15  
16  /***
17   * ¥á¡¼¥?¡£
18   * 
19   * @since 1.0
20   * @author Tomohiro Otsuka
21   * @version $Id: Mail.java,v 1.8 2004/09/16 04:52:45 otsuka Exp $
22   */
23  public class Mail {
24  
25  	/*** <code>ISO-2022-JP</code> */
26  	public static final String JIS_CHARSET = "ISO-2022-JP";
27  
28  	public static final String DOCTYPE_PUBLIC = "-//OZACC//DTD MAIL//EN";
29  
30  	public static final String DOCTYPE_SYSTEM = "http://www.ozacc.com/library/dtd/ozacc-mail.dtd";
31  
32  	private String charset = JIS_CHARSET;
33  
34  	private String text;
35  
36  	private InternetAddress from;
37  
38  	private String subject;
39  
40  	private List to;
41  
42  	private List cc;
43  
44  	private List bcc;
45  
46  	private InternetAddress returnPath;
47  
48  	private InternetAddress replyTo;
49  
50  	private String importance;
51  
52  	private Map xHeaders;
53  
54  	/***
55  	 * ¥³¥ó¥¹¥È¥é¥¯¥¿¡£
56  	 */
57  	public Mail() {}
58  
59  	/***
60  	 * ¥³¥ó¥¹¥È¥é¥¯¥¿¡£
61  	 * °¸Àè¤äº¹½Ð¿Í¤Î̾Á°¤ò¥¨¥ó¥³¡¼¥É¤¹¤?»?¤Ë»ÈÍѤ¹¤?ʸ»ú¥³¡¼¥É¤ò»ØÄꤷ¤Þ¤¹¡£
62  	 * ¥Ç¥Õ¥©¥?¥È¤Ï<code>ISO-2022-JP</code>¤Ç¤¹¡£
63  	 * <p>
64  	 * Æ?Ëܸ?´Ä¶­¤ÇÍøÍѤ¹¤?¾?¹ç¤ÏÄ̾?Êѹ¹¤¹¤?ɬÍפϤ¢¤ê¤Þ¤»¤ó¡£
65  	 * 
66  	 * @param charset ¥¨¥ó¥³¡¼¥É¤Ë»ÈÍѤ¹¤?ʸ»ú¥³¡¼¥É
67  	 */
68  	public Mail(String charset) {
69  		this();
70  		this.charset = charset;
71  	}
72  
73  	/***
74  	 * ¥³¥Ô¡¼¥³¥ó¥¹¥È¥é¥¯¥¿¡£
75  	 * ¥·¥ã¥ú½¼¥³¥Ô¡¼(shallow copy)¤Ç¤¹¡£
76  	 * 
77  	 * @since 1.0.2
78  	 * 
79  	 * @param original ¥³¥Ô¡¼¸µ¤ÎMail¥¤¥ó¥¹¥¿¥ó¥¹
80  	 */
81  	public Mail(Mail original) {
82  		this.bcc = original.bcc;
83  		this.cc = original.cc;
84  		this.charset = original.charset;
85  		this.from = original.from;
86  		this.importance = original.importance;
87  		this.replyTo = original.replyTo;
88  		this.returnPath = original.returnPath;
89  		this.subject = original.subject;
90  		this.text = original.text;
91  		this.to = original.to;
92  		this.xHeaders = original.xHeaders;
93  	}
94  
95  	/***
96  	 * ¥¨¥ó¥³¡¼¥É¤Ë»ÈÍѤ¹¤?ʸ»ú¥³¡¼¥É¤òÊÖ¤·¤Þ¤¹¡£
97  	 * 
98  	 * @return ¥¨¥ó¥³¡¼¥É¤Ë»ÈÍѤ¹¤?ʸ»ú¥³¡¼¥É
99  	 */
100 	public String getCharset() {
101 		return charset;
102 	}
103 
104 	/***
105 	 * ¥á¡¼¥?¤Î½ÅÍ×ÅÙ¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£
106 	 * °ú¿ô¤Ç»ØÄ?²Äǽ¤ÊÃͤϡÖhigh¡×¡¢¡Önormal¡×¡¢¡Ölow¡×¤Î¤¤¤º¤?¤«¤Ç¤¹¡£
107 	 * 
108 	 * @param importance ¥á¡¼¥?¤Î½ÅÍ×ÅÙ¡£¡Öhigh¡×¡¢¡Önormal¡×¡¢¡Ölow¡×¤Î¤¤¤º¤?¤«¡£
109 	 * @throws IllegalArgumentException »ØÄ?²Äǽ¤ÊÃͰʳ°¤¬»ØÄꤵ¤?¤¿¾?¹?
110 	 * 
111 	 * @see Mail.Importance
112 	 */
113 	public void setImportance(String importance) throws IllegalArgumentException {
114 		if ("high".equals(importance) || "normal".equals(importance) || "low".equals(importance)) {
115 			this.importance = importance;
116 		} else {
117 			throw new IllegalArgumentException("'" + importance + "'¤Ï¡¢¥á¡¼¥?½ÅÍ×Å٤ˤϻØÄê¤Ç¤­¤Ê¤¤ÃͤǤ¹¡£");
118 		}
119 	}
120 
121 	/***
122 	 * ¥á¡¼¥?¤Î½ÅÍ×ÅÙ¤òÊÖ¤·¤Þ¤¹¡£
123 	 * ÃͤϡÖhigh¡×¡¢¡Önormal¡×¡¢¡Ölow¡×¤Î¤¤¤º¤?¤«¤Ç¤¹¡£
124 	 * 
125 	 * @return ¥á¡¼¥?¤Î½ÅÍ×ÅÙ¡£¡Öhigh¡×¡¢¡Önormal¡×¡¢¡Ölow¡×¤Î¤¤¤º¤?¤«¡£
126 	 */
127 	public String getImportance() {
128 		return importance;
129 	}
130 
131 	/***
132 	 * ¥á¡¼¥?¤ÎÁ÷¿®À襢¥É¥?¥¹¤òÄɲä·¤Þ¤¹¡£
133 	 * 
134 	 * @param address Á÷¿®À襢¥É¥?¥¹
135 	 */
136 	public void addTo(InternetAddress address) {
137 		if (to == null) {
138 			to = new ArrayList();
139 		}
140 		to.add(address);
141 	}
142 
143 	/***
144 	 * ¥á¡¼¥?¤ÎÁ÷¿®À襢¥É¥?¥¹¤òÄɲä·¤Þ¤¹¡£
145 	 * 
146 	 * @param email Á÷¿®À襢¥É¥?¥¹
147 	 * @throws IllegalArgumentException ÉÔÀµ¤Ê¥Õ¥©¡¼¥Þ¥Ã¥È¤Î¥¢¥É¥?¥¹¤¬»ØÄꤵ¤?¤¿¾?¹?
148 	 */
149 	public void addTo(String email) throws IllegalArgumentException {
150 		try {
151 			addTo(new InternetAddress(email));
152 		} catch (AddressException e) {
153 			throw new IllegalArgumentException(e.getMessage());
154 		}
155 	}
156 
157 	/***
158 	 * ¥á¡¼¥?¤ÎÁ÷¿®Àè̾¤È¥¢¥É¥?¥¹¤òÄɲä·¤Þ¤¹¡£
159 	 * ̾Á°¤ÏJIS_CHARSET¤Ç¥¨¥ó¥³¡¼¥É¤µ¤?¤Þ¤¹¡£
160 	 * 
161 	 * @param email Á÷¿®À襢¥É¥?¥¹
162 	 * @param name Á÷¿®Àè̾
163 	 * @throws IllegalArgumentException ÉÔÀµ¤Ê¥Õ¥©¡¼¥Þ¥Ã¥È¤Î¥¢¥É¥?¥¹¤¬»ØÄꤵ¤?¤¿¾?¹?
164 	 */
165 	public void addTo(String email, String name) throws IllegalArgumentException {
166 		if (charset.equals(JIS_CHARSET)) {
167 			name = Cp932.toJIS(name);
168 		}
169 		try {
170 			addTo(new InternetAddress(email, name, charset));
171 		} catch (UnsupportedEncodingException e) {
172 			throw new IllegalArgumentException(e.getMessage());
173 		}
174 	}
175 
176 	/***
177 	 * ¥á¡¼¥?¤ÎÁ÷¿®À襢¥É¥?¥¹¤ÎÇÛÎó¤òÊÖ¤·¤Þ¤¹¡£
178 	 * Á÷¿®À襢¥É¥?¥¹¤¬°?·?¤â¥»¥Ã¥È¤µ¤?¤Æ¤¤¤Ê¤¤¤È¤­¤Ï¶õ¤ÎÇÛÎó¤òÊÖ¤·¤Þ¤¹¡£
179 	 * 
180 	 * @return Á÷¿®À襢¥É¥?¥¹¤ÎÇÛÎ?
181 	 */
182 	public InternetAddress[] getTo() {
183 		if (to == null) {
184 			return new InternetAddress[0];
185 		}
186 		return (InternetAddress[])to.toArray(new InternetAddress[to.size()]);
187 	}
188 
189 	/***
190 	 * CC¥¢¥É¥?¥¹¤òÄɲä·¤Þ¤¹¡£
191 	 * 
192 	 * @param address CC¤Î¥¢¥É¥?¥¹
193 	 */
194 	public void addCc(InternetAddress address) {
195 		if (cc == null) {
196 			cc = new ArrayList();
197 		}
198 		cc.add(address);
199 	}
200 
201 	/***
202 	 * CC¥¢¥É¥?¥¹¤òÄɲä·¤Þ¤¹¡£
203 	 * 
204 	 * @param email CC¤Î¥¢¥É¥?¥¹
205 	 * @throws IllegalArgumentException ÉÔÀµ¤Ê¥Õ¥©¡¼¥Þ¥Ã¥È¤Î¥¢¥É¥?¥¹¤¬»ØÄꤵ¤?¤¿¾?¹?
206 	 */
207 	public void addCc(String email) throws IllegalArgumentException {
208 		try {
209 			addCc(new InternetAddress(email));
210 		} catch (AddressException e) {
211 			throw new IllegalArgumentException(e.getMessage());
212 		}
213 	}
214 
215 	/***
216 	 * CC¤Î°¸Ì¾¤È¥¢¥É¥?¥¹¤òÄɲä·¤Þ¤¹¡£
217 	 * ̾Á°¤ÏJIS_CHARSET¤Ç¥¨¥ó¥³¡¼¥É¤µ¤?¤Þ¤¹¡£
218 	 * 
219 	 * @param email CC¤Î¥¢¥É¥?¥¹
220 	 * @param name CC¤Î°¸Ì¾
221 	 * @throws IllegalArgumentException ÉÔÀµ¤Ê¥Õ¥©¡¼¥Þ¥Ã¥È¤Î¥¢¥É¥?¥¹¤¬»ØÄꤵ¤?¤¿¾?¹?
222 	 */
223 	public void addCc(String email, String name) throws IllegalArgumentException {
224 		if (charset.equals(JIS_CHARSET)) {
225 			name = Cp932.toJIS(name);
226 		}
227 		try {
228 			addCc(new InternetAddress(email, name, charset));
229 		} catch (UnsupportedEncodingException e) {
230 			throw new IllegalArgumentException(e.getMessage());
231 		}
232 	}
233 
234 	/***
235 	 * ¥á¡¼¥?¤ÎCC¥¢¥É¥?¥¹ÇÛÎó¤òÊÖ¤·¤Þ¤¹¡£
236 	 * CC¥¢¥É¥?¥¹¤¬°?·?¤â¥»¥Ã¥È¤µ¤?¤Æ¤¤¤Ê¤¤¤È¤­¤Ï¶õ¤ÎÇÛÎó¤òÊÖ¤·¤Þ¤¹¡£
237 	 * 
238 	 * @return CC¥¢¥É¥?¥¹¤ÎÇÛÎ?
239 	 */
240 	public InternetAddress[] getCc() {
241 		if (cc == null) {
242 			return new InternetAddress[0];
243 		}
244 		return (InternetAddress[])cc.toArray(new InternetAddress[cc.size()]);
245 	}
246 
247 	/***
248 	 * BCC¥¢¥É¥?¥¹¤òÄɲä·¤Þ¤¹¡£
249 	 * 
250 	 * @param address BCC¤Î¥¢¥É¥?¥¹
251 	 */
252 	public void addBcc(InternetAddress address) {
253 		if (bcc == null) {
254 			bcc = new ArrayList();
255 		}
256 		bcc.add(address);
257 	}
258 
259 	/***
260 	 * BCC¥¢¥É¥?¥¹¤òÄɲä·¤Þ¤¹¡£
261 	 * 
262 	 * @param email BCC¤Î¥¢¥É¥?¥¹
263 	 * @throws IllegalArgumentException ÉÔÀµ¤Ê¥Õ¥©¡¼¥Þ¥Ã¥È¤Î¥¢¥É¥?¥¹¤¬»ØÄꤵ¤?¤¿¾?¹?
264 	 */
265 	public void addBcc(String email) throws IllegalArgumentException {
266 		try {
267 			addBcc(new InternetAddress(email));
268 		} catch (AddressException e) {
269 			throw new IllegalArgumentException(e.getMessage());
270 		}
271 	}
272 
273 	/***
274 	 * ¥á¡¼¥?¤ÎBCC¥¢¥É¥?¥¹¤ÎÇÛÎó¤òÊÖ¤·¤Þ¤¹¡£
275 	 * BCC¥¢¥É¥?¥¹¤¬°?·?¤â¥»¥Ã¥È¤µ¤?¤Æ¤¤¤Ê¤¤¤È¤­¤Ï¶õ¤ÎÇÛÎó¤òÊÖ¤·¤Þ¤¹¡£
276 	 * 
277 	 * @return BCC¥¢¥É¥?¥¹¤ÎÇÛÎ?
278 	 */
279 	public InternetAddress[] getBcc() {
280 		if (bcc == null) {
281 			return new InternetAddress[0];
282 		}
283 		return (InternetAddress[])bcc.toArray(new InternetAddress[bcc.size()]);
284 	}
285 
286 	/***
287 	 * ¥á¡¼¥?¤Îº¹½Ð¿Í¥¢¥É¥?¥¹¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£
288 	 * 
289 	 * @param address º¹½Ð¿Í¥¢¥É¥?¥¹
290 	 */
291 	public void setFrom(InternetAddress address) {
292 		from = address;
293 	}
294 
295 	/***
296 	 * ¥á¡¼¥?¤Îº¹½Ð¿Í¥¢¥É¥?¥¹¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£
297 	 * 
298 	 * @param email º¹½Ð¿Í¥¢¥É¥?¥¹
299 	 * @throws IllegalArgumentException ÉÔÀµ¤Ê¥Õ¥©¡¼¥Þ¥Ã¥È¤Î¥¢¥É¥?¥¹¤¬»ØÄꤵ¤?¤¿¾?¹?
300 	 */
301 	public void setFrom(String email) throws IllegalArgumentException {
302 		try {
303 			setFrom(new InternetAddress(email));
304 		} catch (AddressException e) {
305 			throw new IllegalArgumentException(e.getMessage());
306 		}
307 	}
308 
309 	/***
310 	 * ¥á¡¼¥?¤Îº¹½Ð¿Í̾¤È¥¢¥É¥?¥¹¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£
311 	 * ̾Á°¤ÏJIS_CHARSET¤Ç¥¨¥ó¥³¡¼¥É¤µ¤?¤Þ¤¹¡£
312 	 * 
313 	 * @param email º¹½Ð¿Í¥¢¥É¥?¥¹
314 	 * @param name º¹½Ð¿Í̾
315 	 * @throws IllegalArgumentException ÉÔÀµ¤Ê¥Õ¥©¡¼¥Þ¥Ã¥È¤Î¥¢¥É¥?¥¹¤¬»ØÄꤵ¤?¤¿¾?¹?
316 	 */
317 	public void setFrom(String email, String name) throws IllegalArgumentException {
318 		if (charset.equals(JIS_CHARSET)) {
319 			name = Cp932.toJIS(name);
320 		}
321 		try {
322 			setFrom(new InternetAddress(email, name, charset));
323 		} catch (UnsupportedEncodingException e) {
324 			throw new IllegalArgumentException(e.getMessage());
325 		}
326 	}
327 
328 	/***
329 	 * ¥á¡¼¥?¤Îº¹½Ð¿Í¥¢¥É¥?¥¹¤òÊÖ¤·¤Þ¤¹¡£¥»¥Ã¥È¤µ¤?¤Æ¤¤¤Ê¤¤¾?¹ç¤Ïnull¤òÊÖ¤·¤Þ¤¹¡£
330 	 * 
331 	 * @return ¥á¡¼¥?¤Îº¹½Ð¿Í¥¢¥É¥?¥¹
332 	 */
333 	public InternetAddress getFrom() {
334 		return from;
335 	}
336 
337 	/***
338 	 * Return-Path¥¢¥É¥?¥¹¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£
339 	 * 
340 	 * @param address Return-Path¥¢¥É¥?¥¹
341 	 */
342 	public void setReturnPath(InternetAddress address) {
343 		returnPath = address;
344 	}
345 
346 	/***
347 	 * Return-Path¥¢¥É¥?¥¹¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£
348 	 * 
349 	 * @param email Return-Path¥¢¥É¥?¥¹
350 	 * @throws IllegalArgumentException ÉÔÀµ¤Ê¥Õ¥©¡¼¥Þ¥Ã¥È¤Î¥¢¥É¥?¥¹¤¬»ØÄꤵ¤?¤¿¾?¹?
351 	 */
352 	public void setReturnPath(String email) throws IllegalArgumentException {
353 		try {
354 			setReturnPath(new InternetAddress(email));
355 		} catch (AddressException e) {
356 			throw new IllegalArgumentException(e.getMessage());
357 		}
358 	}
359 
360 	/***
361 	 * Return-Path¥¢¥É¥?¥¹¤òÊÖ¤·¤Þ¤¹¡£
362 	 * 
363 	 * @return Return-Path¥¢¥É¥?¥¹
364 	 */
365 	public InternetAddress getReturnPath() {
366 		return returnPath;
367 	}
368 
369 	/***
370 	 * ÊÖ¿®À襢¥É¥?¥¹¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£
371 	 * 
372 	 * @param address ÊÖ¿®À襢¥É¥?¥¹
373 	 */
374 	public void setReplyTo(InternetAddress address) {
375 		replyTo = address;
376 	}
377 
378 	/***
379 	 * ÊÖ¿®À襢¥É¥?¥¹¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£
380 	 * 
381 	 * @param email ÊÖ¿®À襢¥É¥?¥¹
382 	 * @throws IllegalArgumentException ÉÔÀµ¤Ê¥Õ¥©¡¼¥Þ¥Ã¥È¤Î¥¢¥É¥?¥¹¤¬»ØÄꤵ¤?¤¿¾?¹?
383 	 */
384 	public void setReplyTo(String email) throws IllegalArgumentException {
385 		try {
386 			setReplyTo(new InternetAddress(email));
387 		} catch (AddressException e) {
388 			throw new IllegalArgumentException(e.getMessage());
389 		}
390 	}
391 
392 	/***
393 	 * ¥á¡¼¥?¤ÎÊÖ¿®À襢¥É¥?¥¹¤òÊÖ¤·¤Þ¤¹¡£¥»¥Ã¥È¤µ¤?¤Æ¤¤¤Ê¤¤¾?¹ç¤Ïnull¤òÊÖ¤·¤Þ¤¹¡£
394 	 * 
395 	 * @return ÊÖ¿®À襢¥É¥?¥¹
396 	 */
397 	public InternetAddress getReplyTo() {
398 		return replyTo;
399 	}
400 
401 	/***
402 	 * ¥á¡¼¥?¤Î·?̾¤òÊÖ¤·¤Þ¤¹¡£¥»¥Ã¥È¤µ¤?¤Æ¤¤¤Ê¤¤¾?¹ç¤Ï¶õʸ»úÎó¤òÊÖ¤·¤Þ¤¹¡£
403 	 * 
404 	 * @return ¥á¡¼¥?¤Î·?̾
405 	 */
406 	public String getSubject() {
407 		if (subject == null) {
408 			return "";
409 		}
410 		return subject;
411 	}
412 
413 	/***
414 	 * ¥á¡¼¥?¤Î·?̾¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£
415 	 * 
416 	 * @param subject ¥á¡¼¥?¤Î·?̾
417 	 */
418 	public void setSubject(String subject) {
419 		this.subject = subject;
420 	}
421 
422 	/***
423 	 * ¥á¡¼¥?ËÜʸ¤òÊÖ¤·¤Þ¤¹¡£
424 	 * ËÜʸ¥»¥Ã¥È¤µ¤?¤Æ¤¤¤Ê¤¤¾?¹ç¤Ï¶õʸ»úÎó¤òÊÖ¤·¤Þ¤¹¡£
425 	 * 
426 	 * @return ¥á¡¼¥?ËÜʸ
427 	 */
428 	public String getText() {
429 		if (text == null) {
430 			return "";
431 		}
432 		return text;
433 	}
434 
435 	/***
436 	 * ¥á¡¼¥?ËÜʸ¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£
437 	 * 
438 	 * @param text ¥á¡¼¥?ËÜʸ
439 	 */
440 	public void setText(String text) {
441 		this.text = text;
442 	}
443 
444 	/***
445 	 * ¥á¡¼¥?¥Ø¥Ã¥À¤ËǤ°Õ¤Î¥Ø¥Ã¥À¤òÄɲä·¤Þ¤¹¡£
446 	 * Ǥ°Õ¥Ø¥Ã¥À¤Ï¡ÖX-key: value¡×¤Î¥Õ¥©¡¼¥Þ¥Ã¥È¤Ç¥á¡¼¥?¥Ø¥Ã¥À¤ËÁȤ߹?¤Þ¤?¤Þ¤¹¡£
447 	 *  
448 	 * @param key Ǥ°Õ¥Ø¥Ã¥À̾¡£Æ¬¤¬"X-"¤Ç»Ï¤Þ¤Ã¤Æ¤¤¤Ê¤±¤?¤Ð¡¢¼«Æ°Åª¤ËÉÕÍ¿¤µ¤?¤Þ¤¹¡£
449 	 * @param value Ǥ°Õ¥Ø¥Ã¥À¤ÎÃÍ
450 	 */
451 	public void addXHeader(String key, String value) {
452 		if (xHeaders == null) {
453 			xHeaders = new HashMap();
454 		}
455 		if (key.startsWith("X-")) {
456 			xHeaders.put(key, value);
457 		} else {
458 			xHeaders.put("X-" + key, value);
459 		}
460 	}
461 
462 	/***
463 	 * ¥á¡¼¥?¤ÎǤ°Õ¥Ø¥Ã¥À̾¤ÈÃͤÎMap¥¤¥ó¥¹¥¿¥ó¥¹¤òÊÖ¤·¤Þ¤¹¡£
464 	 * Ǥ°Õ¥Ø¥Ã¥À¤¬°?·?¤â¥»¥Ã¥È¤µ¤?¤Æ¤¤¤Ê¤¤¤È¤­¤Ïnull¤òÊÖ¤·¤Þ¤¹¡£
465 	 * <p>
466 	 * ¤³¤ÎMap¥¤¥ó¥¹¥¿¥ó¥¹¤Ø¤Î½¤Àµ¤Ï¤Ç¤­¤Þ¤»¤ó¡£(unmodifiableMap¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£)
467 	 * 
468 	 * @return ¥á¡¼¥?¤ÎǤ°Õ¥Ø¥Ã¥À̾¤ÈÃͤÎMap¥¤¥ó¥¹¥¿¥ó¥¹¡£¤Þ¤¿¤Ïnull¡£
469 	 */
470 	public Map getXHeaders() {
471 		if (xHeaders == null) {
472 			return null;
473 		}
474 		return Collections.unmodifiableMap(xHeaders);
475 	}
476 
477 	/***
478 	 * ¥á¡¼¥?ÆâÍÆ¤ò½ÐÎϤ·¤Þ¤¹¡£<br>
479 	 * ¥á¡¼¥?¤Î¥½¡¼¥¹¤Ë»÷¤¿¥Õ¥©¡¼¥Þ¥Ã¥È¤Ç½ÐÎϤµ¤?¤Þ¤¹¡£
480 	 * 
481 	 * @see java.lang.Object#toString()
482 	 */
483 	public String toString() {
484 		StringBuffer buf = new StringBuffer(1000);
485 		buf.append("Mail\n");
486 		buf.append("Return-Path: ").append(returnPath).append("\n");
487 		buf.append("From: ").append(from != null ? from.toUnicodeString() : null).append("\n");
488 		buf.append("To: ").append(arrayToCommaDelimitedString(to)).append("\n");
489 		buf.append("Cc: ").append(arrayToCommaDelimitedString(cc)).append("\n");
490 		buf.append("Bcc: ").append(arrayToCommaDelimitedString(bcc)).append("\n");
491 		buf.append("Subject: ").append(subject).append("\n");
492 
493 		if (xHeaders != null) {
494 			for (Iterator itr = xHeaders.keySet().iterator(); itr.hasNext();) {
495 				String header = (String)itr.next();
496 				String value = (String)xHeaders.get(header);
497 				buf.append(header).append(": ").append(value).append("\n");
498 			}
499 		}
500 
501 		buf.append("\n");
502 		buf.append(text);
503 
504 		return buf.toString();
505 	}
506 
507 	/***
508 	 * @param list
509 	 * @return 
510 	 */
511 	private String arrayToCommaDelimitedString(List list) {
512 		if (list == null) {
513 			return "null";
514 		} else {
515 			StringBuffer sb = new StringBuffer();
516 			for (int i = 0, num = list.size(); i < num; i++) {
517 				if (i > 0) {
518 					sb.append(", ");
519 				}
520 				sb.append(((InternetAddress)list.get(i)).toUnicodeString());
521 			}
522 			return sb.toString();
523 		}
524 	}
525 
526 	/***
527 	 * ¥»¥Ã¥È¤µ¤?¤Æ¤¤¤?Á÷¿®À襢¥É¥?¥¹(To¥¢¥É¥?¥¹)¤òÁ´¤Æ¥¯¥?¥¢¤·¤Þ¤¹¡£
528 	 *
529 	 * @since 1.0.2
530 	 */
531 	public void clearTo() {
532 		to = null;
533 	}
534 
535 	/***
536 	 * ¥»¥Ã¥È¤µ¤?¤Æ¤¤¤?CC¥¢¥É¥?¥¹¤òÁ´¤Æ¥¯¥?¥¢¤·¤Þ¤¹¡£
537 	 *
538 	 * @since 1.0.2
539 	 */
540 	public void clearCc() {
541 		cc = null;
542 	}
543 
544 	/***
545 	 * ¥»¥Ã¥È¤µ¤?¤Æ¤¤¤?BCC¥¢¥É¥?¥¹¤òÁ´¤Æ¥¯¥?¥¢¤·¤Þ¤¹¡£
546 	 *
547 	 * @since 1.0.2
548 	 */
549 	public void clearBcc() {
550 		bcc = null;
551 	}
552 
553 	/***
554 	 * ¥á¡¼¥?¤Î½ÅÍ×ÅÙ¡£Ä?¿ô¤Î¤ß¤òÄ?µÁ¡£
555 	 * 
556 	 * @author Tomohiro Otsuka
557 	 * @version $Id: Mail.java,v 1.8 2004/09/16 04:52:45 otsuka Exp $
558 	 */
559 	public static class Importance {
560 
561 		/*** ½ÅÍ×ÅÙ¡Ö¹â¡× */
562 		public static final String HIGH = "high";
563 
564 		/*** ½ÅÍ×ÅÙ¡ÖÃæ¡× */
565 		public static final String NORMAL = "normal";
566 
567 		/*** ½ÅÍ×ÅÙ¡ÖÄã¡× */
568 		public static final String LOW = "low";
569 
570 	}
571 }