Merge pull request #3410 from k9mail/modularize
Move email protocol implementations to separate Gradle modules
This commit is contained in:
commit
1a65fb90e3
242 changed files with 686 additions and 371 deletions
|
@ -1,2 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest package="com.fsck.k9.mail" />
|
|
@ -1,229 +0,0 @@
|
|||
package com.fsck.k9.mail;
|
||||
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import com.fsck.k9.mail.ServerSettings.Type;
|
||||
import com.fsck.k9.mail.store.webdav.WebDavStore;
|
||||
|
||||
|
||||
public class TransportUris {
|
||||
/**
|
||||
* Decodes the contents of transport-specific URIs and puts them into a {@link ServerSettings}
|
||||
* object.
|
||||
*
|
||||
* @param uri
|
||||
* the transport-specific URI to decode
|
||||
*
|
||||
* @return A {@link ServerSettings} object holding the settings contained in the URI.
|
||||
*/
|
||||
public static ServerSettings decodeTransportUri(String uri) {
|
||||
if (uri.startsWith("smtp")) {
|
||||
return decodeSmtpUri(uri);
|
||||
} else if (uri.startsWith("webdav")) {
|
||||
return decodeWebDavUri(uri);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Not a valid transport URI");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a transport URI from the information supplied in the {@link ServerSettings} object.
|
||||
*
|
||||
* @param server
|
||||
* The {@link ServerSettings} object that holds the server settings.
|
||||
*
|
||||
* @return A transport URI that holds the same information as the {@code server} parameter.
|
||||
*/
|
||||
public static String createTransportUri(ServerSettings server) {
|
||||
if (Type.SMTP == server.type) {
|
||||
return createSmtpUri(server);
|
||||
} else if (Type.WebDAV == server.type) {
|
||||
return createWebDavUri(server);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Not a valid transport URI");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Decodes a SmtpTransport URI.
|
||||
*
|
||||
* NOTE: In contrast to ImapStore and Pop3Store, the authType is appended at the end!
|
||||
*
|
||||
* <p>Possible forms:</p>
|
||||
* <pre>
|
||||
* smtp://user:password:auth@server:port ConnectionSecurity.NONE
|
||||
* smtp+tls+://user:password:auth@server:port ConnectionSecurity.STARTTLS_REQUIRED
|
||||
* smtp+ssl+://user:password:auth@server:port ConnectionSecurity.SSL_TLS_REQUIRED
|
||||
* </pre>
|
||||
*/
|
||||
private static ServerSettings decodeSmtpUri(String uri) {
|
||||
String host;
|
||||
int port;
|
||||
ConnectionSecurity connectionSecurity;
|
||||
AuthType authType = null;
|
||||
String username = null;
|
||||
String password = null;
|
||||
String clientCertificateAlias = null;
|
||||
|
||||
URI smtpUri;
|
||||
try {
|
||||
smtpUri = new URI(uri);
|
||||
} catch (URISyntaxException use) {
|
||||
throw new IllegalArgumentException("Invalid SmtpTransport URI", use);
|
||||
}
|
||||
|
||||
String scheme = smtpUri.getScheme();
|
||||
/*
|
||||
* Currently available schemes are:
|
||||
* smtp
|
||||
* smtp+tls+
|
||||
* smtp+ssl+
|
||||
*
|
||||
* The following are obsolete schemes that may be found in pre-existing
|
||||
* settings from earlier versions or that may be found when imported. We
|
||||
* continue to recognize them and re-map them appropriately:
|
||||
* smtp+tls
|
||||
* smtp+ssl
|
||||
*/
|
||||
if (scheme.equals("smtp")) {
|
||||
connectionSecurity = ConnectionSecurity.NONE;
|
||||
port = ServerSettings.Type.SMTP.defaultPort;
|
||||
} else if (scheme.startsWith("smtp+tls")) {
|
||||
connectionSecurity = ConnectionSecurity.STARTTLS_REQUIRED;
|
||||
port = ServerSettings.Type.SMTP.defaultPort;
|
||||
} else if (scheme.startsWith("smtp+ssl")) {
|
||||
connectionSecurity = ConnectionSecurity.SSL_TLS_REQUIRED;
|
||||
port = ServerSettings.Type.SMTP.defaultTlsPort;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unsupported protocol (" + scheme + ")");
|
||||
}
|
||||
|
||||
host = smtpUri.getHost();
|
||||
|
||||
if (smtpUri.getPort() != -1) {
|
||||
port = smtpUri.getPort();
|
||||
}
|
||||
|
||||
if (smtpUri.getUserInfo() != null) {
|
||||
String[] userInfoParts = smtpUri.getUserInfo().split(":");
|
||||
if (userInfoParts.length == 1) {
|
||||
authType = AuthType.PLAIN;
|
||||
username = decodeUtf8(userInfoParts[0]);
|
||||
} else if (userInfoParts.length == 2) {
|
||||
authType = AuthType.PLAIN;
|
||||
username = decodeUtf8(userInfoParts[0]);
|
||||
password = decodeUtf8(userInfoParts[1]);
|
||||
} else if (userInfoParts.length == 3) {
|
||||
// NOTE: In SmtpTransport URIs, the authType comes last!
|
||||
authType = AuthType.valueOf(userInfoParts[2]);
|
||||
username = decodeUtf8(userInfoParts[0]);
|
||||
if (authType == AuthType.EXTERNAL) {
|
||||
clientCertificateAlias = decodeUtf8(userInfoParts[1]);
|
||||
} else {
|
||||
password = decodeUtf8(userInfoParts[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new ServerSettings(ServerSettings.Type.SMTP, host, port, connectionSecurity,
|
||||
authType, username, password, clientCertificateAlias);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a SmtpTransport URI with the supplied settings.
|
||||
*
|
||||
* @param server
|
||||
* The {@link ServerSettings} object that holds the server settings.
|
||||
*
|
||||
* @return A SmtpTransport URI that holds the same information as the {@code server} parameter.
|
||||
*
|
||||
* @see com.fsck.k9.mail.store.StoreConfig#getTransportUri()
|
||||
*/
|
||||
private static String createSmtpUri(ServerSettings server) {
|
||||
String userEnc = (server.username != null) ?
|
||||
encodeUtf8(server.username) : "";
|
||||
String passwordEnc = (server.password != null) ?
|
||||
encodeUtf8(server.password) : "";
|
||||
String clientCertificateAliasEnc = (server.clientCertificateAlias != null) ?
|
||||
encodeUtf8(server.clientCertificateAlias) : "";
|
||||
|
||||
String scheme;
|
||||
switch (server.connectionSecurity) {
|
||||
case SSL_TLS_REQUIRED:
|
||||
scheme = "smtp+ssl+";
|
||||
break;
|
||||
case STARTTLS_REQUIRED:
|
||||
scheme = "smtp+tls+";
|
||||
break;
|
||||
default:
|
||||
case NONE:
|
||||
scheme = "smtp";
|
||||
break;
|
||||
}
|
||||
|
||||
String userInfo;
|
||||
AuthType authType = server.authenticationType;
|
||||
// NOTE: authType is append at last item, in contrast to ImapStore and Pop3Store!
|
||||
if (authType != null) {
|
||||
if (AuthType.EXTERNAL == authType) {
|
||||
userInfo = userEnc + ":" + clientCertificateAliasEnc + ":" + authType.name();
|
||||
} else {
|
||||
userInfo = userEnc + ":" + passwordEnc + ":" + authType.name();
|
||||
}
|
||||
} else {
|
||||
userInfo = userEnc + ":" + passwordEnc;
|
||||
}
|
||||
try {
|
||||
return new URI(scheme, userInfo, server.host, server.port, null, null,
|
||||
null).toString();
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IllegalArgumentException("Can't create SmtpTransport URI", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a WebDavTransport URI.
|
||||
*
|
||||
* <p>
|
||||
* <b>Note:</b> Everything related to sending messages via WebDAV is handled by
|
||||
* {@link WebDavStore}. So the transport URI is the same as the store URI.
|
||||
* </p>
|
||||
*/
|
||||
private static ServerSettings decodeWebDavUri(String uri) {
|
||||
return WebDavStore.decodeUri(uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a WebDavTransport URI.
|
||||
*
|
||||
* <p>
|
||||
* <b>Note:</b> Everything related to sending messages via WebDAV is handled by
|
||||
* {@link WebDavStore}. So the transport URI is the same as the store URI.
|
||||
* </p>
|
||||
*/
|
||||
private static String createWebDavUri(ServerSettings server) {
|
||||
return WebDavStore.createUri(server);
|
||||
}
|
||||
|
||||
private static String encodeUtf8(String s) {
|
||||
try {
|
||||
return URLEncoder.encode(s, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("UTF-8 not found");
|
||||
}
|
||||
}
|
||||
|
||||
private static String decodeUtf8(String s) {
|
||||
try {
|
||||
return URLDecoder.decode(s, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("UTF-8 not found");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
package com.fsck.k9.mail.store.imap
|
||||
|
||||
import com.fsck.k9.mail.MessagingException
|
||||
|
||||
class FolderNotFoundException(val folderServerId: String)
|
||||
: MessagingException("Folder not found: $folderServerId")
|
|
@ -19,7 +19,12 @@ configurations.all {
|
|||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${versions.kotlin}"
|
||||
|
||||
implementation project(':k9mail-library')
|
||||
implementation project(":mail:common")
|
||||
implementation project(":mail:protocols:imap")
|
||||
implementation project(":mail:protocols:pop3")
|
||||
implementation project(":mail:protocols:webdav")
|
||||
implementation project(":mail:protocols:smtp")
|
||||
|
||||
implementation project(':plugins:HoloColorPicker')
|
||||
implementation project(':plugins:openpgp-api-lib:openpgp-api')
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ import com.fsck.k9.mail.NetworkType;
|
|||
import com.fsck.k9.mail.filter.Base64;
|
||||
import com.fsck.k9.mail.ssl.LocalKeyStore;
|
||||
import com.fsck.k9.mail.store.RemoteStore;
|
||||
import com.fsck.k9.mail.store.RemoteStoreManager;
|
||||
import com.fsck.k9.mail.store.StoreConfig;
|
||||
import com.fsck.k9.mailstore.LocalStore;
|
||||
import com.fsck.k9.mailstore.StorageManager;
|
||||
|
@ -1186,7 +1187,7 @@ public class Account implements BaseAccount, StoreConfig {
|
|||
}
|
||||
|
||||
public RemoteStore getRemoteStore() throws MessagingException {
|
||||
return RemoteStore.getInstance(K9.app, this);
|
||||
return RemoteStoreManager.getInstance(K9.app, this);
|
||||
}
|
||||
|
||||
// It'd be great if this actually went into the store implementation
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
package com.fsck.k9;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
@ -10,12 +11,12 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import android.content.Context;
|
||||
import timber.log.Timber;
|
||||
|
||||
import com.fsck.k9.mail.store.RemoteStore;
|
||||
import com.fsck.k9.mail.store.RemoteStoreManager;
|
||||
import com.fsck.k9.mailstore.LocalStore;
|
||||
import com.fsck.k9.preferences.StorageEditor;
|
||||
import com.fsck.k9.preferences.Storage;
|
||||
import com.fsck.k9.preferences.StorageEditor;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
||||
public class Preferences {
|
||||
|
@ -126,7 +127,7 @@ public class Preferences {
|
|||
}
|
||||
|
||||
try {
|
||||
RemoteStore.removeInstance(account);
|
||||
RemoteStoreManager.removeInstance(account);
|
||||
} catch (Exception e) {
|
||||
Timber.e(e, "Failed to reset remote store for account %s", account.getUuid());
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ import com.fsck.k9.helper.SizeFormatter;
|
|||
import com.fsck.k9.mail.AuthType;
|
||||
import com.fsck.k9.mail.ServerSettings;
|
||||
import com.fsck.k9.mail.TransportUris;
|
||||
import com.fsck.k9.mail.store.RemoteStore;
|
||||
import com.fsck.k9.mail.store.RemoteStoreManager;
|
||||
import com.fsck.k9.mailstore.StorageManager;
|
||||
import com.fsck.k9.preferences.SettingsExporter;
|
||||
import com.fsck.k9.preferences.SettingsImportExportException;
|
||||
|
@ -744,7 +744,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
|||
}
|
||||
|
||||
private void show(final Accounts activity, boolean restore) {
|
||||
ServerSettings incoming = RemoteStore.decodeStoreUri(mAccount.getStoreUri());
|
||||
ServerSettings incoming = RemoteStoreManager.decodeStoreUri(mAccount.getStoreUri());
|
||||
ServerSettings outgoing = TransportUris.decodeTransportUri(mAccount.getTransportUri());
|
||||
|
||||
/*
|
||||
|
@ -962,9 +962,9 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
|||
if (mIncomingPassword != null) {
|
||||
// Set incoming server password
|
||||
String storeUri = mAccount.getStoreUri();
|
||||
ServerSettings incoming = RemoteStore.decodeStoreUri(storeUri);
|
||||
ServerSettings incoming = RemoteStoreManager.decodeStoreUri(storeUri);
|
||||
ServerSettings newIncoming = incoming.newPassword(mIncomingPassword);
|
||||
String newStoreUri = RemoteStore.createStoreUri(newIncoming);
|
||||
String newStoreUri = RemoteStoreManager.createStoreUri(newIncoming);
|
||||
mAccount.setStoreUri(newStoreUri);
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ import com.fsck.k9.mail.AuthType;
|
|||
import com.fsck.k9.mail.ConnectionSecurity;
|
||||
import com.fsck.k9.mail.ServerSettings;
|
||||
import com.fsck.k9.mail.TransportUris;
|
||||
import com.fsck.k9.mail.store.RemoteStore;
|
||||
import com.fsck.k9.mail.store.RemoteStoreManager;
|
||||
import com.fsck.k9.view.ClientCertificateSpinner;
|
||||
import com.fsck.k9.view.ClientCertificateSpinner.OnClientCertificateChangedListener;
|
||||
import timber.log.Timber;
|
||||
|
@ -320,7 +320,7 @@ public class AccountSetupBasics extends K9Activity
|
|||
mAccount.setStoreUri(incomingUri.toString());
|
||||
mAccount.setTransportUri(outgoingUri.toString());
|
||||
|
||||
ServerSettings incomingSettings = RemoteStore.decodeStoreUri(incomingUri.toString());
|
||||
ServerSettings incomingSettings = RemoteStoreManager.decodeStoreUri(incomingUri.toString());
|
||||
mAccount.setDeletePolicy(AccountCreator.getDefaultDeletePolicy(incomingSettings.type));
|
||||
|
||||
// Check incoming here. Then check outgoing in onActivityResult()
|
||||
|
@ -409,7 +409,7 @@ public class AccountSetupBasics extends K9Activity
|
|||
ConnectionSecurity.SSL_TLS_REQUIRED, authenticationType, email, password, clientCertificateAlias);
|
||||
ServerSettings transportServer = new ServerSettings(ServerSettings.Type.SMTP, "mail." + domain, -1,
|
||||
ConnectionSecurity.SSL_TLS_REQUIRED, authenticationType, email, password, clientCertificateAlias);
|
||||
String storeUri = RemoteStore.createStoreUri(storeServer);
|
||||
String storeUri = RemoteStoreManager.createStoreUri(storeServer);
|
||||
String transportUri = TransportUris.createTransportUri(transportServer);
|
||||
mAccount.setStoreUri(storeUri);
|
||||
mAccount.setTransportUri(transportUri);
|
||||
|
|
|
@ -42,6 +42,7 @@ import com.fsck.k9.mail.ServerSettings;
|
|||
import com.fsck.k9.mail.ServerSettings.Type;
|
||||
import com.fsck.k9.mail.TransportUris;
|
||||
import com.fsck.k9.mail.store.RemoteStore;
|
||||
import com.fsck.k9.mail.store.RemoteStoreManager;
|
||||
import com.fsck.k9.mail.store.imap.ImapStoreSettings;
|
||||
import com.fsck.k9.mail.store.webdav.WebDavStoreSettings;
|
||||
import com.fsck.k9.service.MailService;
|
||||
|
@ -173,7 +174,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||
boolean editSettings = Intent.ACTION_EDIT.equals(getIntent().getAction());
|
||||
|
||||
try {
|
||||
ServerSettings settings = RemoteStore.decodeStoreUri(mAccount.getStoreUri());
|
||||
ServerSettings settings = RemoteStoreManager.decodeStoreUri(mAccount.getStoreUri());
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
// The first item is selected if settings.authenticationType is null or is not in mAuthTypeAdapter
|
||||
|
@ -592,7 +593,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||
ServerSettings settings = new ServerSettings(mStoreType, host, port,
|
||||
connectionSecurity, authType, username, password, clientCertificateAlias, extra);
|
||||
|
||||
mAccount.setStoreUri(RemoteStore.createStoreUri(settings));
|
||||
mAccount.setStoreUri(RemoteStoreManager.createStoreUri(settings));
|
||||
|
||||
mAccount.setCompression(NetworkType.MOBILE, mCompressionMobile.isChecked());
|
||||
mAccount.setCompression(NetworkType.WIFI, mCompressionWifi.isChecked());
|
||||
|
|
|
@ -67,7 +67,6 @@ import com.fsck.k9.mail.FetchProfile;
|
|||
import com.fsck.k9.mail.FetchProfile.Item;
|
||||
import com.fsck.k9.mail.Flag;
|
||||
import com.fsck.k9.mail.Folder;
|
||||
import com.fsck.k9.mail.Folder.FolderType;
|
||||
import com.fsck.k9.mail.Message;
|
||||
import com.fsck.k9.mail.Message.RecipientType;
|
||||
import com.fsck.k9.mail.MessageRetrievalListener;
|
||||
|
|
102
k9mail/src/main/java/com/fsck/k9/mail/TransportUris.java
Normal file
102
k9mail/src/main/java/com/fsck/k9/mail/TransportUris.java
Normal file
|
@ -0,0 +1,102 @@
|
|||
package com.fsck.k9.mail;
|
||||
|
||||
|
||||
import com.fsck.k9.mail.ServerSettings.Type;
|
||||
import com.fsck.k9.mail.store.webdav.WebDavStore;
|
||||
import com.fsck.k9.mail.transport.smtp.SmtpTransportUriCreator;
|
||||
import com.fsck.k9.mail.transport.smtp.SmtpTransportUriDecoder;
|
||||
|
||||
|
||||
public class TransportUris {
|
||||
/**
|
||||
* Decodes the contents of transport-specific URIs and puts them into a {@link ServerSettings}
|
||||
* object.
|
||||
*
|
||||
* @param uri
|
||||
* the transport-specific URI to decode
|
||||
*
|
||||
* @return A {@link ServerSettings} object holding the settings contained in the URI.
|
||||
*/
|
||||
public static ServerSettings decodeTransportUri(String uri) {
|
||||
if (uri.startsWith("smtp")) {
|
||||
return decodeSmtpUri(uri);
|
||||
} else if (uri.startsWith("webdav")) {
|
||||
return decodeWebDavUri(uri);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Not a valid transport URI");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a transport URI from the information supplied in the {@link ServerSettings} object.
|
||||
*
|
||||
* @param server
|
||||
* The {@link ServerSettings} object that holds the server settings.
|
||||
*
|
||||
* @return A transport URI that holds the same information as the {@code server} parameter.
|
||||
*/
|
||||
public static String createTransportUri(ServerSettings server) {
|
||||
if (Type.SMTP == server.type) {
|
||||
return createSmtpUri(server);
|
||||
} else if (Type.WebDAV == server.type) {
|
||||
return createWebDavUri(server);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Not a valid transport URI");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Decodes a SmtpTransport URI.
|
||||
*
|
||||
* NOTE: In contrast to ImapStore and Pop3Store, the authType is appended at the end!
|
||||
*
|
||||
* <p>Possible forms:</p>
|
||||
* <pre>
|
||||
* smtp://user:password:auth@server:port ConnectionSecurity.NONE
|
||||
* smtp+tls+://user:password:auth@server:port ConnectionSecurity.STARTTLS_REQUIRED
|
||||
* smtp+ssl+://user:password:auth@server:port ConnectionSecurity.SSL_TLS_REQUIRED
|
||||
* </pre>
|
||||
*/
|
||||
private static ServerSettings decodeSmtpUri(String uri) {
|
||||
return SmtpTransportUriDecoder.decodeSmtpUri(uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a SmtpTransport URI with the supplied settings.
|
||||
*
|
||||
* @param server
|
||||
* The {@link ServerSettings} object that holds the server settings.
|
||||
*
|
||||
* @return A SmtpTransport URI that holds the same information as the {@code server} parameter.
|
||||
*
|
||||
* @see com.fsck.k9.mail.store.StoreConfig#getTransportUri()
|
||||
*/
|
||||
private static String createSmtpUri(ServerSettings server) {
|
||||
return SmtpTransportUriCreator.createSmtpUri(server);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a WebDavTransport URI.
|
||||
*
|
||||
* <p>
|
||||
* <b>Note:</b> Everything related to sending messages via WebDAV is handled by
|
||||
* {@link WebDavStore}. So the transport URI is the same as the store URI.
|
||||
* </p>
|
||||
*/
|
||||
private static ServerSettings decodeWebDavUri(String uri) {
|
||||
return WebDavStore.decodeUri(uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a WebDavTransport URI.
|
||||
*
|
||||
* <p>
|
||||
* <b>Note:</b> Everything related to sending messages via WebDAV is handled by
|
||||
* {@link WebDavStore}. So the transport URI is the same as the store URI.
|
||||
* </p>
|
||||
*/
|
||||
private static String createWebDavUri(ServerSettings server) {
|
||||
return WebDavStore.createUri(server);
|
||||
}
|
||||
}
|
|
@ -2,46 +2,29 @@ package com.fsck.k9.mail.store;
|
|||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
|
||||
import com.fsck.k9.mail.Folder;
|
||||
import com.fsck.k9.mail.Message;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
import com.fsck.k9.mail.PushReceiver;
|
||||
import com.fsck.k9.mail.Pusher;
|
||||
import com.fsck.k9.mail.ServerSettings;
|
||||
import com.fsck.k9.mail.ServerSettings.Type;
|
||||
import com.fsck.k9.mail.oauth.OAuth2TokenProvider;
|
||||
import com.fsck.k9.mail.ssl.DefaultTrustedSocketFactory;
|
||||
import com.fsck.k9.mail.ssl.TrustedSocketFactory;
|
||||
import com.fsck.k9.mail.store.imap.ImapStore;
|
||||
import com.fsck.k9.mail.store.pop3.Pop3Store;
|
||||
import com.fsck.k9.mail.store.webdav.WebDavHttpClient;
|
||||
import com.fsck.k9.mail.store.webdav.WebDavStore;
|
||||
|
||||
|
||||
public abstract class RemoteStore {
|
||||
public static final int SOCKET_CONNECT_TIMEOUT = 30000;
|
||||
public static final int SOCKET_READ_TIMEOUT = 60000;
|
||||
|
||||
protected StoreConfig mStoreConfig;
|
||||
protected TrustedSocketFactory mTrustedSocketFactory;
|
||||
|
||||
public abstract class RemoteStoreManager {
|
||||
/**
|
||||
* Remote stores indexed by Uri.
|
||||
*/
|
||||
private static Map<String, RemoteStore> sStores = new HashMap<>();
|
||||
|
||||
|
||||
public RemoteStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory) {
|
||||
mStoreConfig = storeConfig;
|
||||
mTrustedSocketFactory = trustedSocketFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an instance of a remote mail store.
|
||||
*/
|
||||
|
@ -83,7 +66,7 @@ public abstract class RemoteStore {
|
|||
/**
|
||||
* Release reference to a remote mail store instance.
|
||||
*
|
||||
* @param storeConfig {@link com.fsck.k9.mail.store.StoreConfig} instance that is used to get the remote mail store instance.
|
||||
* @param storeConfig {@link StoreConfig} instance that is used to get the remote mail store instance.
|
||||
*/
|
||||
public static void removeInstance(StoreConfig storeConfig) {
|
||||
String uri = storeConfig.getStoreUri();
|
||||
|
@ -95,17 +78,17 @@ public abstract class RemoteStore {
|
|||
}
|
||||
|
||||
/**
|
||||
* Decodes the contents of store-specific URIs and puts them into a {@link com.fsck.k9.mail.ServerSettings}
|
||||
* Decodes the contents of store-specific URIs and puts them into a {@link ServerSettings}
|
||||
* object.
|
||||
*
|
||||
* @param uri
|
||||
* the store-specific URI to decode
|
||||
*
|
||||
* @return A {@link com.fsck.k9.mail.ServerSettings} object holding the settings contained in the URI.
|
||||
* @return A {@link ServerSettings} object holding the settings contained in the URI.
|
||||
*
|
||||
* @see com.fsck.k9.mail.store.imap.ImapStore#decodeUri(String)
|
||||
* @see com.fsck.k9.mail.store.pop3.Pop3Store#decodeUri(String)
|
||||
* @see com.fsck.k9.mail.store.webdav.WebDavStore#decodeUri(String)
|
||||
* @see ImapStore#decodeUri(String)
|
||||
* @see Pop3Store#decodeUri(String)
|
||||
* @see WebDavStore#decodeUri(String)
|
||||
*/
|
||||
public static ServerSettings decodeStoreUri(String uri) {
|
||||
if (uri.startsWith("imap")) {
|
||||
|
@ -120,16 +103,16 @@ public abstract class RemoteStore {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates a store URI from the information supplied in the {@link com.fsck.k9.mail.ServerSettings} object.
|
||||
* Creates a store URI from the information supplied in the {@link ServerSettings} object.
|
||||
*
|
||||
* @param server
|
||||
* The {@link com.fsck.k9.mail.ServerSettings} object that holds the server settings.
|
||||
* The {@link ServerSettings} object that holds the server settings.
|
||||
*
|
||||
* @return A store URI that holds the same information as the {@code server} parameter.
|
||||
*
|
||||
* @see com.fsck.k9.mail.store.imap.ImapStore#createUri(com.fsck.k9.mail.ServerSettings)
|
||||
* @see com.fsck.k9.mail.store.pop3.Pop3Store#createUri(com.fsck.k9.mail.ServerSettings)
|
||||
* @see com.fsck.k9.mail.store.webdav.WebDavStore#createUri(com.fsck.k9.mail.ServerSettings)
|
||||
* @see ImapStore#createUri(ServerSettings)
|
||||
* @see Pop3Store#createUri(ServerSettings)
|
||||
* @see WebDavStore#createUri(ServerSettings)
|
||||
*/
|
||||
public static String createStoreUri(ServerSettings server) {
|
||||
if (Type.IMAP == server.type) {
|
||||
|
@ -142,36 +125,4 @@ public abstract class RemoteStore {
|
|||
throw new IllegalArgumentException("Not a valid store URI");
|
||||
}
|
||||
}
|
||||
|
||||
public abstract Folder<? extends Message> getFolder(String name);
|
||||
|
||||
public abstract List<? extends Folder > getPersonalNamespaces(boolean forceListAll) throws MessagingException;
|
||||
|
||||
public abstract void checkSettings() throws MessagingException;
|
||||
|
||||
public boolean isCopyCapable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isMoveCapable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isPushCapable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isExpungeCapable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isSeenFlagSupported() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void sendMessages(List<? extends Message> messages) throws MessagingException { }
|
||||
|
||||
public Pusher getPusher(PushReceiver receiver) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -20,19 +20,18 @@ import java.util.TreeMap;
|
|||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Environment;
|
||||
|
||||
import com.fsck.k9.mail.TransportUris;
|
||||
import timber.log.Timber;
|
||||
import android.util.Xml;
|
||||
|
||||
import com.fsck.k9.Account;
|
||||
import com.fsck.k9.Preferences;
|
||||
import com.fsck.k9.helper.FileHelper;
|
||||
import com.fsck.k9.mail.ServerSettings;
|
||||
import com.fsck.k9.mail.store.RemoteStore;
|
||||
import com.fsck.k9.mail.TransportUris;
|
||||
import com.fsck.k9.mail.store.RemoteStoreManager;
|
||||
import com.fsck.k9.preferences.Settings.InvalidSettingValueException;
|
||||
import com.fsck.k9.preferences.Settings.SettingsDescription;
|
||||
import org.xmlpull.v1.XmlSerializer;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
||||
public class SettingsExporter {
|
||||
|
@ -235,7 +234,7 @@ public class SettingsExporter {
|
|||
}
|
||||
|
||||
// Write incoming server settings
|
||||
ServerSettings incoming = RemoteStore.decodeStoreUri(account.getStoreUri());
|
||||
ServerSettings incoming = RemoteStoreManager.decodeStoreUri(account.getStoreUri());
|
||||
serializer.startTag(null, INCOMING_SERVER_ELEMENT);
|
||||
serializer.attribute(null, TYPE_ATTRIBUTE, incoming.type.name());
|
||||
|
||||
|
|
|
@ -17,9 +17,6 @@ import android.content.SharedPreferences;
|
|||
import android.support.annotation.VisibleForTesting;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.fsck.k9.mail.TransportUris;
|
||||
import timber.log.Timber;
|
||||
|
||||
import com.fsck.k9.Account;
|
||||
import com.fsck.k9.Identity;
|
||||
import com.fsck.k9.K9;
|
||||
|
@ -27,12 +24,14 @@ import com.fsck.k9.Preferences;
|
|||
import com.fsck.k9.mail.AuthType;
|
||||
import com.fsck.k9.mail.ConnectionSecurity;
|
||||
import com.fsck.k9.mail.ServerSettings;
|
||||
import com.fsck.k9.mail.TransportUris;
|
||||
import com.fsck.k9.mail.filter.Base64;
|
||||
import com.fsck.k9.mail.store.RemoteStore;
|
||||
import com.fsck.k9.mail.store.RemoteStoreManager;
|
||||
import com.fsck.k9.preferences.Settings.InvalidSettingValueException;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
||||
public class SettingsImporter {
|
||||
|
@ -347,7 +346,7 @@ public class SettingsImporter {
|
|||
|
||||
// Write incoming server settings (storeUri)
|
||||
ServerSettings incoming = new ImportedServerSettings(account.incoming);
|
||||
String storeUri = RemoteStore.createStoreUri(incoming);
|
||||
String storeUri = RemoteStoreManager.createStoreUri(incoming);
|
||||
putString(editor, accountKeyPrefix + Account.STORE_URI_KEY, Base64.encode(storeUri));
|
||||
|
||||
// Mark account as disabled if the AuthType isn't EXTERNAL and the
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'org.jetbrains.kotlin.android'
|
||||
|
||||
apply from: '../gradle/plugins/checkstyle-android.gradle'
|
||||
apply from: '../gradle/plugins/findbugs-android.gradle'
|
||||
apply from: "${rootProject.projectDir}/gradle/plugins/checkstyle-android.gradle"
|
||||
apply from: "${rootProject.projectDir}/gradle/plugins/findbugs-android.gradle"
|
||||
|
||||
if (rootProject.testCoverage) {
|
||||
apply plugin: 'jacoco'
|
||||
|
@ -15,22 +15,17 @@ dependencies {
|
|||
implementation "org.apache.james:apache-mime4j-dom:0.8.1"
|
||||
implementation "com.squareup.okio:okio:${versions.okio}"
|
||||
implementation "commons-io:commons-io:${versions.commonsIo}"
|
||||
implementation "com.jcraft:jzlib:1.0.7"
|
||||
implementation "com.beetstra.jutf7:jutf7:1.0.0"
|
||||
implementation "com.android.support:support-annotations:${versions.supportLibrary}"
|
||||
implementation "com.jakewharton.timber:timber:${versions.timber}"
|
||||
|
||||
androidTestImplementation "com.android.support.test:runner:0.4.1"
|
||||
androidTestImplementation "com.madgag.spongycastle:pg:1.51.0.0"
|
||||
|
||||
testImplementation project(":mail:testing")
|
||||
testImplementation "org.robolectric:robolectric:${versions.robolectric}"
|
||||
testImplementation "junit:junit:${versions.junit}"
|
||||
testImplementation "com.google.truth:truth:${versions.truth}"
|
||||
testImplementation "org.mockito:mockito-core:${versions.mockito}"
|
||||
|
||||
// The Android Gradle plugin doesn't seem to put the Apache HTTP Client on the runtime classpath anymore when
|
||||
// running JVM tests.
|
||||
testImplementation "org.apache.httpcomponents:httpclient:4.5.5"
|
||||
}
|
||||
|
||||
android {
|
||||
|
@ -43,9 +38,6 @@ android {
|
|||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
// for using Apache HTTP Client
|
||||
useLibrary 'org.apache.http.legacy'
|
||||
|
||||
buildTypes {
|
||||
debug {
|
||||
testCoverageEnabled rootProject.testCoverage
|
||||
|
@ -61,13 +53,4 @@ android {
|
|||
sourceCompatibility JavaVersion.VERSION_1_7
|
||||
targetCompatibility JavaVersion.VERSION_1_7
|
||||
}
|
||||
|
||||
packagingOptions {
|
||||
exclude 'META-INF/DEPENDENCIES'
|
||||
exclude 'META-INF/LICENSE'
|
||||
exclude 'META-INF/LICENSE.txt'
|
||||
exclude 'META-INF/NOTICE'
|
||||
exclude 'META-INF/NOTICE.txt'
|
||||
exclude 'LICENSE.txt'
|
||||
}
|
||||
}
|
2
mail/common/src/main/AndroidManifest.xml
Normal file
2
mail/common/src/main/AndroidManifest.xml
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest package="com.fsck.k9.mail.common" />
|
|
@ -0,0 +1,58 @@
|
|||
package com.fsck.k9.mail.store;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.fsck.k9.mail.Folder;
|
||||
import com.fsck.k9.mail.Message;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
import com.fsck.k9.mail.PushReceiver;
|
||||
import com.fsck.k9.mail.Pusher;
|
||||
import com.fsck.k9.mail.ssl.TrustedSocketFactory;
|
||||
|
||||
|
||||
public abstract class RemoteStore {
|
||||
public static final int SOCKET_CONNECT_TIMEOUT = 30000;
|
||||
public static final int SOCKET_READ_TIMEOUT = 60000;
|
||||
|
||||
protected StoreConfig mStoreConfig;
|
||||
protected TrustedSocketFactory mTrustedSocketFactory;
|
||||
|
||||
|
||||
public RemoteStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory) {
|
||||
mStoreConfig = storeConfig;
|
||||
mTrustedSocketFactory = trustedSocketFactory;
|
||||
}
|
||||
|
||||
public abstract Folder<? extends Message> getFolder(String name);
|
||||
|
||||
public abstract List<? extends Folder > getPersonalNamespaces(boolean forceListAll) throws MessagingException;
|
||||
|
||||
public abstract void checkSettings() throws MessagingException;
|
||||
|
||||
public boolean isCopyCapable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isMoveCapable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isPushCapable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isExpungeCapable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isSeenFlagSupported() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void sendMessages(List<? extends Message> messages) throws MessagingException { }
|
||||
|
||||
public Pusher getPusher(PushReceiver receiver) {
|
||||
return null;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue