From f6de6f8e424b919a2439a783fe78245721b14be7 Mon Sep 17 00:00:00 2001 From: cketti Date: Tue, 7 Jun 2011 04:07:50 +0200 Subject: [PATCH] Save name of the store type in StoreSettings --- src/com/fsck/k9/mail/Store.java | 19 +++++++++++++++++-- src/com/fsck/k9/mail/store/ImapStore.java | 8 +++++--- src/com/fsck/k9/mail/store/Pop3Store.java | 5 ++++- src/com/fsck/k9/mail/store/WebDavStore.java | 12 +++++++----- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/com/fsck/k9/mail/Store.java b/src/com/fsck/k9/mail/Store.java index 11ed2d8ef..33fd4e5dd 100644 --- a/src/com/fsck/k9/mail/Store.java +++ b/src/com/fsck/k9/mail/Store.java @@ -120,6 +120,11 @@ public abstract class Store { * @see Account#getStoreUri() */ public static class StoreSettings { + /** + * Name of the store type (e.g. "IMAP"). + */ + public final String type; + /** * The host name of the incoming server. */ @@ -162,6 +167,8 @@ public abstract class Store { /** * Creates a new {@code StoreSettings} object. * + * @param type + * see {@link StoreSettings#type} * @param host * see {@link StoreSettings#host} * @param port @@ -175,8 +182,10 @@ public abstract class Store { * @param password * see {@link StoreSettings#password} */ - public StoreSettings(String host, int port, ConnectionSecurity connectionSecurity, - String authenticationType, String username, String password) { + public StoreSettings(String type, String host, int port, + ConnectionSecurity connectionSecurity, String authenticationType, String username, + String password) { + this.type = type; this.host = host; this.port = port; this.connectionSecurity = connectionSecurity; @@ -193,6 +202,12 @@ public abstract class Store { public Map getExtra() { return null; } + + protected void putIfNotNull(Map map, String key, String value) { + if (value != null) { + map.put(key, value); + } + } } diff --git a/src/com/fsck/k9/mail/store/ImapStore.java b/src/com/fsck/k9/mail/store/ImapStore.java index 052c2b427..8db0d1fb1 100644 --- a/src/com/fsck/k9/mail/store/ImapStore.java +++ b/src/com/fsck/k9/mail/store/ImapStore.java @@ -223,20 +223,22 @@ public class ImapStore extends Store { * @see ImapStore#decodeUri(String) */ private static class ImapStoreSettings extends StoreSettings { - private static final String PATH_PREFIX_KEY = "path_prefix"; + private static final String STORE_TYPE = "IMAP"; + private static final String PATH_PREFIX_KEY = "pathPrefix"; public final String pathPrefix; protected ImapStoreSettings(String host, int port, ConnectionSecurity connectionSecurity, String authenticationType, String username, String password, String pathPrefix) { - super(host, port, connectionSecurity, authenticationType, username, password); + super(STORE_TYPE, host, port, connectionSecurity, authenticationType, username, + password); this.pathPrefix = pathPrefix; } @Override public Map getExtra() { Map extra = new HashMap(); - extra.put(PATH_PREFIX_KEY, pathPrefix); + putIfNotNull(extra, PATH_PREFIX_KEY, pathPrefix); return extra; } } diff --git a/src/com/fsck/k9/mail/store/Pop3Store.java b/src/com/fsck/k9/mail/store/Pop3Store.java index f6b7c86cc..c6a275c9f 100644 --- a/src/com/fsck/k9/mail/store/Pop3Store.java +++ b/src/com/fsck/k9/mail/store/Pop3Store.java @@ -26,6 +26,8 @@ import java.util.HashSet; import java.util.List; public class Pop3Store extends Store { + private static final String STORE_TYPE = "POP3"; + public static final int CONNECTION_SECURITY_NONE = 0; public static final int CONNECTION_SECURITY_TLS_OPTIONAL = 1; public static final int CONNECTION_SECURITY_TLS_REQUIRED = 2; @@ -99,7 +101,8 @@ public class Pop3Store extends Store { } } - return new StoreSettings(host, port, connectionSecurity, null, username, password); + return new StoreSettings(STORE_TYPE, host, port, connectionSecurity, null, username, + password); } diff --git a/src/com/fsck/k9/mail/store/WebDavStore.java b/src/com/fsck/k9/mail/store/WebDavStore.java index 69a460cba..94d446eff 100644 --- a/src/com/fsck/k9/mail/store/WebDavStore.java +++ b/src/com/fsck/k9/mail/store/WebDavStore.java @@ -191,6 +191,7 @@ public class WebDavStore extends Store { * @see WebDavStore#decodeUri(String) */ private static class WebDavStoreSettings extends StoreSettings { + private static final String STORE_TYPE = "WebDAV"; private static final String ALIAS_KEY = "alias"; private static final String PATH_KEY = "path"; private static final String AUTH_PATH_KEY = "authPath"; @@ -204,7 +205,8 @@ public class WebDavStore extends Store { protected WebDavStoreSettings(String host, int port, ConnectionSecurity connectionSecurity, String authenticationType, String username, String password, String alias, String path, String authPath, String mailboxPath) { - super(host, port, connectionSecurity, authenticationType, username, password); + super(STORE_TYPE, host, port, connectionSecurity, authenticationType, username, + password); this.alias = alias; this.path = path; this.authPath = authPath; @@ -214,10 +216,10 @@ public class WebDavStore extends Store { @Override public Map getExtra() { Map extra = new HashMap(); - extra.put(ALIAS_KEY, alias); - extra.put(PATH_KEY, path); - extra.put(AUTH_PATH_KEY, authPath); - extra.put(MAILBOX_PATH_KEY, mailboxPath); + putIfNotNull(extra, ALIAS_KEY, alias); + putIfNotNull(extra, PATH_KEY, path); + putIfNotNull(extra, AUTH_PATH_KEY, authPath); + putIfNotNull(extra, MAILBOX_PATH_KEY, mailboxPath); return extra; } }