mirror of
https://github.com/moparisthebest/k-9
synced 2025-01-12 06:08:25 -05:00
Extended ImapStore URI to support empty IMAP path prefix
This commit is contained in:
parent
d6fbeb2913
commit
9e0ea7dd79
@ -156,6 +156,7 @@ public class ImapStore extends Store {
|
||||
String username = null;
|
||||
String password = null;
|
||||
String pathPrefix = null;
|
||||
boolean autoDetectNamespace = true;
|
||||
|
||||
URI imapUri;
|
||||
try {
|
||||
@ -215,15 +216,25 @@ public class ImapStore extends Store {
|
||||
}
|
||||
|
||||
String path = imapUri.getPath();
|
||||
if (path != null && path.length() > 0) {
|
||||
pathPrefix = path.substring(1);
|
||||
if (pathPrefix != null && pathPrefix.trim().length() == 0) {
|
||||
pathPrefix = null;
|
||||
if (path != null && path.length() > 1) {
|
||||
// Strip off the leading "/"
|
||||
String cleanPath = path.substring(1);
|
||||
|
||||
if (cleanPath.length() >= 2 && cleanPath.charAt(1) == '|') {
|
||||
autoDetectNamespace = cleanPath.charAt(0) == '1';
|
||||
if (!autoDetectNamespace) {
|
||||
pathPrefix = cleanPath.substring(2);
|
||||
}
|
||||
} else {
|
||||
pathPrefix = cleanPath;
|
||||
if (pathPrefix.length() > 0) {
|
||||
autoDetectNamespace = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new ImapStoreSettings(host, port, connectionSecurity, authenticationType, username,
|
||||
password, pathPrefix);
|
||||
password, autoDetectNamespace, pathPrefix);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -280,7 +291,16 @@ public class ImapStore extends Store {
|
||||
String userInfo = authType.toString() + ":" + userEnc + ":" + passwordEnc;
|
||||
try {
|
||||
Map<String, String> extra = server.getExtra();
|
||||
String path = (extra != null) ? "/" + extra.get(ImapStoreSettings.PATH_PREFIX_KEY) : null;
|
||||
String path = null;
|
||||
if (extra != null) {
|
||||
boolean autoDetectNamespace = Boolean.TRUE.toString().equals(
|
||||
extra.get(ImapStoreSettings.AUTODETECT_NAMESPACE_KEY));
|
||||
String pathPrefix = extra.get(ImapStoreSettings.PATH_PREFIX_KEY);
|
||||
path = "/" + (autoDetectNamespace ? "1" : "0") + "|" +
|
||||
((pathPrefix == null) ? "" : pathPrefix);
|
||||
} else {
|
||||
path = "/1|";
|
||||
}
|
||||
return new URI(scheme, userInfo, server.host, server.port,
|
||||
path,
|
||||
null, null).toString();
|
||||
@ -295,20 +315,25 @@ public class ImapStore extends Store {
|
||||
* @see ImapStore#decodeUri(String)
|
||||
*/
|
||||
private static class ImapStoreSettings extends ServerSettings {
|
||||
private static final String AUTODETECT_NAMESPACE_KEY = "autoDetectNamespace";
|
||||
private static final String PATH_PREFIX_KEY = "pathPrefix";
|
||||
|
||||
public final boolean autoDetectNamespace;
|
||||
public final String pathPrefix;
|
||||
|
||||
protected ImapStoreSettings(String host, int port, ConnectionSecurity connectionSecurity,
|
||||
String authenticationType, String username, String password, String pathPrefix) {
|
||||
String authenticationType, String username, String password,
|
||||
boolean autodetectNamespace, String pathPrefix) {
|
||||
super(STORE_TYPE, host, port, connectionSecurity, authenticationType, username,
|
||||
password);
|
||||
this.autoDetectNamespace = autodetectNamespace;
|
||||
this.pathPrefix = pathPrefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getExtra() {
|
||||
Map<String, String> extra = new HashMap<String, String>();
|
||||
extra.put(AUTODETECT_NAMESPACE_KEY, Boolean.valueOf(autoDetectNamespace).toString());
|
||||
putIfNotNull(extra, PATH_PREFIX_KEY, pathPrefix);
|
||||
return extra;
|
||||
}
|
||||
@ -316,7 +341,7 @@ public class ImapStore extends Store {
|
||||
@Override
|
||||
public ServerSettings newPassword(String newPassword) {
|
||||
return new ImapStoreSettings(host, port, connectionSecurity, authenticationType,
|
||||
username, newPassword, pathPrefix);
|
||||
username, newPassword, autoDetectNamespace, pathPrefix);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user