Search in sources :

Example 1 with NetworkType

use of com.fsck.k9.mail.NetworkType in project k-9 by k9mail.

the class Account method delete.

protected synchronized void delete(Preferences preferences) {
    deleteCertificates();
    // Get the list of account UUIDs
    String[] uuids = preferences.getStorage().getString("accountUuids", "").split(",");
    // Create a list of all account UUIDs excluding this account
    List<String> newUuids = new ArrayList<>(uuids.length);
    for (String uuid : uuids) {
        if (!uuid.equals(mUuid)) {
            newUuids.add(uuid);
        }
    }
    StorageEditor editor = preferences.getStorage().edit();
    // Only change the 'accountUuids' value if this account's UUID was listed before
    if (newUuids.size() < uuids.length) {
        String accountUuids = Utility.combine(newUuids.toArray(), ',');
        editor.putString("accountUuids", accountUuids);
    }
    editor.remove(mUuid + ".storeUri");
    editor.remove(mUuid + ".transportUri");
    editor.remove(mUuid + ".description");
    editor.remove(mUuid + ".name");
    editor.remove(mUuid + ".email");
    editor.remove(mUuid + ".alwaysBcc");
    editor.remove(mUuid + ".automaticCheckIntervalMinutes");
    editor.remove(mUuid + ".pushPollOnConnect");
    editor.remove(mUuid + ".idleRefreshMinutes");
    editor.remove(mUuid + ".lastAutomaticCheckTime");
    editor.remove(mUuid + ".latestOldMessageSeenTime");
    editor.remove(mUuid + ".notifyNewMail");
    editor.remove(mUuid + ".notifySelfNewMail");
    editor.remove(mUuid + ".deletePolicy");
    editor.remove(mUuid + ".draftsFolderName");
    editor.remove(mUuid + ".sentFolderName");
    editor.remove(mUuid + ".trashFolderName");
    editor.remove(mUuid + ".archiveFolderName");
    editor.remove(mUuid + ".spamFolderName");
    editor.remove(mUuid + ".autoExpandFolderName");
    editor.remove(mUuid + ".accountNumber");
    editor.remove(mUuid + ".vibrate");
    editor.remove(mUuid + ".vibratePattern");
    editor.remove(mUuid + ".vibrateTimes");
    editor.remove(mUuid + ".ring");
    editor.remove(mUuid + ".ringtone");
    editor.remove(mUuid + ".folderDisplayMode");
    editor.remove(mUuid + ".folderSyncMode");
    editor.remove(mUuid + ".folderPushMode");
    editor.remove(mUuid + ".folderTargetMode");
    editor.remove(mUuid + ".signatureBeforeQuotedText");
    editor.remove(mUuid + ".expungePolicy");
    editor.remove(mUuid + ".syncRemoteDeletions");
    editor.remove(mUuid + ".maxPushFolders");
    editor.remove(mUuid + ".searchableFolders");
    editor.remove(mUuid + ".chipColor");
    editor.remove(mUuid + ".led");
    editor.remove(mUuid + ".ledColor");
    editor.remove(mUuid + ".goToUnreadMessageSearch");
    editor.remove(mUuid + ".subscribedFoldersOnly");
    editor.remove(mUuid + ".maximumPolledMessageAge");
    editor.remove(mUuid + ".maximumAutoDownloadMessageSize");
    editor.remove(mUuid + ".messageFormatAuto");
    editor.remove(mUuid + ".quoteStyle");
    editor.remove(mUuid + ".quotePrefix");
    editor.remove(mUuid + ".sortTypeEnum");
    editor.remove(mUuid + ".sortAscending");
    editor.remove(mUuid + ".showPicturesEnum");
    editor.remove(mUuid + ".replyAfterQuote");
    editor.remove(mUuid + ".stripSignature");
    // this is no longer set, but cleans up legacy values
    editor.remove(mUuid + ".cryptoApp");
    editor.remove(mUuid + ".cryptoAutoSignature");
    editor.remove(mUuid + ".cryptoAutoEncrypt");
    editor.remove(mUuid + ".cryptoApp");
    editor.remove(mUuid + ".cryptoKey");
    editor.remove(mUuid + ".cryptoSupportSignOnly");
    editor.remove(mUuid + ".enabled");
    editor.remove(mUuid + ".markMessageAsReadOnView");
    editor.remove(mUuid + ".alwaysShowCcBcc");
    editor.remove(mUuid + ".allowRemoteSearch");
    editor.remove(mUuid + ".remoteSearchFullText");
    editor.remove(mUuid + ".remoteSearchNumResults");
    editor.remove(mUuid + ".defaultQuotedTextShown");
    editor.remove(mUuid + ".displayCount");
    editor.remove(mUuid + ".inboxFolderName");
    editor.remove(mUuid + ".localStorageProvider");
    editor.remove(mUuid + ".messageFormat");
    editor.remove(mUuid + ".messageReadReceipt");
    editor.remove(mUuid + ".notifyMailCheck");
    for (NetworkType type : NetworkType.values()) {
        editor.remove(mUuid + ".useCompression." + type.name());
    }
    deleteIdentities(preferences.getStorage(), editor);
    // TODO: Remove preference settings that may exist for individual
    // folders in the account.
    editor.commit();
}
Also used : NetworkType(com.fsck.k9.mail.NetworkType) ArrayList(java.util.ArrayList) StorageEditor(com.fsck.k9.preferences.StorageEditor)

Example 2 with NetworkType

use of com.fsck.k9.mail.NetworkType in project k-9 by k9mail.

the class Account method save.

public synchronized void save(Preferences preferences) {
    StorageEditor editor = preferences.getStorage().edit();
    if (!preferences.getStorage().getString("accountUuids", "").contains(mUuid)) {
        /*
             * When the account is first created we assign it a unique account number. The
             * account number will be unique to that account for the lifetime of the account.
             * So, we get all the existing account numbers, sort them ascending, loop through
             * the list and check if the number is greater than 1 + the previous number. If so
             * we use the previous number + 1 as the account number. This refills gaps.
             * mAccountNumber starts as -1 on a newly created account. It must be -1 for this
             * algorithm to work.
             *
             * I bet there is a much smarter way to do this. Anyone like to suggest it?
             */
        List<Account> accounts = preferences.getAccounts();
        int[] accountNumbers = new int[accounts.size()];
        for (int i = 0; i < accounts.size(); i++) {
            accountNumbers[i] = accounts.get(i).getAccountNumber();
        }
        Arrays.sort(accountNumbers);
        for (int accountNumber : accountNumbers) {
            if (accountNumber > mAccountNumber + 1) {
                break;
            }
            mAccountNumber = accountNumber;
        }
        mAccountNumber++;
        String accountUuids = preferences.getStorage().getString("accountUuids", "");
        accountUuids += (accountUuids.length() != 0 ? "," : "") + mUuid;
        editor.putString("accountUuids", accountUuids);
    }
    editor.putString(mUuid + ".storeUri", Base64.encode(mStoreUri));
    editor.putString(mUuid + ".localStorageProvider", mLocalStorageProviderId);
    editor.putString(mUuid + ".transportUri", Base64.encode(mTransportUri));
    editor.putString(mUuid + ".description", mDescription);
    editor.putString(mUuid + ".alwaysBcc", mAlwaysBcc);
    editor.putInt(mUuid + ".automaticCheckIntervalMinutes", mAutomaticCheckIntervalMinutes);
    editor.putInt(mUuid + ".idleRefreshMinutes", mIdleRefreshMinutes);
    editor.putBoolean(mUuid + ".pushPollOnConnect", mPushPollOnConnect);
    editor.putInt(mUuid + ".displayCount", mDisplayCount);
    editor.putLong(mUuid + ".latestOldMessageSeenTime", mLatestOldMessageSeenTime);
    editor.putBoolean(mUuid + ".notifyNewMail", mNotifyNewMail);
    editor.putString(mUuid + ".folderNotifyNewMailMode", mFolderNotifyNewMailMode.name());
    editor.putBoolean(mUuid + ".notifySelfNewMail", mNotifySelfNewMail);
    editor.putBoolean(mUuid + ".notifyContactsMailOnly", mNotifyContactsMailOnly);
    editor.putBoolean(mUuid + ".notifyMailCheck", mNotifySync);
    editor.putInt(mUuid + ".deletePolicy", mDeletePolicy.setting);
    editor.putString(mUuid + ".inboxFolderName", mInboxFolderName);
    editor.putString(mUuid + ".draftsFolderName", mDraftsFolderName);
    editor.putString(mUuid + ".sentFolderName", mSentFolderName);
    editor.putString(mUuid + ".trashFolderName", mTrashFolderName);
    editor.putString(mUuid + ".archiveFolderName", mArchiveFolderName);
    editor.putString(mUuid + ".spamFolderName", mSpamFolderName);
    editor.putString(mUuid + ".autoExpandFolderName", mAutoExpandFolderName);
    editor.putInt(mUuid + ".accountNumber", mAccountNumber);
    editor.putString(mUuid + ".sortTypeEnum", mSortType.name());
    editor.putBoolean(mUuid + ".sortAscending", mSortAscending.get(mSortType));
    editor.putString(mUuid + ".showPicturesEnum", mShowPictures.name());
    editor.putString(mUuid + ".folderDisplayMode", mFolderDisplayMode.name());
    editor.putString(mUuid + ".folderSyncMode", mFolderSyncMode.name());
    editor.putString(mUuid + ".folderPushMode", mFolderPushMode.name());
    editor.putString(mUuid + ".folderTargetMode", mFolderTargetMode.name());
    editor.putBoolean(mUuid + ".signatureBeforeQuotedText", this.mIsSignatureBeforeQuotedText);
    editor.putString(mUuid + ".expungePolicy", mExpungePolicy.name());
    editor.putBoolean(mUuid + ".syncRemoteDeletions", mSyncRemoteDeletions);
    editor.putInt(mUuid + ".maxPushFolders", mMaxPushFolders);
    editor.putString(mUuid + ".searchableFolders", searchableFolders.name());
    editor.putInt(mUuid + ".chipColor", mChipColor);
    editor.putBoolean(mUuid + ".goToUnreadMessageSearch", goToUnreadMessageSearch);
    editor.putBoolean(mUuid + ".subscribedFoldersOnly", subscribedFoldersOnly);
    editor.putInt(mUuid + ".maximumPolledMessageAge", maximumPolledMessageAge);
    editor.putInt(mUuid + ".maximumAutoDownloadMessageSize", maximumAutoDownloadMessageSize);
    if (MessageFormat.AUTO.equals(mMessageFormat)) {
        // saving MessageFormat.AUTO as is to the database will cause downgrades to crash on
        // startup, so we save as MessageFormat.TEXT instead with a separate flag for auto.
        editor.putString(mUuid + ".messageFormat", Account.MessageFormat.TEXT.name());
        mMessageFormatAuto = true;
    } else {
        editor.putString(mUuid + ".messageFormat", mMessageFormat.name());
        mMessageFormatAuto = false;
    }
    editor.putBoolean(mUuid + ".messageFormatAuto", mMessageFormatAuto);
    editor.putBoolean(mUuid + ".messageReadReceipt", mMessageReadReceipt);
    editor.putString(mUuid + ".quoteStyle", mQuoteStyle.name());
    editor.putString(mUuid + ".quotePrefix", mQuotePrefix);
    editor.putBoolean(mUuid + ".defaultQuotedTextShown", mDefaultQuotedTextShown);
    editor.putBoolean(mUuid + ".replyAfterQuote", mReplyAfterQuote);
    editor.putBoolean(mUuid + ".stripSignature", mStripSignature);
    editor.putLong(mUuid + ".cryptoKey", mCryptoKey);
    editor.putBoolean(mUuid + ".allowRemoteSearch", mAllowRemoteSearch);
    editor.putBoolean(mUuid + ".remoteSearchFullText", mRemoteSearchFullText);
    editor.putInt(mUuid + ".remoteSearchNumResults", mRemoteSearchNumResults);
    editor.putBoolean(mUuid + ".enabled", mEnabled);
    editor.putBoolean(mUuid + ".markMessageAsReadOnView", mMarkMessageAsReadOnView);
    editor.putBoolean(mUuid + ".alwaysShowCcBcc", mAlwaysShowCcBcc);
    editor.putBoolean(mUuid + ".vibrate", mNotificationSetting.shouldVibrate());
    editor.putInt(mUuid + ".vibratePattern", mNotificationSetting.getVibratePattern());
    editor.putInt(mUuid + ".vibrateTimes", mNotificationSetting.getVibrateTimes());
    editor.putBoolean(mUuid + ".ring", mNotificationSetting.shouldRing());
    editor.putString(mUuid + ".ringtone", mNotificationSetting.getRingtone());
    editor.putBoolean(mUuid + ".led", mNotificationSetting.isLed());
    editor.putInt(mUuid + ".ledColor", mNotificationSetting.getLedColor());
    for (NetworkType type : NetworkType.values()) {
        Boolean useCompression = compressionMap.get(type);
        if (useCompression != null) {
            editor.putBoolean(mUuid + ".useCompression." + type, useCompression);
        }
    }
    saveIdentities(preferences.getStorage(), editor);
    editor.commit();
}
Also used : NetworkType(com.fsck.k9.mail.NetworkType) StorageEditor(com.fsck.k9.preferences.StorageEditor)

Example 3 with NetworkType

use of com.fsck.k9.mail.NetworkType in project k-9 by k9mail.

the class ImapConnection method shouldEnableCompression.

private boolean shouldEnableCompression() {
    boolean useCompression = true;
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    if (networkInfo != null) {
        int type = networkInfo.getType();
        if (K9MailLib.isDebug()) {
            Log.d(LOG_TAG, "On network type " + type);
        }
        NetworkType networkType = NetworkType.fromConnectivityManagerType(type);
        useCompression = settings.useCompression(networkType);
    }
    if (K9MailLib.isDebug()) {
        Log.d(LOG_TAG, "useCompression " + useCompression);
    }
    return useCompression;
}
Also used : NetworkInfo(android.net.NetworkInfo) NetworkType(com.fsck.k9.mail.NetworkType)

Example 4 with NetworkType

use of com.fsck.k9.mail.NetworkType in project k-9 by k9mail.

the class Account method loadAccount.

/**
     * Load stored settings for this account.
     */
private synchronized void loadAccount(Preferences preferences) {
    Storage storage = preferences.getStorage();
    mStoreUri = Base64.decode(storage.getString(mUuid + ".storeUri", null));
    mLocalStorageProviderId = storage.getString(mUuid + ".localStorageProvider", StorageManager.getInstance(K9.app).getDefaultProviderId());
    mTransportUri = Base64.decode(storage.getString(mUuid + ".transportUri", null));
    mDescription = storage.getString(mUuid + ".description", null);
    mAlwaysBcc = storage.getString(mUuid + ".alwaysBcc", mAlwaysBcc);
    mAutomaticCheckIntervalMinutes = storage.getInt(mUuid + ".automaticCheckIntervalMinutes", -1);
    mIdleRefreshMinutes = storage.getInt(mUuid + ".idleRefreshMinutes", 24);
    mPushPollOnConnect = storage.getBoolean(mUuid + ".pushPollOnConnect", true);
    mDisplayCount = storage.getInt(mUuid + ".displayCount", K9.DEFAULT_VISIBLE_LIMIT);
    if (mDisplayCount < 0) {
        mDisplayCount = K9.DEFAULT_VISIBLE_LIMIT;
    }
    mLatestOldMessageSeenTime = storage.getLong(mUuid + ".latestOldMessageSeenTime", 0);
    mNotifyNewMail = storage.getBoolean(mUuid + ".notifyNewMail", false);
    mFolderNotifyNewMailMode = getEnumStringPref(storage, mUuid + ".folderNotifyNewMailMode", FolderMode.ALL);
    mNotifySelfNewMail = storage.getBoolean(mUuid + ".notifySelfNewMail", true);
    mNotifyContactsMailOnly = storage.getBoolean(mUuid + ".notifyContactsMailOnly", false);
    mNotifySync = storage.getBoolean(mUuid + ".notifyMailCheck", false);
    mDeletePolicy = DeletePolicy.fromInt(storage.getInt(mUuid + ".deletePolicy", DeletePolicy.NEVER.setting));
    mInboxFolderName = storage.getString(mUuid + ".inboxFolderName", INBOX);
    mDraftsFolderName = storage.getString(mUuid + ".draftsFolderName", "Drafts");
    mSentFolderName = storage.getString(mUuid + ".sentFolderName", "Sent");
    mTrashFolderName = storage.getString(mUuid + ".trashFolderName", "Trash");
    mArchiveFolderName = storage.getString(mUuid + ".archiveFolderName", "Archive");
    mSpamFolderName = storage.getString(mUuid + ".spamFolderName", "Spam");
    mExpungePolicy = getEnumStringPref(storage, mUuid + ".expungePolicy", Expunge.EXPUNGE_IMMEDIATELY);
    mSyncRemoteDeletions = storage.getBoolean(mUuid + ".syncRemoteDeletions", true);
    mMaxPushFolders = storage.getInt(mUuid + ".maxPushFolders", 10);
    goToUnreadMessageSearch = storage.getBoolean(mUuid + ".goToUnreadMessageSearch", false);
    subscribedFoldersOnly = storage.getBoolean(mUuid + ".subscribedFoldersOnly", false);
    maximumPolledMessageAge = storage.getInt(mUuid + ".maximumPolledMessageAge", -1);
    maximumAutoDownloadMessageSize = storage.getInt(mUuid + ".maximumAutoDownloadMessageSize", 32768);
    mMessageFormat = getEnumStringPref(storage, mUuid + ".messageFormat", DEFAULT_MESSAGE_FORMAT);
    mMessageFormatAuto = storage.getBoolean(mUuid + ".messageFormatAuto", DEFAULT_MESSAGE_FORMAT_AUTO);
    if (mMessageFormatAuto && mMessageFormat == MessageFormat.TEXT) {
        mMessageFormat = MessageFormat.AUTO;
    }
    mMessageReadReceipt = storage.getBoolean(mUuid + ".messageReadReceipt", DEFAULT_MESSAGE_READ_RECEIPT);
    mQuoteStyle = getEnumStringPref(storage, mUuid + ".quoteStyle", DEFAULT_QUOTE_STYLE);
    mQuotePrefix = storage.getString(mUuid + ".quotePrefix", DEFAULT_QUOTE_PREFIX);
    mDefaultQuotedTextShown = storage.getBoolean(mUuid + ".defaultQuotedTextShown", DEFAULT_QUOTED_TEXT_SHOWN);
    mReplyAfterQuote = storage.getBoolean(mUuid + ".replyAfterQuote", DEFAULT_REPLY_AFTER_QUOTE);
    mStripSignature = storage.getBoolean(mUuid + ".stripSignature", DEFAULT_STRIP_SIGNATURE);
    for (NetworkType type : NetworkType.values()) {
        Boolean useCompression = storage.getBoolean(mUuid + ".useCompression." + type, true);
        compressionMap.put(type, useCompression);
    }
    mAutoExpandFolderName = storage.getString(mUuid + ".autoExpandFolderName", INBOX);
    mAccountNumber = storage.getInt(mUuid + ".accountNumber", 0);
    mChipColor = storage.getInt(mUuid + ".chipColor", ColorPicker.getRandomColor());
    mSortType = getEnumStringPref(storage, mUuid + ".sortTypeEnum", SortType.SORT_DATE);
    mSortAscending.put(mSortType, storage.getBoolean(mUuid + ".sortAscending", false));
    mShowPictures = getEnumStringPref(storage, mUuid + ".showPicturesEnum", ShowPictures.NEVER);
    mNotificationSetting.setVibrate(storage.getBoolean(mUuid + ".vibrate", false));
    mNotificationSetting.setVibratePattern(storage.getInt(mUuid + ".vibratePattern", 0));
    mNotificationSetting.setVibrateTimes(storage.getInt(mUuid + ".vibrateTimes", 5));
    mNotificationSetting.setRing(storage.getBoolean(mUuid + ".ring", true));
    mNotificationSetting.setRingtone(storage.getString(mUuid + ".ringtone", "content://settings/system/notification_sound"));
    mNotificationSetting.setLed(storage.getBoolean(mUuid + ".led", true));
    mNotificationSetting.setLedColor(storage.getInt(mUuid + ".ledColor", mChipColor));
    mFolderDisplayMode = getEnumStringPref(storage, mUuid + ".folderDisplayMode", FolderMode.NOT_SECOND_CLASS);
    mFolderSyncMode = getEnumStringPref(storage, mUuid + ".folderSyncMode", FolderMode.FIRST_CLASS);
    mFolderPushMode = getEnumStringPref(storage, mUuid + ".folderPushMode", FolderMode.FIRST_CLASS);
    mFolderTargetMode = getEnumStringPref(storage, mUuid + ".folderTargetMode", FolderMode.NOT_SECOND_CLASS);
    searchableFolders = getEnumStringPref(storage, mUuid + ".searchableFolders", Searchable.ALL);
    mIsSignatureBeforeQuotedText = storage.getBoolean(mUuid + ".signatureBeforeQuotedText", false);
    identities = loadIdentities(storage);
    mCryptoKey = storage.getLong(mUuid + ".cryptoKey", NO_OPENPGP_KEY);
    mAllowRemoteSearch = storage.getBoolean(mUuid + ".allowRemoteSearch", false);
    mRemoteSearchFullText = storage.getBoolean(mUuid + ".remoteSearchFullText", false);
    mRemoteSearchNumResults = storage.getInt(mUuid + ".remoteSearchNumResults", DEFAULT_REMOTE_SEARCH_NUM_RESULTS);
    mEnabled = storage.getBoolean(mUuid + ".enabled", true);
    mMarkMessageAsReadOnView = storage.getBoolean(mUuid + ".markMessageAsReadOnView", true);
    mAlwaysShowCcBcc = storage.getBoolean(mUuid + ".alwaysShowCcBcc", false);
    cacheChips();
    // Use email address as account description if necessary
    if (mDescription == null) {
        mDescription = getEmail();
    }
}
Also used : Storage(com.fsck.k9.preferences.Storage) NetworkType(com.fsck.k9.mail.NetworkType)

Aggregations

NetworkType (com.fsck.k9.mail.NetworkType)4 StorageEditor (com.fsck.k9.preferences.StorageEditor)2 NetworkInfo (android.net.NetworkInfo)1 Storage (com.fsck.k9.preferences.Storage)1 ArrayList (java.util.ArrayList)1