1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 11:42:16 -05:00

Add a per-account setting to choose how much of each message to download automatically.

This commit is contained in:
Jesse Vincent 2010-07-11 11:59:14 +00:00
parent e59987fdcb
commit ae339f1ac8
10 changed files with 101 additions and 16 deletions

View File

@ -96,6 +96,39 @@
<item>365</item>
</string-array>
<string-array name="account_settings_autodownload_message_size_entries">
<item>@string/account_settings_autodownload_message_size_1</item>
<item>@string/account_settings_autodownload_message_size_2</item>
<item>@string/account_settings_autodownload_message_size_4</item>
<item>@string/account_settings_autodownload_message_size_8</item>
<item>@string/account_settings_autodownload_message_size_16</item>
<item>@string/account_settings_autodownload_message_size_32</item>
<item>@string/account_settings_autodownload_message_size_64</item>
<item>@string/account_settings_autodownload_message_size_128</item>
<item>@string/account_settings_autodownload_message_size_256</item>
<item>@string/account_settings_autodownload_message_size_512</item>
<item>@string/account_settings_autodownload_message_size_1024</item>
<item>@string/account_settings_autodownload_message_size_2048</item>
<item>@string/account_settings_autodownload_message_size_0</item>
</string-array>
<string-array name="account_settings_autodownload_message_size_values">
<item>1024</item>
<item>2048</item>
<item>4096</item>
<item>8192</item>
<item>16384</item>
<item>32768</item>
<item>65536</item>
<item>131072</item>
<item>262144</item>
<item>524288</item>
<item>1048576</item>
<item>2097152</item>
<item>0</item>
</string-array>
<string-array name="account_settings_folder_display_mode_entries">
<item>@string/account_settings_folder_display_mode_all</item>
<item>@string/account_settings_folder_display_mode_first_class</item>

View File

@ -519,6 +519,22 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin
<string name="account_settings_mail_display_count_label">Number of messages to display</string>
<string name="account_settings_autodownload_message_size_label">Automatically download message content up to</string>
<string name="account_settings_autodownload_message_size_1">1Kb</string>
<string name="account_settings_autodownload_message_size_2">2Kb</string>
<string name="account_settings_autodownload_message_size_4">4Kb</string>
<string name="account_settings_autodownload_message_size_8">8Kb</string>
<string name="account_settings_autodownload_message_size_16">16Kb</string>
<string name="account_settings_autodownload_message_size_32">32Kb</string>
<string name="account_settings_autodownload_message_size_64">64Kb</string>
<string name="account_settings_autodownload_message_size_128">128Kb</string>
<string name="account_settings_autodownload_message_size_256">256Kb</string>
<string name="account_settings_autodownload_message_size_512">512Kb</string>
<string name="account_settings_autodownload_message_size_1024">1Mb</string>
<string name="account_settings_autodownload_message_size_2048">2Mb</string>
<string name="account_settings_autodownload_message_size_any">any size</string>
<string name="account_settings_autodownload_message_size_0">only download headers</string>
<string name="account_settings_message_age_label">Sync messages newer than</string>
<string name="account_settings_message_age_any">the Big Bang</string>
<string name="account_settings_message_age_0">one day</string>

View File

@ -95,6 +95,13 @@
android:entryValues="@array/account_settings_message_age_values"
android:dialogTitle="@string/account_settings_message_age_label" />
<ListPreference
android:key="account_autodownload_size"
android:title="@string/account_settings_autodownload_message_size_label"
android:entries="@array/account_settings_autodownload_message_size_entries"
android:entryValues="@array/account_settings_autodownload_message_size_values"
android:dialogTitle="@string/account_settings_autodownload_message_size_label" />
<ListPreference
android:key="folder_sync_mode"
android:title="@string/account_settings_folder_sync_mode_label"

View File

@ -101,6 +101,7 @@ public class Account implements BaseAccount
private Searchable searchableFolders;
private boolean subscribedFoldersOnly;
private int maximumPolledMessageAge;
private int maximumAutoDownloadMessageSize;
// Tracks if we have sent a notification for this account for
// current set of fetched messages
private boolean mRingNotified;
@ -167,6 +168,7 @@ public class Account implements BaseAccount
goToUnreadMessageSearch = false;
subscribedFoldersOnly = false;
maximumPolledMessageAge = -1;
maximumAutoDownloadMessageSize = 32768;
mQuotePrefix = DEFAULT_QUOTE_PREFIX;
mSyncRemoteDeletions = true;
@ -243,6 +245,8 @@ public class Account implements BaseAccount
false);
maximumPolledMessageAge = preferences.getPreferences().getInt(mUuid
+ ".maximumPolledMessageAge", -1);
maximumAutoDownloadMessageSize = preferences.getPreferences().getInt(mUuid
+ ".maximumAutoDownloadMessageSize", 32768);
mQuotePrefix = preferences.getPreferences().getString(mUuid + ".quotePrefix", DEFAULT_QUOTE_PREFIX);
for (String type : networkTypes)
{
@ -415,6 +419,7 @@ public class Account implements BaseAccount
editor.remove(mUuid + ".goToUnreadMessageSearch");
editor.remove(mUuid + ".subscribedFoldersOnly");
editor.remove(mUuid + ".maximumPolledMessageAge");
editor.remove(mUuid + ".maximumAutoDownloadMessageSize");
editor.remove(mUuid + ".quotePrefix");
for (String type : networkTypes)
{
@ -508,6 +513,7 @@ public class Account implements BaseAccount
editor.putBoolean(mUuid + ".goToUnreadMessageSearch", goToUnreadMessageSearch);
editor.putBoolean(mUuid + ".subscribedFoldersOnly", subscribedFoldersOnly);
editor.putInt(mUuid + ".maximumPolledMessageAge", maximumPolledMessageAge);
editor.putInt(mUuid + ".maximumAutoDownloadMessageSize", maximumAutoDownloadMessageSize);
editor.putString(mUuid + ".quotePrefix", mQuotePrefix);
for (String type : networkTypes)
@ -1331,6 +1337,16 @@ public class Account implements BaseAccount
this.maximumPolledMessageAge = maximumPolledMessageAge;
}
public synchronized int getMaximumAutoDownloadMessageSize()
{
return maximumAutoDownloadMessageSize;
}
public synchronized void setMaximumAutoDownloadMessageSize(int maximumAutoDownloadMessageSize)
{
this.maximumAutoDownloadMessageSize = maximumAutoDownloadMessageSize;
}
public Date getEarliestPollDate()
{
int age = getMaximumPolledMessageAge();

View File

@ -57,6 +57,7 @@ public class AccountSettings extends K9PreferenceActivity
private static final String PREFERENCE_LED_COLOR = "led_color";
private static final String PREFERENCE_NOTIFICATION_OPENS_UNREAD = "notification_opens_unread";
private static final String PREFERENCE_MESSAGE_AGE = "account_message_age";
private static final String PREFERENCE_MESSAGE_SIZE = "account_autodownload_size";
private static final String PREFERENCE_QUOTE_PREFIX = "account_quote_prefix";
private static final String PREFERENCE_SYNC_REMOTE_DELETIONS = "account_sync_remote_deletetions";
@ -67,6 +68,7 @@ public class AccountSettings extends K9PreferenceActivity
private ListPreference mCheckFrequency;
private ListPreference mDisplayCount;
private ListPreference mMessageAge;
private ListPreference mMessageSize;
private CheckBoxPreference mAccountDefault;
private CheckBoxPreference mAccountNotify;
private CheckBoxPreference mAccountNotifySelf;
@ -313,6 +315,25 @@ public class AccountSettings extends K9PreferenceActivity
}
});
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()));
@ -511,6 +532,7 @@ public class AccountSettings extends K9PreferenceActivity
mAccount.setShowOngoing(mAccountNotifySync.isChecked());
mAccount.setDisplayCount(Integer.parseInt(mDisplayCount.getValue()));
mAccount.setMaximumPolledMessageAge(Integer.parseInt(mMessageAge.getValue()));
mAccount.setMaximumAutoDownloadMessageSize(Integer.parseInt(mMessageSize.getValue()));
mAccount.setVibrate(mAccountVibrate.isChecked());
mAccount.setVibratePattern(Integer.parseInt(mAccountVibratePattern.getValue()));
mAccount.setVibrateTimes(Integer.parseInt(mAccountVibrateTimes.getText()));

View File

@ -101,7 +101,6 @@ public class MessagingController implements Runnable
* </pre>
* So 25k gives good performance and a reasonable data footprint. Sounds good to me.
*/
private static final int MAX_SMALL_MESSAGE_SIZE = Store.FETCH_BODY_SANE_SUGGESTED_SIZE;
private static final String PENDING_COMMAND_MOVE_OR_COPY = "com.fsck.k9.MessagingController.moveOrCopy";
private static final String PENDING_COMMAND_MOVE_OR_COPY_BULK = "com.fsck.k9.MessagingController.moveOrCopyBulk";
@ -1621,7 +1620,7 @@ public class MessagingController implements Runnable
return;
}
if (message.getSize() > (MAX_SMALL_MESSAGE_SIZE))
if (message.getSize() > account.getMaximumAutoDownloadMessageSize())
{
largeMessages.add(message);
}
@ -1841,11 +1840,11 @@ public class MessagingController implements Runnable
{
/*
* Mark the message as fully downloaded if the message size is smaller than
* the FETCH_BODY_SANE_SUGGESTED_SIZE, otherwise mark as only a partial
* the account's autodownload size limit, otherwise mark as only a partial
* download. This will prevent the system from downloading the same message
* twice.
*/
if (message.getSize() < Store.FETCH_BODY_SANE_SUGGESTED_SIZE)
if (message.getSize() < account.getMaximumAutoDownloadMessageSize())
{
localMessage.setFlag(Flag.X_DOWNLOADED_FULL, true);
}

View File

@ -22,13 +22,6 @@ import java.util.List;
*/
public abstract class Store
{
/**
* A global suggestion to Store implementors on how much of the body
* should be returned on FetchProfile.Item.BODY_SANE requests.
*/
//Matching MessagingController.MAX_SMALL_MESSAGE_SIZE
public static final int FETCH_BODY_SANE_SUGGESTED_SIZE = (50 * 1024);
protected static final int SOCKET_CONNECT_TIMEOUT = 30000;
protected static final int SOCKET_READ_TIMEOUT = 60000;

View File

@ -1205,7 +1205,7 @@ public class ImapStore extends Store
}
if (fp.contains(FetchProfile.Item.BODY_SANE))
{
fetchFields.add(String.format("BODY.PEEK[]<0.%d>", FETCH_BODY_SANE_SUGGESTED_SIZE));
fetchFields.add(String.format("BODY.PEEK[]<0.%d>", mAccount.getMaximumAutoDownloadMessageSize()));
}
if (fp.contains(FetchProfile.Item.BODY))
{
@ -1327,7 +1327,7 @@ public class ImapStore extends Store
String partId = parts[0];
if ("TEXT".equalsIgnoreCase(partId))
{
fetch = String.format("BODY.PEEK[TEXT]<0.%d>", FETCH_BODY_SANE_SUGGESTED_SIZE);
fetch = String.format("BODY.PEEK[TEXT]<0.%d>", mAccount.getMaximumAutoDownloadMessageSize());
}
else
{

View File

@ -697,7 +697,7 @@ public class Pop3Store extends Store
* divided by the maximum line size (76).
*/
fetchBody(pop3Message,
FETCH_BODY_SANE_SUGGESTED_SIZE / 76);
(mAccount.getMaximumAutoDownloadMessageSize() / 76));
}
else if (fp.contains(FetchProfile.Item.STRUCTURE))
{

View File

@ -1537,9 +1537,8 @@ public class WebDavStore extends Store
if (fp.contains(FetchProfile.Item.BODY_SANE))
{
fetchMessages(messages, listener, FETCH_BODY_SANE_SUGGESTED_SIZE / 76);
fetchMessages(messages, listener, (mAccount.getMaximumAutoDownloadMessageSize() / 76));
}
if (fp.contains(FetchProfile.Item.BODY))
{
fetchMessages(messages, listener, -1);