Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
JWebServices for Exchange
>
Tutorial
> Archive item
The following example shows you how to archive items.
import java.util.ArrayList; import java.util.Calendar; import java.util.List; import com.independentsoft.exchange.FindItemResponse; import com.independentsoft.exchange.IsLessThanOrEqualTo; import com.independentsoft.exchange.ItemId; import com.independentsoft.exchange.ItemInfoResponse; import com.independentsoft.exchange.ItemShape; import com.independentsoft.exchange.Message; import com.independentsoft.exchange.MessagePropertyPath; import com.independentsoft.exchange.RequestServerVersion; import com.independentsoft.exchange.Service; import com.independentsoft.exchange.ServiceException; import com.independentsoft.exchange.ShapeType; import com.independentsoft.exchange.StandardFolder; public class Example { public static void main(String[] args) { try { Service service = new Service("https://myserver/ews/Exchange.asmx", "username", "password"); service.setRequestServerVersion(RequestServerVersion.EXCHANGE_2013); List
items = new ArrayList
(); Calendar localCalendar = Calendar.getInstance(); localCalendar.add(Calendar.MONTH, -1); IsLessThanOrEqualTo restriction = new IsLessThanOrEqualTo(MessagePropertyPath.RECEIVED_TIME, localCalendar.getTime()); FindItemResponse response = service.findItem(StandardFolder.INBOX, new ItemShape(ShapeType.ID), restriction); for (int i = 0; i < response.getItems().size(); i++) { if (response.getItems().get(i) instanceof Message) { items.add(response.getItems().get(i).getItemId()); } } if (items.size() > 0) { List
archiveResponse = service.archiveItem(items, StandardFolder.INBOX); } } catch (ServiceException e) { System.out.println(e.getMessage()); System.out.println(e.getXmlMessage()); e.printStackTrace(); } } }
Need help? Ask our developers:
Name*
Email*
Message*