Commit 22c0287e authored by Mickaël Guessant's avatar Mickaël Guessant

Carddav: do not send empty EmailAddresses collection tag

git-svn-id: https://svn.code.sf.net/p/davmail/code/trunk@2469 3d1905a2-6b24-0410-a738-b14d5a86fcbd
parent b5ff47b1
......@@ -58,20 +58,27 @@ public class IndexedFieldUpdate extends FieldUpdate {
@Override
public void write(String itemType, Writer writer) throws IOException {
if (itemType == null) {
// use collection name on create
writer.write("<t:");
writer.write(collectionName);
writer.write(">");
StringBuilder buffer = new StringBuilder();
// check if at least one non null value
boolean hasValue = false;
for (FieldUpdate fieldUpdate : updates) {
fieldUpdate.fieldURI.appendValue(buffer, null, fieldUpdate.value);
if (fieldUpdate.value != null) {hasValue = true; }
}
writer.write(buffer.toString());
if (hasValue) {
// use collection name on create
writer.write("<t:");
writer.write(collectionName);
writer.write(">");
StringBuilder buffer = new StringBuilder();
for (FieldUpdate fieldUpdate : updates) {
fieldUpdate.fieldURI.appendValue(buffer, null, fieldUpdate.value);
}
writer.write(buffer.toString());
writer.write("</t:");
writer.write(collectionName);
writer.write(">");
writer.write("</t:");
writer.write(collectionName);
writer.write(">");
}
} else {
// on update, write each fieldupdate
for (FieldUpdate fieldUpdate : updates) {
......
......@@ -23,7 +23,9 @@ import davmail.util.IOUtil;
import org.apache.commons.codec.binary.Base64;
import java.io.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/**
......@@ -589,4 +591,45 @@ public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase
VProperty property = new VProperty("ADR;TYPE=WORK:;;via 25 aprile\\, 25;Lallio;BG;24048;Italia");
assertEquals("via 25 aprile, 25", property.getValues().get(2));
}
/* Huge contact folder creation
public void testJohnDoes() throws IOException {
testCreateFolder();
for (int i = 0;i<10000;i++) {
String itemBody = "BEGIN:VCARD\n" +
"VERSION:4.0\n" +
"EMAIL:john.doe"+i+"@acme.com\n" +
"FN:John Doe"+i+"\n" +
"N:Doe"+i+";John;;;\n" +
"TEL;TYPE=HOME:+1-234-56789\n" +
"UID:5516ecf5-6ee0-4d60-b5e8-a654c7447f0a\n" +
"END:VCARD";
itemName = UUID.randomUUID().toString() + ".vcf";
ExchangeSession.ItemResult result = session.createOrUpdateContact("testcontactfolder", itemName, itemBody, null, null);
assertEquals(201, result.status);
}
//result = session.createOrUpdateContact("testcontactfolder", itemName, itemBody, null, null);
//assertEquals(201, result.status);
}*/
/**
*/
public void testEmptyEmail2() throws IOException {
testCreateFolder();
String itemBody = "BEGIN:VCARD\n" +
"VERSION:3.0\n" +
"UID:sd9327nnob97w02a36zoo9adf9vt692pr1hq\n" +
"FN:First Last\n" +
"N:Last;First;;;\n" +
"REV:20161222T092209Z\n" +
"TEL;TYPE=cell:+47 00000000\n" +
"END:VCARD";
itemName = UUID.randomUUID().toString() + ".vcf";
ExchangeSession.ItemResult result = session.createOrUpdateContact("testcontactfolder", itemName, itemBody, null, null);
assertEquals(201, result.status);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment