Exchange Web Services get Message Message-ID

匿名 (未验证) 提交于 2019-12-03 01:13:01

问题:

I'm using the Java EWS library to try to sync messages from an Exchange mailbox. I'm able to get a list off all new messages created since the last sync date, however, I would really like to find out the Message-ID property of the message before loading it from exchange.

Background: I'm trying to integrate EWS sync into an existing mail storage system. The Message-ID identification is solely for performance reasons, as our system already has millions of messaged processed outside of EWS. Having to download them again would cause major performance overhead.

//Sample code to fetch the message from sync  ChangeCollection<ItemChange> icc = service.syncFolderItems( folder.getId()                     , PropertySet.FirstClassProperties // propertySet                     , null // ignoredItemIds                     , 25 // maxChangesReturned                     , SyncFolderItemsScope.NormalItems                     , currSyncState );  for ( ItemChange ic : icc ) {     if (ic.getChangeType() == ChangeType.Create)     {         Item item = ic.getItem();         //how to get the Message-ID     } 

Right now, the best way I see to retrieve the Message-ID is by calling ic.getItem().getInternetMessageHeaders() after calling ic.load(). But that requires loading the entire message from exchange, and I would to avoid this step.

Edit: Another way to grab the Message-ID is

EmailMessage em = EmailMessage.bind( service, item.getId() ); em.getInternetMessageId() 

However, that still loads the entire message.

The other solution is to start associating messages by the ItemId, but even that's not perfect: http://daniellang.net/exchange-web-services-itemid-is-not-permanent/

More about Message-ID: http://en.wikipedia.org/wiki/Message-ID

回答1:

I believe the solution is this:

EmailMessage em = EmailMessage.bind( service, item.getId(),                    new PropertySet( EmailMessageSchema.InternetMessageId) ); 

Explanation :

We have to bind the item to an email message, but instead of grabbing all the info, we only ask for the ID and any additional properties we want through the PropertySet parameter.

Inspired by this answer: https://stackoverflow.com/a/22482779/138228



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!