mirror of
https://github.com/moparisthebest/davmail
synced 2025-01-07 03:38:05 -05:00
Carddav: workaround for iPhone categories encoding
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1225 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
88c92d6a06
commit
50fe026ee9
@ -104,7 +104,9 @@ public class VCardReader extends ICSBufferedReader {
|
|||||||
} else if (c == 'r') {
|
} else if (c == 'r') {
|
||||||
c = '\r';
|
c = '\r';
|
||||||
}
|
}
|
||||||
} else if (c == ',' && !"NOTE".equals(key)) {
|
}
|
||||||
|
// iPhone encodes category separator
|
||||||
|
if (c == ',' && !"NOTE".equals(key)) {
|
||||||
// convert multiple values to multiline values (e.g. street)
|
// convert multiple values to multiline values (e.g. street)
|
||||||
c = '\n';
|
c = '\n';
|
||||||
}
|
}
|
||||||
|
@ -754,9 +754,9 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
//noinspection VariableNotUsedInsideIf
|
//noinspection VariableNotUsedInsideIf
|
||||||
if (etag == null) {
|
if (etag == null) {
|
||||||
itemResult.status = HttpStatus.SC_CREATED;
|
itemResult.status = HttpStatus.SC_CREATED;
|
||||||
LOGGER.debug("Created event " + getHref());
|
LOGGER.debug("Created contact " + getHref());
|
||||||
} else {
|
} else {
|
||||||
LOGGER.warn("Updated event " + getHref());
|
LOGGER.debug("Updated contact " + getHref());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -946,8 +946,11 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
String itemType = responses.get(0).type;
|
String itemType = responses.get(0).type;
|
||||||
if ("Contact".equals(itemType)) {
|
if ("Contact".equals(itemType)) {
|
||||||
// retrieve Contact properties
|
// retrieve Contact properties
|
||||||
// TODO: need to check list size
|
List<ExchangeSession.Contact> contacts = searchContacts(folderPath, CONTACT_ATTRIBUTES, equals("urlcompname", urlcompname));
|
||||||
return searchContacts(folderPath, CONTACT_ATTRIBUTES, equals("urlcompname", urlcompname)).get(0);
|
if (contacts.isEmpty()) {
|
||||||
|
throw new DavMailException("EXCEPTION_ITEM_NOT_FOUND");
|
||||||
|
}
|
||||||
|
return contacts.get(0);
|
||||||
} else if ("CalendarItem".equals(itemType)
|
} else if ("CalendarItem".equals(itemType)
|
||||||
|| "MeetingRequest".equals(itemType)) {
|
|| "MeetingRequest".equals(itemType)) {
|
||||||
return new Event(responses.get(0));
|
return new Event(responses.get(0));
|
||||||
|
@ -25,6 +25,7 @@ import java.io.ByteArrayOutputStream;
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,6 +35,16 @@ import java.util.UUID;
|
|||||||
public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase {
|
public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase {
|
||||||
static String itemName;
|
static String itemName;
|
||||||
|
|
||||||
|
protected ExchangeSession.Contact getCurrentContact() throws IOException {
|
||||||
|
if (itemName != null) {
|
||||||
|
return (ExchangeSession.Contact) session.getItem("testcontactfolder", itemName);
|
||||||
|
} else {
|
||||||
|
List<ExchangeSession.Contact> contacts = session.searchContacts("testcontactfolder", ExchangeSession.CONTACT_ATTRIBUTES, null);
|
||||||
|
itemName = contacts.get(0).itemName;
|
||||||
|
return contacts.get(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void testCreateFolder() throws IOException {
|
public void testCreateFolder() throws IOException {
|
||||||
// recreate empty folder
|
// recreate empty folder
|
||||||
session.deleteFolder("testcontactfolder");
|
session.deleteFolder("testcontactfolder");
|
||||||
@ -76,7 +87,7 @@ public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase
|
|||||||
vCardWriter.appendProperty("ROLE", "profession");
|
vCardWriter.appendProperty("ROLE", "profession");
|
||||||
vCardWriter.appendProperty("X-AIM", "im");
|
vCardWriter.appendProperty("X-AIM", "im");
|
||||||
vCardWriter.appendProperty("BDAY", "20000102T000000Z");
|
vCardWriter.appendProperty("BDAY", "20000102T000000Z");
|
||||||
vCardWriter.appendProperty("CATEGORIES", "keywords");
|
vCardWriter.appendProperty("CATEGORIES", "keyword1,keyword2");
|
||||||
|
|
||||||
vCardWriter.appendProperty("X-ASSISTANT", "secretarycn");
|
vCardWriter.appendProperty("X-ASSISTANT", "secretarycn");
|
||||||
vCardWriter.appendProperty("X-MANAGER", "manager");
|
vCardWriter.appendProperty("X-MANAGER", "manager");
|
||||||
@ -159,7 +170,7 @@ public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase
|
|||||||
assertEquals("secretarycn", contact.get("secretarycn"));
|
assertEquals("secretarycn", contact.get("secretarycn"));
|
||||||
assertEquals("manager", contact.get("manager"));
|
assertEquals("manager", contact.get("manager"));
|
||||||
assertEquals("spousecn", contact.get("spousecn"));
|
assertEquals("spousecn", contact.get("spousecn"));
|
||||||
assertEquals("keywords", contact.get("keywords"));
|
assertEquals("keyword1,keyword2", contact.get("keywords"));
|
||||||
|
|
||||||
assertEquals("true", contact.get("private"));
|
assertEquals("true", contact.get("private"));
|
||||||
|
|
||||||
@ -168,7 +179,7 @@ public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testUpdateContact() throws IOException {
|
public void testUpdateContact() throws IOException {
|
||||||
ExchangeSession.Contact contact = (ExchangeSession.Contact) session.getItem("testcontactfolder", itemName);
|
ExchangeSession.Contact contact = getCurrentContact();
|
||||||
|
|
||||||
VCardWriter vCardWriter = new VCardWriter();
|
VCardWriter vCardWriter = new VCardWriter();
|
||||||
vCardWriter.startCard();
|
vCardWriter.startCard();
|
||||||
@ -178,7 +189,7 @@ public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase
|
|||||||
ExchangeSession.ItemResult result = session.createOrUpdateContact("testcontactfolder", itemName, vCardWriter.toString(), contact.etag, null);
|
ExchangeSession.ItemResult result = session.createOrUpdateContact("testcontactfolder", itemName, vCardWriter.toString(), contact.etag, null);
|
||||||
assertEquals(200, result.status);
|
assertEquals(200, result.status);
|
||||||
|
|
||||||
contact = (ExchangeSession.Contact) session.getItem("testcontactfolder", itemName);
|
contact = getCurrentContact();
|
||||||
assertNull(contact.get("cn"));
|
assertNull(contact.get("cn"));
|
||||||
assertNull(contact.get("sn"));
|
assertNull(contact.get("sn"));
|
||||||
assertNull(contact.get("givenName"));
|
assertNull(contact.get("givenName"));
|
||||||
@ -249,7 +260,7 @@ public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testUpperCaseParamName() throws IOException {
|
public void testUpperCaseParamName() throws IOException {
|
||||||
ExchangeSession.Contact contact = (ExchangeSession.Contact) session.getItem("testcontactfolder", itemName);
|
ExchangeSession.Contact contact = getCurrentContact();
|
||||||
|
|
||||||
VCardWriter vCardWriter = new VCardWriter();
|
VCardWriter vCardWriter = new VCardWriter();
|
||||||
vCardWriter.startCard();
|
vCardWriter.startCard();
|
||||||
@ -259,7 +270,7 @@ public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase
|
|||||||
ExchangeSession.ItemResult result = session.createOrUpdateContact("testcontactfolder", itemName, vCardWriter.toString(), contact.etag, null);
|
ExchangeSession.ItemResult result = session.createOrUpdateContact("testcontactfolder", itemName, vCardWriter.toString(), contact.etag, null);
|
||||||
assertEquals(200, result.status);
|
assertEquals(200, result.status);
|
||||||
|
|
||||||
contact = (ExchangeSession.Contact) session.getItem("testcontactfolder", itemName);
|
contact = getCurrentContact();
|
||||||
|
|
||||||
assertEquals("mobile", contact.get("mobile"));
|
assertEquals("mobile", contact.get("mobile"));
|
||||||
|
|
||||||
@ -332,4 +343,22 @@ public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase
|
|||||||
assertEquals("http://www.myhomepage.org", contact.get("personalHomePage"));
|
assertEquals("http://www.myhomepage.org", contact.get("personalHomePage"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void testIphoneEncodedCategories() throws IOException {
|
||||||
|
ExchangeSession.Contact contact = getCurrentContact();
|
||||||
|
|
||||||
|
VCardWriter vCardWriter = new VCardWriter();
|
||||||
|
vCardWriter.startCard();
|
||||||
|
vCardWriter.appendProperty("CATEGORIES", "rouge,vert");
|
||||||
|
vCardWriter.endCard();
|
||||||
|
|
||||||
|
ExchangeSession.ItemResult result = session.createOrUpdateContact("testcontactfolder", itemName, vCardWriter.toString(), contact.etag, null);
|
||||||
|
assertEquals(200, result.status);
|
||||||
|
|
||||||
|
contact = getCurrentContact();
|
||||||
|
|
||||||
|
assertEquals("rouge,vert", contact.get("keywords"));
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user