EWS: xml encode values

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1231 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-07-20 15:00:48 +00:00
parent 5946ea1e98
commit 897a116348
5 changed files with 34 additions and 92 deletions

View File

@ -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("<t:ExtendedFieldURI ");
buffer.append("<t:ExtendedFieldURI");
if (propertyTag != null) {
buffer.append("PropertyTag=\"").append(propertyTag).append("\" ");
buffer.append(" PropertyTag=\"").append(propertyTag).append('"');
}
if (distinguishedPropertySetId != null) {
buffer.append("DistinguishedPropertySetId=\"").append(distinguishedPropertySetId).append("\" ");
buffer.append(" DistinguishedPropertySetId=\"").append(distinguishedPropertySetId).append('"');
}
if (propertySetId != null) {
buffer.append("PropertySetId=\"").append(propertySetId).append("\" ");
buffer.append(" PropertySetId=\"").append(propertySetId).append('"');
}
if (propertyName != null) {
buffer.append("PropertyName=\"").append(propertyName).append("\" ");
buffer.append(" PropertyName=\"").append(propertyName).append('"');
}
if (propertyId != 0) {
buffer.append("PropertyId=\"").append(String.valueOf(propertyId)).append("\" ");
buffer.append(" PropertyId=\"").append(String.valueOf(propertyId)).append('"');
}
if (propertyType != null) {
buffer.append("PropertyType=\"").append(propertyType.toString()).append("\" ");
buffer.append(" PropertyType=\"").append(propertyType.toString()).append('"');
}
buffer.append("/>");
}
@ -129,14 +131,14 @@ public class ExtendedFieldURI implements FieldURI {
String[] values = value.split("\n");
for (final String singleValue : values) {
buffer.append("<t:Value>");
buffer.append(singleValue);
buffer.append(StringUtil.xmlEncode(singleValue));
buffer.append("</t:Value>");
}
buffer.append("</t:Values>");
} else {
buffer.append("<t:Value>");
buffer.append(value);
buffer.append(StringUtil.xmlEncode(value));
buffer.append("</t:Value>");
}
buffer.append("</t:ExtendedProperty>");

View File

@ -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("<t:");
buffer.append(fieldIndex);
buffer.append('>');
buffer.append(value);
buffer.append(StringUtil.xmlEncode(value));
buffer.append("</t:");
buffer.append(fieldIndex);
buffer.append('>');

View File

@ -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("<t:");
buffer.append(fieldName);
buffer.append('>');
buffer.append(value);
buffer.append(StringUtil.xmlEncode(value));
buffer.append("</t:");
buffer.append(fieldName);
buffer.append('>');

View File

@ -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<DavProperty> list = new ArrayList<DavProperty>();
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<DavProperty> list = new ArrayList<DavProperty>();
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());
} */
}

View File

@ -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"));
}
}