OSDN Git Service

Migrated to jakarta namespace and bumped version number to 2.0.0
[spring-ext/ozacc-mail.git] / src / main / java / com / ozacc / mail / fetch / impl / sk_jp / PlainPartExtractor.java
1 /*
2  * @(#) $Id: PlainPartExtractor.java,v 1.1.2.1 2004/09/29 00:57:59 otsuka Exp $
3  * $Revision: 1.1.2.1 $
4  * Copyright (c) 2000 Shin Kinoshita All Rights Reserved.
5  */
6 package com.ozacc.mail.fetch.impl.sk_jp;
7
8 import java.io.IOException;
9
10 import jakarta.mail.MessagingException;
11 import jakarta.mail.Part;
12 import jakarta.mail.internet.ContentType;
13 import jakarta.mail.internet.MimeMessage;
14
15 /**
16  * text/plainを結合した文字列を得るPartHandlerです。
17  * 
18  * @version $Revision: 1.1.2.1 $ $Date: 2004/09/29 00:57:59 $
19  * @author Shin
20  */
21 public class PlainPartExtractor implements PartHandler {
22
23         private String text = null;
24
25         public boolean processPart(Part part, ContentType context) throws MessagingException,
26                                                                                                                                 IOException {
27                 if (!part.isMimeType("text/plain")) {
28                         return true;
29                 }
30                 if (text == null) {
31                         // 最初のテキストパートを無条件に抽出
32                         text = (String)MultipartUtility.getContent(part);
33                 } else {
34                         String disposition = part.getDisposition();
35                         if (disposition == null || disposition.equalsIgnoreCase(Part.INLINE)) {
36                                 text += "\r\n\r\n-- inline --\r\n\r\n" + (String)MultipartUtility.getContent(part);
37                         }
38                 }
39                 return true;
40         }
41
42         public String getText() {
43                 return text;
44         }
45
46         public static void main(String[] args) throws Exception {
47                 MimeMessage msg = new MimeMessage(jakarta.mail.Session.getDefaultInstance(System
48                                 .getProperties(), null), System.in);
49                 PlainPartExtractor h = new PlainPartExtractor();
50                 MultipartUtility.process(msg, h);
51
52                 System.out.println("This is the detected text/plain parts.");
53                 System.out.println(h.getText());
54         }
55 }