Carddav: fix line folding in generated VCARD

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1246 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-07-21 15:38:44 +00:00
parent 10db0a079a
commit 3a9c3daae4
1 changed files with 12 additions and 12 deletions

View File

@ -29,15 +29,16 @@ public class VCardWriter extends ICSBufferedWriter {
public void appendProperty(String propertyName, String propertyValue) { public void appendProperty(String propertyName, String propertyValue) {
if ((propertyValue != null) && (propertyValue.length() > 0)) { if ((propertyValue != null) && (propertyValue.length() > 0)) {
write(propertyName); StringBuilder buffer = new StringBuilder();
write(":"); buffer.append(propertyName);
writeLine(encodeMultiline(propertyValue)); buffer.append(':');
appendMultilineEncodedValue(buffer, propertyValue);
writeLine(buffer.toString());
} }
} }
protected String encodeMultiline(String value) { protected void appendMultilineEncodedValue(StringBuilder buffer, String value) {
StringBuilder buffer = new StringBuilder();
for (int i = 0; i < value.length(); i++) { for (int i = 0; i < value.length(); i++) {
char c = value.charAt(i); char c = value.charAt(i);
if (c == '\n') { if (c == '\n') {
@ -46,7 +47,6 @@ public class VCardWriter extends ICSBufferedWriter {
buffer.append(value.charAt(i)); buffer.append(value.charAt(i));
} }
} }
return buffer.toString();
} }
public void appendProperty(String propertyName, String... propertyValue) { public void appendProperty(String propertyName, String... propertyValue) {
@ -58,19 +58,19 @@ public class VCardWriter extends ICSBufferedWriter {
} }
} }
if (hasValue) { if (hasValue) {
write(propertyName);
write(":");
boolean first = true; boolean first = true;
StringBuilder valueBuffer = new StringBuilder(); StringBuilder buffer = new StringBuilder();
buffer.append(propertyName);
buffer.append(':');
for (String value : propertyValue) { for (String value : propertyValue) {
if (first) { if (first) {
first = false; first = false;
} else { } else {
valueBuffer.append(';'); buffer.append(';');
} }
appendEncodedValue(valueBuffer, value); appendEncodedValue(buffer, value);
} }
writeLine(valueBuffer.toString()); writeLine(buffer.toString());
} }
} }