Question

I need to get the MimeType of an item object:

What I've got: - Item object (microsoft.exchange.webservices.data.Item) from the EWS

What I want: - The mimetype of this Item(e.g. String "text/plain")

Is there even a mimetype in exchange?

(I am using the java ews api version 1.2.0)

Was it helpful?

Solution

I have been looking for an Javamail implementation EWS which would allow me to connect to EWS as if I were connecting to any other protocol (IMAP, POP etc) over Javamail. Clearly MS does not seem interested in providing Javamail style implementation that as they provide their own open source EWS Java API (v2.0) https://github.com/OfficeDev/ews-java-api . The documentation is limited to getting started, but if you were into writing a full fledged email client then the documentation might seem lacking. Best to look at the source.

After reading through the source I found Item.getMimeContent() as the method that came closest to anything that looked like providing a content type for the message envelope. But looking at the output of that method I realized that it provides pretty much everything about the message and not just its content type.

So here are the two options that work

  1. EmailMessage.getInternetMessageHeaders().find("Content-Type").getValue() This provides the exact content type only. Any other part (e.g boundary, information or charset) is not present. However this option will work for your purpose since you are only interested in mime type
  2. The more Javamail friendly alternative I found was a relatively less maintained library called javamail4ews. This library provides a bridge between the EWS Java API and Java Mail. You can use that or if not interesting as a whole take a look at the EwsMessage. It basically converts the EmailMessage class from EWS Java API into Java's MimeMessage which has the relevant getContentType method.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top