mirror of
https://github.com/moparisthebest/davmail
synced 2025-01-08 12:18:07 -05:00
EWS: fix CalendarItem creation, no need to wrap ics in a MIME message
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1165 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
a0339007c4
commit
72e57df57a
@ -1952,6 +1952,7 @@ public abstract class ExchangeSession {
|
|||||||
String eventClass = null;
|
String eventClass = null;
|
||||||
String organizer = null;
|
String organizer = null;
|
||||||
String action = null;
|
String action = null;
|
||||||
|
String method = null;
|
||||||
boolean sound = false;
|
boolean sound = false;
|
||||||
|
|
||||||
List<AllDayState> allDayStates = new ArrayList<AllDayState>();
|
List<AllDayState> allDayStates = new ArrayList<AllDayState>();
|
||||||
@ -2007,6 +2008,8 @@ public abstract class ExchangeSession {
|
|||||||
hasCdoBusyStatus = true;
|
hasCdoBusyStatus = true;
|
||||||
} else if ("BEGIN:VTIMEZONE".equals(line)) {
|
} else if ("BEGIN:VTIMEZONE".equals(line)) {
|
||||||
hasTimezone = true;
|
hasTimezone = true;
|
||||||
|
} else if (key.equals("METHOD")) {
|
||||||
|
method = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2031,6 +2034,14 @@ public abstract class ExchangeSession {
|
|||||||
if (validTimezoneId != null && line.indexOf(";TZID=") >= 0) {
|
if (validTimezoneId != null && line.indexOf(";TZID=") >= 0) {
|
||||||
line = fixTimezoneId(line, validTimezoneId);
|
line = fixTimezoneId(line, validTimezoneId);
|
||||||
}
|
}
|
||||||
|
if (!fromServer && "BEGIN:VCALENDAR".equals(line) && method == null) {
|
||||||
|
result.writeLine(line);
|
||||||
|
// append missing method
|
||||||
|
if (method == null) {
|
||||||
|
result.writeLine("METHOD:PUBLISH");
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (fromServer && line.startsWith("PRODID:") && eventClass != null) {
|
if (fromServer && line.startsWith("PRODID:") && eventClass != null) {
|
||||||
result.writeLine(line);
|
result.writeLine(line);
|
||||||
// set global calendarserver access for iCal 4
|
// set global calendarserver access for iCal 4
|
||||||
|
@ -22,10 +22,19 @@ package davmail.exchange.ews;
|
|||||||
* Create Item method.
|
* Create Item method.
|
||||||
*/
|
*/
|
||||||
public class CreateItemMethod extends EWSMethod {
|
public class CreateItemMethod extends EWSMethod {
|
||||||
public CreateItemMethod(MessageDisposition messageDisposition, FolderId savedItemFolderId, EWSMethod.Item item) {
|
public CreateItemMethod(MessageDisposition messageDisposition, FolderId savedItemFolderId, EWSMethod.Item item) {
|
||||||
super("Item", "CreateItem");
|
super("Item", "CreateItem");
|
||||||
this.savedItemFolderId = savedItemFolderId;
|
this.savedItemFolderId = savedItemFolderId;
|
||||||
this.item = item;
|
this.item = item;
|
||||||
addMethodOption(messageDisposition);
|
addMethodOption(messageDisposition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CreateItemMethod(MessageDisposition messageDisposition, SendMeetingInvitations sendMeetingInvitations, FolderId savedItemFolderId, EWSMethod.Item item) {
|
||||||
|
super("Item", "CreateItem");
|
||||||
|
this.savedItemFolderId = savedItemFolderId;
|
||||||
|
this.item = item;
|
||||||
|
addMethodOption(messageDisposition);
|
||||||
|
addMethodOption(sendMeetingInvitations);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@ 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 javax.mail.MessagingException;
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -194,7 +193,7 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
localProperties.put("bcc", bcc);
|
localProperties.put("bcc", bcc);
|
||||||
UpdateItemMethod updateItemMethod = new UpdateItemMethod(MessageDisposition.SaveOnly,
|
UpdateItemMethod updateItemMethod = new UpdateItemMethod(MessageDisposition.SaveOnly,
|
||||||
ConflictResolution.AlwaysOverwrite,
|
ConflictResolution.AlwaysOverwrite,
|
||||||
CalendarItemCreateOrDeleteOperation.SendToNone,
|
SendMeetingInvitationsOrCancellations.SendToNone,
|
||||||
itemId, buildProperties(localProperties));
|
itemId, buildProperties(localProperties));
|
||||||
executeMethod(updateItemMethod);
|
executeMethod(updateItemMethod);
|
||||||
}
|
}
|
||||||
@ -205,7 +204,7 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
public void updateMessage(ExchangeSession.Message message, Map<String, String> properties) throws IOException {
|
public void updateMessage(ExchangeSession.Message message, Map<String, String> properties) throws IOException {
|
||||||
UpdateItemMethod updateItemMethod = new UpdateItemMethod(MessageDisposition.SaveOnly,
|
UpdateItemMethod updateItemMethod = new UpdateItemMethod(MessageDisposition.SaveOnly,
|
||||||
ConflictResolution.AlwaysOverwrite,
|
ConflictResolution.AlwaysOverwrite,
|
||||||
CalendarItemCreateOrDeleteOperation.SendToNone,
|
SendMeetingInvitationsOrCancellations.SendToNone,
|
||||||
((EwsExchangeSession.Message) message).itemId, buildProperties(properties));
|
((EwsExchangeSession.Message) message).itemId, buildProperties(properties));
|
||||||
executeMethod(updateItemMethod);
|
executeMethod(updateItemMethod);
|
||||||
}
|
}
|
||||||
@ -738,7 +737,7 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
// update
|
// update
|
||||||
createOrUpdateItemMethod = new UpdateItemMethod(MessageDisposition.SaveOnly,
|
createOrUpdateItemMethod = new UpdateItemMethod(MessageDisposition.SaveOnly,
|
||||||
ConflictResolution.AlwaysOverwrite,
|
ConflictResolution.AlwaysOverwrite,
|
||||||
CalendarItemCreateOrDeleteOperation.SendToNone,
|
SendMeetingInvitationsOrCancellations.SendToNone,
|
||||||
currentItemId, buildProperties());
|
currentItemId, buildProperties());
|
||||||
} else {
|
} else {
|
||||||
// create
|
// create
|
||||||
@ -753,7 +752,7 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
itemResult.status = createOrUpdateItemMethod.getStatusCode();
|
itemResult.status = createOrUpdateItemMethod.getStatusCode();
|
||||||
if (itemResult.status == HttpURLConnection.HTTP_OK) {
|
if (itemResult.status == HttpURLConnection.HTTP_OK) {
|
||||||
//noinspection VariableNotUsedInsideIf
|
//noinspection VariableNotUsedInsideIf
|
||||||
if (etag != null) {
|
if (etag == null) {
|
||||||
itemResult.status = HttpStatus.SC_CREATED;
|
itemResult.status = HttpStatus.SC_CREATED;
|
||||||
LOGGER.debug("Updated event " + getHref());
|
LOGGER.debug("Updated event " + getHref());
|
||||||
} else {
|
} else {
|
||||||
@ -763,6 +762,7 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
|
|
||||||
ItemId newItemId = new ItemId(createOrUpdateItemMethod.getResponseItem());
|
ItemId newItemId = new ItemId(createOrUpdateItemMethod.getResponseItem());
|
||||||
GetItemMethod getItemMethod = new GetItemMethod(BaseShape.ID_ONLY, newItemId, false);
|
GetItemMethod getItemMethod = new GetItemMethod(BaseShape.ID_ONLY, newItemId, false);
|
||||||
|
getItemMethod.addAdditionalProperty(Field.get("etag"));
|
||||||
executeMethod(getItemMethod);
|
executeMethod(getItemMethod);
|
||||||
itemResult.etag = getItemMethod.getResponseItem().get(Field.get("etag").getResponseName());
|
itemResult.etag = getItemMethod.getResponseItem().get(Field.get("etag").getResponseName());
|
||||||
|
|
||||||
@ -790,6 +790,11 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
super(folderPath, itemName, contentClass, itemBody, etag, noneMatch);
|
super(folderPath, itemName, contentClass, itemBody, etag, noneMatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemResult createOrUpdate() throws IOException {
|
||||||
|
return createOrUpdate(fixICS(itemBody, false).getBytes("UTF-8"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ItemResult createOrUpdate(byte[] mimeContent) throws IOException {
|
protected ItemResult createOrUpdate(byte[] mimeContent) throws IOException {
|
||||||
@ -826,14 +831,19 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
// update
|
// update
|
||||||
createOrUpdateItemMethod = new UpdateItemMethod(MessageDisposition.SaveOnly,
|
createOrUpdateItemMethod = new UpdateItemMethod(MessageDisposition.SaveOnly,
|
||||||
ConflictResolution.AlwaysOverwrite,
|
ConflictResolution.AlwaysOverwrite,
|
||||||
CalendarItemCreateOrDeleteOperation.SendToNone,
|
SendMeetingInvitationsOrCancellations.SendToNone,
|
||||||
currentItemId, updates);
|
currentItemId, updates);
|
||||||
} else {
|
} else {
|
||||||
// create
|
// create
|
||||||
EWSMethod.Item newItem = new EWSMethod.Item();
|
EWSMethod.Item newItem = new EWSMethod.Item();
|
||||||
newItem.type = "Message";
|
newItem.type = "CalendarItem";
|
||||||
newItem.mimeContent = Base64.encodeBase64(mimeContent);
|
newItem.mimeContent = Base64.encodeBase64(mimeContent);
|
||||||
createOrUpdateItemMethod = new CreateItemMethod(MessageDisposition.SaveOnly, getFolderId(folderPath), newItem);
|
HashSet<FieldUpdate> updates = new HashSet<FieldUpdate>();
|
||||||
|
// force urlcompname
|
||||||
|
updates.add(Field.createFieldUpdate("urlcompname", convertItemNameToEML(itemName)));
|
||||||
|
//updates.add(Field.createFieldUpdate("outlookmessageclass", "IPM.Appointment"));
|
||||||
|
newItem.setFieldUpdates(updates);
|
||||||
|
createOrUpdateItemMethod = new CreateItemMethod(MessageDisposition.SaveOnly, SendMeetingInvitations.SendToNone, getFolderId(folderPath), newItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
executeMethod(createOrUpdateItemMethod);
|
executeMethod(createOrUpdateItemMethod);
|
||||||
@ -841,7 +851,7 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
itemResult.status = createOrUpdateItemMethod.getStatusCode();
|
itemResult.status = createOrUpdateItemMethod.getStatusCode();
|
||||||
if (itemResult.status == HttpURLConnection.HTTP_OK) {
|
if (itemResult.status == HttpURLConnection.HTTP_OK) {
|
||||||
//noinspection VariableNotUsedInsideIf
|
//noinspection VariableNotUsedInsideIf
|
||||||
if (etag != null) {
|
if (etag == null) {
|
||||||
itemResult.status = HttpStatus.SC_CREATED;
|
itemResult.status = HttpStatus.SC_CREATED;
|
||||||
LOGGER.debug("Updated event " + getHref());
|
LOGGER.debug("Updated event " + getHref());
|
||||||
} else {
|
} else {
|
||||||
@ -851,6 +861,7 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
|
|
||||||
ItemId newItemId = new ItemId(createOrUpdateItemMethod.getResponseItem());
|
ItemId newItemId = new ItemId(createOrUpdateItemMethod.getResponseItem());
|
||||||
GetItemMethod getItemMethod = new GetItemMethod(BaseShape.ID_ONLY, newItemId, false);
|
GetItemMethod getItemMethod = new GetItemMethod(BaseShape.ID_ONLY, newItemId, false);
|
||||||
|
getItemMethod.addAdditionalProperty(Field.get("etag"));
|
||||||
executeMethod(getItemMethod);
|
executeMethod(getItemMethod);
|
||||||
itemResult.etag = getItemMethod.getResponseItem().get(Field.get("etag").getResponseName());
|
itemResult.etag = getItemMethod.getResponseItem().get(Field.get("etag").getResponseName());
|
||||||
|
|
||||||
@ -864,11 +875,9 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
LOGGER.debug("Get event: " + permanentUrl);
|
LOGGER.debug("Get event: " + permanentUrl);
|
||||||
try {
|
try {
|
||||||
byte[] content = getContent(itemId);
|
byte[] content = getContent(itemId);
|
||||||
result = getICS(new ByteArrayInputStream(content));
|
result = new String(content);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw buildHttpException(e);
|
throw buildHttpException(e);
|
||||||
} catch (MessagingException e) {
|
|
||||||
throw buildHttpException(e);
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -955,7 +964,7 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
localProperties.put("read", "1");
|
localProperties.put("read", "1");
|
||||||
UpdateItemMethod updateItemMethod = new UpdateItemMethod(MessageDisposition.SaveOnly,
|
UpdateItemMethod updateItemMethod = new UpdateItemMethod(MessageDisposition.SaveOnly,
|
||||||
ConflictResolution.AlwaysOverwrite,
|
ConflictResolution.AlwaysOverwrite,
|
||||||
CalendarItemCreateOrDeleteOperation.SendToNone,
|
SendMeetingInvitationsOrCancellations.SendToNone,
|
||||||
new ItemId(responses.get(0)), buildProperties(localProperties));
|
new ItemId(responses.get(0)), buildProperties(localProperties));
|
||||||
executeMethod(updateItemMethod);
|
executeMethod(updateItemMethod);
|
||||||
}
|
}
|
||||||
|
32
src/java/davmail/exchange/ews/SendMeetingInvitations.java
Normal file
32
src/java/davmail/exchange/ews/SendMeetingInvitations.java
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
|
||||||
|
* Copyright (C) 2010 Mickael Guessant
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
package davmail.exchange.ews;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Item update option.
|
||||||
|
*/
|
||||||
|
public class SendMeetingInvitations extends AttributeOption {
|
||||||
|
private SendMeetingInvitations(String value) {
|
||||||
|
super("SendMeetingInvitations", value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final SendMeetingInvitations SendToNone = new SendMeetingInvitations("SendToNone");
|
||||||
|
public static final SendMeetingInvitations SendOnlyToAll = new SendMeetingInvitations("SendOnlyToAll");
|
||||||
|
public static final SendMeetingInvitations SendToAllAndSaveCopy = new SendMeetingInvitations("SendToAllAndSaveCopy");
|
||||||
|
}
|
@ -21,12 +21,12 @@ package davmail.exchange.ews;
|
|||||||
/**
|
/**
|
||||||
* Item update option.
|
* Item update option.
|
||||||
*/
|
*/
|
||||||
public class CalendarItemCreateOrDeleteOperation extends AttributeOption {
|
public class SendMeetingInvitationsOrCancellations extends AttributeOption {
|
||||||
private CalendarItemCreateOrDeleteOperation(String value) {
|
private SendMeetingInvitationsOrCancellations(String value) {
|
||||||
super("SendMeetingInvitationsOrCancellations", value);
|
super("SendMeetingInvitationsOrCancellations", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final CalendarItemCreateOrDeleteOperation SendToNone = new CalendarItemCreateOrDeleteOperation("SendToNone");
|
public static final SendMeetingInvitationsOrCancellations SendToNone = new SendMeetingInvitationsOrCancellations("SendToNone");
|
||||||
public static final CalendarItemCreateOrDeleteOperation SendOnlyToAll = new CalendarItemCreateOrDeleteOperation("SendOnlyToAll");
|
public static final SendMeetingInvitationsOrCancellations SendOnlyToAll = new SendMeetingInvitationsOrCancellations("SendOnlyToAll");
|
||||||
public static final CalendarItemCreateOrDeleteOperation SendToAllAndSaveCopy = new CalendarItemCreateOrDeleteOperation("SendToAllAndSaveCopy");
|
public static final SendMeetingInvitationsOrCancellations SendToAllAndSaveCopy = new SendMeetingInvitationsOrCancellations("SendToAllAndSaveCopy");
|
||||||
}
|
}
|
@ -25,13 +25,13 @@ import java.util.Set;
|
|||||||
*/
|
*/
|
||||||
public class UpdateItemMethod extends EWSMethod {
|
public class UpdateItemMethod extends EWSMethod {
|
||||||
public UpdateItemMethod(MessageDisposition messageDisposition, ConflictResolution conflictResolution,
|
public UpdateItemMethod(MessageDisposition messageDisposition, ConflictResolution conflictResolution,
|
||||||
CalendarItemCreateOrDeleteOperation calendarItemCreateOrDeleteOperation,
|
SendMeetingInvitationsOrCancellations sendMeetingInvitationsOrCancellations,
|
||||||
ItemId itemId, Set<FieldUpdate> updates) {
|
ItemId itemId, Set<FieldUpdate> updates) {
|
||||||
super("Item", "UpdateItem");
|
super("Item", "UpdateItem");
|
||||||
this.itemId = itemId;
|
this.itemId = itemId;
|
||||||
this.updates = updates;
|
this.updates = updates;
|
||||||
addMethodOption(messageDisposition);
|
addMethodOption(messageDisposition);
|
||||||
addMethodOption(conflictResolution);
|
addMethodOption(conflictResolution);
|
||||||
addMethodOption(calendarItemCreateOrDeleteOperation);
|
addMethodOption(sendMeetingInvitationsOrCancellations);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user