mirror of
https://github.com/moparisthebest/davmail
synced 2025-02-28 17:31:52 -05:00
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:
parent
aa2cadbe87
commit
404bcf96be
@ -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,8 +379,18 @@ public class VProperty {
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
protected void appendParamValue(StringBuilder buffer, String value) {
|
||||
if (value.indexOf(';') >= 0 || value.indexOf(',') >= 0
|
||||
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('"');
|
||||
@ -390,6 +398,7 @@ public class VProperty {
|
||||
buffer.append(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append and encode \n to \\n in value.
|
||||
|
40
src/test/davmail/exchange/TestVProperty.java
Normal file
40
src/test/davmail/exchange/TestVProperty.java
Normal 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());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user