OSDN Git Service

CVS最新版の全ファイルを追加
[spring-ext/ozacc-mail.git] / src / java / com / ozacc / mail / fetch / impl / sk_jp / FirstPlainPartExtractor.java
1 /*\r
2  * @(#) $Id: FirstPlainPartExtractor.java,v 1.1.2.1 2004/09/29 00:57:59 otsuka Exp $\r
3  * $Revision: 1.1.2.1 $\r
4  * Copyright (c) 2000 Shin Kinoshita All Rights Reserved.\r
5  */\r
6 package com.ozacc.mail.fetch.impl.sk_jp;\r
7 \r
8 import java.io.IOException;\r
9 import javax.mail.Part;\r
10 import javax.mail.MessagingException;\r
11 import javax.mail.internet.ContentType;\r
12 \r
13 /**\r
14  * 最初に見つけたtext/plainパートの本文を得るPartHandlerです。\r
15  * <P>\r
16  * </P>\r
17  * @version $Revision: 1.1.2.1 $ $Date: 2004/09/29 00:57:59 $\r
18  * @author Shin\r
19  */\r
20 public class FirstPlainPartExtractor implements PartHandler {\r
21 \r
22         private String text = null;\r
23 \r
24         public boolean processPart(Part part, ContentType context) throws MessagingException,\r
25                                                                                                                                 IOException {\r
26                 String type = part.getContentType();\r
27                 // Bug fixed. Thx > ei\r
28                 // http://www.sk-jp.com/cgi-bin/treebbs.cgi?kako=1&all=1292&s=1292\r
29                 if (!part.isMimeType("text/plain") && type != null && !type.trim().equalsIgnoreCase("text")) {\r
30                         return true;\r
31                 }\r
32                 text = (String)MultipartUtility.getContent(part);\r
33                 return false;\r
34         }\r
35 \r
36         public String getText() {\r
37                 return text;\r
38         }\r
39 \r
40         public static void main(String[] args) throws Exception {\r
41                 javax.mail.internet.MimeMessage msg = new javax.mail.internet.MimeMessage(\r
42                                 javax.mail.Session.getDefaultInstance(System.getProperties(), null), System.in);\r
43                 FirstPlainPartExtractor h = new FirstPlainPartExtractor();\r
44                 MultipartUtility.process(msg, h);\r
45 \r
46                 System.out.println("This is the first detected text/plain part.");\r
47                 System.out.println(h.getText());\r
48         }\r
49 }