1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-13 03:02:22 -05:00

Carddav: Add Anniversary support

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1235 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-07-20 16:33:58 +00:00
parent 8ed3ee021d
commit 2c95fc14dc
6 changed files with 66 additions and 31 deletions

View File

@ -1731,16 +1731,9 @@ public abstract class ExchangeSession {
writer.appendProperty("ROLE", get("profession"));
writer.appendProperty("NICKNAME", get("nickname"));
writer.appendProperty("X-AIM", get("im"));
// convert bday value
String bday = get("bday");
if (bday != null && bday.length() > 0) {
try {
SimpleDateFormat parser = ExchangeSession.getZuluDateFormat();
writer.appendProperty("BDAY", ExchangeSession.getVcardBdayFormat().format(parser.parse(bday)));
} catch (ParseException e) {
LOGGER.warn("Invalid date: " + bday);
}
}
writer.appendProperty("BDAY", convertZuluDateToBday(get("bday")));
writer.appendProperty("X-ANNIVERSARY", convertZuluDateToBday(get("anniversary")));
writer.appendProperty("CATEGORIES", get("keywords"));
@ -1767,6 +1760,19 @@ public abstract class ExchangeSession {
return writer.toString();
}
protected String convertZuluDateToBday(String value) {
String result = null;
if (value != null && value.length() > 0) {
try {
SimpleDateFormat parser = ExchangeSession.getZuluDateFormat();
result = ExchangeSession.getVcardBdayFormat().format(parser.parse(value));
} catch (ParseException e) {
LOGGER.warn("Invalid date: " + value);
}
}
return result;
}
}
/**
@ -2771,20 +2777,9 @@ public abstract class ExchangeSession {
} else if ("X-AIM".equals(property.getKey())) {
properties.put("im", property.getValue());
} else if ("BDAY".equals(property.getKey())) {
String value = property.getValue();
if (value != null) {
try {
SimpleDateFormat parser;
if (value.length() == 10) {
parser = ExchangeSession.getVcardBdayFormat();
} else {
parser = ExchangeSession.getExchangeZuluDateFormat();
}
properties.put("bday", ExchangeSession.getExchangeZuluDateFormatMillisecond().format(parser.parse(value)));
} catch (ParseException e) {
LOGGER.warn("Invalid date: " + value);
}
}
properties.put("bday", convertBDayToZulu(property.getValue()));
} else if ("X-ANNIVERSARY".equals(property.getKey())) {
properties.put("anniversary", convertBDayToZulu(property.getValue()));
} else if ("CATEGORIES".equals(property.getKey())) {
properties.put("keywords", property.getValue());
} else if ("CLASS".equals(property.getKey())) {
@ -2818,6 +2813,25 @@ public abstract class ExchangeSession {
return internalCreateOrUpdateContact(folderPath, itemName, properties, etag, noneMatch);
}
protected String convertBDayToZulu(String value) {
String result = null;
if (value != null && value.length() > 0) {
try {
SimpleDateFormat parser;
if (value.length() == 10) {
parser = ExchangeSession.getVcardBdayFormat();
} else {
parser = ExchangeSession.getExchangeZuluDateFormat();
}
result = ExchangeSession.getExchangeZuluDateFormatMillisecond().format(parser.parse(value));
} catch (ParseException e) {
LOGGER.warn("Invalid date: " + value);
}
}
return result;
}
protected abstract ItemResult internalCreateOrUpdateContact(String folderPath, String itemName, Map<String, String> properties, String etag, String noneMatch) throws IOException;
@ -3117,6 +3131,7 @@ public abstract class ExchangeSession {
CONTACT_ATTRIBUTES.add("extensionattribute3");
CONTACT_ATTRIBUTES.add("extensionattribute4");
CONTACT_ATTRIBUTES.add("bday");
CONTACT_ATTRIBUTES.add("anniversary");
CONTACT_ATTRIBUTES.add("businesshomepage");
CONTACT_ATTRIBUTES.add("personalHomePage");
CONTACT_ATTRIBUTES.add("cn");

View File

@ -571,8 +571,9 @@ public class DavExchangeSession extends ExchangeSession {
for (String attributeName : CONTACT_ATTRIBUTES) {
String value = getPropertyIfExists(properties, attributeName);
if (value != null) {
if ("bday".equals(attributeName) || "lastmodified".equals(attributeName) || "datereceived".equals(attributeName)) {
value = convertDate(value);
if ("bday".equals(attributeName) || "anniversary".equals(attributeName)
|| "lastmodified".equals(attributeName) || "datereceived".equals(attributeName)) {
value = convertDateFromExchange(value);
} else if ("haspicture".equals(attributeName) || "private".equals(attributeName)) {
value = "1".equals(value) ? "true" : "false";
}
@ -1731,7 +1732,7 @@ public class DavExchangeSession extends ExchangeSession {
LOGGER.debug("Deleted to :" + destination);
}
protected String convertDate(String exchangeDateValue) throws DavMailException {
protected String convertDateFromExchange(String exchangeDateValue) throws DavMailException {
String zuluDateValue;
try {
zuluDateValue = getZuluDateFormat().format(getExchangeZuluDateFormatMillisecond().parse(exchangeDateValue));

View File

@ -193,6 +193,7 @@ public class Field {
createField(SCHEMAS_EXCHANGE, "extensionattribute4"); // DistinguishedPropertySetType.Address/0x00008052/String
createField(URN_SCHEMAS_CONTACTS, "bday"); // PR_BIRTHDAY 0x3A42 SystemTime
createField("anniversary", DistinguishedPropertySetType.Address, 0x80DF, "anniversary"); // WeddingAnniversaryLocal
createField(URN_SCHEMAS_CONTACTS, "businesshomepage"); // PR_BUSINESS_HOME_PAGE 0x3A51 String
createField(URN_SCHEMAS_CONTACTS, "personalHomePage"); // PR_PERSONAL_HOME_PAGE 0x3A50 String
//createField(URN_SCHEMAS_CONTACTS, "c"); // country DistinguishedPropertySetType.PublicStrings/urn:schemas:contacts:c/String

View File

@ -254,7 +254,7 @@ public class EwsExchangeSession extends ExchangeSession {
String lastVerbExecuted = response.get(Field.get("lastVerbExecuted").getResponseName());
message.answered = "102".equals(lastVerbExecuted) || "103".equals(lastVerbExecuted);
message.forwarded = "104".equals(lastVerbExecuted);
message.date = convertDate(response.get(Field.get("date").getResponseName()));
message.date = convertDateFromExchange(response.get(Field.get("date").getResponseName()));
message.deleted = "1".equals(response.get(Field.get("deleted").getResponseName()));
if (LOGGER.isDebugEnabled()) {
@ -658,8 +658,8 @@ public class EwsExchangeSession extends ExchangeSession {
for (String attributeName : CONTACT_ATTRIBUTES) {
String value = response.get(Field.get(attributeName).getResponseName());
if (value != null) {
if ("bday".equals(attributeName) || "lastmodified".equals(attributeName) || "datereceived".equals(attributeName)) {
value = convertDate(value);
if ("bday".equals(attributeName) || "anniversary".equals(attributeName) || "lastmodified".equals(attributeName) || "datereceived".equals(attributeName)) {
value = convertDateFromExchange(value);
}
put(attributeName, value);
}
@ -1121,7 +1121,7 @@ public class EwsExchangeSession extends ExchangeSession {
}
}
protected String convertDate(String exchangeDateValue) throws DavMailException {
protected String convertDateFromExchange(String exchangeDateValue) throws DavMailException {
String zuluDateValue;
try {
zuluDateValue = getZuluDateFormat().format(getExchangeZuluDateFormat().parse(exchangeDateValue));

View File

@ -88,6 +88,7 @@ public class Field {
FIELD_MAP.put("extensionattribute4", new ExtendedFieldURI(ExtendedFieldURI.DistinguishedPropertySetType.Address, 0x8052, ExtendedFieldURI.PropertyType.String));
FIELD_MAP.put("bday", new ExtendedFieldURI(0x3A42, ExtendedFieldURI.PropertyType.SystemTime));
FIELD_MAP.put("anniversary", new ExtendedFieldURI(ExtendedFieldURI.DistinguishedPropertySetType.Address, 0x80DF, ExtendedFieldURI.PropertyType.SystemTime));
FIELD_MAP.put("businesshomepage", new ExtendedFieldURI(0x3A51, ExtendedFieldURI.PropertyType.String));
FIELD_MAP.put("personalHomePage", new ExtendedFieldURI(0x3A50, ExtendedFieldURI.PropertyType.String));

View File

@ -423,4 +423,21 @@ public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase
assertEquals("20000102T000000Z", contact.get("bday"));
System.out.println(contact.getBody());
}
public void testAnniversary() throws IOException {
ExchangeSession.Contact contact = getCurrentContact();
VCardWriter vCardWriter = new VCardWriter();
vCardWriter.startCard();
vCardWriter.appendProperty("X-ANNIVERSARY", "2000-01-02");
vCardWriter.endCard();
ExchangeSession.ItemResult result = session.createOrUpdateContact("testcontactfolder", itemName, vCardWriter.toString(), contact.etag, null);
assertEquals(200, result.status);
contact = getCurrentContact();
assertEquals("20000102T000000Z", contact.get("anniversary"));
System.out.println(contact.getBody());
}
}