Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
JWebServices for Exchange
>
Tutorial
> Get conversation items
The following example shows you how to get conversation items.
import java.util.Calendar; import java.util.Date; import java.util.List; import com.independentsoft.exchange.ConversationItemResponse; import com.independentsoft.exchange.ConversationNode; import com.independentsoft.exchange.ConversationRequest; import com.independentsoft.exchange.FindItemResponse; import com.independentsoft.exchange.IsGreaterThanOrEqualTo; import com.independentsoft.exchange.Item; 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); Calendar localCalendar = Calendar.getInstance(); localCalendar.add(Calendar.MINUTE, -15); Date time = localCalendar.getTime(); IsGreaterThanOrEqualTo restriction = new IsGreaterThanOrEqualTo(MessagePropertyPath.RECEIVED_TIME, time); 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) { ConversationRequest request1 = new ConversationRequest(response.getItems().get(i).getItemId()); List
conversations = service.getConversationItems(request1); for (ConversationItemResponse conversation : conversations) { for (ConversationNode node : conversation.getNodes()) { for (Item item : node.getItems()) { if (item instanceof Message) { Message message = (Message)item; System.out.println("Subject:" + message.getSubject()); System.out.println("ReceivedTime:" + message.getReceivedTime()); System.out.println("---------------------------------------------------------"); } } } } } } } catch (ServiceException e) { System.out.println(e.getMessage()); System.out.println(e.getXmlMessage()); e.printStackTrace(); } } }
Need help? Ask our developers:
Name*
Email*
Message*