1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
package com.ozacc.mail.fetch.impl.sk_jp; |
7 |
|
|
8 |
|
import java.io.IOException; |
9 |
|
|
10 |
|
import javax.mail.MessagingException; |
11 |
|
import javax.mail.Part; |
12 |
|
import javax.mail.internet.ContentType; |
13 |
|
import javax.mail.internet.MimeMessage; |
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
0 |
public class PlainPartExtractor implements PartHandler { |
22 |
|
|
23 |
0 |
private String text = null; |
24 |
|
|
25 |
|
public boolean processPart(Part part, ContentType context) throws MessagingException, |
26 |
|
IOException { |
27 |
0 |
if (!part.isMimeType("text/plain")) { |
28 |
0 |
return true; |
29 |
|
} |
30 |
0 |
if (text == null) { |
31 |
|
|
32 |
0 |
text = (String)MultipartUtility.getContent(part); |
33 |
|
} else { |
34 |
0 |
String disposition = part.getDisposition(); |
35 |
0 |
if (disposition == null || disposition.equalsIgnoreCase(Part.INLINE)) { |
36 |
0 |
text += "\r\n\r\n-- inline --\r\n\r\n" + (String)MultipartUtility.getContent(part); |
37 |
|
} |
38 |
|
} |
39 |
0 |
return true; |
40 |
|
} |
41 |
|
|
42 |
|
public String getText() { |
43 |
0 |
return text; |
44 |
|
} |
45 |
|
|
46 |
|
public static void main(String[] args) throws Exception { |
47 |
0 |
MimeMessage msg = new MimeMessage(javax.mail.Session.getDefaultInstance(System |
48 |
0 |
.getProperties(), null), System.in); |
49 |
0 |
PlainPartExtractor h = new PlainPartExtractor(); |
50 |
0 |
MultipartUtility.process(msg, h); |
51 |
|
|
52 |
0 |
System.out.println("This is the detected text/plain parts."); |
53 |
0 |
System.out.println(h.getText()); |
54 |
0 |
} |
55 |
|
} |