exchangewebservices - Microsoft Exchange Java API get messages based on date and number in folder -
i have program has method.
public list<message> getmessages(int start, int end, date earliestdate) throws messagingexception {
using java ews api how messages folder using these variables. instance if wanted 50th-70th message in inbox or want messages 10-20 starting on specific date. date can null doesn't matter much.
i doubt efficient method possible oh well.
public list<message> getmessages(int start, int end, date earliestdate) { if (start < 1 || end < 1 || end < start) { throw new messagingexception(string.format(locale.us, "invalid message set %d %d", start, end)); } int length = end - start; itemview view = new itemview(length); finditemsresults<item> findresults = null; try { if (earliestdate == null) { findresults = mservice.finditems(mfolder.getid(), view); } else{ searchfilter filter = new searchfilter.isgreaterthanorequalto(itemschema.datetimereceived, earliestdate); findresults = mservice.finditems(mfolder.getid(), filter,view); } } catch (exception e) { e.printstacktrace(); } list<message> messages = new arraylist<message>(); int = 0; (item item : findresults) { itemid id = null; emailmessage message = null; try { id = item.getid(); message = new emailmessage(mservice); message.bind(mservice, id); } catch (servicelocalexception e) { e.printstacktrace(); } catch (exception e) { e.printstacktrace(); } messages.add(message); } return messages; }
Comments
Post a Comment