From 87640719ddc32e3130b61f0c62e2df6ad7b14afe Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Tue, 12 Jul 2011 21:47:37 -0400 Subject: [PATCH] Disable "download by date range" for webdav and pop3. The previous behavior caused catastrophic network abuse, downloading messages outside the date range over and over. --- src/com/fsck/k9/Account.java | 12 +++++++ .../k9/activity/setup/AccountSettings.java | 34 ++++++++++++------- .../k9/controller/MessagingController.java | 2 +- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/com/fsck/k9/Account.java b/src/com/fsck/k9/Account.java index d7d431cfc..a1bbda111 100644 --- a/src/com/fsck/k9/Account.java +++ b/src/com/fsck/k9/Account.java @@ -977,6 +977,18 @@ public class Account implements BaseAccount { return Store.getRemoteInstance(this); } + // It'd be great if this actually went into the store implementation + // to get this, but that's expensive and not easilly accessible + // during initialization + public boolean isSearchByDateCapable() { + if (getStoreUri().startsWith("imap")) { + return true; + } else { + return false; + } + } + + @Override public synchronized String toString() { return mDescription; diff --git a/src/com/fsck/k9/activity/setup/AccountSettings.java b/src/com/fsck/k9/activity/setup/AccountSettings.java index 38c9e38e0..4c1d26531 100644 --- a/src/com/fsck/k9/activity/setup/AccountSettings.java +++ b/src/com/fsck/k9/activity/setup/AccountSettings.java @@ -385,18 +385,26 @@ public class AccountSettings extends K9PreferenceActivity { } }); + + mMessageAge = (ListPreference) findPreference(PREFERENCE_MESSAGE_AGE); - 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; - } - }); + + if (!mAccount.isSearchByDateCapable()) { + mMessageAge.setEnabled(false); + } 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())); @@ -683,8 +691,10 @@ public class AccountSettings extends K9PreferenceActivity { mAccount.setNotifySelfNewMail(mAccountNotifySelf.isChecked()); mAccount.setShowOngoing(mAccountNotifySync.isChecked()); mAccount.setDisplayCount(Integer.parseInt(mDisplayCount.getValue())); - mAccount.setMaximumPolledMessageAge(Integer.parseInt(mMessageAge.getValue())); mAccount.setMaximumAutoDownloadMessageSize(Integer.parseInt(mMessageSize.getValue())); + if (mAccount.isSearchByDateCapable()) { + mAccount.setMaximumPolledMessageAge(Integer.parseInt(mMessageAge.getValue())); + } mAccount.getNotificationSetting().setVibrate(mAccountVibrate.isChecked()); mAccount.getNotificationSetting().setVibratePattern(Integer.parseInt(mAccountVibratePattern.getValue())); mAccount.getNotificationSetting().setVibrateTimes(Integer.parseInt(mAccountVibrateTimes.getValue())); diff --git a/src/com/fsck/k9/controller/MessagingController.java b/src/com/fsck/k9/controller/MessagingController.java index 32f1486d6..b51f83dc7 100644 --- a/src/com/fsck/k9/controller/MessagingController.java +++ b/src/com/fsck/k9/controller/MessagingController.java @@ -1534,7 +1534,7 @@ public class MessagingController implements Runnable { return false; } - if (message.olderThan(earliestDate)) { + if (account.isSearchByDateCapable() && message.olderThan(earliestDate)) { if (K9.DEBUG) { Log.d(K9.LOG_TAG, "Message " + message.getUid() + " is older than " + earliestDate + ", hence not saving");