Skip to content

Commit

Permalink
Merge pull request #3218 from k9mail/GH-832_break_up_LocalStore_and_R…
Browse files Browse the repository at this point in the history
…emoteStore

Break up LocalStore and RemoteStore
  • Loading branch information
cketti authored Feb 27, 2018
2 parents 5152d04 + 9519ffa commit fdce9af
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 152 deletions.
51 changes: 0 additions & 51 deletions k9mail-library/src/main/java/com/fsck/k9/mail/Store.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@


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.Store;
import com.fsck.k9.mail.oauth.OAuth2TokenProvider;
import com.fsck.k9.mail.ssl.DefaultTrustedSocketFactory;
import com.fsck.k9.mail.ssl.TrustedSocketFactory;
Expand All @@ -20,7 +24,7 @@
import com.fsck.k9.mail.store.webdav.WebDavStore;


public abstract class RemoteStore extends Store {
public abstract class RemoteStore {
public static final int SOCKET_CONNECT_TIMEOUT = 30000;
public static final int SOCKET_READ_TIMEOUT = 60000;

Expand All @@ -30,7 +34,7 @@ public abstract class RemoteStore extends Store {
/**
* Remote stores indexed by Uri.
*/
private static Map<String, Store> sStores = new HashMap<String, Store>();
private static Map<String, RemoteStore> sStores = new HashMap<>();


public RemoteStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory) {
Expand All @@ -41,14 +45,15 @@ public RemoteStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFa
/**
* Get an instance of a remote mail store.
*/
public static synchronized Store getInstance(Context context, StoreConfig storeConfig) throws MessagingException {
public static synchronized RemoteStore getInstance(Context context, StoreConfig storeConfig)
throws MessagingException {
String uri = storeConfig.getStoreUri();

if (uri.startsWith("local")) {
throw new RuntimeException("Asked to get non-local Store object but given LocalStore URI");
}

Store store = sStores.get(uri);
RemoteStore store = sStores.get(uri);
if (store == null) {
if (uri.startsWith("imap")) {
OAuth2TokenProvider oAuth2TokenProvider = null;
Expand Down Expand Up @@ -137,4 +142,36 @@ public static String createStoreUri(ServerSettings server) {
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -976,11 +976,6 @@ DataSet processRequest(String url, String method, String messageBody, Map<String
return dataset;
}

@Override
public boolean isSendCapable() {
return true;
}

@Override
public void sendMessages(List<? extends Message> messages) throws MessagingException {
WebDavFolder tmpFolder = getFolder(mStoreConfig.getDraftsFolderName());
Expand Down
3 changes: 1 addition & 2 deletions k9mail/src/main/java/com/fsck/k9/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.fsck.k9.mail.Address;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.NetworkType;
import com.fsck.k9.mail.Store;
import com.fsck.k9.mail.Folder.FolderClass;
import com.fsck.k9.mail.filter.Base64;
import com.fsck.k9.mail.store.RemoteStore;
Expand Down Expand Up @@ -1308,7 +1307,7 @@ public LocalStore getLocalStore() throws MessagingException {
return LocalStore.getInstance(this, K9.app);
}

public Store getRemoteStore() throws MessagingException {
public RemoteStore getRemoteStore() throws MessagingException {
return RemoteStore.getInstance(K9.app, this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface.OnCancelListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
Expand All @@ -23,8 +22,6 @@
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceScreen;
import android.preference.RingtonePreference;
import android.widget.CompoundButton;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.Toast;

import com.fsck.k9.Account;
Expand All @@ -46,7 +43,7 @@
import com.fsck.k9.activity.ManageIdentities;
import com.fsck.k9.crypto.OpenPgpApiHelper;
import com.fsck.k9.mail.Folder;
import com.fsck.k9.mail.Store;
import com.fsck.k9.mail.store.RemoteStore;
import com.fsck.k9.mailstore.StorageManager;
import com.fsck.k9.service.MailService;
import com.fsck.k9.ui.dialog.AutocryptPreferEncryptDialog;
Expand Down Expand Up @@ -220,7 +217,7 @@ public void onCreate(Bundle savedInstanceState) {
account = Preferences.getPreferences(this).getAccount(accountUuid);

try {
final Store store = account.getRemoteStore();
RemoteStore store = account.getRemoteStore();
isMoveCapable = store.isMoveCapable();
isPushCapable = store.isPushCapable();
isExpungeCapable = store.isExpungeCapable();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@

package com.fsck.k9.activity.setup;


import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateEncodingException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.Collection;
import java.util.List;
import java.util.Locale;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.DialogFragment;
Expand All @@ -11,33 +21,28 @@
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import timber.log.Timber;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.fsck.k9.*;
import com.fsck.k9.Account;
import com.fsck.k9.K9;
import com.fsck.k9.Preferences;
import com.fsck.k9.R;
import com.fsck.k9.activity.K9Activity;
import com.fsck.k9.controller.MessagingController;
import com.fsck.k9.fragment.ConfirmationDialogFragment;
import com.fsck.k9.fragment.ConfirmationDialogFragment.ConfirmationDialogFragmentListener;
import com.fsck.k9.mail.AuthenticationFailedException;
import com.fsck.k9.mail.CertificateValidationException;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.Store;
import com.fsck.k9.mail.Transport;
import com.fsck.k9.mail.TransportProvider;
import com.fsck.k9.mail.store.webdav.WebDavStore;
import com.fsck.k9.mail.filter.Hex;
import java.security.cert.CertificateException;
import java.security.cert.CertificateEncodingException;
import java.security.cert.X509Certificate;
import java.security.NoSuchAlgorithmException;
import java.security.MessageDigest;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import com.fsck.k9.mail.store.RemoteStore;
import com.fsck.k9.mail.store.webdav.WebDavStore;
import timber.log.Timber;

/**
* Checks the given settings to make sure that they can be used to send and
Expand Down Expand Up @@ -488,7 +493,7 @@ private void checkOutgoing() throws MessagingException {
}

private void checkIncoming() throws MessagingException {
Store store = account.getRemoteStore();
RemoteStore store = account.getRemoteStore();
if (store instanceof WebDavStore) {
publishProgress(R.string.account_setup_check_settings_authenticate);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import com.fsck.k9.mail.NetworkType;
import com.fsck.k9.mail.ServerSettings;
import com.fsck.k9.mail.ServerSettings.Type;
import com.fsck.k9.mail.Store;
import com.fsck.k9.mail.TransportUris;
import com.fsck.k9.mail.store.RemoteStore;
import com.fsck.k9.mail.store.imap.ImapStoreSettings;
Expand Down Expand Up @@ -501,7 +500,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (Intent.ACTION_EDIT.equals(getIntent().getAction())) {
boolean isPushCapable = false;
try {
Store store = mAccount.getRemoteStore();
RemoteStore store = mAccount.getRemoteStore();
isPushCapable = store.isPushCapable();
} catch (Exception e) {
Timber.e(e, "Could not get remote store");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@

package com.fsck.k9.activity.setup;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import timber.log.Timber;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.Spinner;
import com.fsck.k9.*;

import com.fsck.k9.Account;
import com.fsck.k9.K9;
import com.fsck.k9.Preferences;
import com.fsck.k9.R;
import com.fsck.k9.activity.K9Activity;
import com.fsck.k9.mail.Store;
import com.fsck.k9.mail.store.RemoteStore;
import timber.log.Timber;


public class AccountSetupOptions extends K9Activity implements OnClickListener {
private static final String EXTRA_ACCOUNT = "account";
Expand Down Expand Up @@ -112,7 +118,7 @@ public void onCreate(Bundle savedInstanceState) {

boolean isPushCapable = false;
try {
Store store = mAccount.getRemoteStore();
RemoteStore store = mAccount.getRemoteStore();
isPushCapable = store.isPushCapable();
} catch (Exception e) {
Timber.e(e, "Could not get remote store");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@

package com.fsck.k9.activity.setup;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import timber.log.Timber;
import com.fsck.k9.*;

import com.fsck.k9.Account;
import com.fsck.k9.Preferences;
import com.fsck.k9.R;
import com.fsck.k9.activity.FolderInfoHolder;
import com.fsck.k9.activity.K9PreferenceActivity;
import com.fsck.k9.mail.Folder;
import com.fsck.k9.mail.Folder.FolderClass;

import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.Store;
import com.fsck.k9.mail.store.RemoteStore;
import com.fsck.k9.mailstore.LocalFolder;
import com.fsck.k9.mailstore.LocalStore;
import com.fsck.k9.service.MailService;
import timber.log.Timber;

public class FolderSettings extends K9PreferenceActivity {

Expand Down Expand Up @@ -68,7 +71,7 @@ public void onCreate(Bundle savedInstanceState) {

boolean isPushCapable = false;
try {
Store store = mAccount.getRemoteStore();
RemoteStore store = mAccount.getRemoteStore();
isPushCapable = store.isPushCapable();
} catch (Exception e) {
Timber.e(e, "Could not get remote store");
Expand Down
Loading

0 comments on commit fdce9af

Please sign in to comment.