Allow unlabeling self

pull/182/head
M66B 5 years ago
parent 154ded7b5d
commit 908d992fa9

@ -3601,13 +3601,12 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", message.id); args.putLong("id", message.id);
args.putLong("account", message.account); args.putLong("account", message.account);
args.putString("exclude", message.folderName); args.putString("self", message.folderName);
new SimpleTask<String[]>() { new SimpleTask<String[]>() {
@Override @Override
protected String[] onExecute(Context context, Bundle args) { protected String[] onExecute(Context context, Bundle args) {
long account = args.getLong("account"); long account = args.getLong("account");
String exclude = args.getString("exclude");
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
List<EntityFolder> folders = db.folder().getFolders(account, true, true); List<EntityFolder> folders = db.folder().getFolders(account, true, true);
@ -3615,7 +3614,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();
if (folders != null) if (folders != null)
for (EntityFolder folder : folders) for (EntityFolder folder : folders)
if (EntityFolder.USER.equals(folder.type) && !exclude.equals(folder.name)) if (EntityFolder.USER.equals(folder.type))
result.add(folder.name); result.add(folder.name);
Collator collator = Collator.getInstance(Locale.getDefault()); Collator collator = Collator.getInstance(Locale.getDefault());
@ -6209,10 +6208,13 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
@Override @Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
final long id = getArguments().getLong("id"); final long id = getArguments().getLong("id");
String self = getArguments().getString("self");
String[] labels = getArguments().getStringArray("labels"); String[] labels = getArguments().getStringArray("labels");
final String[] folders = getArguments().getStringArray("folders"); final String[] folders = getArguments().getStringArray("folders");
List<String> l = new ArrayList<>(); List<String> l = new ArrayList<>();
if (self != null)
l.add(self);
if (labels != null) if (labels != null)
l.addAll(Arrays.asList(labels)); l.addAll(Arrays.asList(labels));

@ -695,10 +695,39 @@ class Core {
private static void onLabel(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, IMAPStore istore, IMAPFolder ifolder, State state) throws JSONException, MessagingException, IOException { private static void onLabel(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, IMAPStore istore, IMAPFolder ifolder, State state) throws JSONException, MessagingException, IOException {
// Set/clear Gmail label // Set/clear Gmail label
// Gmail does not push label changes
String label = jargs.getString(0); String label = jargs.getString(0);
boolean set = jargs.getBoolean(1); boolean set = jargs.getBoolean(1);
// Gmail does not push label changes DB db = DB.getInstance(context);
if (!set && label.equals(folder.name)) {
// Prevent deleting message
EntityFolder archive = db.folder().getFolderByType(message.account, EntityFolder.ARCHIVE);
if (archive == null)
throw new IllegalArgumentException("label/archive");
Message[] imessages;
Folder iarchive = istore.getFolder(archive.name);
try {
iarchive.open(Folder.READ_ONLY);
imessages = ifolder.search(new MessageIDTerm(message.msgid));
} finally {
if (iarchive.isOpen())
iarchive.close();
}
if (imessages != null && imessages.length > 0)
try {
Message imessage = ifolder.getMessageByUID(message.uid);
imessage.setFlag(Flags.Flag.DELETED, true);
ifolder.expunge();
} catch (MessagingException ex) {
Log.w(ex);
}
else
throw new IllegalArgumentException("label/delete");
} else {
try { try {
Message imessage = ifolder.getMessageByUID(message.uid); Message imessage = ifolder.getMessageByUID(message.uid);
if (imessage instanceof GmailMessage) if (imessage instanceof GmailMessage)
@ -706,8 +735,8 @@ class Core {
} catch (MessagingException ex) { } catch (MessagingException ex) {
Log.w(ex); Log.w(ex);
} }
}
DB db = DB.getInstance(context);
try { try {
db.beginTransaction(); db.beginTransaction();

Loading…
Cancel
Save