Carddav: move value decoding back to VCardReader

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1182 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-07-13 07:57:25 +00:00
parent 9a8323b26b
commit 649bc9cb3b
2 changed files with 29 additions and 36 deletions

View File

@ -2682,41 +2682,7 @@ public abstract class ExchangeSession {
protected ItemResult createOrUpdateContact(String folderPath, String itemName, String itemBody, String etag, String noneMatch) throws IOException {
// parse VCARD body to build contact property map
Map<String, String> properties = new HashMap<String, String>() {
@Override
public String put(String key, String value) {
String currentValue = get(key);
super.put(key, decodeValue(key, value));
return currentValue;
}
private String decodeValue(String key, String value) {
if (value == null || (value.indexOf('\\') < 0 && value.indexOf(',') < 0)) {
return value;
} else {
// decode value
StringBuilder decodedValue = new StringBuilder();
for (int i = 0; i < value.length(); i++) {
char c = value.charAt(i);
if (c == '\\') {
//noinspection AssignmentToForLoopParameter
c = value.charAt(++i);
if (c == 'n') {
c = '\n';
} else if (c == 'r') {
c = '\r';
}
} else if (c == ',' && !"description".equals(key)) {
// convert multiple values to multiline values (e.g. street)
c = '\n';
}
decodedValue.append(c);
}
return decodedValue.toString();
}
}
};
Map<String, String> properties = new HashMap<String, String>();
properties.put("outlookmessageclass", "IPM.Contact");
VCardReader reader = new VCardReader(new StringReader(itemBody));

View File

@ -80,8 +80,35 @@ public class VCardReader extends ICSBufferedReader {
if (values == null) {
values = new ArrayList<String>();
}
values.add(value);
values.add(decodeValue(value));
}
protected String decodeValue(String value) {
if (value == null || (value.indexOf('\\') < 0 && value.indexOf(',') < 0)) {
return value;
} else {
// decode value
StringBuilder decodedValue = new StringBuilder();
for (int i = 0; i < value.length(); i++) {
char c = value.charAt(i);
if (c == '\\') {
//noinspection AssignmentToForLoopParameter
c = value.charAt(++i);
if (c == 'n') {
c = '\n';
} else if (c == 'r') {
c = '\r';
}
} else if (c == ',' && !"NOTE".equals(key)) {
// convert multiple values to multiline values (e.g. street)
c = '\n';
}
decodedValue.append(c);
}
return decodedValue.toString();
}
}
}
/**