1 21 22 27 28 package javax.mail.search; 29 30 import javax.mail.Message ; 31 32 39 public final class HeaderTerm extends StringTerm { 40 45 protected String headerName; 46 47 private static final long serialVersionUID = 8342514650333389122L; 48 49 55 public HeaderTerm(String headerName, String pattern) { 56 super(pattern); 57 this.headerName = headerName; 58 } 59 60 63 public String getHeaderName() { 64 return headerName; 65 } 66 67 73 public boolean match(Message msg) { 74 String [] headers; 75 76 try { 77 headers = msg.getHeader(headerName); 78 } catch (Exception e) { 79 return false; 80 } 81 82 if (headers == null) 83 return false; 84 85 for (int i=0; i < headers.length; i++) 86 if (super.match(headers[i])) 87 return true; 88 return false; 89 } 90 91 94 public boolean equals(Object obj) { 95 if (!(obj instanceof HeaderTerm )) 96 return false; 97 HeaderTerm ht = (HeaderTerm )obj; 98 return ht.headerName.equalsIgnoreCase(headerName) && super.equals(ht); 100 } 101 102 105 public int hashCode() { 106 return headerName.toLowerCase().hashCode() + super.hashCode(); 108 } 109 } 110 | Popular Tags |