Search in sources :

Example 31 with Store

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

the class ImapFolder method fetch.

@Override
public void fetch(List<ImapMessage> messages, FetchProfile fetchProfile, MessageRetrievalListener<ImapMessage> listener) throws MessagingException {
    if (messages == null || messages.isEmpty()) {
        return;
    }
    checkOpen();
    List<String> uids = new ArrayList<>(messages.size());
    HashMap<String, Message> messageMap = new HashMap<>();
    for (Message message : messages) {
        String uid = message.getUid();
        uids.add(uid);
        messageMap.put(uid, message);
    }
    Set<String> fetchFields = new LinkedHashSet<>();
    fetchFields.add("UID");
    if (fetchProfile.contains(FetchProfile.Item.FLAGS)) {
        fetchFields.add("FLAGS");
    }
    if (fetchProfile.contains(FetchProfile.Item.ENVELOPE)) {
        fetchFields.add("INTERNALDATE");
        fetchFields.add("RFC822.SIZE");
        fetchFields.add("BODY.PEEK[HEADER.FIELDS (date subject from content-type to cc " + "reply-to message-id references in-reply-to " + K9MailLib.IDENTITY_HEADER + ")]");
    }
    if (fetchProfile.contains(FetchProfile.Item.STRUCTURE)) {
        fetchFields.add("BODYSTRUCTURE");
    }
    if (fetchProfile.contains(FetchProfile.Item.BODY_SANE)) {
        int maximumAutoDownloadMessageSize = store.getStoreConfig().getMaximumAutoDownloadMessageSize();
        if (maximumAutoDownloadMessageSize > 0) {
            fetchFields.add(String.format(Locale.US, "BODY.PEEK[]<0.%d>", maximumAutoDownloadMessageSize));
        } else {
            fetchFields.add("BODY.PEEK[]");
        }
    }
    if (fetchProfile.contains(FetchProfile.Item.BODY)) {
        fetchFields.add("BODY.PEEK[]");
    }
    String spaceSeparatedFetchFields = combine(fetchFields.toArray(new String[fetchFields.size()]), ' ');
    for (int windowStart = 0; windowStart < messages.size(); windowStart += (FETCH_WINDOW_SIZE)) {
        int windowEnd = Math.min(windowStart + FETCH_WINDOW_SIZE, messages.size());
        List<String> uidWindow = uids.subList(windowStart, windowEnd);
        try {
            String commaSeparatedUids = combine(uidWindow.toArray(new String[uidWindow.size()]), ',');
            String command = String.format("UID FETCH %s (%s)", commaSeparatedUids, spaceSeparatedFetchFields);
            connection.sendCommand(command, false);
            ImapResponse response;
            int messageNumber = 0;
            ImapResponseCallback callback = null;
            if (fetchProfile.contains(FetchProfile.Item.BODY) || fetchProfile.contains(FetchProfile.Item.BODY_SANE)) {
                callback = new FetchBodyCallback(messageMap);
            }
            do {
                response = connection.readResponse(callback);
                if (response.getTag() == null && ImapResponseParser.equalsIgnoreCase(response.get(1), "FETCH")) {
                    ImapList fetchList = (ImapList) response.getKeyedValue("FETCH");
                    String uid = fetchList.getKeyedString("UID");
                    long msgSeq = response.getLong(0);
                    if (uid != null) {
                        try {
                            msgSeqUidMap.put(msgSeq, uid);
                            if (K9MailLib.isDebug()) {
                                Log.v(LOG_TAG, "Stored uid '" + uid + "' for msgSeq " + msgSeq + " into map");
                            }
                        } catch (Exception e) {
                            Log.e(LOG_TAG, "Unable to store uid '" + uid + "' for msgSeq " + msgSeq);
                        }
                    }
                    Message message = messageMap.get(uid);
                    if (message == null) {
                        if (K9MailLib.isDebug()) {
                            Log.d(LOG_TAG, "Do not have message in messageMap for UID " + uid + " for " + getLogId());
                        }
                        handleUntaggedResponse(response);
                        continue;
                    }
                    if (listener != null) {
                        listener.messageStarted(uid, messageNumber++, messageMap.size());
                    }
                    ImapMessage imapMessage = (ImapMessage) message;
                    Object literal = handleFetchResponse(imapMessage, fetchList);
                    if (literal != null) {
                        if (literal instanceof String) {
                            String bodyString = (String) literal;
                            InputStream bodyStream = new ByteArrayInputStream(bodyString.getBytes());
                            imapMessage.parse(bodyStream);
                        } else if (literal instanceof Integer) {
                        // All the work was done in FetchBodyCallback.foundLiteral()
                        } else {
                            // This shouldn't happen
                            throw new MessagingException("Got FETCH response with bogus parameters");
                        }
                    }
                    if (listener != null) {
                        listener.messageFinished(imapMessage, messageNumber, messageMap.size());
                    }
                } else {
                    handleUntaggedResponse(response);
                }
            } while (response.getTag() == null);
        } catch (IOException ioe) {
            throw ioExceptionHandler(connection, ioe);
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Message(com.fsck.k9.mail.Message) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MessagingException(com.fsck.k9.mail.MessagingException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IOException(java.io.IOException) MessagingException(com.fsck.k9.mail.MessagingException) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 32 with Store

use of com.fsck.k9.mail.Store 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 33 with Store

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

the class AccountSetupIncoming method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        if (Intent.ACTION_EDIT.equals(getIntent().getAction())) {
            boolean isPushCapable = false;
            try {
                Store store = mAccount.getRemoteStore();
                isPushCapable = store.isPushCapable();
            } catch (Exception e) {
                Timber.e(e, "Could not get remote store");
            }
            if (isPushCapable && mAccount.getFolderPushMode() != FolderMode.NONE) {
                MailService.actionRestartPushers(this, null);
            }
            mAccount.save(Preferences.getPreferences(this));
            finish();
        } else {
            /*
                 * Set the username and password for the outgoing settings to the username and
                 * password the user just set for incoming.
                 */
            try {
                String username = mUsernameView.getText().toString();
                String password = null;
                String clientCertificateAlias = null;
                AuthType authType = getSelectedAuthType();
                if (AuthType.EXTERNAL == authType) {
                    clientCertificateAlias = mClientCertificateSpinner.getAlias();
                } else {
                    password = mPasswordView.getText().toString();
                }
                URI oldUri = new URI(mAccount.getTransportUri());
                ServerSettings transportServer = new ServerSettings(Type.SMTP, oldUri.getHost(), oldUri.getPort(), ConnectionSecurity.SSL_TLS_REQUIRED, authType, username, password, clientCertificateAlias);
                String transportUri = Transport.createTransportUri(transportServer);
                mAccount.setTransportUri(transportUri);
            } catch (URISyntaxException use) {
            /*
                     * If we can't set up the URL we just continue. It's only for
                     * convenience.
                     */
            }
            AccountSetupOutgoing.actionOutgoingSettings(this, mAccount, mMakeDefault);
            finish();
        }
    }
}
Also used : ServerSettings(com.fsck.k9.mail.ServerSettings) Store(com.fsck.k9.mail.Store) RemoteStore(com.fsck.k9.mail.store.RemoteStore) AuthType(com.fsck.k9.mail.AuthType) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException)

Example 34 with Store

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

the class MessagingController method loadSearchResults.

public void loadSearchResults(final Account account, final String folderName, final List<Message> messages, final MessagingListener listener) {
    threadPool.execute(new Runnable() {

        @Override
        public void run() {
            if (listener != null) {
                listener.enableProgressIndicator(true);
            }
            try {
                Store remoteStore = account.getRemoteStore();
                LocalStore localStore = account.getLocalStore();
                if (remoteStore == null || localStore == null) {
                    throw new MessagingException("Could not get store");
                }
                Folder remoteFolder = remoteStore.getFolder(folderName);
                LocalFolder localFolder = localStore.getFolder(folderName);
                if (remoteFolder == null || localFolder == null) {
                    throw new MessagingException("Folder not found");
                }
                loadSearchResultsSynchronous(messages, localFolder, remoteFolder, listener);
            } catch (MessagingException e) {
                Timber.e(e, "Exception in loadSearchResults");
                addErrorMessage(account, null, e);
            } finally {
                if (listener != null) {
                    listener.enableProgressIndicator(false);
                }
            }
        }
    });
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) MessagingException(com.fsck.k9.mail.MessagingException) LocalStore(com.fsck.k9.mailstore.LocalStore) Store(com.fsck.k9.mail.Store) Pop3Store(com.fsck.k9.mail.store.pop3.Pop3Store) LocalStore(com.fsck.k9.mailstore.LocalStore) Folder(com.fsck.k9.mail.Folder) LocalFolder(com.fsck.k9.mailstore.LocalFolder)

Example 35 with Store

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

the class MessagingController method processPendingMarkAllAsRead.

void processPendingMarkAllAsRead(PendingMarkAllAsRead command, Account account) throws MessagingException {
    String folder = command.folder;
    Folder remoteFolder = null;
    LocalFolder localFolder = null;
    try {
        Store localStore = account.getLocalStore();
        localFolder = (LocalFolder) localStore.getFolder(folder);
        localFolder.open(Folder.OPEN_MODE_RW);
        List<? extends Message> messages = localFolder.getMessages(null, false);
        for (Message message : messages) {
            if (!message.isSet(Flag.SEEN)) {
                message.setFlag(Flag.SEEN, true);
            }
        }
        for (MessagingListener l : getListeners()) {
            l.folderStatusChanged(account, folder, 0);
        }
        if (account.getErrorFolderName().equals(folder)) {
            return;
        }
        Store remoteStore = account.getRemoteStore();
        remoteFolder = remoteStore.getFolder(folder);
        if (!remoteFolder.exists() || !remoteFolder.isFlagSupported(Flag.SEEN)) {
            return;
        }
        remoteFolder.open(Folder.OPEN_MODE_RW);
        if (remoteFolder.getMode() != Folder.OPEN_MODE_RW) {
            return;
        }
        remoteFolder.setFlags(Collections.singleton(Flag.SEEN), true);
        remoteFolder.close();
    } catch (UnsupportedOperationException uoe) {
        Timber.w(uoe, "Could not mark all server-side as read because store doesn't support operation");
    } finally {
        closeFolder(localFolder);
        closeFolder(remoteFolder);
    }
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) LocalMessage(com.fsck.k9.mailstore.LocalMessage) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) LocalStore(com.fsck.k9.mailstore.LocalStore) Store(com.fsck.k9.mail.Store) Pop3Store(com.fsck.k9.mail.store.pop3.Pop3Store) Folder(com.fsck.k9.mail.Folder) LocalFolder(com.fsck.k9.mailstore.LocalFolder)

Aggregations

Store (com.fsck.k9.mail.Store)24 MessagingException (com.fsck.k9.mail.MessagingException)23 LocalStore (com.fsck.k9.mailstore.LocalStore)21 Pop3Store (com.fsck.k9.mail.store.pop3.Pop3Store)20 LocalFolder (com.fsck.k9.mailstore.LocalFolder)19 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)17 Folder (com.fsck.k9.mail.Folder)16 Message (com.fsck.k9.mail.Message)16 LocalMessage (com.fsck.k9.mailstore.LocalMessage)16 ArrayList (java.util.ArrayList)10 SuppressLint (android.annotation.SuppressLint)7 UnavailableStorageException (com.fsck.k9.mailstore.UnavailableStorageException)7 IOException (java.io.IOException)6 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)5 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)5 FetchProfile (com.fsck.k9.mail.FetchProfile)5 Date (java.util.Date)5 Account (com.fsck.k9.Account)4 VisibleForTesting (android.support.annotation.VisibleForTesting)3 SearchAccount (com.fsck.k9.search.SearchAccount)3