mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-23 18:02:15 -05:00
Merge pull request #557 from artbristol/art/account-creation-refactor-2
Remove duplication, enum-ify String
This commit is contained in:
commit
46bac187d5
@ -16,10 +16,13 @@ import java.util.Map;
|
|||||||
* @see com.fsck.k9.mail.store.StoreConfig#getTransportUri()
|
* @see com.fsck.k9.mail.store.StoreConfig#getTransportUri()
|
||||||
*/
|
*/
|
||||||
public class ServerSettings {
|
public class ServerSettings {
|
||||||
|
|
||||||
|
public enum Type { IMAP, SMTP, WebDAV, POP3 }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name of the store or transport type (e.g. "IMAP").
|
* Name of the store or transport type (e.g. IMAP).
|
||||||
*/
|
*/
|
||||||
public final String type;
|
public final Type type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The host name of the server.
|
* The host name of the server.
|
||||||
@ -99,7 +102,7 @@ public class ServerSettings {
|
|||||||
* @param clientCertificateAlias
|
* @param clientCertificateAlias
|
||||||
* see {@link ServerSettings#clientCertificateAlias}
|
* see {@link ServerSettings#clientCertificateAlias}
|
||||||
*/
|
*/
|
||||||
public ServerSettings(String type, String host, int port,
|
public ServerSettings(Type type, String host, int port,
|
||||||
ConnectionSecurity connectionSecurity, AuthType authenticationType, String username,
|
ConnectionSecurity connectionSecurity, AuthType authenticationType, String username,
|
||||||
String password, String clientCertificateAlias) {
|
String password, String clientCertificateAlias) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
@ -135,7 +138,7 @@ public class ServerSettings {
|
|||||||
* @param extra
|
* @param extra
|
||||||
* see {@link ServerSettings#extra}
|
* see {@link ServerSettings#extra}
|
||||||
*/
|
*/
|
||||||
public ServerSettings(String type, String host, int port,
|
public ServerSettings(Type type, String host, int port,
|
||||||
ConnectionSecurity connectionSecurity, AuthType authenticationType, String username,
|
ConnectionSecurity connectionSecurity, AuthType authenticationType, String username,
|
||||||
String password, String clientCertificateAlias, Map<String, String> extra) {
|
String password, String clientCertificateAlias, Map<String, String> extra) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
@ -158,7 +161,7 @@ public class ServerSettings {
|
|||||||
* @param type
|
* @param type
|
||||||
* see {@link ServerSettings#type}
|
* see {@link ServerSettings#type}
|
||||||
*/
|
*/
|
||||||
public ServerSettings(String type) {
|
public ServerSettings(Type type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
host = null;
|
host = null;
|
||||||
port = -1;
|
port = -1;
|
||||||
|
@ -5,6 +5,7 @@ import android.content.Context;
|
|||||||
|
|
||||||
import com.fsck.k9.mail.ssl.DefaultTrustedSocketFactory;
|
import com.fsck.k9.mail.ssl.DefaultTrustedSocketFactory;
|
||||||
import com.fsck.k9.mail.store.StoreConfig;
|
import com.fsck.k9.mail.store.StoreConfig;
|
||||||
|
import com.fsck.k9.mail.ServerSettings.Type;
|
||||||
import com.fsck.k9.mail.transport.SmtpTransport;
|
import com.fsck.k9.mail.transport.SmtpTransport;
|
||||||
import com.fsck.k9.mail.transport.WebDavTransport;
|
import com.fsck.k9.mail.transport.WebDavTransport;
|
||||||
|
|
||||||
@ -63,9 +64,9 @@ public abstract class Transport {
|
|||||||
* @see WebDavTransport#createUri(ServerSettings)
|
* @see WebDavTransport#createUri(ServerSettings)
|
||||||
*/
|
*/
|
||||||
public static String createTransportUri(ServerSettings server) {
|
public static String createTransportUri(ServerSettings server) {
|
||||||
if (SmtpTransport.TRANSPORT_TYPE.equals(server.type)) {
|
if (Type.SMTP == server.type) {
|
||||||
return SmtpTransport.createUri(server);
|
return SmtpTransport.createUri(server);
|
||||||
} else if (WebDavTransport.TRANSPORT_TYPE.equals(server.type)) {
|
} else if (Type.WebDAV == server.type) {
|
||||||
return WebDavTransport.createUri(server);
|
return WebDavTransport.createUri(server);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Not a valid transport URI");
|
throw new IllegalArgumentException("Not a valid transport URI");
|
||||||
|
@ -5,6 +5,7 @@ import android.net.ConnectivityManager;
|
|||||||
|
|
||||||
import com.fsck.k9.mail.MessagingException;
|
import com.fsck.k9.mail.MessagingException;
|
||||||
import com.fsck.k9.mail.ServerSettings;
|
import com.fsck.k9.mail.ServerSettings;
|
||||||
|
import com.fsck.k9.mail.ServerSettings.Type;
|
||||||
import com.fsck.k9.mail.Store;
|
import com.fsck.k9.mail.Store;
|
||||||
import com.fsck.k9.mail.ssl.DefaultTrustedSocketFactory;
|
import com.fsck.k9.mail.ssl.DefaultTrustedSocketFactory;
|
||||||
import com.fsck.k9.mail.ssl.TrustedSocketFactory;
|
import com.fsck.k9.mail.ssl.TrustedSocketFactory;
|
||||||
@ -121,11 +122,11 @@ public abstract class RemoteStore extends Store {
|
|||||||
* @see com.fsck.k9.mail.store.webdav.WebDavStore#createUri(com.fsck.k9.mail.ServerSettings)
|
* @see com.fsck.k9.mail.store.webdav.WebDavStore#createUri(com.fsck.k9.mail.ServerSettings)
|
||||||
*/
|
*/
|
||||||
public static String createStoreUri(ServerSettings server) {
|
public static String createStoreUri(ServerSettings server) {
|
||||||
if (ImapStore.STORE_TYPE.equals(server.type)) {
|
if (Type.IMAP == server.type) {
|
||||||
return ImapStore.createUri(server);
|
return ImapStore.createUri(server);
|
||||||
} else if (Pop3Store.STORE_TYPE.equals(server.type)) {
|
} else if (Type.POP3 == server.type) {
|
||||||
return Pop3Store.createUri(server);
|
return Pop3Store.createUri(server);
|
||||||
} else if (WebDavStore.STORE_TYPE.equals(server.type)) {
|
} else if (Type.WebDAV == server.type) {
|
||||||
return WebDavStore.createUri(server);
|
return WebDavStore.createUri(server);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Not a valid store URI");
|
throw new IllegalArgumentException("Not a valid store URI");
|
||||||
|
@ -77,7 +77,6 @@ import static com.fsck.k9.mail.K9MailLib.PUSH_WAKE_LOCK_TIMEOUT;
|
|||||||
* </pre>
|
* </pre>
|
||||||
*/
|
*/
|
||||||
public class ImapStore extends RemoteStore {
|
public class ImapStore extends RemoteStore {
|
||||||
public static final String STORE_TYPE = "IMAP";
|
|
||||||
|
|
||||||
private static final int IDLE_READ_TIMEOUT_INCREMENT = 5 * 60 * 1000;
|
private static final int IDLE_READ_TIMEOUT_INCREMENT = 5 * 60 * 1000;
|
||||||
private static final int IDLE_FAILURE_COUNT_LIMIT = 10;
|
private static final int IDLE_FAILURE_COUNT_LIMIT = 10;
|
||||||
@ -284,7 +283,7 @@ public class ImapStore extends RemoteStore {
|
|||||||
protected ImapStoreSettings(String host, int port, ConnectionSecurity connectionSecurity,
|
protected ImapStoreSettings(String host, int port, ConnectionSecurity connectionSecurity,
|
||||||
AuthType authenticationType, String username, String password, String clientCertificateAlias,
|
AuthType authenticationType, String username, String password, String clientCertificateAlias,
|
||||||
boolean autodetectNamespace, String pathPrefix) {
|
boolean autodetectNamespace, String pathPrefix) {
|
||||||
super(STORE_TYPE, host, port, connectionSecurity, authenticationType, username,
|
super(Type.IMAP, host, port, connectionSecurity, authenticationType, username,
|
||||||
password, clientCertificateAlias);
|
password, clientCertificateAlias);
|
||||||
this.autoDetectNamespace = autodetectNamespace;
|
this.autoDetectNamespace = autodetectNamespace;
|
||||||
this.pathPrefix = pathPrefix;
|
this.pathPrefix = pathPrefix;
|
||||||
|
@ -38,7 +38,6 @@ import static com.fsck.k9.mail.K9MailLib.LOG_TAG;
|
|||||||
import static com.fsck.k9.mail.CertificateValidationException.Reason.MissingCapability;
|
import static com.fsck.k9.mail.CertificateValidationException.Reason.MissingCapability;
|
||||||
|
|
||||||
public class Pop3Store extends RemoteStore {
|
public class Pop3Store extends RemoteStore {
|
||||||
public static final String STORE_TYPE = "POP3";
|
|
||||||
|
|
||||||
private static final String STLS_COMMAND = "STLS";
|
private static final String STLS_COMMAND = "STLS";
|
||||||
private static final String USER_COMMAND = "USER";
|
private static final String USER_COMMAND = "USER";
|
||||||
@ -140,7 +139,7 @@ public class Pop3Store extends RemoteStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ServerSettings(STORE_TYPE, host, port, connectionSecurity, authType, username,
|
return new ServerSettings(ServerSettings.Type.POP3, host, port, connectionSecurity, authType, username,
|
||||||
password, clientCertificateAlias);
|
password, clientCertificateAlias);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,6 @@ import static com.fsck.k9.mail.K9MailLib.LOG_TAG;
|
|||||||
* </pre>
|
* </pre>
|
||||||
*/
|
*/
|
||||||
public class WebDavStore extends RemoteStore {
|
public class WebDavStore extends RemoteStore {
|
||||||
public static final String STORE_TYPE = "WebDAV";
|
|
||||||
|
|
||||||
// Authentication types
|
// Authentication types
|
||||||
private static final short AUTH_TYPE_NONE = 0;
|
private static final short AUTH_TYPE_NONE = 0;
|
||||||
@ -248,7 +247,7 @@ public class WebDavStore extends RemoteStore {
|
|||||||
protected WebDavStoreSettings(String host, int port, ConnectionSecurity connectionSecurity,
|
protected WebDavStoreSettings(String host, int port, ConnectionSecurity connectionSecurity,
|
||||||
AuthType authenticationType, String username, String password, String clientCertificateAlias, String alias,
|
AuthType authenticationType, String username, String password, String clientCertificateAlias, String alias,
|
||||||
String path, String authPath, String mailboxPath) {
|
String path, String authPath, String mailboxPath) {
|
||||||
super(STORE_TYPE, host, port, connectionSecurity, authenticationType, username,
|
super(Type.WebDAV, host, port, connectionSecurity, authenticationType, username,
|
||||||
password, clientCertificateAlias);
|
password, clientCertificateAlias);
|
||||||
this.alias = alias;
|
this.alias = alias;
|
||||||
this.path = path;
|
this.path = path;
|
||||||
|
@ -32,8 +32,6 @@ import static com.fsck.k9.mail.CertificateValidationException.Reason.MissingCapa
|
|||||||
public class SmtpTransport extends Transport {
|
public class SmtpTransport extends Transport {
|
||||||
private TrustedSocketFactory mTrustedSocketFactory;
|
private TrustedSocketFactory mTrustedSocketFactory;
|
||||||
|
|
||||||
public static final String TRANSPORT_TYPE = "SMTP";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decodes a SmtpTransport URI.
|
* Decodes a SmtpTransport URI.
|
||||||
*
|
*
|
||||||
@ -115,7 +113,7 @@ public class SmtpTransport extends Transport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ServerSettings(TRANSPORT_TYPE, host, port, connectionSecurity,
|
return new ServerSettings(ServerSettings.Type.SMTP, host, port, connectionSecurity,
|
||||||
authType, username, password, clientCertificateAlias);
|
authType, username, password, clientCertificateAlias);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@ import java.util.Collections;
|
|||||||
import static com.fsck.k9.mail.K9MailLib.LOG_TAG;
|
import static com.fsck.k9.mail.K9MailLib.LOG_TAG;
|
||||||
|
|
||||||
public class WebDavTransport extends Transport {
|
public class WebDavTransport extends Transport {
|
||||||
public static final String TRANSPORT_TYPE = WebDavStore.STORE_TYPE;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decodes a WebDavTransport URI.
|
* Decodes a WebDavTransport URI.
|
||||||
|
28
k9mail/src/main/java/com/fsck/k9/account/AccountCreator.java
Normal file
28
k9mail/src/main/java/com/fsck/k9/account/AccountCreator.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package com.fsck.k9.account;
|
||||||
|
|
||||||
|
import com.fsck.k9.Account.DeletePolicy;
|
||||||
|
import com.fsck.k9.mail.ServerSettings.Type;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deals with logic surrounding account creation.
|
||||||
|
* <p/>
|
||||||
|
* TODO Move much of the code from com.fsck.k9.activity.setup.* into here
|
||||||
|
*/
|
||||||
|
public class AccountCreator {
|
||||||
|
|
||||||
|
private static Map<Type, DeletePolicy> defaults = new HashMap<Type, DeletePolicy>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
defaults.put(Type.IMAP, DeletePolicy.ON_DELETE);
|
||||||
|
defaults.put(Type.POP3, DeletePolicy.NEVER);
|
||||||
|
defaults.put(Type.WebDAV, DeletePolicy.ON_DELETE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DeletePolicy calculateDefaultDeletePolicy(Type type) {
|
||||||
|
return defaults.get(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -81,7 +81,6 @@ import com.fsck.k9.mail.Transport;
|
|||||||
import com.fsck.k9.mail.internet.MimeUtility;
|
import com.fsck.k9.mail.internet.MimeUtility;
|
||||||
import com.fsck.k9.mail.store.RemoteStore;
|
import com.fsck.k9.mail.store.RemoteStore;
|
||||||
import com.fsck.k9.mailstore.StorageManager;
|
import com.fsck.k9.mailstore.StorageManager;
|
||||||
import com.fsck.k9.mail.store.webdav.WebDavStore;
|
|
||||||
import com.fsck.k9.preferences.SettingsExporter;
|
import com.fsck.k9.preferences.SettingsExporter;
|
||||||
import com.fsck.k9.preferences.SettingsImportExportException;
|
import com.fsck.k9.preferences.SettingsImportExportException;
|
||||||
import com.fsck.k9.preferences.SettingsImporter;
|
import com.fsck.k9.preferences.SettingsImporter;
|
||||||
@ -779,7 +778,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
|||||||
* Also don't ask when the AuthType is EXTERNAL.
|
* Also don't ask when the AuthType is EXTERNAL.
|
||||||
*/
|
*/
|
||||||
boolean configureOutgoingServer = AuthType.EXTERNAL != outgoing.authenticationType
|
boolean configureOutgoingServer = AuthType.EXTERNAL != outgoing.authenticationType
|
||||||
&& !WebDavStore.STORE_TYPE.equals(outgoing.type)
|
&& !(ServerSettings.Type.WebDAV == outgoing.type)
|
||||||
&& outgoing.username != null
|
&& outgoing.username != null
|
||||||
&& !outgoing.username.isEmpty()
|
&& !outgoing.username.isEmpty()
|
||||||
&& (outgoing.password == null || outgoing.password
|
&& (outgoing.password == null || outgoing.password
|
||||||
|
@ -27,7 +27,6 @@ import android.widget.CompoundButton.OnCheckedChangeListener;
|
|||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
|
||||||
import com.fsck.k9.Account;
|
import com.fsck.k9.Account;
|
||||||
import com.fsck.k9.Account.DeletePolicy;
|
|
||||||
import com.fsck.k9.EmailAddressValidator;
|
import com.fsck.k9.EmailAddressValidator;
|
||||||
import com.fsck.k9.K9;
|
import com.fsck.k9.K9;
|
||||||
import com.fsck.k9.Preferences;
|
import com.fsck.k9.Preferences;
|
||||||
@ -40,9 +39,8 @@ import com.fsck.k9.mail.AuthType;
|
|||||||
import com.fsck.k9.mail.ConnectionSecurity;
|
import com.fsck.k9.mail.ConnectionSecurity;
|
||||||
import com.fsck.k9.mail.ServerSettings;
|
import com.fsck.k9.mail.ServerSettings;
|
||||||
import com.fsck.k9.mail.Transport;
|
import com.fsck.k9.mail.Transport;
|
||||||
import com.fsck.k9.mail.store.imap.ImapStore;
|
|
||||||
import com.fsck.k9.mail.store.RemoteStore;
|
import com.fsck.k9.mail.store.RemoteStore;
|
||||||
import com.fsck.k9.mail.transport.SmtpTransport;
|
import com.fsck.k9.account.AccountCreator;
|
||||||
import com.fsck.k9.view.ClientCertificateSpinner;
|
import com.fsck.k9.view.ClientCertificateSpinner;
|
||||||
import com.fsck.k9.view.ClientCertificateSpinner.OnClientCertificateChangedListener;
|
import com.fsck.k9.view.ClientCertificateSpinner.OnClientCertificateChangedListener;
|
||||||
|
|
||||||
@ -319,21 +317,12 @@ public class AccountSetupBasics extends K9Activity
|
|||||||
mAccount.setEmail(email);
|
mAccount.setEmail(email);
|
||||||
mAccount.setStoreUri(incomingUri.toString());
|
mAccount.setStoreUri(incomingUri.toString());
|
||||||
mAccount.setTransportUri(outgoingUri.toString());
|
mAccount.setTransportUri(outgoingUri.toString());
|
||||||
mAccount.setDraftsFolderName(getString(R.string.special_mailbox_name_drafts));
|
|
||||||
mAccount.setTrashFolderName(getString(R.string.special_mailbox_name_trash));
|
setupFolderNames(incomingUriTemplate.getHost().toLowerCase(Locale.US));
|
||||||
mAccount.setArchiveFolderName(getString(R.string.special_mailbox_name_archive));
|
|
||||||
// Yahoo! has a special folder for Spam, called "Bulk Mail".
|
ServerSettings incomingSettings = RemoteStore.decodeStoreUri(incomingUri.toString());
|
||||||
if (incomingUriTemplate.getHost().toLowerCase(Locale.US).endsWith(".yahoo.com")) {
|
mAccount.setDeletePolicy(AccountCreator.calculateDefaultDeletePolicy(incomingSettings.type));
|
||||||
mAccount.setSpamFolderName("Bulk Mail");
|
|
||||||
} else {
|
|
||||||
mAccount.setSpamFolderName(getString(R.string.special_mailbox_name_spam));
|
|
||||||
}
|
|
||||||
mAccount.setSentFolderName(getString(R.string.special_mailbox_name_sent));
|
|
||||||
if (incomingUri.toString().startsWith("imap")) {
|
|
||||||
mAccount.setDeletePolicy(DeletePolicy.ON_DELETE);
|
|
||||||
} else if (incomingUri.toString().startsWith("pop3")) {
|
|
||||||
mAccount.setDeletePolicy(DeletePolicy.NEVER);
|
|
||||||
}
|
|
||||||
// Check incoming here. Then check outgoing in onActivityResult()
|
// Check incoming here. Then check outgoing in onActivityResult()
|
||||||
AccountSetupCheckSettings.actionCheckSettings(this, mAccount, CheckDirection.INCOMING);
|
AccountSetupCheckSettings.actionCheckSettings(this, mAccount, CheckDirection.INCOMING);
|
||||||
} catch (URISyntaxException use) {
|
} catch (URISyntaxException use) {
|
||||||
@ -416,31 +405,37 @@ public class AccountSetupBasics extends K9Activity
|
|||||||
|
|
||||||
// set default uris
|
// set default uris
|
||||||
// NOTE: they will be changed again in AccountSetupAccountType!
|
// NOTE: they will be changed again in AccountSetupAccountType!
|
||||||
ServerSettings storeServer = new ServerSettings(ImapStore.STORE_TYPE, "mail." + domain, -1,
|
ServerSettings storeServer = new ServerSettings(ServerSettings.Type.IMAP, "mail." + domain, -1,
|
||||||
ConnectionSecurity.SSL_TLS_REQUIRED, authenticationType, user, password, clientCertificateAlias);
|
ConnectionSecurity.SSL_TLS_REQUIRED, authenticationType, user, password, clientCertificateAlias);
|
||||||
ServerSettings transportServer = new ServerSettings(SmtpTransport.TRANSPORT_TYPE, "mail." + domain, -1,
|
ServerSettings transportServer = new ServerSettings(ServerSettings.Type.SMTP, "mail." + domain, -1,
|
||||||
ConnectionSecurity.SSL_TLS_REQUIRED, authenticationType, user, password, clientCertificateAlias);
|
ConnectionSecurity.SSL_TLS_REQUIRED, authenticationType, user, password, clientCertificateAlias);
|
||||||
String storeUri = RemoteStore.createStoreUri(storeServer);
|
String storeUri = RemoteStore.createStoreUri(storeServer);
|
||||||
String transportUri = Transport.createTransportUri(transportServer);
|
String transportUri = Transport.createTransportUri(transportServer);
|
||||||
mAccount.setStoreUri(storeUri);
|
mAccount.setStoreUri(storeUri);
|
||||||
mAccount.setTransportUri(transportUri);
|
mAccount.setTransportUri(transportUri);
|
||||||
|
|
||||||
|
setupFolderNames(domain);
|
||||||
|
|
||||||
|
AccountSetupAccountType.actionSelectAccountType(this, mAccount, false);
|
||||||
|
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupFolderNames(String domain) {
|
||||||
mAccount.setDraftsFolderName(getString(R.string.special_mailbox_name_drafts));
|
mAccount.setDraftsFolderName(getString(R.string.special_mailbox_name_drafts));
|
||||||
mAccount.setTrashFolderName(getString(R.string.special_mailbox_name_trash));
|
mAccount.setTrashFolderName(getString(R.string.special_mailbox_name_trash));
|
||||||
mAccount.setSentFolderName(getString(R.string.special_mailbox_name_sent));
|
mAccount.setSentFolderName(getString(R.string.special_mailbox_name_sent));
|
||||||
mAccount.setArchiveFolderName(getString(R.string.special_mailbox_name_archive));
|
mAccount.setArchiveFolderName(getString(R.string.special_mailbox_name_archive));
|
||||||
|
|
||||||
// Yahoo! has a special folder for Spam, called "Bulk Mail".
|
// Yahoo! has a special folder for Spam, called "Bulk Mail".
|
||||||
if (domain.endsWith(".yahoo.com")) {
|
if (domain.endsWith(".yahoo.com")) {
|
||||||
mAccount.setSpamFolderName("Bulk Mail");
|
mAccount.setSpamFolderName("Bulk Mail");
|
||||||
} else {
|
} else {
|
||||||
mAccount.setSpamFolderName(getString(R.string.special_mailbox_name_spam));
|
mAccount.setSpamFolderName(getString(R.string.special_mailbox_name_spam));
|
||||||
}
|
}
|
||||||
|
|
||||||
AccountSetupAccountType.actionSelectAccountType(this, mAccount, false);
|
|
||||||
|
|
||||||
finish();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
switch (v.getId()) {
|
switch (v.getId()) {
|
||||||
case R.id.next:
|
case R.id.next:
|
||||||
|
@ -16,7 +16,6 @@ import android.widget.AdapterView.OnItemSelectedListener;
|
|||||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||||
|
|
||||||
import com.fsck.k9.*;
|
import com.fsck.k9.*;
|
||||||
import com.fsck.k9.Account.DeletePolicy;
|
|
||||||
import com.fsck.k9.Account.FolderMode;
|
import com.fsck.k9.Account.FolderMode;
|
||||||
import com.fsck.k9.Account.NetworkType;
|
import com.fsck.k9.Account.NetworkType;
|
||||||
import com.fsck.k9.activity.K9Activity;
|
import com.fsck.k9.activity.K9Activity;
|
||||||
@ -25,15 +24,13 @@ import com.fsck.k9.helper.Utility;
|
|||||||
import com.fsck.k9.mail.AuthType;
|
import com.fsck.k9.mail.AuthType;
|
||||||
import com.fsck.k9.mail.ConnectionSecurity;
|
import com.fsck.k9.mail.ConnectionSecurity;
|
||||||
import com.fsck.k9.mail.ServerSettings;
|
import com.fsck.k9.mail.ServerSettings;
|
||||||
|
import com.fsck.k9.mail.ServerSettings.Type;
|
||||||
import com.fsck.k9.mail.Store;
|
import com.fsck.k9.mail.Store;
|
||||||
import com.fsck.k9.mail.Transport;
|
import com.fsck.k9.mail.Transport;
|
||||||
import com.fsck.k9.mail.store.imap.ImapStore;
|
|
||||||
import com.fsck.k9.mail.store.pop3.Pop3Store;
|
|
||||||
import com.fsck.k9.mail.store.RemoteStore;
|
import com.fsck.k9.mail.store.RemoteStore;
|
||||||
import com.fsck.k9.mail.store.webdav.WebDavStore;
|
|
||||||
import com.fsck.k9.mail.store.imap.ImapStore.ImapStoreSettings;
|
import com.fsck.k9.mail.store.imap.ImapStore.ImapStoreSettings;
|
||||||
import com.fsck.k9.mail.store.webdav.WebDavStore.WebDavStoreSettings;
|
import com.fsck.k9.mail.store.webdav.WebDavStore.WebDavStoreSettings;
|
||||||
import com.fsck.k9.mail.transport.SmtpTransport;
|
import com.fsck.k9.account.AccountCreator;
|
||||||
import com.fsck.k9.service.MailService;
|
import com.fsck.k9.service.MailService;
|
||||||
import com.fsck.k9.view.ClientCertificateSpinner;
|
import com.fsck.k9.view.ClientCertificateSpinner;
|
||||||
import com.fsck.k9.view.ClientCertificateSpinner.OnClientCertificateChangedListener;
|
import com.fsck.k9.view.ClientCertificateSpinner.OnClientCertificateChangedListener;
|
||||||
@ -56,7 +53,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
private static final String WEBDAV_PORT = "80";
|
private static final String WEBDAV_PORT = "80";
|
||||||
private static final String WEBDAV_SSL_PORT = "443";
|
private static final String WEBDAV_SSL_PORT = "443";
|
||||||
|
|
||||||
private String mStoreType;
|
private Type mStoreType;
|
||||||
private EditText mUsernameView;
|
private EditText mUsernameView;
|
||||||
private EditText mPasswordView;
|
private EditText mPasswordView;
|
||||||
private ClientCertificateSpinner mClientCertificateSpinner;
|
private ClientCertificateSpinner mClientCertificateSpinner;
|
||||||
@ -190,7 +187,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
mStoreType = settings.type;
|
mStoreType = settings.type;
|
||||||
if (Pop3Store.STORE_TYPE.equals(settings.type)) {
|
if (Type.POP3 == settings.type) {
|
||||||
serverLabelView.setText(R.string.account_setup_incoming_pop_server_label);
|
serverLabelView.setText(R.string.account_setup_incoming_pop_server_label);
|
||||||
mDefaultPort = POP3_PORT;
|
mDefaultPort = POP3_PORT;
|
||||||
mDefaultSslPort = POP3_SSL_PORT;
|
mDefaultSslPort = POP3_SSL_PORT;
|
||||||
@ -202,8 +199,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
findViewById(R.id.compression_section).setVisibility(View.GONE);
|
findViewById(R.id.compression_section).setVisibility(View.GONE);
|
||||||
findViewById(R.id.compression_label).setVisibility(View.GONE);
|
findViewById(R.id.compression_label).setVisibility(View.GONE);
|
||||||
mSubscribedFoldersOnly.setVisibility(View.GONE);
|
mSubscribedFoldersOnly.setVisibility(View.GONE);
|
||||||
mAccount.setDeletePolicy(DeletePolicy.NEVER);
|
} else if (Type.IMAP == settings.type) {
|
||||||
} else if (ImapStore.STORE_TYPE.equals(settings.type)) {
|
|
||||||
serverLabelView.setText(R.string.account_setup_incoming_imap_server_label);
|
serverLabelView.setText(R.string.account_setup_incoming_imap_server_label);
|
||||||
mDefaultPort = IMAP_PORT;
|
mDefaultPort = IMAP_PORT;
|
||||||
mDefaultSslPort = IMAP_SSL_PORT;
|
mDefaultSslPort = IMAP_SSL_PORT;
|
||||||
@ -219,12 +215,11 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
findViewById(R.id.webdav_mailbox_alias_section).setVisibility(View.GONE);
|
findViewById(R.id.webdav_mailbox_alias_section).setVisibility(View.GONE);
|
||||||
findViewById(R.id.webdav_owa_path_section).setVisibility(View.GONE);
|
findViewById(R.id.webdav_owa_path_section).setVisibility(View.GONE);
|
||||||
findViewById(R.id.webdav_auth_path_section).setVisibility(View.GONE);
|
findViewById(R.id.webdav_auth_path_section).setVisibility(View.GONE);
|
||||||
mAccount.setDeletePolicy(DeletePolicy.ON_DELETE);
|
|
||||||
|
|
||||||
if (!Intent.ACTION_EDIT.equals(getIntent().getAction())) {
|
if (!Intent.ACTION_EDIT.equals(getIntent().getAction())) {
|
||||||
findViewById(R.id.imap_folder_setup_section).setVisibility(View.GONE);
|
findViewById(R.id.imap_folder_setup_section).setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
} else if (WebDavStore.STORE_TYPE.equals(settings.type)) {
|
} else if (Type.WebDAV == settings.type) {
|
||||||
serverLabelView.setText(R.string.account_setup_incoming_webdav_server_label);
|
serverLabelView.setText(R.string.account_setup_incoming_webdav_server_label);
|
||||||
mDefaultPort = WEBDAV_PORT;
|
mDefaultPort = WEBDAV_PORT;
|
||||||
mDefaultSslPort = WEBDAV_SSL_PORT;
|
mDefaultSslPort = WEBDAV_SSL_PORT;
|
||||||
@ -253,11 +248,12 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
if (webDavSettings.mailboxPath != null) {
|
if (webDavSettings.mailboxPath != null) {
|
||||||
mWebdavMailboxPathView.setText(webDavSettings.mailboxPath);
|
mWebdavMailboxPathView.setText(webDavSettings.mailboxPath);
|
||||||
}
|
}
|
||||||
mAccount.setDeletePolicy(DeletePolicy.ON_DELETE);
|
|
||||||
} else {
|
} else {
|
||||||
throw new Exception("Unknown account type: " + mAccount.getStoreUri());
|
throw new Exception("Unknown account type: " + mAccount.getStoreUri());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mAccount.setDeletePolicy(AccountCreator.calculateDefaultDeletePolicy(settings.type));
|
||||||
|
|
||||||
// Note that mConnectionSecurityChoices is configured above based on server type
|
// Note that mConnectionSecurityChoices is configured above based on server type
|
||||||
ConnectionSecurityAdapter securityTypesAdapter =
|
ConnectionSecurityAdapter securityTypesAdapter =
|
||||||
ConnectionSecurityAdapter.get(this, mConnectionSecurityChoices);
|
ConnectionSecurityAdapter.get(this, mConnectionSecurityChoices);
|
||||||
@ -551,7 +547,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
URI oldUri = new URI(mAccount.getTransportUri());
|
URI oldUri = new URI(mAccount.getTransportUri());
|
||||||
ServerSettings transportServer = new ServerSettings(SmtpTransport.TRANSPORT_TYPE, oldUri.getHost(), oldUri.getPort(),
|
ServerSettings transportServer = new ServerSettings(Type.SMTP, oldUri.getHost(), oldUri.getPort(),
|
||||||
ConnectionSecurity.SSL_TLS_REQUIRED, authType, username, password, clientCertificateAlias);
|
ConnectionSecurity.SSL_TLS_REQUIRED, authType, username, password, clientCertificateAlias);
|
||||||
String transportUri = Transport.createTransportUri(transportServer);
|
String transportUri = Transport.createTransportUri(transportServer);
|
||||||
mAccount.setTransportUri(transportUri);
|
mAccount.setTransportUri(transportUri);
|
||||||
@ -587,13 +583,13 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
int port = Integer.parseInt(mPortView.getText().toString());
|
int port = Integer.parseInt(mPortView.getText().toString());
|
||||||
|
|
||||||
Map<String, String> extra = null;
|
Map<String, String> extra = null;
|
||||||
if (ImapStore.STORE_TYPE.equals(mStoreType)) {
|
if (Type.IMAP == mStoreType) {
|
||||||
extra = new HashMap<String, String>();
|
extra = new HashMap<String, String>();
|
||||||
extra.put(ImapStoreSettings.AUTODETECT_NAMESPACE_KEY,
|
extra.put(ImapStoreSettings.AUTODETECT_NAMESPACE_KEY,
|
||||||
Boolean.toString(mImapAutoDetectNamespaceView.isChecked()));
|
Boolean.toString(mImapAutoDetectNamespaceView.isChecked()));
|
||||||
extra.put(ImapStoreSettings.PATH_PREFIX_KEY,
|
extra.put(ImapStoreSettings.PATH_PREFIX_KEY,
|
||||||
mImapPathPrefixView.getText().toString());
|
mImapPathPrefixView.getText().toString());
|
||||||
} else if (WebDavStore.STORE_TYPE.equals(mStoreType)) {
|
} else if (Type.WebDAV == mStoreType) {
|
||||||
extra = new HashMap<String, String>();
|
extra = new HashMap<String, String>();
|
||||||
extra.put(WebDavStoreSettings.PATH_KEY,
|
extra.put(WebDavStoreSettings.PATH_KEY,
|
||||||
mWebdavPathPrefixView.getText().toString());
|
mWebdavPathPrefixView.getText().toString());
|
||||||
|
@ -20,10 +20,10 @@ import com.fsck.k9.activity.K9Activity;
|
|||||||
import com.fsck.k9.activity.setup.AccountSetupCheckSettings.CheckDirection;
|
import com.fsck.k9.activity.setup.AccountSetupCheckSettings.CheckDirection;
|
||||||
import com.fsck.k9.helper.Utility;
|
import com.fsck.k9.helper.Utility;
|
||||||
import com.fsck.k9.mail.AuthType;
|
import com.fsck.k9.mail.AuthType;
|
||||||
|
import com.fsck.k9.mail.ServerSettings.Type;
|
||||||
import com.fsck.k9.mail.ConnectionSecurity;
|
import com.fsck.k9.mail.ConnectionSecurity;
|
||||||
import com.fsck.k9.mail.ServerSettings;
|
import com.fsck.k9.mail.ServerSettings;
|
||||||
import com.fsck.k9.mail.Transport;
|
import com.fsck.k9.mail.Transport;
|
||||||
import com.fsck.k9.mail.transport.SmtpTransport;
|
|
||||||
import com.fsck.k9.view.ClientCertificateSpinner;
|
import com.fsck.k9.view.ClientCertificateSpinner;
|
||||||
import com.fsck.k9.view.ClientCertificateSpinner.OnClientCertificateChangedListener;
|
import com.fsck.k9.view.ClientCertificateSpinner.OnClientCertificateChangedListener;
|
||||||
|
|
||||||
@ -485,8 +485,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
|||||||
|
|
||||||
String newHost = mServerView.getText().toString();
|
String newHost = mServerView.getText().toString();
|
||||||
int newPort = Integer.parseInt(mPortView.getText().toString());
|
int newPort = Integer.parseInt(mPortView.getText().toString());
|
||||||
String type = SmtpTransport.TRANSPORT_TYPE;
|
ServerSettings server = new ServerSettings(Type.SMTP, newHost, newPort, securityType, authType, username, password, clientCertificateAlias);
|
||||||
ServerSettings server = new ServerSettings(type, newHost, newPort, securityType, authType, username, password, clientCertificateAlias);
|
|
||||||
uri = Transport.createTransportUri(server);
|
uri = Transport.createTransportUri(server);
|
||||||
mAccount.deleteCertificate(newHost, newPort, CheckDirection.OUTGOING);
|
mAccount.deleteCertificate(newHost, newPort, CheckDirection.OUTGOING);
|
||||||
mAccount.setTransportUri(uri);
|
mAccount.setTransportUri(uri);
|
||||||
|
@ -225,7 +225,7 @@ public class SettingsExporter {
|
|||||||
// Write incoming server settings
|
// Write incoming server settings
|
||||||
ServerSettings incoming = RemoteStore.decodeStoreUri(account.getStoreUri());
|
ServerSettings incoming = RemoteStore.decodeStoreUri(account.getStoreUri());
|
||||||
serializer.startTag(null, INCOMING_SERVER_ELEMENT);
|
serializer.startTag(null, INCOMING_SERVER_ELEMENT);
|
||||||
serializer.attribute(null, TYPE_ATTRIBUTE, incoming.type);
|
serializer.attribute(null, TYPE_ATTRIBUTE, incoming.type.name());
|
||||||
|
|
||||||
writeElement(serializer, HOST_ELEMENT, incoming.host);
|
writeElement(serializer, HOST_ELEMENT, incoming.host);
|
||||||
if (incoming.port != -1) {
|
if (incoming.port != -1) {
|
||||||
@ -257,7 +257,7 @@ public class SettingsExporter {
|
|||||||
// Write outgoing server settings
|
// Write outgoing server settings
|
||||||
ServerSettings outgoing = Transport.decodeTransportUri(account.getTransportUri());
|
ServerSettings outgoing = Transport.decodeTransportUri(account.getTransportUri());
|
||||||
serializer.startTag(null, OUTGOING_SERVER_ELEMENT);
|
serializer.startTag(null, OUTGOING_SERVER_ELEMENT);
|
||||||
serializer.attribute(null, TYPE_ATTRIBUTE, outgoing.type);
|
serializer.attribute(null, TYPE_ATTRIBUTE, outgoing.type.name());
|
||||||
|
|
||||||
writeElement(serializer, HOST_ELEMENT, outgoing.host);
|
writeElement(serializer, HOST_ELEMENT, outgoing.host);
|
||||||
if (outgoing.port != -1) {
|
if (outgoing.port != -1) {
|
||||||
|
@ -28,7 +28,6 @@ import com.fsck.k9.mail.ServerSettings;
|
|||||||
import com.fsck.k9.mail.Transport;
|
import com.fsck.k9.mail.Transport;
|
||||||
import com.fsck.k9.mail.filter.Base64;
|
import com.fsck.k9.mail.filter.Base64;
|
||||||
import com.fsck.k9.mail.store.RemoteStore;
|
import com.fsck.k9.mail.store.RemoteStore;
|
||||||
import com.fsck.k9.mail.store.webdav.WebDavStore;
|
|
||||||
import com.fsck.k9.preferences.Settings.InvalidSettingValueException;
|
import com.fsck.k9.preferences.Settings.InvalidSettingValueException;
|
||||||
|
|
||||||
public class SettingsImporter {
|
public class SettingsImporter {
|
||||||
@ -384,7 +383,7 @@ public class SettingsImporter {
|
|||||||
boolean createAccountDisabled = AuthType.EXTERNAL != incoming.authenticationType &&
|
boolean createAccountDisabled = AuthType.EXTERNAL != incoming.authenticationType &&
|
||||||
(incoming.password == null || incoming.password.isEmpty());
|
(incoming.password == null || incoming.password.isEmpty());
|
||||||
|
|
||||||
if (account.outgoing == null && !WebDavStore.STORE_TYPE.equals(account.incoming.type)) {
|
if (account.outgoing == null && !ServerSettings.Type.WebDAV.name().equals(account.incoming.type)) {
|
||||||
// All account types except WebDAV need to provide outgoing server settings
|
// All account types except WebDAV need to provide outgoing server settings
|
||||||
throw new InvalidSettingValueException();
|
throw new InvalidSettingValueException();
|
||||||
}
|
}
|
||||||
@ -403,7 +402,7 @@ public class SettingsImporter {
|
|||||||
* password required if the AuthType is EXTERNAL.
|
* password required if the AuthType is EXTERNAL.
|
||||||
*/
|
*/
|
||||||
boolean outgoingPasswordNeeded = AuthType.EXTERNAL != outgoing.authenticationType &&
|
boolean outgoingPasswordNeeded = AuthType.EXTERNAL != outgoing.authenticationType &&
|
||||||
!WebDavStore.STORE_TYPE.equals(outgoing.type) &&
|
!(ServerSettings.Type.WebDAV == outgoing.type) &&
|
||||||
outgoing.username != null &&
|
outgoing.username != null &&
|
||||||
!outgoing.username.isEmpty() &&
|
!outgoing.username.isEmpty() &&
|
||||||
(outgoing.password == null || outgoing.password.isEmpty());
|
(outgoing.password == null || outgoing.password.isEmpty());
|
||||||
@ -1100,7 +1099,7 @@ public class SettingsImporter {
|
|||||||
private final ImportedServer mImportedServer;
|
private final ImportedServer mImportedServer;
|
||||||
|
|
||||||
public ImportedServerSettings(ImportedServer server) {
|
public ImportedServerSettings(ImportedServer server) {
|
||||||
super(server.type, server.host, convertPort(server.port),
|
super(ServerSettings.Type.valueOf(server.type), server.host, convertPort(server.port),
|
||||||
convertConnectionSecurity(server.connectionSecurity),
|
convertConnectionSecurity(server.connectionSecurity),
|
||||||
server.authenticationType, server.username, server.password,
|
server.authenticationType, server.username, server.password,
|
||||||
server.clientCertificateAlias);
|
server.clientCertificateAlias);
|
||||||
|
@ -91,7 +91,7 @@ public class ImapStoreUriTest {
|
|||||||
extra.put("autoDetectNamespace", "false");
|
extra.put("autoDetectNamespace", "false");
|
||||||
extra.put("pathPrefix", "customPathPrefix");
|
extra.put("pathPrefix", "customPathPrefix");
|
||||||
|
|
||||||
ServerSettings settings = new ServerSettings(ImapStore.STORE_TYPE, "server", 143,
|
ServerSettings settings = new ServerSettings(ServerSettings.Type.IMAP, "server", 143,
|
||||||
ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", null, extra);
|
ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", null, extra);
|
||||||
|
|
||||||
String uri = RemoteStore.createStoreUri(settings);
|
String uri = RemoteStore.createStoreUri(settings);
|
||||||
@ -105,7 +105,7 @@ public class ImapStoreUriTest {
|
|||||||
extra.put("autoDetectNamespace", "false");
|
extra.put("autoDetectNamespace", "false");
|
||||||
extra.put("pathPrefix", "");
|
extra.put("pathPrefix", "");
|
||||||
|
|
||||||
ServerSettings settings = new ServerSettings(ImapStore.STORE_TYPE, "server", 143,
|
ServerSettings settings = new ServerSettings(ServerSettings.Type.IMAP, "server", 143,
|
||||||
ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", null, extra);
|
ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", null, extra);
|
||||||
|
|
||||||
String uri = RemoteStore.createStoreUri(settings);
|
String uri = RemoteStore.createStoreUri(settings);
|
||||||
@ -115,7 +115,7 @@ public class ImapStoreUriTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateStoreUriImapNoExtra() {
|
public void testCreateStoreUriImapNoExtra() {
|
||||||
ServerSettings settings = new ServerSettings(ImapStore.STORE_TYPE, "server", 143,
|
ServerSettings settings = new ServerSettings(ServerSettings.Type.IMAP, "server", 143,
|
||||||
ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", null);
|
ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", null);
|
||||||
|
|
||||||
String uri = RemoteStore.createStoreUri(settings);
|
String uri = RemoteStore.createStoreUri(settings);
|
||||||
@ -128,7 +128,7 @@ public class ImapStoreUriTest {
|
|||||||
Map<String, String> extra = new HashMap<String, String>();
|
Map<String, String> extra = new HashMap<String, String>();
|
||||||
extra.put("autoDetectNamespace", "true");
|
extra.put("autoDetectNamespace", "true");
|
||||||
|
|
||||||
ServerSettings settings = new ServerSettings(ImapStore.STORE_TYPE, "server", 143,
|
ServerSettings settings = new ServerSettings(ServerSettings.Type.IMAP, "server", 143,
|
||||||
ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", null, extra);
|
ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", null, extra);
|
||||||
|
|
||||||
String uri = RemoteStore.createStoreUri(settings);
|
String uri = RemoteStore.createStoreUri(settings);
|
||||||
@ -138,7 +138,7 @@ public class ImapStoreUriTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateDecodeStoreUriWithSpecialCharactersInUsernameAndPassword() {
|
public void testCreateDecodeStoreUriWithSpecialCharactersInUsernameAndPassword() {
|
||||||
ServerSettings settings = new ServerSettings(ImapStore.STORE_TYPE, "server", 143,
|
ServerSettings settings = new ServerSettings(ServerSettings.Type.IMAP, "server", 143,
|
||||||
ConnectionSecurity.NONE, AuthType.PLAIN, "user@doma:n", "p@ssw:rd%", null, null);
|
ConnectionSecurity.NONE, AuthType.PLAIN, "user@doma:n", "p@ssw:rd%", null, null);
|
||||||
|
|
||||||
String uri = RemoteStore.createStoreUri(settings);
|
String uri = RemoteStore.createStoreUri(settings);
|
||||||
|
Loading…
Reference in New Issue
Block a user