我正在尝试并成功通过IMAP从Exchange服务器获取电子邮件。 我的目的是按日期将“ INBOX”中的电子邮件复制(复制)到特定文件夹。 例如。将所有JANUARY EMAILS从收件箱文件夹复制到“ JANUARY”文件夹。等
我已经做到了,它的工作!但是,它找不到所有一月份的电子邮件。我已经看到很多电子邮件,这些电子邮件没有复制到目标文件夹。
你们有比这更好的解决方案吗?
`Calendar cal1 = null;
cal2.set(2017, 12, 31);
Calendar cal2 = null;
cal1 = Calendar.getInstance();
cal2 = Calendar.getInstance();
cal1.set(2017, 12, 01); // a MONTH BEFORE!!
SimpleDateFormat df1 = new SimpleDateFormat("dd/MM/yyyy");
Date d1 = null;
Date d2 = null;
try {
d1 = df1.parse("01/01/2018");
d2 = df1.parse("31/01/2018");
} catch (ParseException e1) {
e1.printStackTrace();
}
if (init())
;
{
try {
String credentials = String.format(CREDENTIALS_FORMAT, domain, username1);
store = session.getStore(MAIL_PROTOCOL);
for (int i = 0; i < mailboxes.size(); i++) {
store.connect(host, credentials + mailboxes.get(i), password);
folderSource = store.getFolder(SourcefolderName);
folderDest = store.getFolder(DestfolderName);
folderSource.open(Folder.READ_ONLY);
if (!folderDest.exists()) {
folderDest.create(Folder.READ_WRITE);
}
Date datecal1 = new Date(cal1.getTimeInMillis());
Date datecal2 = new Dat`enter code here`e(cal2.getTimeInMillis());
ReceivedDateTerm dateTermCal1 = new ReceivedDateTerm(ComparisonTerm.GE, d1);
ReceivedDateTerm dateTermCal2 = new ReceivedDateTerm(ComparisonTerm.LE, d2); SearchTerm andTerm = new AndTerm(dateTermCal2, dateTermCal1);
Message messages[] = folderSource.search(andTerm);
folderSource.copyMessages(messages, folderDest);'