locked
How to get previous/next email in EWS? RRS feed

  • Question

  • I'm implementing a mailbox system.

    One problem is if I have the id and changekey of a specified email, how to find the previous or next email quickly.

    I've read some Exchange Web Service documents , but cannot solve this problem.

    It seems FindItem/GetItem operations are not very practicable.

    Can anybody help me?

    Thanks!
    Thursday, August 21, 2008 6:40 AM

All replies

  • We dont generate items ids in a way that will let you calculate the id of the next item or the previous one. Generation of these ids is opaque. That said, maybe these alternatives might work for you.

     

    1.     If you are trying to get the next message pertaining to a conversation then you can group the message according to conversation topic and then move through the collection with an index

    This is an example of a find item call that shows how to use distinguished group by for grouping using conversation topic

    Code Snippet

    <FindItem Traversal="Shallow" xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" >

                <ItemShape>

                      <t:BaseShape>Default</< SPAN>t:BaseShape>

                </< SPAN>ItemShape>

                <DistinguishedGroupBy Order="Descending">

                      <t:StandardGroupBy>ConversationTopic</< SPAN>t:StandardGroupBy>

                </< SPAN>DistinguishedGroupBy>

                <ParentFolderIds>

                      <t:DistinguishedFolderId Id="inbox" />

                </< SPAN>ParentFolderIds>

    </< SPAN>FindItem>

     

     

    2.     If you want all the messages in a particular folder then a find item call will return a list of these in the order that they were received in

    For this you can use the find item call above and just omit the DistinguishedGroupBy element.

     

    One other thing option is that if you are looking to enumerate items in a folder sorted on some specific criteria the can be done through EWS as well.

    This is what the sort order element looks like – just place it in the find item call in place of the DistinguishedGroupBy element.

    Code Snippet

    <SortOrder>

                <t:FieldOrder Order="Ascending">

                      <t:FieldURI FieldURI=" message:ConversationIndex" />

                </< SPAN>t:FieldOrder>

    </< SPAN>SortOrder>

     

     

    Thursday, September 4, 2008 4:47 PM