Search in sources :

Example 6 with QuoteStyle

use of com.fsck.k9.Account.QuoteStyle in project k-9 by k9mail.

the class TextBodyBuilderTest method testBuildTextPlain.

@Theory
public void testBuildTextPlain(boolean includeQuotedText, QuoteStyle quoteStyle, boolean isReplyAfterQuote, boolean isSignatureUse, boolean isSignatureBeforeQuotedText, boolean isDraft) {
    String expectedText;
    int expectedMessageLength;
    int expectedMessagePosition;
    // 3.signature
    if (quoteStyle == QuoteStyle.PREFIX && isReplyAfterQuote) {
        String expectedQuotedText = "";
        if (isDraft || includeQuotedText) {
            expectedQuotedText = "quoted text" + "\r\n";
        }
        expectedText = expectedQuotedText;
        expectedText += "message content";
        if (!isDraft && isSignatureUse) {
            expectedText += "\r\n" + "signature";
        }
        expectedMessageLength = "message content".length();
        expectedMessagePosition = expectedQuotedText.length();
    } else // 3.quoted text
    if (isSignatureBeforeQuotedText) {
        expectedText = "message content";
        if (!isDraft && isSignatureUse) {
            expectedText += "\r\n" + "signature";
        }
        if (isDraft || includeQuotedText) {
            expectedText += "\r\n\r\nquoted text";
        }
        expectedMessageLength = "message content".length();
        expectedMessagePosition = 0;
    } else // 1.message content
    // 2.quoted text
    // 3.signature
    {
        expectedText = "message content";
        if (isDraft || includeQuotedText) {
            expectedText += "\r\n\r\nquoted text";
        }
        if (!isDraft && isSignatureUse) {
            expectedText += "\r\n" + "signature";
        }
        expectedMessageLength = "message content".length();
        expectedMessagePosition = 0;
    }
    String quotedText = "quoted text";
    String messageText = "message content";
    String signatureText = "signature";
    TestingTextBodyBuilder textBodyBuilder = new TestingTextBodyBuilder(includeQuotedText, isDraft, quoteStyle, isReplyAfterQuote, isSignatureBeforeQuotedText, isSignatureUse, messageText, signatureText);
    textBodyBuilder.setQuotedText(quotedText);
    TextBody textBody = textBodyBuilder.buildTextPlain();
    assertThat(textBody, instanceOf(TextBody.class));
    assertThat(textBody.getRawText(), is(expectedText));
    assertThat(textBody.getComposedMessageLength(), is(expectedMessageLength));
    assertThat(textBody.getComposedMessageOffset(), is(expectedMessagePosition));
    assertThat(textBody.getRawText().substring(expectedMessagePosition, expectedMessagePosition + expectedMessageLength), is("message content"));
}
Also used : TextBody(com.fsck.k9.mail.internet.TextBody) Theory(org.junit.experimental.theories.Theory)

Example 7 with QuoteStyle

use of com.fsck.k9.Account.QuoteStyle in project k-9 by k9mail.

the class TextBodyBuilderTest method testBuildTextHtml.

@Theory
public void testBuildTextHtml(boolean includeQuotedText, QuoteStyle quoteStyle, boolean isReplyAfterQuote, boolean isSignatureUse, boolean isSignatureBeforeQuotedText, boolean isDraft) {
    String expectedText;
    int expectedMessageLength;
    int expectedMessagePosition = 0;
    String expectedHtmlContent;
    String expectedPrefix = "";
    if (includeQuotedText && quoteStyle == QuoteStyle.PREFIX && isReplyAfterQuote && !isDraft) {
        expectedPrefix = "<br clear=\"all\">";
    }
    String expectedPostfix = "";
    if (!isDraft && includeQuotedText) {
        expectedPostfix = "<br><br>";
    }
    // 3.signature
    if (quoteStyle == QuoteStyle.PREFIX && isReplyAfterQuote) {
        expectedText = expectedPrefix + "<html>message content";
        if (!isDraft && isSignatureUse) {
            expectedText += "\r\n" + "signature";
        }
        expectedText += "</html>";
        expectedMessageLength = expectedText.length();
        String quotedContent = "quoted text";
        if (isDraft || includeQuotedText) {
            expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, 0, false, expectedText, expectedText + quotedContent);
            expectedText += quotedContent;
        } else {
            expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, 0, true, "", quotedContent);
        // expectedText += quotedContent;
        }
    } else // 3.quoted text
    if (isSignatureBeforeQuotedText) {
        expectedText = expectedPrefix + "<html>message content";
        if (!isDraft && isSignatureUse) {
            expectedText += "\r\n" + "signature";
        }
        expectedText += "</html>";
        expectedText += expectedPostfix;
        expectedMessageLength = expectedText.length();
        String quotedContent = "quoted text";
        if (isDraft || includeQuotedText) {
            expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, 0, true, expectedText, expectedText + quotedContent);
            expectedText += quotedContent;
        } else {
            expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, 0, true, "", quotedContent);
        // expectedText += quotedContent;
        }
    } else // 1.message content
    // 2.quoted text
    // 3.signature
    {
        String expectedSignature = "";
        expectedText = expectedPrefix + "<html>message content";
        if (!isDraft && isSignatureUse) {
            if (!includeQuotedText) {
                expectedText += "\r\n" + "signature";
            } else {
                expectedSignature = "<html>\r\nsignature</html>";
            }
        }
        expectedText += "</html>";
        expectedText += expectedPostfix;
        expectedMessageLength = expectedText.length();
        String quotedContent = "quoted text";
        if (isDraft || includeQuotedText) {
            expectedHtmlContent = makeExpectedHtmlContent(expectedText, expectedSignature + quotedContent, expectedSignature.length(), true, expectedText, expectedText + expectedSignature + quotedContent);
            expectedText += expectedSignature + quotedContent;
        } else {
            expectedHtmlContent = makeExpectedHtmlContent(expectedText, quotedContent, 0, true, "", quotedContent);
        // expectedText += quotedContent;
        }
    }
    InsertableHtmlContent insertableHtmlContent = new InsertableHtmlContent();
    String quotedText = "quoted text";
    insertableHtmlContent.setQuotedContent(new StringBuilder(quotedText));
    String messageText = "message content";
    String signatureText = "signature";
    TestingTextBodyBuilder textBodyBuilder = new TestingTextBodyBuilder(includeQuotedText, isDraft, quoteStyle, isReplyAfterQuote, isSignatureBeforeQuotedText, isSignatureUse, messageText, signatureText);
    textBodyBuilder.setQuotedTextHtml(insertableHtmlContent);
    TextBody textBody = textBodyBuilder.buildTextHtml();
    assertThat(textBody, instanceOf(TextBody.class));
    assertThat(textBody.getRawText(), is(expectedText));
    assertThat(textBody.getComposedMessageLength(), is(expectedMessageLength));
    assertThat(textBody.getComposedMessageOffset(), is(expectedMessagePosition));
    assertThat(insertableHtmlContent.toDebugString(), is(expectedHtmlContent));
}
Also used : TextBody(com.fsck.k9.mail.internet.TextBody) InsertableHtmlContent(com.fsck.k9.message.quote.InsertableHtmlContent) Theory(org.junit.experimental.theories.Theory)

Example 8 with QuoteStyle

use of com.fsck.k9.Account.QuoteStyle in project k-9 by k9mail.

the class AccountSettings method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
    mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
    try {
        final Store store = mAccount.getRemoteStore();
        mIsMoveCapable = store.isMoveCapable();
        mIsPushCapable = store.isPushCapable();
        mIsExpungeCapable = store.isExpungeCapable();
        mIsSeenFlagSupported = store.isSeenFlagSupported();
    } catch (Exception e) {
        Timber.e(e, "Could not get remote store");
    }
    addPreferencesFromResource(R.xml.account_settings_preferences);
    mMainScreen = (PreferenceScreen) findPreference(PREFERENCE_SCREEN_MAIN);
    mAccountDescription = (EditTextPreference) findPreference(PREFERENCE_DESCRIPTION);
    mAccountDescription.setSummary(mAccount.getDescription());
    mAccountDescription.setText(mAccount.getDescription());
    mAccountDescription.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            mAccountDescription.setSummary(summary);
            mAccountDescription.setText(summary);
            return false;
        }
    });
    mMarkMessageAsReadOnView = (CheckBoxPreference) findPreference(PREFERENCE_MARK_MESSAGE_AS_READ_ON_VIEW);
    mMarkMessageAsReadOnView.setChecked(mAccount.isMarkMessageAsReadOnView());
    mMessageFormat = (ListPreference) findPreference(PREFERENCE_MESSAGE_FORMAT);
    mMessageFormat.setValue(mAccount.getMessageFormat().name());
    mMessageFormat.setSummary(mMessageFormat.getEntry());
    mMessageFormat.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mMessageFormat.findIndexOfValue(summary);
            mMessageFormat.setSummary(mMessageFormat.getEntries()[index]);
            mMessageFormat.setValue(summary);
            return false;
        }
    });
    mAlwaysShowCcBcc = (CheckBoxPreference) findPreference(PREFERENCE_ALWAYS_SHOW_CC_BCC);
    mAlwaysShowCcBcc.setChecked(mAccount.isAlwaysShowCcBcc());
    mMessageReadReceipt = (CheckBoxPreference) findPreference(PREFERENCE_MESSAGE_READ_RECEIPT);
    mMessageReadReceipt.setChecked(mAccount.isMessageReadReceiptAlways());
    mAccountQuotePrefix = (EditTextPreference) findPreference(PREFERENCE_QUOTE_PREFIX);
    mAccountQuotePrefix.setSummary(mAccount.getQuotePrefix());
    mAccountQuotePrefix.setText(mAccount.getQuotePrefix());
    mAccountQuotePrefix.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String value = newValue.toString();
            mAccountQuotePrefix.setSummary(value);
            mAccountQuotePrefix.setText(value);
            return false;
        }
    });
    mAccountDefaultQuotedTextShown = (CheckBoxPreference) findPreference(PREFERENCE_DEFAULT_QUOTED_TEXT_SHOWN);
    mAccountDefaultQuotedTextShown.setChecked(mAccount.isDefaultQuotedTextShown());
    mReplyAfterQuote = (CheckBoxPreference) findPreference(PREFERENCE_REPLY_AFTER_QUOTE);
    mReplyAfterQuote.setChecked(mAccount.isReplyAfterQuote());
    mStripSignature = (CheckBoxPreference) findPreference(PREFERENCE_STRIP_SIGNATURE);
    mStripSignature.setChecked(mAccount.isStripSignature());
    mComposingScreen = (PreferenceScreen) findPreference(PREFERENCE_SCREEN_COMPOSING);
    Preference.OnPreferenceChangeListener quoteStyleListener = new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final QuoteStyle style = QuoteStyle.valueOf(newValue.toString());
            int index = mQuoteStyle.findIndexOfValue(newValue.toString());
            mQuoteStyle.setSummary(mQuoteStyle.getEntries()[index]);
            if (style == QuoteStyle.PREFIX) {
                mComposingScreen.addPreference(mAccountQuotePrefix);
                mComposingScreen.addPreference(mReplyAfterQuote);
            } else if (style == QuoteStyle.HEADER) {
                mComposingScreen.removePreference(mAccountQuotePrefix);
                mComposingScreen.removePreference(mReplyAfterQuote);
            }
            return true;
        }
    };
    mQuoteStyle = (ListPreference) findPreference(PREFERENCE_QUOTE_STYLE);
    mQuoteStyle.setValue(mAccount.getQuoteStyle().name());
    mQuoteStyle.setSummary(mQuoteStyle.getEntry());
    mQuoteStyle.setOnPreferenceChangeListener(quoteStyleListener);
    // Call the onPreferenceChange() handler on startup to update the Preference dialogue based
    // upon the existing quote style setting.
    quoteStyleListener.onPreferenceChange(mQuoteStyle, mAccount.getQuoteStyle().name());
    mCheckFrequency = (ListPreference) findPreference(PREFERENCE_FREQUENCY);
    mCheckFrequency.setValue(String.valueOf(mAccount.getAutomaticCheckIntervalMinutes()));
    mCheckFrequency.setSummary(mCheckFrequency.getEntry());
    mCheckFrequency.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mCheckFrequency.findIndexOfValue(summary);
            mCheckFrequency.setSummary(mCheckFrequency.getEntries()[index]);
            mCheckFrequency.setValue(summary);
            return false;
        }
    });
    mDisplayMode = (ListPreference) findPreference(PREFERENCE_DISPLAY_MODE);
    mDisplayMode.setValue(mAccount.getFolderDisplayMode().name());
    mDisplayMode.setSummary(mDisplayMode.getEntry());
    mDisplayMode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mDisplayMode.findIndexOfValue(summary);
            mDisplayMode.setSummary(mDisplayMode.getEntries()[index]);
            mDisplayMode.setValue(summary);
            return false;
        }
    });
    mSyncMode = (ListPreference) findPreference(PREFERENCE_SYNC_MODE);
    mSyncMode.setValue(mAccount.getFolderSyncMode().name());
    mSyncMode.setSummary(mSyncMode.getEntry());
    mSyncMode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mSyncMode.findIndexOfValue(summary);
            mSyncMode.setSummary(mSyncMode.getEntries()[index]);
            mSyncMode.setValue(summary);
            return false;
        }
    });
    mTargetMode = (ListPreference) findPreference(PREFERENCE_TARGET_MODE);
    mTargetMode.setValue(mAccount.getFolderTargetMode().name());
    mTargetMode.setSummary(mTargetMode.getEntry());
    mTargetMode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mTargetMode.findIndexOfValue(summary);
            mTargetMode.setSummary(mTargetMode.getEntries()[index]);
            mTargetMode.setValue(summary);
            return false;
        }
    });
    mDeletePolicy = (ListPreference) findPreference(PREFERENCE_DELETE_POLICY);
    if (!mIsSeenFlagSupported) {
        removeListEntry(mDeletePolicy, DeletePolicy.MARK_AS_READ.preferenceString());
    }
    mDeletePolicy.setValue(mAccount.getDeletePolicy().preferenceString());
    mDeletePolicy.setSummary(mDeletePolicy.getEntry());
    mDeletePolicy.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mDeletePolicy.findIndexOfValue(summary);
            mDeletePolicy.setSummary(mDeletePolicy.getEntries()[index]);
            mDeletePolicy.setValue(summary);
            return false;
        }
    });
    mExpungePolicy = (ListPreference) findPreference(PREFERENCE_EXPUNGE_POLICY);
    if (mIsExpungeCapable) {
        mExpungePolicy.setValue(mAccount.getExpungePolicy().name());
        mExpungePolicy.setSummary(mExpungePolicy.getEntry());
        mExpungePolicy.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

            public boolean onPreferenceChange(Preference preference, Object newValue) {
                final String summary = newValue.toString();
                int index = mExpungePolicy.findIndexOfValue(summary);
                mExpungePolicy.setSummary(mExpungePolicy.getEntries()[index]);
                mExpungePolicy.setValue(summary);
                return false;
            }
        });
    } else {
        ((PreferenceScreen) findPreference(PREFERENCE_SCREEN_INCOMING)).removePreference(mExpungePolicy);
    }
    mSyncRemoteDeletions = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_REMOTE_DELETIONS);
    mSyncRemoteDeletions.setChecked(mAccount.syncRemoteDeletions());
    mSearchableFolders = (ListPreference) findPreference(PREFERENCE_SEARCHABLE_FOLDERS);
    mSearchableFolders.setValue(mAccount.getSearchableFolders().name());
    mSearchableFolders.setSummary(mSearchableFolders.getEntry());
    mSearchableFolders.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mSearchableFolders.findIndexOfValue(summary);
            mSearchableFolders.setSummary(mSearchableFolders.getEntries()[index]);
            mSearchableFolders.setValue(summary);
            return false;
        }
    });
    mDisplayCount = (ListPreference) findPreference(PREFERENCE_DISPLAY_COUNT);
    mDisplayCount.setValue(String.valueOf(mAccount.getDisplayCount()));
    mDisplayCount.setSummary(mDisplayCount.getEntry());
    mDisplayCount.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mDisplayCount.findIndexOfValue(summary);
            mDisplayCount.setSummary(mDisplayCount.getEntries()[index]);
            mDisplayCount.setValue(summary);
            return false;
        }
    });
    mMessageAge = (ListPreference) findPreference(PREFERENCE_MESSAGE_AGE);
    if (!mAccount.isSearchByDateCapable()) {
        ((PreferenceScreen) findPreference(PREFERENCE_SCREEN_INCOMING)).removePreference(mMessageAge);
    } else {
        mMessageAge.setValue(String.valueOf(mAccount.getMaximumPolledMessageAge()));
        mMessageAge.setSummary(mMessageAge.getEntry());
        mMessageAge.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

            public boolean onPreferenceChange(Preference preference, Object newValue) {
                final String summary = newValue.toString();
                int index = mMessageAge.findIndexOfValue(summary);
                mMessageAge.setSummary(mMessageAge.getEntries()[index]);
                mMessageAge.setValue(summary);
                return false;
            }
        });
    }
    mMessageSize = (ListPreference) findPreference(PREFERENCE_MESSAGE_SIZE);
    mMessageSize.setValue(String.valueOf(mAccount.getMaximumAutoDownloadMessageSize()));
    mMessageSize.setSummary(mMessageSize.getEntry());
    mMessageSize.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mMessageSize.findIndexOfValue(summary);
            mMessageSize.setSummary(mMessageSize.getEntries()[index]);
            mMessageSize.setValue(summary);
            return false;
        }
    });
    mAccountDefault = (CheckBoxPreference) findPreference(PREFERENCE_DEFAULT);
    mAccountDefault.setChecked(mAccount.equals(Preferences.getPreferences(this).getDefaultAccount()));
    mAccountShowPictures = (ListPreference) findPreference(PREFERENCE_SHOW_PICTURES);
    mAccountShowPictures.setValue("" + mAccount.getShowPictures());
    mAccountShowPictures.setSummary(mAccountShowPictures.getEntry());
    mAccountShowPictures.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mAccountShowPictures.findIndexOfValue(summary);
            mAccountShowPictures.setSummary(mAccountShowPictures.getEntries()[index]);
            mAccountShowPictures.setValue(summary);
            return false;
        }
    });
    mLocalStorageProvider = (ListPreference) findPreference(PREFERENCE_LOCAL_STORAGE_PROVIDER);
    {
        final Map<String, String> providers;
        providers = StorageManager.getInstance(this).getAvailableProviders();
        int i = 0;
        final String[] providerLabels = new String[providers.size()];
        final String[] providerIds = new String[providers.size()];
        for (final Map.Entry<String, String> entry : providers.entrySet()) {
            providerIds[i] = entry.getKey();
            providerLabels[i] = entry.getValue();
            i++;
        }
        mLocalStorageProvider.setEntryValues(providerIds);
        mLocalStorageProvider.setEntries(providerLabels);
        mLocalStorageProvider.setValue(mAccount.getLocalStorageProviderId());
        mLocalStorageProvider.setSummary(providers.get(mAccount.getLocalStorageProviderId()));
        mLocalStorageProvider.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

            public boolean onPreferenceChange(Preference preference, Object newValue) {
                mLocalStorageProvider.setSummary(providers.get(newValue));
                return true;
            }
        });
    }
    // IMAP-specific preferences
    mSearchScreen = (PreferenceScreen) findPreference(PREFERENCE_SCREEN_SEARCH);
    mCloudSearchEnabled = (CheckBoxPreference) findPreference(PREFERENCE_CLOUD_SEARCH_ENABLED);
    mRemoteSearchNumResults = (ListPreference) findPreference(PREFERENCE_REMOTE_SEARCH_NUM_RESULTS);
    mRemoteSearchNumResults.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference pref, Object newVal) {
            updateRemoteSearchLimit((String) newVal);
            return true;
        }
    });
    //mRemoteSearchFullText = (CheckBoxPreference) findPreference(PREFERENCE_REMOTE_SEARCH_FULL_TEXT);
    mPushPollOnConnect = (CheckBoxPreference) findPreference(PREFERENCE_PUSH_POLL_ON_CONNECT);
    mIdleRefreshPeriod = (ListPreference) findPreference(PREFERENCE_IDLE_REFRESH_PERIOD);
    mMaxPushFolders = (ListPreference) findPreference(PREFERENCE_MAX_PUSH_FOLDERS);
    if (mIsPushCapable) {
        mPushPollOnConnect.setChecked(mAccount.isPushPollOnConnect());
        mCloudSearchEnabled.setChecked(mAccount.allowRemoteSearch());
        String searchNumResults = Integer.toString(mAccount.getRemoteSearchNumResults());
        mRemoteSearchNumResults.setValue(searchNumResults);
        updateRemoteSearchLimit(searchNumResults);
        //mRemoteSearchFullText.setChecked(mAccount.isRemoteSearchFullText());
        mIdleRefreshPeriod.setValue(String.valueOf(mAccount.getIdleRefreshMinutes()));
        mIdleRefreshPeriod.setSummary(mIdleRefreshPeriod.getEntry());
        mIdleRefreshPeriod.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

            public boolean onPreferenceChange(Preference preference, Object newValue) {
                final String summary = newValue.toString();
                int index = mIdleRefreshPeriod.findIndexOfValue(summary);
                mIdleRefreshPeriod.setSummary(mIdleRefreshPeriod.getEntries()[index]);
                mIdleRefreshPeriod.setValue(summary);
                return false;
            }
        });
        mMaxPushFolders.setValue(String.valueOf(mAccount.getMaxPushFolders()));
        mMaxPushFolders.setSummary(mMaxPushFolders.getEntry());
        mMaxPushFolders.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

            public boolean onPreferenceChange(Preference preference, Object newValue) {
                final String summary = newValue.toString();
                int index = mMaxPushFolders.findIndexOfValue(summary);
                mMaxPushFolders.setSummary(mMaxPushFolders.getEntries()[index]);
                mMaxPushFolders.setValue(summary);
                return false;
            }
        });
        mPushMode = (ListPreference) findPreference(PREFERENCE_PUSH_MODE);
        mPushMode.setValue(mAccount.getFolderPushMode().name());
        mPushMode.setSummary(mPushMode.getEntry());
        mPushMode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

            public boolean onPreferenceChange(Preference preference, Object newValue) {
                final String summary = newValue.toString();
                int index = mPushMode.findIndexOfValue(summary);
                mPushMode.setSummary(mPushMode.getEntries()[index]);
                mPushMode.setValue(summary);
                return false;
            }
        });
    } else {
        PreferenceScreen incomingPrefs = (PreferenceScreen) findPreference(PREFERENCE_SCREEN_INCOMING);
        incomingPrefs.removePreference((PreferenceScreen) findPreference(PREFERENCE_SCREEN_PUSH_ADVANCED));
        incomingPrefs.removePreference((ListPreference) findPreference(PREFERENCE_PUSH_MODE));
        mMainScreen.removePreference(mSearchScreen);
    }
    mAccountNotify = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFY);
    mAccountNotify.setChecked(mAccount.isNotifyNewMail());
    mAccountNotifyNewMailMode = (ListPreference) findPreference(PREFERENCE_NOTIFY_NEW_MAIL_MODE);
    mAccountNotifyNewMailMode.setValue(mAccount.getFolderNotifyNewMailMode().name());
    mAccountNotifyNewMailMode.setSummary(mAccountNotifyNewMailMode.getEntry());
    mAccountNotifyNewMailMode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mAccountNotifyNewMailMode.findIndexOfValue(summary);
            mAccountNotifyNewMailMode.setSummary(mAccountNotifyNewMailMode.getEntries()[index]);
            mAccountNotifyNewMailMode.setValue(summary);
            return false;
        }
    });
    mAccountNotifySelf = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFY_SELF);
    mAccountNotifySelf.setChecked(mAccount.isNotifySelfNewMail());
    mAccountNotifyContactsMailOnly = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFY_CONTACTS_MAIL_ONLY);
    mAccountNotifyContactsMailOnly.setChecked(mAccount.isNotifyContactsMailOnly());
    mAccountNotifySync = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFY_SYNC);
    mAccountNotifySync.setChecked(mAccount.isShowOngoing());
    mAccountRingtone = (RingtonePreference) findPreference(PREFERENCE_RINGTONE);
    // XXX: The following two lines act as a workaround for the RingtonePreference
    //      which does not let us set/get the value programmatically
    SharedPreferences prefs = mAccountRingtone.getPreferenceManager().getSharedPreferences();
    String currentRingtone = (!mAccount.getNotificationSetting().shouldRing() ? null : mAccount.getNotificationSetting().getRingtone());
    prefs.edit().putString(PREFERENCE_RINGTONE, currentRingtone).commit();
    mAccountVibrate = (CheckBoxPreference) findPreference(PREFERENCE_VIBRATE);
    mAccountVibrate.setChecked(mAccount.getNotificationSetting().shouldVibrate());
    mAccountVibratePattern = (ListPreference) findPreference(PREFERENCE_VIBRATE_PATTERN);
    mAccountVibratePattern.setValue(String.valueOf(mAccount.getNotificationSetting().getVibratePattern()));
    mAccountVibratePattern.setSummary(mAccountVibratePattern.getEntry());
    mAccountVibratePattern.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mAccountVibratePattern.findIndexOfValue(summary);
            mAccountVibratePattern.setSummary(mAccountVibratePattern.getEntries()[index]);
            mAccountVibratePattern.setValue(summary);
            doVibrateTest(preference);
            return false;
        }
    });
    mAccountVibrateTimes = (ListPreference) findPreference(PREFERENCE_VIBRATE_TIMES);
    mAccountVibrateTimes.setValue(String.valueOf(mAccount.getNotificationSetting().getVibrateTimes()));
    mAccountVibrateTimes.setSummary(String.valueOf(mAccount.getNotificationSetting().getVibrateTimes()));
    mAccountVibrateTimes.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String value = newValue.toString();
            mAccountVibrateTimes.setSummary(value);
            mAccountVibrateTimes.setValue(value);
            doVibrateTest(preference);
            return false;
        }
    });
    mAccountLed = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFICATION_LED);
    mAccountLed.setChecked(mAccount.getNotificationSetting().isLed());
    mNotificationOpensUnread = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFICATION_OPENS_UNREAD);
    mNotificationOpensUnread.setChecked(mAccount.goToUnreadMessageSearch());
    new PopulateFolderPrefsTask().execute();
    mChipColor = findPreference(PREFERENCE_CHIP_COLOR);
    mChipColor.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference preference) {
            onChooseChipColor();
            return false;
        }
    });
    mLedColor = findPreference(PREFERENCE_LED_COLOR);
    mLedColor.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference preference) {
            onChooseLedColor();
            return false;
        }
    });
    findPreference(PREFERENCE_COMPOSITION).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference preference) {
            onCompositionSettings();
            return true;
        }
    });
    findPreference(PREFERENCE_MANAGE_IDENTITIES).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference preference) {
            onManageIdentities();
            return true;
        }
    });
    findPreference(PREFERENCE_INCOMING).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference preference) {
            mIncomingChanged = true;
            onIncomingSettings();
            return true;
        }
    });
    findPreference(PREFERENCE_OUTGOING).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference preference) {
            onOutgoingSettings();
            return true;
        }
    });
    mHasCrypto = K9.isOpenPgpProviderConfigured();
    PreferenceScreen cryptoMenu = (PreferenceScreen) findPreference(PREFERENCE_CRYPTO);
    if (mHasCrypto) {
        mCryptoKey = (OpenPgpKeyPreference) findPreference(PREFERENCE_CRYPTO_KEY);
        mCryptoKey.setValue(mAccount.getCryptoKey());
        mCryptoKey.setOpenPgpProvider(K9.getOpenPgpProvider());
        // TODO: other identities?
        mCryptoKey.setDefaultUserId(OpenPgpApiHelper.buildUserId(mAccount.getIdentity(0)));
        mCryptoKey.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

            public boolean onPreferenceChange(Preference preference, Object newValue) {
                long value = (Long) newValue;
                mCryptoKey.setValue(value);
                return false;
            }
        });
        cryptoMenu.setOnPreferenceClickListener(null);
    } else {
        cryptoMenu.setSummary(R.string.account_settings_no_openpgp_provider_configured);
        cryptoMenu.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                Dialog dialog = ((PreferenceScreen) preference).getDialog();
                if (dialog != null) {
                    dialog.dismiss();
                }
                Toast.makeText(AccountSettings.this, R.string.no_crypto_provider_see_global, Toast.LENGTH_SHORT).show();
                return true;
            }
        });
    }
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) SharedPreferences(android.content.SharedPreferences) Store(com.fsck.k9.mail.Store) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener) QuoteStyle(com.fsck.k9.Account.QuoteStyle) OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) CheckBoxPreference(android.preference.CheckBoxPreference) EditTextPreference(android.preference.EditTextPreference) OpenPgpKeyPreference(org.openintents.openpgp.util.OpenPgpKeyPreference) RingtonePreference(android.preference.RingtonePreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) Dialog(android.app.Dialog) ColorPickerDialog(com.fsck.k9.activity.ColorPickerDialog) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener) Map(java.util.Map)

Example 9 with QuoteStyle

use of com.fsck.k9.Account.QuoteStyle 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)3 TextBody (com.fsck.k9.mail.internet.TextBody)3 MessageFormat (com.fsck.k9.Account.MessageFormat)2 SimpleMessageFormat (com.fsck.k9.message.SimpleMessageFormat)2 InsertableHtmlContent (com.fsck.k9.message.quote.InsertableHtmlContent)2 StorageEditor (com.fsck.k9.preferences.StorageEditor)2 Theory (org.junit.experimental.theories.Theory)2 Dialog (android.app.Dialog)1 SharedPreferences (android.content.SharedPreferences)1 CheckBoxPreference (android.preference.CheckBoxPreference)1 EditTextPreference (android.preference.EditTextPreference)1 ListPreference (android.preference.ListPreference)1 Preference (android.preference.Preference)1 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)1 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)1 PreferenceScreen (android.preference.PreferenceScreen)1 RingtonePreference (android.preference.RingtonePreference)1 QuoteStyle (com.fsck.k9.Account.QuoteStyle)1 ColorPickerDialog (com.fsck.k9.activity.ColorPickerDialog)1 MessagingException (com.fsck.k9.mail.MessagingException)1