Caldav: fix sendEvent regression, conflict on outbox notifications

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1290 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-07-26 22:20:34 +00:00
parent 5dba7b1cd4
commit 957bc7f189
2 changed files with 24 additions and 17 deletions

View File

@ -2368,12 +2368,12 @@ public abstract class ExchangeSession {
} }
/** /**
* Create or update item * Build Mime body for event or event message.
* *
* @return action result * @return mimeContent as byte array or null
* @throws IOException on error * @throws IOException on error
*/ */
public ItemResult createOrUpdate() throws IOException { public byte[] createMimeContent() throws IOException {
String boundary = UUID.randomUUID().toString(); String boundary = UUID.randomUUID().toString();
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
MimeOutputStreamWriter writer = new MimeOutputStreamWriter(baos); MimeOutputStreamWriter writer = new MimeOutputStreamWriter(baos);
@ -2397,14 +2397,14 @@ public abstract class ExchangeSession {
writer.writeHeader("Cc", participants.optionalAttendees); writer.writeHeader("Cc", participants.optionalAttendees);
// do not send notification if no recipients found // do not send notification if no recipients found
if (participants.attendees == null && participants.optionalAttendees == null) { if (participants.attendees == null && participants.optionalAttendees == null) {
status = HttpStatus.SC_NO_CONTENT; return null;
} }
} else { } else {
// notify only organizer // notify only organizer
writer.writeHeader("To", participants.organizer); writer.writeHeader("To", participants.organizer);
// do not send notification if no recipients found // do not send notification if no recipients found
if (participants.organizer == null) { if (participants.organizer == null) {
status = HttpStatus.SC_NO_CONTENT; return null;
} }
} }
@ -2470,13 +2470,23 @@ public abstract class ExchangeSession {
writer.writeLn(); writer.writeLn();
writer.writeLn("------=_NextPart_" + boundary + "--"); writer.writeLn("------=_NextPart_" + boundary + "--");
writer.close(); writer.close();
return baos.toByteArray();
}
/**
* Create or update item
*
* @return action result
* @throws IOException on error
*/
public ItemResult createOrUpdate() throws IOException {
byte[] mimeContent = createMimeContent();
ItemResult itemResult; ItemResult itemResult;
if (status == 0) { if (mimeContent != null) {
itemResult = createOrUpdate(baos.toByteArray()); itemResult = createOrUpdate(mimeContent);
} else { } else {
itemResult = new ItemResult(); itemResult = new ItemResult();
itemResult.status = status; itemResult.status = HttpStatus.SC_NO_CONTENT;
} }
return itemResult; return itemResult;

View File

@ -1293,16 +1293,13 @@ public class DavExchangeSession extends ExchangeSession {
@Override @Override
public int sendEvent(String icsBody) throws IOException { public int sendEvent(String icsBody) throws IOException {
String itemName = UUID.randomUUID().toString() + ".EML"; String itemName = UUID.randomUUID().toString() + ".EML";
int status = internalCreateOrUpdateEvent(draftsUrl, itemName, "urn:content-classes:calendarmessage", icsBody, null, null).status; byte[] mimeContent = (new Event(getFolderPath(DRAFTS), itemName, "urn:content-classes:calendarmessage", icsBody, null, null)).createMimeContent();
if (status != HttpStatus.SC_CREATED) { if (mimeContent == null) {
return status; // no recipients, cancel
return HttpStatus.SC_NO_CONTENT;
} else { } else {
MoveMethod method = new MoveMethod(URIUtil.encodePath(draftsUrl + '/' + itemName), URIUtil.encodePath(sendmsgUrl), true); sendMessage(mimeContent);
status = DavGatewayHttpClientFacade.executeHttpMethod(httpClient, method); return HttpStatus.SC_OK;
if (status != HttpStatus.SC_OK) {
throw DavGatewayHttpClientFacade.buildHttpException(method);
}
return status;
} }
} }