Prevent crash

This commit is contained in:
M66B 2020-05-28 08:15:55 +02:00
parent e3413d4c69
commit 9db851be98
1 changed files with 42 additions and 29 deletions

View File

@ -4190,45 +4190,58 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
String thread = args.getString("thread");
long id = args.getLong("id");
DB db = DB.getInstance(context);
EntityAccount account = db.account().getAccount(aid);
if (account != null && account.color != null)
args.putInt("color", account.color);
EntityFolder trash = db.folder().getFolderByType(aid, EntityFolder.TRASH);
EntityFolder archive = db.folder().getFolderByType(aid, EntityFolder.ARCHIVE);
List<EntityMessage> messages = db.message().getMessagesByThread(
aid, thread, threading ? null : id, null);
EntityAccount account;
EntityFolder trash;
EntityFolder archive;
boolean trashable = false;
boolean snoozable = false;
boolean archivable = false;
for (EntityMessage message : messages) {
EntityFolder folder = db.folder().getFolder(message.folder);
if (!folder.read_only &&
!EntityFolder.DRAFTS.equals(folder.type) &&
!EntityFolder.OUTBOX.equals(folder.type) &&
// allow sent
!EntityFolder.TRASH.equals(folder.type) &&
!EntityFolder.JUNK.equals(folder.type))
trashable = true;
DB db = DB.getInstance(context);
try {
db.beginTransaction();
if (!EntityFolder.OUTBOX.equals(folder.type))
snoozable = true;
account = db.account().getAccount(aid);
if (account != null && account.color != null)
args.putInt("color", account.color);
if (!folder.read_only &&
!EntityFolder.isOutgoing(folder.type) &&
!EntityFolder.TRASH.equals(folder.type) &&
!EntityFolder.JUNK.equals(folder.type) &&
!EntityFolder.ARCHIVE.equals(folder.type))
archivable = true;
trash = db.folder().getFolderByType(aid, EntityFolder.TRASH);
archive = db.folder().getFolderByType(aid, EntityFolder.ARCHIVE);
List<EntityMessage> messages = db.message().getMessagesByThread(
aid, thread, threading ? null : id, null);
for (EntityMessage message : messages) {
EntityFolder folder = db.folder().getFolder(message.folder);
if (!folder.read_only &&
!EntityFolder.DRAFTS.equals(folder.type) &&
!EntityFolder.OUTBOX.equals(folder.type) &&
// allow sent
!EntityFolder.TRASH.equals(folder.type) &&
!EntityFolder.JUNK.equals(folder.type))
trashable = true;
if (!EntityFolder.OUTBOX.equals(folder.type))
snoozable = true;
if (!folder.read_only &&
!EntityFolder.isOutgoing(folder.type) &&
!EntityFolder.TRASH.equals(folder.type) &&
!EntityFolder.JUNK.equals(folder.type) &&
!EntityFolder.ARCHIVE.equals(folder.type))
archivable = true;
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return new Boolean[]{
trash == null || account.protocol == EntityAccount.TYPE_POP,
trash == null ||
(account != null && account.protocol == EntityAccount.TYPE_POP),
trashable,
snoozable,
archivable && archive != null};