Added POP3 option to leave messages on server

pull/162/head
M66B 5 years ago
parent 8e245517f3
commit 13997a0848

File diff suppressed because it is too large Load Diff

@ -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);

@ -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();
}

@ -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;

@ -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);

@ -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) {

@ -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<>();

@ -248,7 +248,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvColorHint" />
<CheckBox
android:id="@+id/cbSynchronize"
android:layout_width="wrap_content"
@ -267,6 +266,15 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbSynchronize" />
<CheckBox
android:id="@+id/cbLeave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_leave_on_server"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbPrimary" />
<!-- keep alive -->
<TextView
@ -277,7 +285,7 @@
android:text="@string/title_keep_alive_interval"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbPrimary" />
app:layout_constraintTop_toBottomOf="@id/cbLeave" />
<EditText
android:id="@+id/etInterval"

@ -393,6 +393,7 @@
<string name="title_use_ip">Use local IP address instead of host name</string>
<string name="title_primary_account">Primary (default account)</string>
<string name="title_primary_identity">Primary (default identity)</string>
<string name="title_leave_on_server">Leave messages on server</string>
<string name="title_keep_alive_interval">Keep-alive/poll interval (minutes)</string>
<string name="title_partial_fetch" translatable="false">Partial fetch</string>
<string name="title_check">Check</string>

Loading…
Cancel
Save