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