Set flags with UID command

pull/194/merge
M66B 3 years ago
parent fb26698e5a
commit 86d655c98e

@ -866,6 +866,9 @@ class Core {
// Mark message (un)seen
DB db = DB.getInstance(context);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean uid_command = prefs.getBoolean("uid_command", false);
if (flag != Flags.Flag.SEEN && flag != Flags.Flag.FLAGGED)
throw new IllegalArgumentException("Invalid flag=" + flag);
@ -901,15 +904,38 @@ class Core {
if (uids.size() == 0)
return;
Message[] imessages = ifolder.getMessagesByUID(Helper.toLongArray(uids));
for (Message imessage : imessages)
if (imessage == null)
if (messages.size() == 1)
throw new MessageRemovedException();
else
throw new MessagingException("Set flag: message missing");
if (uid_command) {
String flags;
if (flag == Flags.Flag.SEEN)
flags = "\\Seen";
else if (flag == Flags.Flag.FLAGGED)
flags = "\\Flagged";
else
throw new IllegalArgumentException("Unknown flag=" + flag);
ifolder.doCommand(new IMAPFolder.ProtocolCommand() {
@Override
public Object doCommand(IMAPProtocol protocol) throws ProtocolException {
for (long uid : uids) {
Response[] r = protocol.command(
"UID STORE " + uid + (set ? " +" : " -") + "FLAGS " + flags, null);
protocol.notifyResponseHandlers(r);
protocol.handleResult(r[r.length - 1]);
}
return null;
}
});
} else {
Message[] imessages = ifolder.getMessagesByUID(Helper.toLongArray(uids));
for (Message imessage : imessages)
if (imessage == null)
if (messages.size() == 1)
throw new MessageRemovedException();
else
throw new MessagingException("Set flag: message missing");
ifolder.setFlags(imessages, new Flags(flag), set);
ifolder.setFlags(imessages, new Flags(flag), set);
}
for (EntityMessage message : messages)
if (flag == Flags.Flag.SEEN && !message.seen.equals(set))

@ -146,6 +146,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private SwitchCompat swUndoManager;
private SwitchCompat swWebViewLegacy;
private SwitchCompat swModSeq;
private SwitchCompat swUid;
private SwitchCompat swExpunge;
private SwitchCompat swUidExpunge;
private SwitchCompat swAuthPlain;
@ -190,7 +191,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
"protocol", "debug", "log_level", "test1", "test2", "test3", "test4", "test5",
"query_threads", "wal", "checkpoints", "sqlite_cache",
"chunk_size", "undo_manager", "webview_legacy",
"use_modseq", "perform_expunge", "uid_expunge",
"use_modseq", "uid_command", "perform_expunge", "uid_expunge",
"auth_plain", "auth_login", "auth_ntlm", "auth_sasl",
"keep_alive_poll", "empty_pool", "idle_done",
"exact_alarms", "infra", "dup_msgids", "test_iab"
@ -291,6 +292,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swUndoManager = view.findViewById(R.id.swUndoManager);
swWebViewLegacy = view.findViewById(R.id.swWebViewLegacy);
swModSeq = view.findViewById(R.id.swModSeq);
swUid = view.findViewById(R.id.swUid);
swExpunge = view.findViewById(R.id.swExpunge);
swUidExpunge = view.findViewById(R.id.swUidExpunge);
swAuthPlain = view.findViewById(R.id.swAuthPlain);
@ -891,6 +893,13 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
}
});
swUid.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("uid_command", checked).apply();
}
});
swExpunge.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -1439,6 +1448,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swUndoManager.setChecked(prefs.getBoolean("undo_manager", false));
swWebViewLegacy.setChecked(prefs.getBoolean("webview_legacy", false));
swModSeq.setChecked(prefs.getBoolean("use_modseq", true));
swUid.setChecked(prefs.getBoolean("uid_command", false));
swExpunge.setChecked(prefs.getBoolean("perform_expunge", true));
swUidExpunge.setChecked(prefs.getBoolean("uid_expunge", false));
swUidExpunge.setEnabled(swExpunge.isChecked());

@ -871,6 +871,17 @@
app:layout_constraintTop_toBottomOf="@id/swWebViewLegacy"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swUid"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_uid"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swModSeq"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swExpunge"
android:layout_width="0dp"
@ -880,7 +891,7 @@
android:text="@string/title_advanced_expunge"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swModSeq"
app:layout_constraintTop_toBottomOf="@id/swUid"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat

@ -692,6 +692,7 @@
<string name="title_advanced_undo_manager" translatable="false">Use Android\'s undo manager</string>
<string name="title_advanced_webview_legacy" translatable="false">Old WebView behavior</string>
<string name="title_advanced_modseq" translatable="false">MODSEQ</string>
<string name="title_advanced_uid" translatable="false">UID command</string>
<string name="title_advanced_expunge" translatable="false">AUTO EXPUNGE</string>
<string name="title_advanced_uid_expunge" translatable="false">UID EXPUNGE</string>
<string name="title_advanced_hide_deleted" translatable="false">Hide deleted messages</string>

Loading…
Cancel
Save