Carddav: fix contact folder path handling and add create contact unit test
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1136 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
fb5f496960
commit
e6ef48c90e
|
@ -85,6 +85,10 @@ public class VCardReader extends ICSBufferedReader {
|
|||
*/
|
||||
public VCardReader(Reader in) throws IOException {
|
||||
super(in);
|
||||
String firstLine = readLine();
|
||||
if (firstLine == null || !"BEGIN:VCARD".equals(firstLine)) {
|
||||
throw new IOException("Invalid VCard body: "+firstLine);
|
||||
}
|
||||
}
|
||||
|
||||
protected static enum State {
|
||||
|
|
|
@ -33,6 +33,8 @@ public class VCardWriter extends ICSBufferedWriter {
|
|||
write(":");
|
||||
if (propertyValue.indexOf('\n') >= 0) {
|
||||
writeLine(propertyValue.replaceAll("\\n", "\\\\n"));
|
||||
} else {
|
||||
writeLine(propertyValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -583,38 +583,10 @@ public class DavExchangeSession extends ExchangeSession {
|
|||
|
||||
protected List<DavConstants> buildProperties() throws IOException {
|
||||
ArrayList<DavConstants> list = new ArrayList<DavConstants>();
|
||||
list.add(Field.createDavProperty("contentclass", contentClass));
|
||||
list.add(Field.createDavProperty("outlookmessageclass", "IPM.Contact"));
|
||||
for (Map.Entry<String, String> entry : entrySet()) {
|
||||
list.add(Field.createDavProperty(entry.getKey(), entry.getValue()));
|
||||
}
|
||||
|
||||
ICSBufferedReader reader = new ICSBufferedReader(new StringReader(itemBody));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
int index = line.indexOf(':');
|
||||
if (index >= 0) {
|
||||
String key = line.substring(0, index);
|
||||
String value = line.substring(index + 1);
|
||||
if ("FN".equals(key)) {
|
||||
list.add(Field.createDavProperty("cn", value));
|
||||
list.add(Field.createDavProperty("subject", value));
|
||||
list.add(Field.createDavProperty("fileas", value));
|
||||
|
||||
} else if ("N".equals(key)) {
|
||||
String[] values = value.split(";");
|
||||
if (values.length > 0) {
|
||||
list.add(Field.createDavProperty("sn", values[0]));
|
||||
}
|
||||
if (values.length > 1) {
|
||||
list.add(Field.createDavProperty("givenName", values[1]));
|
||||
}
|
||||
} else if ("TEL;TYPE=cell".equals(key)) {
|
||||
list.add(Field.createDavProperty("mobile", value));
|
||||
} else if ("TEL;TYPE=work".equals(key)) {
|
||||
list.add(Field.createDavProperty("telephoneNumber", value));
|
||||
} else if ("TEL;TYPE=home".equals(key)) {
|
||||
list.add(Field.createDavProperty("homePhone", value));
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
@ -1260,7 +1232,7 @@ public class DavExchangeSession extends ExchangeSession {
|
|||
|
||||
@Override
|
||||
public ItemResult internalCreateOrUpdateEvent(String folderPath, String itemName, String contentClass, String icsBody, String etag, String noneMatch) throws IOException {
|
||||
return new Event(folderPath, itemName, contentClass, icsBody, etag, noneMatch).createOrUpdate();
|
||||
return new Event(getFolderPath(folderPath), itemName, contentClass, icsBody, etag, noneMatch).createOrUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1374,7 +1346,7 @@ public class DavExchangeSession extends ExchangeSession {
|
|||
|
||||
@Override
|
||||
protected ItemResult internalCreateOrUpdateContact(String folderPath, String itemName, Map<String, String> properties, String etag, String noneMatch) throws IOException {
|
||||
return new Contact(folderPath, itemName, properties, etag, noneMatch).createOrUpdate();
|
||||
return new Contact(getFolderPath(folderPath), itemName, properties, etag, noneMatch).createOrUpdate();
|
||||
}
|
||||
|
||||
protected List<DavConstants> buildProperties(Map<String, String> properties) {
|
||||
|
|
|
@ -21,10 +21,7 @@ package davmail.exchange;
|
|||
import davmail.exchange.dav.DavExchangeSession;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Test ExchangeSession contact features.
|
||||
|
@ -32,6 +29,15 @@ import java.util.Set;
|
|||
@SuppressWarnings({"UseOfSystemOutOrSystemErr"})
|
||||
public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase {
|
||||
|
||||
@Override
|
||||
public void setUp() throws IOException {
|
||||
super.setUp();
|
||||
// recreate empty folder
|
||||
session.deleteFolder("testcontactfolder");
|
||||
session.createContactFolder("testcontactfolder");
|
||||
}
|
||||
|
||||
|
||||
public void testSearchContacts() throws IOException {
|
||||
List<ExchangeSession.Contact> contacts = session.searchContacts(ExchangeSession.CONTACTS, ExchangeSession.CONTACT_ATTRIBUTES, null);
|
||||
for (ExchangeSession.Contact contact : contacts) {
|
||||
|
@ -56,4 +62,15 @@ public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase
|
|||
System.out.println(session.searchContacts(ExchangeSession.CONTACTS, attributes, session.equals("uid", contact.get("uid"))));
|
||||
}
|
||||
}
|
||||
|
||||
public void testCreateContact() throws IOException {
|
||||
VCardWriter vCardWriter = new VCardWriter();
|
||||
vCardWriter.startCard();
|
||||
vCardWriter.appendProperty("N", "surname", "given name", "honorific prefix", "honorific suffix");
|
||||
vCardWriter.appendProperty("FN", "test name");
|
||||
vCardWriter.endCard();
|
||||
|
||||
session.createOrUpdateContact("testcontactfolder", UUID.randomUUID().toString() + ".vcf", vCardWriter.toString(), null, null);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue