From 897a1163481fbbf3a11092491f2248cf2064d2b3 Mon Sep 17 00:00:00 2001 From: mguessan Date: Tue, 20 Jul 2010 15:00:48 +0000 Subject: [PATCH] EWS: xml encode values git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1231 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- .../exchange/ews/ExtendedFieldURI.java | 20 ++--- .../davmail/exchange/ews/IndexedFieldURI.java | 4 +- .../exchange/ews/UnindexedFieldURI.java | 4 +- .../exchange/ExchangeSessionContactTest.java | 81 ------------------- .../exchange/TestExchangeSessionContact.java | 17 ++++ 5 files changed, 34 insertions(+), 92 deletions(-) delete mode 100644 src/test/davmail/exchange/ExchangeSessionContactTest.java diff --git a/src/java/davmail/exchange/ews/ExtendedFieldURI.java b/src/java/davmail/exchange/ews/ExtendedFieldURI.java index d842ff4b..895b91fd 100644 --- a/src/java/davmail/exchange/ews/ExtendedFieldURI.java +++ b/src/java/davmail/exchange/ews/ExtendedFieldURI.java @@ -18,6 +18,8 @@ */ package davmail.exchange.ews; +import davmail.util.StringUtil; + /** * Extended MAPI property. */ @@ -93,24 +95,24 @@ public class ExtendedFieldURI implements FieldURI { } public void appendTo(StringBuilder buffer) { - buffer.append(""); } @@ -129,14 +131,14 @@ public class ExtendedFieldURI implements FieldURI { String[] values = value.split("\n"); for (final String singleValue : values) { buffer.append(""); - buffer.append(singleValue); + buffer.append(StringUtil.xmlEncode(singleValue)); buffer.append(""); } buffer.append(""); } else { buffer.append(""); - buffer.append(value); + buffer.append(StringUtil.xmlEncode(value)); buffer.append(""); } buffer.append(""); diff --git a/src/java/davmail/exchange/ews/IndexedFieldURI.java b/src/java/davmail/exchange/ews/IndexedFieldURI.java index 7d47e4a8..155d1264 100644 --- a/src/java/davmail/exchange/ews/IndexedFieldURI.java +++ b/src/java/davmail/exchange/ews/IndexedFieldURI.java @@ -18,6 +18,8 @@ */ package davmail.exchange.ews; +import davmail.util.StringUtil; + /** * Indexed FieldURI */ @@ -52,7 +54,7 @@ public class IndexedFieldURI implements FieldURI { buffer.append("'); - buffer.append(value); + buffer.append(StringUtil.xmlEncode(value)); buffer.append("'); diff --git a/src/java/davmail/exchange/ews/UnindexedFieldURI.java b/src/java/davmail/exchange/ews/UnindexedFieldURI.java index 8432e2f7..22062c8f 100644 --- a/src/java/davmail/exchange/ews/UnindexedFieldURI.java +++ b/src/java/davmail/exchange/ews/UnindexedFieldURI.java @@ -18,6 +18,8 @@ */ package davmail.exchange.ews; +import davmail.util.StringUtil; + /** * Unindexed Field URI */ @@ -57,7 +59,7 @@ public class UnindexedFieldURI implements FieldURI { buffer.append("'); - buffer.append(value); + buffer.append(StringUtil.xmlEncode(value)); buffer.append("'); diff --git a/src/test/davmail/exchange/ExchangeSessionContactTest.java b/src/test/davmail/exchange/ExchangeSessionContactTest.java deleted file mode 100644 index 2fa0c327..00000000 --- a/src/test/davmail/exchange/ExchangeSessionContactTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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; - -import davmail.Settings; -import davmail.http.DavGatewayHttpClientFacade; -import junit.framework.TestCase; -import org.apache.commons.httpclient.util.URIUtil; -import org.apache.jackrabbit.webdav.client.methods.PropPatchMethod; -import org.apache.jackrabbit.webdav.property.DavProperty; -import org.apache.jackrabbit.webdav.property.DavPropertyName; -import org.apache.jackrabbit.webdav.property.DefaultDavProperty; -import org.apache.jackrabbit.webdav.xml.Namespace; -import org.apache.log4j.Level; - -import java.io.IOException; -import java.util.ArrayList; - -/** - * Test contact search - */ -public class ExchangeSessionContactTest extends AbstractExchangeSessionTestCase { - @Override - public void setUp() throws IOException { - super.setUp(); - } - /* - public void testSearchPrivateFlag() throws IOException { - ExchangeSession.MessageList messageList = session.searchMessages("Contacts", " AND \"http://schemas.microsoft.com/mapi/proptag/0x360003\" = 2"); - assertEquals(1, messageList.size()); - } - - public void testSearchPrivateFlag2() throws IOException { - ExchangeSession.MessageList messageList = session.searchMessages("Contacts", " AND \"http://schemas.microsoft.com/mapi/sensitivity\" = 2"); - assertEquals(1, messageList.size()); - } - public void testSearchPrivateFlag3() throws IOException { - ExchangeSession.MessageList messageList = session.searchMessages("Contacts", " AND \"http://schemas.microsoft.com/exchange/sensitivity\" = 2"); - assertEquals(1, messageList.size()); - } - - public void testSearchPrivateFlag4() throws IOException { - ExchangeSession.MessageList messageList = session.searchMessages("Contacts", " AND Cast(\"http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/0x8506\" as \"boolean\") = true"); - assertEquals(1, messageList.size()); - } - // - public void testUnsetPrivateFlag() throws IOException { - String messageUrl = URIUtil.encodePathQuery(session.getFolderPath("Contacts") + '/' + "test test" + ".EML"); - ArrayList list = new ArrayList(); - list.add(new DefaultDavProperty(DavPropertyName.create("sensitivity", Namespace.getNamespace("http://schemas.microsoft.com/mapi/")), "0")); - PropPatchMethod propPatchMethod = new PropPatchMethod(messageUrl, list); - DavGatewayHttpClientFacade.executeMethod(session.getHttpClient(), propPatchMethod); - } - - public void testSetPrivateFlag() throws IOException { - String messageUrl = URIUtil.encodePathQuery(session.getFolderPath("Contacts") + '/' + "test test" + ".EML"); - ArrayList list = new ArrayList(); - list.add(new DefaultDavProperty(DavPropertyName.create("sensitivity", Namespace.getNamespace("http://schemas.microsoft.com/mapi/")), "2")); - PropPatchMethod propPatchMethod = new PropPatchMethod(messageUrl, list); - //DavGatewayHttpClientFacade.executeMethod(session.getHttpClient(), propPatchMethod); - - ExchangeSession.MessageList messageList = session.searchMessages("Contacts", " AND Cast(\"http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/0x8506\" as \"boolean\") = true"); - assertEquals(1, messageList.size()); - } */ -} diff --git a/src/test/davmail/exchange/TestExchangeSessionContact.java b/src/test/davmail/exchange/TestExchangeSessionContact.java index 1aa5ee54..2da8c6d0 100644 --- a/src/test/davmail/exchange/TestExchangeSessionContact.java +++ b/src/test/davmail/exchange/TestExchangeSessionContact.java @@ -389,4 +389,21 @@ public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase assertEquals("mobile, with comma", contact.get("mobile")); } + + public void testAmpersAndValue() throws IOException { + ExchangeSession.Contact contact = getCurrentContact(); + + VCardWriter vCardWriter = new VCardWriter(); + vCardWriter.startCard(); + vCardWriter.appendProperty("FN", "common & name"); + vCardWriter.endCard(); + + ExchangeSession.ItemResult result = session.createOrUpdateContact("testcontactfolder", itemName, vCardWriter.toString(), contact.etag, null); + assertEquals(200, result.status); + + contact = getCurrentContact(); + + assertEquals("common & name", contact.get("cn")); + + } }