POP3: reversed message order support

This commit is contained in:
M66B 2023-02-15 17:37:15 +01:00
parent 89f2cee08c
commit 22f4725be0
7 changed files with 30 additions and 19 deletions

View File

@ -2981,7 +2981,8 @@ class Core {
List<TupleUidl> ids = db.message().getUidls(folder.id);
int max = (account.max_messages == null
? imessages.length
: Math.min(imessages.length, account.max_messages));
: Math.min(imessages.length, Math.abs(account.max_messages)));
boolean reversed = (account.max_messages != null && account.max_messages < 0);
boolean sync = true;
if (!hasUidl && sync_quick_pop && !force &&
@ -3003,6 +3004,7 @@ class Core {
" device=" + ids.size() +
" server=" + imessages.length +
" max=" + max + "/" + account.max_messages +
" reversed=" + reversed +
" last=" + folder.last_sync_count +
" sync=" + sync +
" uidl=" + hasUidl);
@ -3075,7 +3077,7 @@ class Core {
}
boolean _new = true;
for (int i = imessages.length - 1; i >= imessages.length - max; i--) {
for (int i = reversed ? 0 : imessages.length - 1; reversed ? i < max : i >= imessages.length - max; i += reversed ? 1 : -1) {
state.ensureRunning("Sync/POP3");
Message imessage = imessages[i];
@ -3392,8 +3394,8 @@ class Core {
}
if (account.max_messages != null && !account.leave_on_device) {
int hidden = db.message().setMessagesUiHide(folder.id, account.max_messages);
int deleted = db.message().deleteMessagesKeep(folder.id, account.max_messages + 100);
int hidden = db.message().setMessagesUiHide(folder.id, Math.abs(account.max_messages));
int deleted = db.message().deleteMessagesKeep(folder.id, Math.abs(account.max_messages) + 100);
EntityLog.log(context, account.name + " POP" +
" cleanup max=" + account.max_messages + "" +
" hidden=" + hidden + " deleted=" + deleted);

View File

@ -58,7 +58,6 @@ public class EntityAccount extends EntityOrder implements Serializable {
// https://tools.ietf.org/html/rfc2177
static final int DEFAULT_KEEP_ALIVE_INTERVAL = 15; // minutes
static final int DEFAULT_POLL_INTERVAL = 15; // minutes
static final int DEFAULT_MAX_MESSAGES = 250; // POP3
static final int QUOTA_WARNING = 95; // percent
@ -120,7 +119,7 @@ public class EntityAccount extends EntityOrder implements Serializable {
public Boolean leave_deleted = false;
@NonNull
public Boolean leave_on_device = false;
public Integer max_messages; // POP3
public Integer max_messages = null; // POP3
@NonNull
public Boolean auto_seen = true;
@ColumnInfo(name = "separator")

View File

@ -529,11 +529,9 @@ public class FragmentGmail extends FragmentBase {
account.synchronize = true;
account.primary = (primary == null);
if (pop) {
// https://support.google.com/mail/answer/7104828
// https://support.google.com/mail/answer/7104828
if (pop)
account.leave_on_device = true;
account.max_messages = EntityAccount.DEFAULT_MAX_MESSAGES;
}
account.created = new Date().getTime();
account.last_connected = account.created;

View File

@ -891,9 +891,6 @@ public class FragmentOAuth extends FragmentBase {
account.partial_fetch = provider.partial;
account.raw_fetch = provider.raw;
if (pop)
account.max_messages = EntityAccount.DEFAULT_MAX_MESSAGES;
account.created = new Date().getTime();
account.last_connected = account.created;

View File

@ -445,6 +445,8 @@ public class FragmentPop extends FragmentBase {
if (TextUtils.isEmpty(interval))
interval = Integer.toString(EntityAccount.DEFAULT_POLL_INTERVAL);
Integer max_messages = (TextUtils.isEmpty(max) ? null : Integer.parseInt(max));
if (max_messages != null && max_messages == 0)
max_messages = null;
int poll_interval = Math.max(1, Integer.parseInt(interval));
if (TextUtils.isEmpty(name))
@ -793,11 +795,10 @@ public class FragmentPop extends FragmentBase {
cbLeaveDeleted.setChecked(account == null ? true : account.leave_deleted);
cbLeaveDevice.setChecked(account == null ? false : account.leave_on_device);
if (account != null && account.max_messages == null)
etMax.setText(null);
if (account != null && account.max_messages != null)
etMax.setText(Integer.toString(account.max_messages));
else
etMax.setText(Integer.toString(account == null
? EntityAccount.DEFAULT_MAX_MESSAGES : account.max_messages));
etMax.setText(null);
etInterval.setText(account == null ? "" : Long.toString(account.poll_interval));
cbUnmetered.setChecked(jcondition.optBoolean("unmetered"));

View File

@ -469,12 +469,22 @@
android:id="@+id/etMax"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:inputType="numberSigned"
android:maxLength="9"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvMax" />
<TextView
android:id="@+id/tvMaxRemark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_max_messages_remark"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etMax" />
<!-- keep alive -->
<TextView
@ -485,7 +495,7 @@
android:text="@string/title_keep_poll_interval"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etMax" />
app:layout_constraintTop_toBottomOf="@id/tvMaxRemark" />
<eu.faircode.email.EditTextPlain
android:id="@+id/etInterval"

View File

@ -1112,6 +1112,10 @@
<string name="title_leave_deleted">Leave deleted messages on server</string>
<string name="title_leave_on_device">Leave messages on device</string>
<string name="title_max_messages">Maximum number of messages to download (blank for all)</string>
<string name="title_max_messages_remark">
Enter a positive number to download the messages at the end (most common)
and a negative number to download the messages at the beginning (least common)
</string>
<string name="title_keep_poll_interval">Poll interval (minutes)</string>
<string name="title_keep_alive_interval">Keep-alive interval (minutes)</string>
<string name="title_keep_alive_noop">Restart IMAP IDLE periodically</string>