1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| package javax.mail.search; |
19 |
| |
20 |
| import java.io.IOException; |
21 |
| import javax.mail.Message; |
22 |
| import javax.mail.MessagingException; |
23 |
| import javax.mail.Part; |
24 |
| import javax.mail.Multipart; |
25 |
| import javax.mail.BodyPart; |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| public final class BodyTerm extends StringTerm { |
34 |
0
| public BodyTerm(String pattern) {
|
35 |
0
| super(pattern);
|
36 |
| } |
37 |
| |
38 |
0
| public boolean match(Message message) {
|
39 |
0
| try {
|
40 |
0
| return matchPart(message);
|
41 |
| } catch (IOException e) { |
42 |
0
| return false;
|
43 |
| } catch (MessagingException e) { |
44 |
0
| return false;
|
45 |
| } |
46 |
| } |
47 |
| |
48 |
0
| private boolean matchPart(Part part) throws MessagingException, IOException {
|
49 |
0
| if (part.isMimeType("multipart/*")) {
|
50 |
0
| Multipart mp = (Multipart) part.getContent();
|
51 |
0
| int count = mp.getCount();
|
52 |
0
| for (int i=0; i < count; i++) {
|
53 |
0
| BodyPart bp = mp.getBodyPart(i);
|
54 |
0
| if (matchPart(bp)) {
|
55 |
0
| return true;
|
56 |
| } |
57 |
| } |
58 |
0
| return false;
|
59 |
0
| } else if (part.isMimeType("text/*")) {
|
60 |
0
| String content = (String) part.getContent();
|
61 |
0
| return super.match(content);
|
62 |
| } else { |
63 |
0
| return false;
|
64 |
| } |
65 |
| } |
66 |
| } |