Caldav: fix multivalued param support in VProperty and always quote CN values

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1610 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2011-01-13 10:14:18 +00:00
parent aa2cadbe87
commit 404bcf96be
2 changed files with 60 additions and 11 deletions

View File

@ -150,7 +150,7 @@ public class VProperty {
if (state == State.VALUE) {
addValue(line.substring(startIndex));
} else {
throw new IllegalArgumentException("Invalid property line: "+line);
throw new IllegalArgumentException("Invalid property line: " + line);
}
}
}
@ -360,9 +360,7 @@ public class VProperty {
buffer.append(';').append(param.name);
if (param.values != null) {
buffer.append('=');
for (String value : param.values) {
appendParamValue(buffer, value);
}
appendParamValues(buffer, param);
}
}
}
@ -381,13 +379,24 @@ public class VProperty {
return buffer.toString();
}
protected void appendParamValue(StringBuilder buffer, String value) {
if (value.indexOf(';') >= 0 || value.indexOf(',') >= 0
|| value.indexOf('(') >= 0 || value.indexOf('/') >= 0
|| value.indexOf(':') >= 0) {
buffer.append('"').append(value).append('"');
} else {
buffer.append(value);
protected void appendParamValues(StringBuilder buffer, Param param) {
boolean first = true;
for (String value : param.values) {
if (first) {
first = false;
} else {
buffer.append(',');
}
// always quote CN param
if ("CN".equalsIgnoreCase(param.name)
// quote param values with special characters
|| value.indexOf(';') >= 0 || value.indexOf(',') >= 0
|| value.indexOf('(') >= 0 || value.indexOf('/') >= 0
|| value.indexOf(':') >= 0) {
buffer.append('"').append(value).append('"');
} else {
buffer.append(value);
}
}
}

View File

@ -0,0 +1,40 @@
/*
* DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
* Copyright (C) 2011 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 junit.framework.TestCase;
/**
* Test VProperty.
*/
public class TestVProperty extends TestCase {
public void testMultivaluedParam() {
String line = "TEL;TYPE=home,voice:homePhone";
VProperty vProperty = new VProperty(line);
assertNotNull(vProperty);
assertEquals(line, vProperty.toString());
}
public void testQuoteCn() {
String line = "ATTENDEE;CN=\"test\":MAILTO:test@company.com";
VProperty vProperty = new VProperty(line);
assertNotNull(vProperty);
assertEquals(line, vProperty.toString());
}
}