exchangewebservices - EWS Java how to find emails older than xx days and Delete all in one shot -
i want find items in folder older xx days , delete items found in 1 shot. able find items matching criteria. here code.
import org.joda.time.datetime; int purgedays = 14; try { itemview view = new itemview(integer.max_value); folder purgefolder = folder.bind(service, folderid); // need convert mon sep 12 16:31:27 cdt 2016 searchfilter searchfilter = new searchfilter.islessthanorequalto(itemschema.datetimereceived, (datetime.now().minusdays(purgedays).todate())); finditemsresults<item> emailstopurge = service.finditems(purgefolder.getid(), searchfilter, view); if (emailstopurge != null && emailstopurge.getitems() != null && emailstopurge.gettotalcount() > 0 ) { // want delete items @ once emailstopurge.deleteall(); } else { log.info("found no emails purge mailbox-"+ username); } } catch (exception e) { log.error("exception "+ e.getmessage()); }
have @ deleteitems method on exchangeservice class https://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.data.exchangeservice.deleteitems(v=exchg.80).aspx allows send batch deleteitem request. suggest page deletes though @ no more 1000 items @ time else may have issue throttling and/or requests timing out.
Comments
Post a Comment