Java Reference
In-Depth Information
public final class ReceivedDateTerm extends DateTerm
public final class SentDateTerm extends DateTerm
It also provides several classes for combining searches:
public final class AndTerm extends SearchTerm
public abstract class ComparisonTerm extends SearchTerm
public final class NotTerm extends SearchTerm
public final class OrTerm extends SearchTerm
Set up a SearchTerm matching your desired parameters and pass it to one of these two
search() methods in the Folder class:
public Message [] search ( SearchTerm term ) throws SearchException ,
FolderNotFoundException , IllegalStateException , MessagingException
public Message [] search ( SearchTerm term , Message [] messages )
throws SearchException , FolderNotFoundException ,
IllegalStateException , MessagingException
A SearchException indicates that the search term is more complicated than the im‐
plementation can handle.
For example, this search term seeks out all messages from billg@microsoft.com :
Address billg = new InternetAddress ( "billg@microsoft.com" );
SearchTerm term = new FromTerm ( billg );
This search term looks for all messages from billg@microsoft.com in 2012 or later:
Address billg = new InternetAddress ( "billg@microsoft.com" );
SearchTerm term1 = new FromTerm ( billg );
Calendar calendar = Calendar . getInstance ();
calendar . set ( 2012 , 0 , 1 );
Date date = calendar . getTime ();
SearchTerm term2 = new SentDateTerm ( ComparisonTerm . GE , date );
SearchTerm term = new AndTerm ( term1 , term2 );
Example 8-1 is a simple variation of the MailClient program in Example 6-1 . It allows
the user to list email addresses on the command line after the initial URL, like this:
% java SearchClient imap://elharo@mail.ibiblio.org/INBOX
willis@nvx.com billg@microsoft.com
Only messages from the specified users will be returned. However, if no email addresses
are given, all messages will be returned.
Example 8-1. A mail client that searches by From: address
import javax.mail.* ;
import javax.mail.search.* ;
import javax.mail.internet.* ;
import java.util.* ;
import java.io.* ;
public class SearchClient {
Search WWH ::




Custom Search