1 21 22 27 28 package javax.mail.search; 29 30 import javax.mail.*; 31 32 39 public final class BodyTerm extends StringTerm { 40 41 private static final long serialVersionUID = -4888862527916911385L; 42 43 47 public BodyTerm(String pattern) { 48 super(pattern); 50 } 51 52 58 public boolean match(Message msg) { 59 return matchPart(msg); 60 } 61 62 66 private boolean matchPart(Part p) { 67 try { 68 72 if (p.isMimeType("text/*")) { 73 String s = (String )p.getContent(); 74 if (s == null) 75 return false; 76 84 return super.match(s); 85 } else if (p.isMimeType("multipart/*")) { 86 Multipart mp = (Multipart)p.getContent(); 87 int count = mp.getCount(); 88 for (int i = 0; i < count; i++) 89 if (matchPart(mp.getBodyPart(i))) 90 return true; 91 } else if (p.isMimeType("message/rfc822")) { 92 return matchPart((Part)p.getContent()); 93 } 94 } catch (Exception ex) { 95 } 96 return false; 97 } 98 99 102 public boolean equals(Object obj) { 103 if (!(obj instanceof BodyTerm )) 104 return false; 105 return super.equals(obj); 106 } 107 } 108 | Popular Tags |