mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 03:02:22 -05:00
Caldav: need to encode colon (:) in urlcompname search, implement a last failover on item search
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1351 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
3eaa08c431
commit
4835b2ba2d
@ -1117,6 +1117,10 @@ public class DavExchangeSession extends ExchangeSession {
|
||||
displayName = getPropertyIfExists(properties, "displayname");
|
||||
}
|
||||
|
||||
protected String getPermanentUrl() {
|
||||
return permanentUrl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
@ -1678,19 +1682,34 @@ public class DavExchangeSession extends ExchangeSession {
|
||||
public Item getItem(String folderPath, String itemName) throws IOException {
|
||||
String emlItemName = convertItemNameToEML(itemName);
|
||||
String itemPath = getFolderPath(folderPath) + '/' + emlItemName;
|
||||
MultiStatusResponse[] responses;
|
||||
MultiStatusResponse[] responses = null;
|
||||
try {
|
||||
responses = DavGatewayHttpClientFacade.executePropFindMethod(httpClient, URIUtil.encodePath(itemPath), 0, EVENT_REQUEST_PROPERTIES_NAME_SET);
|
||||
if (responses.length == 0) {
|
||||
throw new HttpNotFoundException(itemPath + " not found");
|
||||
}
|
||||
} catch (HttpNotFoundException e) {
|
||||
try {
|
||||
LOGGER.debug(itemPath + " not found, searching by urlcompname");
|
||||
// failover: try to get event by displayname
|
||||
responses = searchItems(folderPath, EVENT_REQUEST_PROPERTIES, isEqualTo("urlcompname", emlItemName), FolderQueryTraversal.Shallow, 1);
|
||||
if (responses.length == 0) {
|
||||
throw new HttpNotFoundException(itemPath + " not found");
|
||||
}
|
||||
} catch (HttpNotFoundException e2) {
|
||||
LOGGER.debug("last failover: search all items");
|
||||
List<ExchangeSession.Event> events = getAllEvents(folderPath);
|
||||
for (ExchangeSession.Event event : events) {
|
||||
if (itemName.equals(event.getName())) {
|
||||
responses = DavGatewayHttpClientFacade.executePropFindMethod(httpClient, ((DavExchangeSession.Event) event).getPermanentUrl(), 0, EVENT_REQUEST_PROPERTIES_NAME_SET);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (responses == null || responses.length == 0) {
|
||||
throw new HttpNotFoundException(itemPath + " not found");
|
||||
}
|
||||
LOGGER.warn("search by urlcompname failed, actual value is "+getPropertyIfExists(responses[0].getProperties(HttpStatus.SC_OK), "urlcompname"));
|
||||
}
|
||||
}
|
||||
// build item
|
||||
String contentClass = getPropertyIfExists(responses[0].getProperties(HttpStatus.SC_OK), "contentclass");
|
||||
|
@ -137,6 +137,7 @@ public final class StringUtil {
|
||||
|
||||
private static final Pattern F8FF_PATTERN = Pattern.compile("_xF8FF_");
|
||||
private static final Pattern PLUS_PATTERN = Pattern.compile("\\+");
|
||||
private static final Pattern COLON_PATTERN = Pattern.compile(":");
|
||||
private static final Pattern SLASH_PATTERN = Pattern.compile("/");
|
||||
private static final Pattern UNDERSCORE_PATTERN = Pattern.compile("_");
|
||||
private static final Pattern DASH_PATTERN = Pattern.compile("-");
|
||||
@ -255,6 +256,9 @@ public final class StringUtil {
|
||||
if (result.indexOf('+') >= 0) {
|
||||
result = PLUS_PATTERN.matcher(result).replaceAll("%2B");
|
||||
}
|
||||
if (result.indexOf(':') >= 0) {
|
||||
result = COLON_PATTERN.matcher(result).replaceAll("%3A");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user