mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-03 02:05:36 +00:00
Keep browsed messages
This commit is contained in:
parent
8d4f8ce225
commit
3dabbbb677
7 changed files with 1211 additions and 19 deletions
1148
app/schemas/eu.faircode.email.DB/10.json
Normal file
1148
app/schemas/eu.faircode.email.DB/10.json
Normal file
File diff suppressed because it is too large
Load diff
|
@ -46,7 +46,7 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
|
|||
// https://developer.android.com/topic/libraries/architecture/room.html
|
||||
|
||||
@Database(
|
||||
version = 9,
|
||||
version = 10,
|
||||
entities = {
|
||||
EntityIdentity.class,
|
||||
EntityAccount.class,
|
||||
|
@ -184,6 +184,14 @@ public abstract class DB extends RoomDatabase {
|
|||
db.execSQL("ALTER TABLE `folder` ADD COLUMN `keywords` TEXT");
|
||||
}
|
||||
})
|
||||
.addMigrations(new Migration(9, 10) {
|
||||
@Override
|
||||
public void migrate(SupportSQLiteDatabase db) {
|
||||
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
|
||||
db.execSQL("ALTER TABLE `message` ADD COLUMN `ui_browsed` INTEGER NOT NULL DEFAULT 0");
|
||||
db.execSQL("CREATE INDEX `index_message_ui_browsed` ON `message` (`ui_browsed`)");
|
||||
}
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -308,8 +308,12 @@ public interface DaoMessage {
|
|||
@Query("DELETE FROM message WHERE folder = :folder AND seen")
|
||||
int deleteSeenMessages(long folder);
|
||||
|
||||
@Query("DELETE FROM message WHERE folder = :folder AND received < :received AND NOT uid IS NULL")
|
||||
int deleteMessagesBefore(long folder, long received);
|
||||
@Query("DELETE FROM message" +
|
||||
" WHERE folder = :folder" +
|
||||
" AND received < :received" +
|
||||
" AND NOT uid IS NULL" +
|
||||
" AND (NOT ui_browsed OR :browsed)")
|
||||
int deleteMessagesBefore(long folder, long received, boolean browsed);
|
||||
|
||||
@Query("DELETE FROM message WHERE ui_found")
|
||||
int deleteFoundMessages();
|
||||
|
|
|
@ -76,7 +76,8 @@ import static androidx.room.ForeignKey.SET_NULL;
|
|||
@Index(value = {"ui_seen"}),
|
||||
@Index(value = {"ui_hide"}),
|
||||
@Index(value = {"ui_found"}),
|
||||
@Index(value = {"ui_ignored"})
|
||||
@Index(value = {"ui_ignored"}),
|
||||
@Index(value = {"ui_browsed"})
|
||||
}
|
||||
)
|
||||
public class EntityMessage implements Serializable {
|
||||
|
@ -134,6 +135,8 @@ public class EntityMessage implements Serializable {
|
|||
public Boolean ui_found = false;
|
||||
@NonNull
|
||||
public Boolean ui_ignored = false;
|
||||
@NonNull
|
||||
public Boolean ui_browsed = false;
|
||||
public String error;
|
||||
public Long last_attempt; // send
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ import com.google.android.material.snackbar.Snackbar;
|
|||
import com.sun.mail.imap.IMAPFolder;
|
||||
import com.sun.mail.imap.IMAPStore;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.mail.Folder;
|
||||
|
@ -177,8 +178,22 @@ public class FragmentFolder extends FragmentEx {
|
|||
}
|
||||
|
||||
if (folder != null) {
|
||||
Calendar cal_keep = Calendar.getInstance();
|
||||
cal_keep.add(Calendar.DAY_OF_MONTH, -keep_days);
|
||||
cal_keep.set(Calendar.HOUR_OF_DAY, 0);
|
||||
cal_keep.set(Calendar.MINUTE, 0);
|
||||
cal_keep.set(Calendar.SECOND, 0);
|
||||
cal_keep.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
long keep_time = cal_keep.getTimeInMillis();
|
||||
if (keep_time < 0)
|
||||
keep_time = 0;
|
||||
|
||||
Log.i(Helper.TAG, "Updating folder=" + name);
|
||||
db.folder().setFolderProperties(id, name, display, hide, synchronize, unified, sync_days, keep_days);
|
||||
|
||||
db.message().deleteMessagesBefore(id, keep_time, true);
|
||||
|
||||
if (!synchronize)
|
||||
db.folder().setFolderError(id, null);
|
||||
}
|
||||
|
|
|
@ -888,7 +888,10 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
long id;
|
||||
try {
|
||||
db.beginTransaction();
|
||||
id = synchronizeMessage(ServiceSynchronize.this, folder, ifolder, (IMAPMessage) imessage, false, false);
|
||||
id = synchronizeMessage(
|
||||
ServiceSynchronize.this,
|
||||
folder, ifolder, (IMAPMessage) imessage,
|
||||
false, false, false);
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
|
@ -971,7 +974,10 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
long id;
|
||||
try {
|
||||
db.beginTransaction();
|
||||
id = synchronizeMessage(ServiceSynchronize.this, folder, ifolder, (IMAPMessage) e.getMessage(), false, false);
|
||||
id = synchronizeMessage(
|
||||
ServiceSynchronize.this,
|
||||
folder, ifolder, (IMAPMessage) e.getMessage(),
|
||||
false, false, false);
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
|
@ -1822,27 +1828,27 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
cal_keep.set(Calendar.SECOND, 0);
|
||||
cal_keep.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
long sync = cal_sync.getTimeInMillis();
|
||||
if (sync < 0)
|
||||
sync = 0;
|
||||
long sync_time = cal_sync.getTimeInMillis();
|
||||
if (sync_time < 0)
|
||||
sync_time = 0;
|
||||
|
||||
long keep = cal_keep.getTimeInMillis();
|
||||
if (keep < 0)
|
||||
keep = 0;
|
||||
long keep_time = cal_keep.getTimeInMillis();
|
||||
if (keep_time < 0)
|
||||
keep_time = 0;
|
||||
|
||||
Log.i(Helper.TAG, folder.name + " sync=" + new Date(sync) + " keep=" + new Date(keep));
|
||||
Log.i(Helper.TAG, folder.name + " sync=" + new Date(sync_time) + " keep=" + new Date(keep_time));
|
||||
|
||||
// Delete old local messages
|
||||
int old = db.message().deleteMessagesBefore(folder.id, keep);
|
||||
int old = db.message().deleteMessagesBefore(folder.id, keep_time, false);
|
||||
Log.i(Helper.TAG, folder.name + " local old=" + old);
|
||||
|
||||
// Get list of local uids
|
||||
List<Long> uids = db.message().getUids(folder.id, sync);
|
||||
List<Long> uids = db.message().getUids(folder.id, sync_time);
|
||||
Log.i(Helper.TAG, folder.name + " local count=" + uids.size());
|
||||
|
||||
// Reduce list of local uids
|
||||
long search = SystemClock.elapsedRealtime();
|
||||
Message[] imessages = ifolder.search(new ReceivedDateTerm(ComparisonTerm.GE, new Date(sync)));
|
||||
Message[] imessages = ifolder.search(new ReceivedDateTerm(ComparisonTerm.GE, new Date(sync_time)));
|
||||
Log.i(Helper.TAG, folder.name + " remote count=" + imessages.length +
|
||||
" search=" + (SystemClock.elapsedRealtime() - search) + " ms");
|
||||
|
||||
|
@ -1913,7 +1919,10 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
for (int j = isub.length - 1; j >= 0; j--)
|
||||
try {
|
||||
db.beginTransaction();
|
||||
ids[from + j] = synchronizeMessage(this, folder, ifolder, (IMAPMessage) isub[j], false, true);
|
||||
ids[from + j] = synchronizeMessage(
|
||||
this,
|
||||
folder, ifolder, (IMAPMessage) isub[j],
|
||||
false, false, true);
|
||||
db.setTransactionSuccessful();
|
||||
Thread.sleep(20);
|
||||
} catch (MessageRemovedException ex) {
|
||||
|
@ -1979,7 +1988,10 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
}
|
||||
}
|
||||
|
||||
static Long synchronizeMessage(Context context, EntityFolder folder, IMAPFolder ifolder, IMAPMessage imessage, boolean found, boolean full) throws MessagingException, IOException {
|
||||
static Long synchronizeMessage(
|
||||
Context context,
|
||||
EntityFolder folder, IMAPFolder ifolder, IMAPMessage imessage,
|
||||
boolean found, boolean browsed, boolean full) throws MessagingException, IOException {
|
||||
long uid = ifolder.getUID(imessage);
|
||||
|
||||
if (imessage.isExpunged()) {
|
||||
|
|
|
@ -205,7 +205,9 @@ public class ViewModelBrowse extends ViewModel {
|
|||
EntityMessage message = db.message().getMessageByUid(state.fid, uid, state.search != null);
|
||||
if (message == null) {
|
||||
ServiceSynchronize.synchronizeMessage(
|
||||
state.context, folder, state.ifolder, (IMAPMessage) isub[j], state.search != null, false);
|
||||
state.context,
|
||||
folder, state.ifolder, (IMAPMessage) isub[j],
|
||||
state.search != null, state.search == null, false);
|
||||
count++;
|
||||
}
|
||||
} catch (MessageRemovedException ex) {
|
||||
|
|
Loading…
Reference in a new issue