-
SearchTerm orTerm = new OrTerm(
-
new FromStringTerm(“智联招聘”),
-
new SubjectTerm(“最新职位信息”));
-
Message[] messages = folder.search(orTerm);
3、搜索发件人不包含“智联招聘“所有的邮件
[java] view plain copy
-
SearchTerm notTerm = new NotTerm(new FromStringTerm(“智联招聘”));
-
Message[] messages = folder.search(notTerm);
4、搜索周一到今天收到的的所有邮件
[java] view plain copy
-
Calendar calendar = Calendar.getInstance();
-
calendar.set(Calendar.DAY_OF_WEEK, calendar.get(Calendar.DAY_OF_WEEK - (Calendar.DAY_OF_WEEK - 1)) - 1);
-
Date mondayDate = calendar.getTime();
-
SearchTerm comparisonTermGe = new SentDateTerm(ComparisonTerm.GE, mondayDate);
-
SearchTerm comparisonTermLe = new SentDateTerm(ComparisonTerm.LE, new Date());
-
SearchTerm comparisonAndTerm = new AndTerm(comparisonTermGe, comparisonTermLe);
-
Message[] messages = folder.search(comparisonAndTerm);
5、搜索大于或等于100KB的所有邮件
[java] view plain copy
-
int mailSize = 1024 * 100;
-
SearchTerm intComparisonTerm = new SizeTerm(IntegerComparisonTerm.GE, mailSize);
-
Message[] messages = folder.search(intComparisonTerm);
ComparisonTerm类常用于日期和数字比较中,它使用六个常量EQ(=)、GE(>=)、GT(>)、LE(<=)、LT(<)、NE(!=)来表示六种不同的比较操作。
完整代码:
[java] view plain copy
-
package org.yangxin.study.jm;
-
import java.io.BufferedReader;
-
import java.io.InputStreamReader;
-
import java.util.Calendar;
-
import java.util.Date;
-
import java.util.Properties;
-
import javax.mail.Flags.Flag;
-
import javax.mail.Folder;
-
import javax.mail.Message;
-
import javax.mail.Session;
-
import javax.mail.Store;