mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 11:12: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");
|
displayName = getPropertyIfExists(properties, "displayname");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String getPermanentUrl() {
|
||||||
|
return permanentUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
@ -1678,19 +1682,34 @@ public class DavExchangeSession extends ExchangeSession {
|
|||||||
public Item getItem(String folderPath, String itemName) throws IOException {
|
public Item getItem(String folderPath, String itemName) throws IOException {
|
||||||
String emlItemName = convertItemNameToEML(itemName);
|
String emlItemName = convertItemNameToEML(itemName);
|
||||||
String itemPath = getFolderPath(folderPath) + '/' + emlItemName;
|
String itemPath = getFolderPath(folderPath) + '/' + emlItemName;
|
||||||
MultiStatusResponse[] responses;
|
MultiStatusResponse[] responses = null;
|
||||||
try {
|
try {
|
||||||
responses = DavGatewayHttpClientFacade.executePropFindMethod(httpClient, URIUtil.encodePath(itemPath), 0, EVENT_REQUEST_PROPERTIES_NAME_SET);
|
responses = DavGatewayHttpClientFacade.executePropFindMethod(httpClient, URIUtil.encodePath(itemPath), 0, EVENT_REQUEST_PROPERTIES_NAME_SET);
|
||||||
if (responses.length == 0) {
|
if (responses.length == 0) {
|
||||||
throw new HttpNotFoundException(itemPath + " not found");
|
throw new HttpNotFoundException(itemPath + " not found");
|
||||||
}
|
}
|
||||||
} catch (HttpNotFoundException e) {
|
} catch (HttpNotFoundException e) {
|
||||||
|
try {
|
||||||
LOGGER.debug(itemPath + " not found, searching by urlcompname");
|
LOGGER.debug(itemPath + " not found, searching by urlcompname");
|
||||||
// failover: try to get event by displayname
|
// failover: try to get event by displayname
|
||||||
responses = searchItems(folderPath, EVENT_REQUEST_PROPERTIES, isEqualTo("urlcompname", emlItemName), FolderQueryTraversal.Shallow, 1);
|
responses = searchItems(folderPath, EVENT_REQUEST_PROPERTIES, isEqualTo("urlcompname", emlItemName), FolderQueryTraversal.Shallow, 1);
|
||||||
if (responses.length == 0) {
|
if (responses.length == 0) {
|
||||||
throw new HttpNotFoundException(itemPath + " not found");
|
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
|
// build item
|
||||||
String contentClass = getPropertyIfExists(responses[0].getProperties(HttpStatus.SC_OK), "contentclass");
|
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 F8FF_PATTERN = Pattern.compile("_xF8FF_");
|
||||||
private static final Pattern PLUS_PATTERN = Pattern.compile("\\+");
|
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 SLASH_PATTERN = Pattern.compile("/");
|
||||||
private static final Pattern UNDERSCORE_PATTERN = Pattern.compile("_");
|
private static final Pattern UNDERSCORE_PATTERN = Pattern.compile("_");
|
||||||
private static final Pattern DASH_PATTERN = Pattern.compile("-");
|
private static final Pattern DASH_PATTERN = Pattern.compile("-");
|
||||||
@ -255,6 +256,9 @@ public final class StringUtil {
|
|||||||
if (result.indexOf('+') >= 0) {
|
if (result.indexOf('+') >= 0) {
|
||||||
result = PLUS_PATTERN.matcher(result).replaceAll("%2B");
|
result = PLUS_PATTERN.matcher(result).replaceAll("%2B");
|
||||||
}
|
}
|
||||||
|
if (result.indexOf(':') >= 0) {
|
||||||
|
result = COLON_PATTERN.matcher(result).replaceAll("%3A");
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user