Added POP3 option to leave messages on server

This commit is contained in:
M66B
2019-09-25 13:26:56 +02:00
parent 8e245517f3
commit 13997a0848
9 changed files with 1904 additions and 12 deletions

View File

@@ -216,7 +216,7 @@ class Core {
// Do nothing
break;
case EntityOperation.DELETE:
onDelete(context, jargs, folder, message, (POP3Folder) ifolder, state);
onDelete(context, jargs, account, folder, message, (POP3Folder) ifolder, state);
break;
case EntityOperation.SYNC:
onSynchronizeMessages(context, jargs, account, folder, (POP3Folder) ifolder, (POP3Store) istore, state);
@@ -818,11 +818,11 @@ class Core {
}
}
private static void onDelete(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, POP3Folder ifolder, State state) throws MessagingException {
private static void onDelete(Context context, JSONArray jargs, EntityAccount account, EntityFolder folder, EntityMessage message, POP3Folder ifolder, State state) throws MessagingException {
// Delete message
DB db = DB.getInstance(context);
if (EntityFolder.INBOX.equals(folder.type)) {
if (!account.browse && EntityFolder.INBOX.equals(folder.type)) {
Message[] imessages = ifolder.getMessages();
Log.i(folder.name + " POP messages=" + imessages.length);

View File

@@ -58,7 +58,7 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 102,
version = 103,
entities = {
EntityIdentity.class,
EntityAccount.class,
@@ -1020,6 +1020,13 @@ public abstract class DB extends RoomDatabase {
db.execSQL("ALTER TABLE `account` ADD COLUMN `auto_seen` INTEGER NOT NULL DEFAULT 1");
}
})
.addMigrations(new Migration(102, 103) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("UPDATE `account` SET browse = 1 WHERE pop = 1");
}
})
.build();
}

View File

@@ -55,7 +55,7 @@ public class EntityAccount extends EntityOrder implements Serializable {
public Long id;
@NonNull
public Boolean pop = false; // obsolete
public Boolean pop = false;
@NonNull
public String host; // POP3/IMAP
@NonNull
@@ -85,7 +85,7 @@ public class EntityAccount extends EntityOrder implements Serializable {
@NonNull
public Boolean notify = false;
@NonNull
public Boolean browse = true;
public Boolean browse = true; // Leave messages on server
@NonNull
public Boolean auto_seen = true;
public Character separator;

View File

@@ -76,6 +76,7 @@ public class FragmentPop extends FragmentBase {
private CheckBox cbSynchronize;
private CheckBox cbPrimary;
private CheckBox cbLeave;
private EditText etInterval;
private Button btnSave;
@@ -125,6 +126,7 @@ public class FragmentPop extends FragmentBase {
cbSynchronize = view.findViewById(R.id.cbSynchronize);
cbPrimary = view.findViewById(R.id.cbPrimary);
cbLeave = view.findViewById(R.id.cbLeave);
etInterval = view.findViewById(R.id.etInterval);
btnSave = view.findViewById(R.id.btnSave);
@@ -193,8 +195,9 @@ public class FragmentPop extends FragmentBase {
args.putString("name", etName.getText().toString());
args.putInt("color", color);
args.putBoolean("primary", cbPrimary.isChecked());
args.putBoolean("synchronize", cbSynchronize.isChecked());
args.putBoolean("primary", cbPrimary.isChecked());
args.putBoolean("leave", cbLeave.isChecked());
args.putString("interval", etInterval.getText().toString());
new SimpleTask<Boolean>() {
@@ -230,6 +233,7 @@ public class FragmentPop extends FragmentBase {
boolean synchronize = args.getBoolean("synchronize");
boolean primary = args.getBoolean("primary");
boolean leave = args.getBoolean("leave");
String interval = args.getString("interval");
boolean pro = ActivityBilling.isPro(context);
@@ -267,6 +271,7 @@ public class FragmentPop extends FragmentBase {
!user.equals(account.user) || !password.equals(account.password)));
boolean reload = (check || account == null ||
account.synchronize != synchronize ||
account.browse != leave ||
!account.poll_interval.equals(Integer.parseInt(interval)));
Log.i("Account check=" + check + " reload=" + reload);
@@ -314,7 +319,7 @@ public class FragmentPop extends FragmentBase {
account.synchronize = synchronize;
account.primary = (account.synchronize && primary);
account.browse = false;
account.browse = leave;
account.poll_interval = Integer.parseInt(interval);
if (!update)
@@ -459,6 +464,7 @@ public class FragmentPop extends FragmentBase {
cbSynchronize.setChecked(account == null ? true : account.synchronize);
cbPrimary.setChecked(account == null ? false : account.primary);
cbLeave.setChecked(account == null ? true : account.browse);
etInterval.setText(account == null ? "" : Long.toString(account.poll_interval));
color = (account == null || account.color == null ? Color.TRANSPARENT : account.color);

View File

@@ -85,8 +85,6 @@ public class MailService implements AutoCloseable {
properties.put("mail." + protocol + ".writetimeout", Integer.toString(WRITE_TIMEOUT)); // one thread overhead
properties.put("mail." + protocol + ".timeout", Integer.toString(READ_TIMEOUT));
//properties.put("mail." + protocol + ".rsetbeforequit", "true");
} else if ("imap".equals(protocol) || "imaps".equals(protocol)) {
// https://javaee.github.io/javamail/docs/api/com/sun/mail/imap/package-summary.html#properties
properties.put("mail." + protocol + ".ssl.checkserveridentity", checkserveridentity);
@@ -158,6 +156,10 @@ public class MailService implements AutoCloseable {
properties.put("mail." + protocol + ".separatestoreconnection", "true");
}
void setLeaveOnServer(boolean keep) {
properties.put("mail." + protocol + ".rsetbeforequit", Boolean.toString(keep));
}
public void connect(EntityAccount account) throws MessagingException {
String password = connect(account.host, account.port, account.auth_type, account.user, account.password);
if (password != null) {

View File

@@ -712,6 +712,8 @@ public class ServiceSynchronize extends ServiceBase {
final MailService iservice = new MailService(
this, account.getProtocol(), account.realm, account.insecure, debug);
iservice.setPartialFetch(account.partial_fetch);
if (account.pop)
iservice.setLeaveOnServer(account.browse);
final Map<EntityFolder, IMAPFolder> mapFolders = new HashMap<>();
List<Thread> idlers = new ArrayList<>();