first commit
This commit is contained in:
commit
4d332ef662
27586 changed files with 3281783 additions and 0 deletions
|
|
@ -0,0 +1,26 @@
|
|||
package javax.mail.search;
|
||||
|
||||
import javax.mail.Address;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
|
||||
public abstract class AddressStringTerm extends StringTerm {
|
||||
private static final long serialVersionUID = 3086821234204980368L;
|
||||
|
||||
protected AddressStringTerm(String pattern) {
|
||||
super(pattern, true);
|
||||
}
|
||||
|
||||
protected boolean match(Address a) {
|
||||
if (a instanceof InternetAddress) {
|
||||
InternetAddress ia = (InternetAddress)a;
|
||||
return match(ia.toUnicodeString());
|
||||
}
|
||||
return match(a.toString());
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof AddressStringTerm))
|
||||
return false;
|
||||
return super.equals(obj);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package javax.mail.search;
|
||||
|
||||
import javax.mail.Address;
|
||||
|
||||
public abstract class AddressTerm extends SearchTerm {
|
||||
protected Address address;
|
||||
|
||||
private static final long serialVersionUID = 2005405551929769980L;
|
||||
|
||||
protected AddressTerm(Address address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public Address getAddress() {
|
||||
return this.address;
|
||||
}
|
||||
|
||||
protected boolean match(Address a) {
|
||||
return a.equals(this.address);
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof AddressTerm))
|
||||
return false;
|
||||
AddressTerm at = (AddressTerm)obj;
|
||||
return at.address.equals(this.address);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.address.hashCode();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
package javax.mail.search;
|
||||
|
||||
import javax.mail.Message;
|
||||
|
||||
public final class AndTerm extends SearchTerm {
|
||||
private SearchTerm[] terms;
|
||||
|
||||
private static final long serialVersionUID = -3583274505380989582L;
|
||||
|
||||
public AndTerm(SearchTerm t1, SearchTerm t2) {
|
||||
this.terms = new SearchTerm[2];
|
||||
this.terms[0] = t1;
|
||||
this.terms[1] = t2;
|
||||
}
|
||||
|
||||
public AndTerm(SearchTerm[] t) {
|
||||
this.terms = new SearchTerm[t.length];
|
||||
for (int i = 0; i < t.length; i++)
|
||||
this.terms[i] = t[i];
|
||||
}
|
||||
|
||||
public SearchTerm[] getTerms() {
|
||||
return (SearchTerm[])this.terms.clone();
|
||||
}
|
||||
|
||||
public boolean match(Message msg) {
|
||||
for (int i = 0; i < this.terms.length; i++) {
|
||||
if (!this.terms[i].match(msg))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof AndTerm))
|
||||
return false;
|
||||
AndTerm at = (AndTerm)obj;
|
||||
if (at.terms.length != this.terms.length)
|
||||
return false;
|
||||
for (int i = 0; i < this.terms.length; i++) {
|
||||
if (!this.terms[i].equals(at.terms[i]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int hash = 0;
|
||||
for (int i = 0; i < this.terms.length; i++)
|
||||
hash += this.terms[i].hashCode();
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package javax.mail.search;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.mail.Message;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Multipart;
|
||||
import javax.mail.Part;
|
||||
|
||||
public final class BodyTerm extends StringTerm {
|
||||
private static final long serialVersionUID = -4888862527916911385L;
|
||||
|
||||
public BodyTerm(String pattern) {
|
||||
super(pattern);
|
||||
}
|
||||
|
||||
public boolean match(Message msg) {
|
||||
return matchPart(msg);
|
||||
}
|
||||
|
||||
private boolean matchPart(Part p) {
|
||||
try {
|
||||
if (p.isMimeType("text/*")) {
|
||||
String s = (String)p.getContent();
|
||||
if (s == null)
|
||||
return false;
|
||||
return match(s);
|
||||
}
|
||||
if (p.isMimeType("multipart/*")) {
|
||||
Multipart mp = (Multipart)p.getContent();
|
||||
int count = mp.getCount();
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (matchPart(mp.getBodyPart(i)))
|
||||
return true;
|
||||
}
|
||||
} else if (p.isMimeType("message/rfc822")) {
|
||||
return matchPart((Part)p.getContent());
|
||||
}
|
||||
} catch (MessagingException e) {
|
||||
|
||||
} catch (IOException e) {
|
||||
|
||||
} catch (RuntimeException e) {}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof BodyTerm))
|
||||
return false;
|
||||
return super.equals(obj);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package javax.mail.search;
|
||||
|
||||
public abstract class ComparisonTerm extends SearchTerm {
|
||||
public static final int LE = 1;
|
||||
|
||||
public static final int LT = 2;
|
||||
|
||||
public static final int EQ = 3;
|
||||
|
||||
public static final int NE = 4;
|
||||
|
||||
public static final int GT = 5;
|
||||
|
||||
public static final int GE = 6;
|
||||
|
||||
protected int comparison;
|
||||
|
||||
private static final long serialVersionUID = 1456646953666474308L;
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof ComparisonTerm))
|
||||
return false;
|
||||
ComparisonTerm ct = (ComparisonTerm)obj;
|
||||
return (ct.comparison == this.comparison);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.comparison;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package javax.mail.search;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public abstract class DateTerm extends ComparisonTerm {
|
||||
protected Date date;
|
||||
|
||||
private static final long serialVersionUID = 4818873430063720043L;
|
||||
|
||||
protected DateTerm(int comparison, Date date) {
|
||||
this.comparison = comparison;
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return new Date(this.date.getTime());
|
||||
}
|
||||
|
||||
public int getComparison() {
|
||||
return this.comparison;
|
||||
}
|
||||
|
||||
protected boolean match(Date d) {
|
||||
switch (this.comparison) {
|
||||
case 1:
|
||||
return (d.before(this.date) || d.equals(this.date));
|
||||
case 2:
|
||||
return d.before(this.date);
|
||||
case 3:
|
||||
return d.equals(this.date);
|
||||
case 4:
|
||||
return !d.equals(this.date);
|
||||
case 5:
|
||||
return d.after(this.date);
|
||||
case 6:
|
||||
return (d.after(this.date) || d.equals(this.date));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof DateTerm))
|
||||
return false;
|
||||
DateTerm dt = (DateTerm)obj;
|
||||
return (dt.date.equals(this.date) && super.equals(obj));
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.date.hashCode() + super.hashCode();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
package javax.mail.search;
|
||||
|
||||
import javax.mail.Flags;
|
||||
import javax.mail.Message;
|
||||
import javax.mail.MessagingException;
|
||||
|
||||
public final class FlagTerm extends SearchTerm {
|
||||
private boolean set;
|
||||
|
||||
private Flags flags;
|
||||
|
||||
private static final long serialVersionUID = -142991500302030647L;
|
||||
|
||||
public FlagTerm(Flags flags, boolean set) {
|
||||
this.flags = flags;
|
||||
this.set = set;
|
||||
}
|
||||
|
||||
public Flags getFlags() {
|
||||
return (Flags)this.flags.clone();
|
||||
}
|
||||
|
||||
public boolean getTestSet() {
|
||||
return this.set;
|
||||
}
|
||||
|
||||
public boolean match(Message msg) {
|
||||
try {
|
||||
Flags f = msg.getFlags();
|
||||
if (this.set) {
|
||||
if (f.contains(this.flags))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
Flags.Flag[] sf = this.flags.getSystemFlags();
|
||||
for (int i = 0; i < sf.length; i++) {
|
||||
if (f.contains(sf[i]))
|
||||
return false;
|
||||
}
|
||||
String[] s = this.flags.getUserFlags();
|
||||
for (int j = 0; j < s.length; j++) {
|
||||
if (f.contains(s[j]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch (MessagingException e) {
|
||||
return false;
|
||||
} catch (RuntimeException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof FlagTerm))
|
||||
return false;
|
||||
FlagTerm ft = (FlagTerm)obj;
|
||||
return (ft.set == this.set && ft.flags.equals(this.flags));
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.set ? this.flags.hashCode() : (this.flags.hashCode() ^ 0xFFFFFFFF);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package javax.mail.search;
|
||||
|
||||
import javax.mail.Address;
|
||||
import javax.mail.Message;
|
||||
|
||||
public final class FromStringTerm extends AddressStringTerm {
|
||||
private static final long serialVersionUID = 5801127523826772788L;
|
||||
|
||||
public FromStringTerm(String pattern) {
|
||||
super(pattern);
|
||||
}
|
||||
|
||||
public boolean match(Message msg) {
|
||||
Address[] from;
|
||||
try {
|
||||
from = msg.getFrom();
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
if (from == null)
|
||||
return false;
|
||||
for (int i = 0; i < from.length; i++) {
|
||||
if (match(from[i]))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof FromStringTerm))
|
||||
return false;
|
||||
return super.equals(obj);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package javax.mail.search;
|
||||
|
||||
import javax.mail.Address;
|
||||
import javax.mail.Message;
|
||||
|
||||
public final class FromTerm extends AddressTerm {
|
||||
private static final long serialVersionUID = 5214730291502658665L;
|
||||
|
||||
public FromTerm(Address address) {
|
||||
super(address);
|
||||
}
|
||||
|
||||
public boolean match(Message msg) {
|
||||
Address[] from;
|
||||
try {
|
||||
from = msg.getFrom();
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
if (from == null)
|
||||
return false;
|
||||
for (int i = 0; i < from.length; i++) {
|
||||
if (match(from[i]))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof FromTerm))
|
||||
return false;
|
||||
return super.equals(obj);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package javax.mail.search;
|
||||
|
||||
import java.util.Locale;
|
||||
import javax.mail.Message;
|
||||
|
||||
public final class HeaderTerm extends StringTerm {
|
||||
private String headerName;
|
||||
|
||||
private static final long serialVersionUID = 8342514650333389122L;
|
||||
|
||||
public HeaderTerm(String headerName, String pattern) {
|
||||
super(pattern);
|
||||
this.headerName = headerName;
|
||||
}
|
||||
|
||||
public String getHeaderName() {
|
||||
return this.headerName;
|
||||
}
|
||||
|
||||
public boolean match(Message msg) {
|
||||
String[] headers;
|
||||
try {
|
||||
headers = msg.getHeader(this.headerName);
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
if (headers == null)
|
||||
return false;
|
||||
for (int i = 0; i < headers.length; i++) {
|
||||
if (match(headers[i]))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof HeaderTerm))
|
||||
return false;
|
||||
HeaderTerm ht = (HeaderTerm)obj;
|
||||
return (ht.headerName.equalsIgnoreCase(this.headerName) && super.equals(ht));
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.headerName.toLowerCase(Locale.ENGLISH).hashCode() + super.hashCode();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
package javax.mail.search;
|
||||
|
||||
public abstract class IntegerComparisonTerm extends ComparisonTerm {
|
||||
protected int number;
|
||||
|
||||
private static final long serialVersionUID = -6963571240154302484L;
|
||||
|
||||
protected IntegerComparisonTerm(int comparison, int number) {
|
||||
this.comparison = comparison;
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public int getNumber() {
|
||||
return this.number;
|
||||
}
|
||||
|
||||
public int getComparison() {
|
||||
return this.comparison;
|
||||
}
|
||||
|
||||
protected boolean match(int i) {
|
||||
switch (this.comparison) {
|
||||
case 1:
|
||||
return (i <= this.number);
|
||||
case 2:
|
||||
return (i < this.number);
|
||||
case 3:
|
||||
return (i == this.number);
|
||||
case 4:
|
||||
return (i != this.number);
|
||||
case 5:
|
||||
return (i > this.number);
|
||||
case 6:
|
||||
return (i >= this.number);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof IntegerComparisonTerm))
|
||||
return false;
|
||||
IntegerComparisonTerm ict = (IntegerComparisonTerm)obj;
|
||||
return (ict.number == this.number && super.equals(obj));
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.number + super.hashCode();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package javax.mail.search;
|
||||
|
||||
import javax.mail.Message;
|
||||
|
||||
public final class MessageIDTerm extends StringTerm {
|
||||
private static final long serialVersionUID = -2121096296454691963L;
|
||||
|
||||
public MessageIDTerm(String msgid) {
|
||||
super(msgid);
|
||||
}
|
||||
|
||||
public boolean match(Message msg) {
|
||||
String[] s;
|
||||
try {
|
||||
s = msg.getHeader("Message-ID");
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
if (s == null)
|
||||
return false;
|
||||
for (int i = 0; i < s.length; i++) {
|
||||
if (match(s[i]))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof MessageIDTerm))
|
||||
return false;
|
||||
return super.equals(obj);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package javax.mail.search;
|
||||
|
||||
import javax.mail.Message;
|
||||
|
||||
public final class MessageNumberTerm extends IntegerComparisonTerm {
|
||||
private static final long serialVersionUID = -5379625829658623812L;
|
||||
|
||||
public MessageNumberTerm(int number) {
|
||||
super(3, number);
|
||||
}
|
||||
|
||||
public boolean match(Message msg) {
|
||||
int msgno;
|
||||
try {
|
||||
msgno = msg.getMessageNumber();
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
return match(msgno);
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof MessageNumberTerm))
|
||||
return false;
|
||||
return super.equals(obj);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package javax.mail.search;
|
||||
|
||||
import javax.mail.Message;
|
||||
|
||||
public final class NotTerm extends SearchTerm {
|
||||
private SearchTerm term;
|
||||
|
||||
private static final long serialVersionUID = 7152293214217310216L;
|
||||
|
||||
public NotTerm(SearchTerm t) {
|
||||
this.term = t;
|
||||
}
|
||||
|
||||
public SearchTerm getTerm() {
|
||||
return this.term;
|
||||
}
|
||||
|
||||
public boolean match(Message msg) {
|
||||
return !this.term.match(msg);
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof NotTerm))
|
||||
return false;
|
||||
NotTerm nt = (NotTerm)obj;
|
||||
return nt.term.equals(this.term);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.term.hashCode() << 1;
|
||||
}
|
||||
}
|
||||
53
rus/WEB-INF/lib/javax.mail_src/javax/mail/search/OrTerm.java
Normal file
53
rus/WEB-INF/lib/javax.mail_src/javax/mail/search/OrTerm.java
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
package javax.mail.search;
|
||||
|
||||
import javax.mail.Message;
|
||||
|
||||
public final class OrTerm extends SearchTerm {
|
||||
private SearchTerm[] terms;
|
||||
|
||||
private static final long serialVersionUID = 5380534067523646936L;
|
||||
|
||||
public OrTerm(SearchTerm t1, SearchTerm t2) {
|
||||
this.terms = new SearchTerm[2];
|
||||
this.terms[0] = t1;
|
||||
this.terms[1] = t2;
|
||||
}
|
||||
|
||||
public OrTerm(SearchTerm[] t) {
|
||||
this.terms = new SearchTerm[t.length];
|
||||
for (int i = 0; i < t.length; i++)
|
||||
this.terms[i] = t[i];
|
||||
}
|
||||
|
||||
public SearchTerm[] getTerms() {
|
||||
return (SearchTerm[])this.terms.clone();
|
||||
}
|
||||
|
||||
public boolean match(Message msg) {
|
||||
for (int i = 0; i < this.terms.length; i++) {
|
||||
if (this.terms[i].match(msg))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof OrTerm))
|
||||
return false;
|
||||
OrTerm ot = (OrTerm)obj;
|
||||
if (ot.terms.length != this.terms.length)
|
||||
return false;
|
||||
for (int i = 0; i < this.terms.length; i++) {
|
||||
if (!this.terms[i].equals(ot.terms[i]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int hash = 0;
|
||||
for (int i = 0; i < this.terms.length; i++)
|
||||
hash += this.terms[i].hashCode();
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package javax.mail.search;
|
||||
|
||||
import java.util.Date;
|
||||
import javax.mail.Message;
|
||||
|
||||
public final class ReceivedDateTerm extends DateTerm {
|
||||
private static final long serialVersionUID = -2756695246195503170L;
|
||||
|
||||
public ReceivedDateTerm(int comparison, Date date) {
|
||||
super(comparison, date);
|
||||
}
|
||||
|
||||
public boolean match(Message msg) {
|
||||
Date d;
|
||||
try {
|
||||
d = msg.getReceivedDate();
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
if (d == null)
|
||||
return false;
|
||||
return match(d);
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof ReceivedDateTerm))
|
||||
return false;
|
||||
return super.equals(obj);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package javax.mail.search;
|
||||
|
||||
import javax.mail.Address;
|
||||
import javax.mail.Message;
|
||||
|
||||
public final class RecipientStringTerm extends AddressStringTerm {
|
||||
private Message.RecipientType type;
|
||||
|
||||
private static final long serialVersionUID = -8293562089611618849L;
|
||||
|
||||
public RecipientStringTerm(Message.RecipientType type, String pattern) {
|
||||
super(pattern);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Message.RecipientType getRecipientType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public boolean match(Message msg) {
|
||||
Address[] recipients;
|
||||
try {
|
||||
recipients = msg.getRecipients(this.type);
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
if (recipients == null)
|
||||
return false;
|
||||
for (int i = 0; i < recipients.length; i++) {
|
||||
if (match(recipients[i]))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof RecipientStringTerm))
|
||||
return false;
|
||||
RecipientStringTerm rst = (RecipientStringTerm)obj;
|
||||
return (rst.type.equals(this.type) && super.equals(obj));
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.type.hashCode() + super.hashCode();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package javax.mail.search;
|
||||
|
||||
import javax.mail.Address;
|
||||
import javax.mail.Message;
|
||||
|
||||
public final class RecipientTerm extends AddressTerm {
|
||||
private Message.RecipientType type;
|
||||
|
||||
private static final long serialVersionUID = 6548700653122680468L;
|
||||
|
||||
public RecipientTerm(Message.RecipientType type, Address address) {
|
||||
super(address);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Message.RecipientType getRecipientType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public boolean match(Message msg) {
|
||||
Address[] recipients;
|
||||
try {
|
||||
recipients = msg.getRecipients(this.type);
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
if (recipients == null)
|
||||
return false;
|
||||
for (int i = 0; i < recipients.length; i++) {
|
||||
if (match(recipients[i]))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof RecipientTerm))
|
||||
return false;
|
||||
RecipientTerm rt = (RecipientTerm)obj;
|
||||
return (rt.type.equals(this.type) && super.equals(obj));
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.type.hashCode() + super.hashCode();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package javax.mail.search;
|
||||
|
||||
import javax.mail.MessagingException;
|
||||
|
||||
public class SearchException extends MessagingException {
|
||||
private static final long serialVersionUID = -7092886778226268686L;
|
||||
|
||||
public SearchException() {}
|
||||
|
||||
public SearchException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package javax.mail.search;
|
||||
|
||||
import java.io.Serializable;
|
||||
import javax.mail.Message;
|
||||
|
||||
public abstract class SearchTerm implements Serializable {
|
||||
private static final long serialVersionUID = -6652358452205992789L;
|
||||
|
||||
public abstract boolean match(Message paramMessage);
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package javax.mail.search;
|
||||
|
||||
import java.util.Date;
|
||||
import javax.mail.Message;
|
||||
|
||||
public final class SentDateTerm extends DateTerm {
|
||||
private static final long serialVersionUID = 5647755030530907263L;
|
||||
|
||||
public SentDateTerm(int comparison, Date date) {
|
||||
super(comparison, date);
|
||||
}
|
||||
|
||||
public boolean match(Message msg) {
|
||||
Date d;
|
||||
try {
|
||||
d = msg.getSentDate();
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
if (d == null)
|
||||
return false;
|
||||
return match(d);
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof SentDateTerm))
|
||||
return false;
|
||||
return super.equals(obj);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package javax.mail.search;
|
||||
|
||||
import javax.mail.Message;
|
||||
|
||||
public final class SizeTerm extends IntegerComparisonTerm {
|
||||
private static final long serialVersionUID = -2556219451005103709L;
|
||||
|
||||
public SizeTerm(int comparison, int size) {
|
||||
super(comparison, size);
|
||||
}
|
||||
|
||||
public boolean match(Message msg) {
|
||||
int size;
|
||||
try {
|
||||
size = msg.getSize();
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
if (size == -1)
|
||||
return false;
|
||||
return match(size);
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof SizeTerm))
|
||||
return false;
|
||||
return super.equals(obj);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
package javax.mail.search;
|
||||
|
||||
public abstract class StringTerm extends SearchTerm {
|
||||
protected String pattern;
|
||||
|
||||
protected boolean ignoreCase;
|
||||
|
||||
private static final long serialVersionUID = 1274042129007696269L;
|
||||
|
||||
protected StringTerm(String pattern) {
|
||||
this.pattern = pattern;
|
||||
this.ignoreCase = true;
|
||||
}
|
||||
|
||||
protected StringTerm(String pattern, boolean ignoreCase) {
|
||||
this.pattern = pattern;
|
||||
this.ignoreCase = ignoreCase;
|
||||
}
|
||||
|
||||
public String getPattern() {
|
||||
return this.pattern;
|
||||
}
|
||||
|
||||
public boolean getIgnoreCase() {
|
||||
return this.ignoreCase;
|
||||
}
|
||||
|
||||
protected boolean match(String s) {
|
||||
int len = s.length() - this.pattern.length();
|
||||
for (int i = 0; i <= len; i++) {
|
||||
if (s.regionMatches(this.ignoreCase, i, this.pattern, 0,
|
||||
this.pattern.length()))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof StringTerm))
|
||||
return false;
|
||||
StringTerm st = (StringTerm)obj;
|
||||
if (this.ignoreCase)
|
||||
return (st.pattern.equalsIgnoreCase(this.pattern) && st.ignoreCase == this.ignoreCase);
|
||||
return (st.pattern.equals(this.pattern) && st.ignoreCase == this.ignoreCase);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.ignoreCase ? this.pattern.hashCode() : (this.pattern.hashCode() ^ 0xFFFFFFFF);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package javax.mail.search;
|
||||
|
||||
import javax.mail.Message;
|
||||
|
||||
public final class SubjectTerm extends StringTerm {
|
||||
private static final long serialVersionUID = 7481568618055573432L;
|
||||
|
||||
public SubjectTerm(String pattern) {
|
||||
super(pattern);
|
||||
}
|
||||
|
||||
public boolean match(Message msg) {
|
||||
String subj;
|
||||
try {
|
||||
subj = msg.getSubject();
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
if (subj == null)
|
||||
return false;
|
||||
return match(subj);
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof SubjectTerm))
|
||||
return false;
|
||||
return super.equals(obj);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue