1 21 22 package org.armedbear.j.mail; 23 24 import java.util.List ; 25 import org.armedbear.j.Utilities; 26 27 public final class GenericMailboxFilter extends MailboxFilter 28 { 29 private String pattern; 30 private boolean ignoreCase; 31 32 public GenericMailboxFilter(String pattern) 33 { 34 this.pattern = pattern; 35 ignoreCase = Utilities.isLowerCase(pattern); 36 } 37 38 public boolean accept(MailboxEntry entry) 39 { 40 String subject = entry.getSubject(); 41 if (subject != null) { 42 if (ignoreCase) { 43 if (subject.toLowerCase().indexOf(pattern) >= 0) 44 return true; } else { 46 if (subject.indexOf(pattern) >= 0) 47 return true; } 49 } 50 MailAddress[] from = entry.getFrom(); 51 if (from != null) { 52 if (ignoreCase) { 53 for (int i = from.length-1; i >= 0; i--) { 54 if (from[i].matchesIgnoreCase(pattern)) 55 return true; 56 } 57 } else { 58 for (int i = from.length-1; i >= 0; i--) { 59 if (from[i].matches(pattern)) 60 return true; 61 } 62 } 63 } 64 return false; 65 } 66 } 67 | Popular Tags |