1
0
mirror of https://github.com/moparisthebest/davmail synced 2025-01-07 11:48:02 -05:00

Carddav: convert image to jpeg over EWS

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1190 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-07-17 21:34:14 +00:00
parent 25bd69f3da
commit 09640307dc

View File

@ -30,10 +30,9 @@ import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.URIException; import org.apache.commons.httpclient.URIException;
import org.apache.commons.httpclient.methods.HeadMethod; import org.apache.commons.httpclient.methods.HeadMethod;
import java.io.BufferedReader; import javax.imageio.ImageIO;
import java.io.ByteArrayInputStream; import java.awt.image.BufferedImage;
import java.io.IOException; import java.io.*;
import java.io.InputStreamReader;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.NoRouteToHostException; import java.net.NoRouteToHostException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
@ -753,8 +752,13 @@ public class EwsExchangeSession extends ExchangeSession {
ItemId newItemId = new ItemId(createOrUpdateItemMethod.getResponseItem()); ItemId newItemId = new ItemId(createOrUpdateItemMethod.getResponseItem());
if (photo != null) { if (photo != null) {
// convert image to jpeg
BufferedImage image = ImageIO.read(new ByteArrayInputStream(Base64.decodeBase64(photo.getBytes())));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(image, "jpg", baos);
// TODO: handle photo update, fix attachment mapi properties (available only with Exchange 2010) // TODO: handle photo update, fix attachment mapi properties (available only with Exchange 2010)
FileAttachment attachment = new FileAttachment("ContactPicture.jpg", "image/jpeg", photo); FileAttachment attachment = new FileAttachment("ContactPicture.jpg", "image/jpeg", new String(Base64.encodeBase64(baos.toByteArray())));
// update photo attachment // update photo attachment
CreateAttachmentMethod createAttachmentMethod = new CreateAttachmentMethod(newItemId, attachment); CreateAttachmentMethod createAttachmentMethod = new CreateAttachmentMethod(newItemId, attachment);
executeMethod(createAttachmentMethod); executeMethod(createAttachmentMethod);
@ -941,7 +945,7 @@ public class EwsExchangeSession extends ExchangeSession {
public ContactPhoto getContactPhoto(ExchangeSession.Contact contact) throws IOException { public ContactPhoto getContactPhoto(ExchangeSession.Contact contact) throws IOException {
ContactPhoto contactPhoto = null; ContactPhoto contactPhoto = null;
GetItemMethod getItemMethod = new GetItemMethod(BaseShape.ID_ONLY, ((EwsExchangeSession.Contact)contact).itemId, false); GetItemMethod getItemMethod = new GetItemMethod(BaseShape.ID_ONLY, ((EwsExchangeSession.Contact) contact).itemId, false);
getItemMethod.addAdditionalProperty(Field.get("attachments")); getItemMethod.addAdditionalProperty(Field.get("attachments"));
executeMethod(getItemMethod); executeMethod(getItemMethod);
EWSMethod.Item item = getItemMethod.getResponseItem(); EWSMethod.Item item = getItemMethod.getResponseItem();