mirror of
https://github.com/moparisthebest/davmail
synced 2025-01-06 03:08:02 -05:00
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:
parent
9a8323b26b
commit
649bc9cb3b
@ -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));
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user