mirror of
https://github.com/moparisthebest/davmail
synced 2025-01-12 22:18:11 -05:00
Carddav: Implement phone, address and email properties
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1138 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
96b816b42b
commit
27ad92e9b9
@ -2625,6 +2625,16 @@ public abstract class ExchangeSession {
|
||||
}
|
||||
|
||||
protected static final String[] VCARD_N_PROPERTIES = {"sn", "givenName", "middlename", "personaltitle", "namesuffix"};
|
||||
protected static final String[] VCARD_ADR_HOME_PROPERTIES = {null, null, "homeStreet", "homeCity", "homeState", "homePostalCode", "homeCountry"};
|
||||
protected static final String[] VCARD_ADR_WORK_PROPERTIES = {"postofficebox", "roomnumber", "street", "l", "st", "postalcode", "co"};
|
||||
|
||||
protected void convertContactProperties(Map<String, String> properties, String[] contactProperties, List<String> values) {
|
||||
for (int i = 0; i < values.size() && i < contactProperties.length; i++) {
|
||||
if (contactProperties[i] != null) {
|
||||
properties.put(contactProperties[i], values.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected ItemResult createOrUpdateContact(String folderPath, String itemName, String itemBody, String etag, String noneMatch) throws IOException {
|
||||
// parse VCARD body to build contact property map
|
||||
@ -2640,10 +2650,7 @@ public abstract class ExchangeSession {
|
||||
properties.put("fileas", property.getValue());
|
||||
|
||||
} else if ("N".equals(property.getKey())) {
|
||||
List<String> values = property.getValues();
|
||||
for (int i = 0; i < values.size() && i < VCARD_N_PROPERTIES.length; i++) {
|
||||
properties.put(VCARD_N_PROPERTIES[i], values.get(i));
|
||||
}
|
||||
convertContactProperties(properties, VCARD_N_PROPERTIES, property.getValues());
|
||||
} else if ("NICKNAME".equals(property.getKey())) {
|
||||
properties.put("nickname", property.getValue());
|
||||
} else if ("TEL".equals(property.getKey())) {
|
||||
@ -2656,7 +2663,69 @@ public abstract class ExchangeSession {
|
||||
if (property.hasParam("TYPE", "home")) {
|
||||
properties.put("homePhone", property.getValue());
|
||||
}
|
||||
if (property.hasParam("TYPE", "fax")) {
|
||||
properties.put("facsimiletelephonenumber", property.getValue());
|
||||
}
|
||||
if (property.hasParam("TYPE", "pager")) {
|
||||
properties.put("pager", property.getValue());
|
||||
}
|
||||
} else if ("ADR".equals(property.getKey())) {
|
||||
// address
|
||||
if (property.hasParam("TYPE", "home")) {
|
||||
convertContactProperties(properties, VCARD_ADR_HOME_PROPERTIES, property.getValues());
|
||||
} else if (property.hasParam("TYPE", "work")) {
|
||||
convertContactProperties(properties, VCARD_ADR_WORK_PROPERTIES, property.getValues());
|
||||
}
|
||||
} else if ("EMAIL".equals(property.getKey())) {
|
||||
if (property.hasParam("TYPE", "work")) {
|
||||
properties.put("email1", property.getValue());
|
||||
}
|
||||
if (property.hasParam("TYPE", "home")) {
|
||||
properties.put("email2", property.getValue());
|
||||
}
|
||||
if (property.hasParam("TYPE", "other")) {
|
||||
properties.put("email3", property.getValue());
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
||||
|
||||
writer.appendProperty("EMAIL;TYPE=work", get("email1"));
|
||||
writer.appendProperty("EMAIL;TYPE=home", get("email2"));
|
||||
writer.appendProperty("EMAIL;TYPE=other", get("email3"));
|
||||
|
||||
writer.appendProperty("ORG", get("o"), get("department"));
|
||||
writer.appendProperty("URL;WORK", get("businesshomepage"));
|
||||
writer.appendProperty("TITLE", get("title"));
|
||||
writer.appendProperty("NOTE", get("description"));
|
||||
|
||||
writer.appendProperty("CUSTOM1", get("extensionattribute1"));
|
||||
writer.appendProperty("CUSTOM2", get("extensionattribute2"));
|
||||
writer.appendProperty("CUSTOM3", get("extensionattribute3"));
|
||||
writer.appendProperty("CUSTOM4", get("extensionattribute4"));
|
||||
|
||||
writer.appendProperty("ROLE", get("profession"));
|
||||
writer.appendProperty("NICKNAME", get("nickname"));
|
||||
writer.appendProperty("X-AIM", get("im"));
|
||||
|
||||
writer.appendProperty("BDAY", get("bday"));
|
||||
|
||||
writer.appendProperty("X-EVOLUTION-ASSISTANT", get("secretarycn"));
|
||||
writer.appendProperty("X-EVOLUTION-MANAGER", get("manager"));
|
||||
writer.appendProperty("X-EVOLUTION-SPOUSE", get("spousecn"));
|
||||
|
||||
|
||||
String lastModified = get("lastmodified");
|
||||
if (lastModified != null) {
|
||||
try {
|
||||
writer.appendProperty("REV", getZuluDateFormat().format(getExchangeZuluDateFormatMillisecond().parse(lastModified)));
|
||||
} catch (ParseException e) {
|
||||
LOGGER.warn("Invalid date: " + lastModified);
|
||||
}
|
||||
}
|
||||
writer.endCard();
|
||||
|
||||
*/
|
||||
}
|
||||
return internalCreateOrUpdateContact(folderPath, itemName, properties, etag, noneMatch);
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ import davmail.exception.DavMailAuthenticationException;
|
||||
import davmail.exception.DavMailException;
|
||||
import davmail.exception.HttpNotFoundException;
|
||||
import davmail.exchange.ExchangeSession;
|
||||
import davmail.exchange.ICSBufferedReader;
|
||||
import davmail.http.DavGatewayHttpClientFacade;
|
||||
import davmail.ui.tray.DavGatewayTray;
|
||||
import davmail.util.StringUtil;
|
||||
@ -584,7 +583,11 @@ public class DavExchangeSession extends ExchangeSession {
|
||||
protected List<DavConstants> buildProperties() throws IOException {
|
||||
ArrayList<DavConstants> list = new ArrayList<DavConstants>();
|
||||
for (Map.Entry<String, String> entry : entrySet()) {
|
||||
list.add(Field.createDavProperty(entry.getKey(), entry.getValue()));
|
||||
String key = entry.getKey();
|
||||
if (key.startsWith("email")) {
|
||||
key = "write"+key;
|
||||
}
|
||||
list.add(Field.createDavProperty(key, entry.getValue()));
|
||||
}
|
||||
|
||||
return list;
|
||||
|
@ -18,7 +18,6 @@
|
||||
*/
|
||||
package davmail.exchange.dav;
|
||||
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import org.apache.jackrabbit.webdav.DavConstants;
|
||||
import org.apache.jackrabbit.webdav.property.DavPropertyName;
|
||||
import org.apache.jackrabbit.webdav.property.DefaultDavProperty;
|
||||
@ -193,9 +192,10 @@ public class Field {
|
||||
createField(URN_SCHEMAS_CONTACTS, "co"); // workAddressCountry DistinguishedPropertySetType.PublicStrings/0x00008049/String
|
||||
createField(URN_SCHEMAS_CONTACTS, "department"); // PR_DEPARTMENT_NAME 0x3A18 String
|
||||
// email with display name
|
||||
//createField(URN_SCHEMAS_CONTACTS, "email1"); // DistinguishedPropertySetType.PublicStrings/urn:schemas:contacts:email1/String
|
||||
//createField(URN_SCHEMAS_CONTACTS, "email2"); // DistinguishedPropertySetType.PublicStrings/urn:schemas:contacts:email2/String
|
||||
//createField(URN_SCHEMAS_CONTACTS, "email3"); // DistinguishedPropertySetType.PublicStrings/urn:schemas:contacts:email3/String
|
||||
createField("writeemail1", URN_SCHEMAS_CONTACTS, "email1"); // DistinguishedPropertySetType.PublicStrings/urn:schemas:contacts:email1/String
|
||||
createField("writeemail2", URN_SCHEMAS_CONTACTS, "email2"); // DistinguishedPropertySetType.PublicStrings/urn:schemas:contacts:email2/String
|
||||
createField("writeemail3", URN_SCHEMAS_CONTACTS, "email3"); // DistinguishedPropertySetType.PublicStrings/urn:schemas:contacts:email3/String
|
||||
// email only
|
||||
createField("email1", DistinguishedPropertySetType.Address, 0x8083, "email1"); // Email1EmailAddress
|
||||
createField("email2", DistinguishedPropertySetType.Address, 0x8093, "email2"); // Email2EmailAddress
|
||||
createField("email3", DistinguishedPropertySetType.Address, 0x80A3, "email3"); // Email3EmailAddress
|
||||
@ -264,16 +264,17 @@ public class Field {
|
||||
}
|
||||
|
||||
protected static void createField(String alias, DistinguishedPropertySetType propertySetType, int propertyTag, String responseAlias) {
|
||||
String name;
|
||||
String uriName;
|
||||
if (propertySetType == DistinguishedPropertySetType.Address) {
|
||||
// Address namespace expects integer names
|
||||
name = String.valueOf(propertyTag);
|
||||
uriName = String.valueOf(propertyTag);
|
||||
} else {
|
||||
// Common namespace expects hex names
|
||||
name = "0x" + toHexString(propertyTag);
|
||||
uriName = "0x" + toHexString(propertyTag);
|
||||
}
|
||||
String name = "_x" + propertyTypeMap.get(PropertyType.String10) + "_x" + toHexString(propertyTag);
|
||||
Field field = new Field(alias, Namespace.getNamespace(SCHEMAS_MAPI_ID.getURI() +
|
||||
'{' + distinguishedPropertySetMap.get(propertySetType) + "}/"), name, responseAlias, null);
|
||||
'{' + distinguishedPropertySetMap.get(propertySetType) + "}/"), name, uriName, responseAlias, null);
|
||||
fieldMap.put(field.alias, field);
|
||||
}
|
||||
|
||||
@ -313,9 +314,13 @@ public class Field {
|
||||
}
|
||||
|
||||
public Field(String alias, Namespace namespace, String name, String responseAlias, String cast) {
|
||||
this(alias, namespace, name, name, responseAlias, cast);
|
||||
}
|
||||
|
||||
public Field(String alias, Namespace namespace, String name, String uriName, String responseAlias, String cast) {
|
||||
davPropertyName = DavPropertyName.create(name, namespace);
|
||||
this.alias = alias;
|
||||
this.uri = namespace.getURI() + name;
|
||||
this.uri = namespace.getURI() + uriName;
|
||||
if (responseAlias == null) {
|
||||
this.requestPropertyString = '"' + uri + '"';
|
||||
this.responsePropertyName = davPropertyName;
|
||||
|
@ -66,6 +66,20 @@ public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase
|
||||
vCardWriter.appendProperty("N", "sn", "givenName", "middlename", "personaltitle", "namesuffix");
|
||||
vCardWriter.appendProperty("FN", "common name");
|
||||
vCardWriter.appendProperty("NICKNAME", "nickname");
|
||||
|
||||
vCardWriter.appendProperty("TEL;TYPE=cell", "mobile");
|
||||
vCardWriter.appendProperty("TEL;TYPE=work", "telephoneNumber");
|
||||
vCardWriter.appendProperty("TEL;TYPE=home,voice", "homePhone");
|
||||
vCardWriter.appendProperty("TEL;TYPE=fax", "facsimiletelephonenumber");
|
||||
vCardWriter.appendProperty("TEL;TYPE=pager", "pager");
|
||||
|
||||
vCardWriter.appendProperty("ADR;TYPE=home", null, null, "homeStreet", "homeCity", "homeState", "homePostalCode", "homeCountry");
|
||||
vCardWriter.appendProperty("ADR;TYPE=work", "postofficebox", "roomnumber", "street", "l", "st", "postalcode", "co");
|
||||
|
||||
vCardWriter.appendProperty("EMAIL;TYPE=work", "email1@local.net");
|
||||
vCardWriter.appendProperty("EMAIL;TYPE=home", "email2@local.net");
|
||||
vCardWriter.appendProperty("EMAIL;TYPE=other", "email3@local.net");
|
||||
|
||||
vCardWriter.endCard();
|
||||
|
||||
session.createOrUpdateContact("testcontactfolder", itemName, vCardWriter.toString(), null, null);
|
||||
@ -82,5 +96,29 @@ public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase
|
||||
assertEquals("namesuffix", contact.get("namesuffix"));
|
||||
assertNotNull("lastmodified");
|
||||
assertEquals("nickname", contact.get("nickname"));
|
||||
|
||||
assertEquals("mobile", contact.get("mobile"));
|
||||
assertEquals("telephoneNumber", contact.get("telephoneNumber"));
|
||||
assertEquals("homePhone", contact.get("homePhone"));
|
||||
assertEquals("facsimiletelephonenumber", contact.get("facsimiletelephonenumber"));
|
||||
assertEquals("pager", contact.get("pager"));
|
||||
|
||||
assertEquals("homeStreet", contact.get("homeStreet"));
|
||||
assertEquals("homeCity", contact.get("homeCity"));
|
||||
assertEquals("homeState", contact.get("homeState"));
|
||||
assertEquals("homePostalCode", contact.get("homePostalCode"));
|
||||
assertEquals("homeCountry", contact.get("homeCountry"));
|
||||
|
||||
assertEquals("postofficebox", contact.get("postofficebox"));
|
||||
assertEquals("roomnumber", contact.get("roomnumber"));
|
||||
assertEquals("street", contact.get("street"));
|
||||
assertEquals("l", contact.get("l"));
|
||||
assertEquals("st", contact.get("st"));
|
||||
assertEquals("postalcode", contact.get("postalcode"));
|
||||
assertEquals("co", contact.get("co"));
|
||||
|
||||
assertEquals("email1@local.net", contact.get("email1"));
|
||||
assertEquals("email2@local.net", contact.get("email2"));
|
||||
assertEquals("email3@local.net", contact.get("email3"));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user