Repository: thundernest/k-9
Issue: NPE in k9 and empty list when querying messages from 3rd party application (Gadgetbridge)

### Expected behavior

We should get a list of messages
### Actual behavior

We get an empty list and k9 logs a NPE
`
                                                java.lang.NullPointerException: Attempt to invoke virtual method 'com.fsck.k9.Account com.fsck.k9.mailstore.LocalMessage.getAccount()' on a null object reference
                                                    at com.fsck.k9.provider.MessageProvider$MesssageInfoHolderRetrieverListener.listLocalMessagesAddMessages(MessageProvider.java:939)
                                                    at com.fsck.k9.controller.MessagingController$6.messageFinished(MessagingController.java:534)
                                                    at com.fsck.k9.controller.MessagingController$6.messageFinished(MessagingController.java:520)
                                                    at com.fsck.k9.mailstore.LocalStore$13.doDbWork(LocalStore.java:610)
                                                    at com.fsck.k9.mailstore.LocalStore$13.doDbWork(LocalStore.java:596)
                                                    at com.fsck.k9.mailstore.LockableDatabase.execute(LockableDatabase.java:275)
                                                    at com.fsck.k9.mailstore.LocalStore.getMessages(LocalStore.java:596)
                                                    at com.fsck.k9.mailstore.LocalStore.searchForMessages(LocalStore.java:583)
                                                    at com.fsck.k9.controller.MessagingController.searchLocalMessagesSynchronous(MessagingController.java:548)
                                                    at com.fsck.k9.controller.MessagingController$5.run(MessagingController.java:500)
                                                    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                    at java.lang.Thread.run(Thread.java:818)
`
### Steps to reproduce

`
try (Cursor c = context.getContentResolver().query(Uri.parse("content://com.fsck.k9.messageprovider/inbox_messages", messagesProjection, null, null, null)) {

// c.getCount() will be 0

}  
`
### Environment

K-9 Mail version: 5.113

Android version: CM13 (6.0.1)

Account type (IMAP, POP3, WebDAV/Exchange): IMAP


Changed files:
k9mail/src/main/java/com/fsck/k9/provider/MessageProvider.java

diff --git a/k9mail/src/main/java/com/fsck/k9/provider/MessageProvider.java b/k9mail/src/main/java/com/fsck/k9/provider/MessageProvider.java
index 760dc0660..20e2e3e3c 100644
--- a/k9mail/src/main/java/com/fsck/k9/provider/MessageProvider.java
+++ b/k9mail/src/main/java/com/fsck/k9/provider/MessageProvider.java
@@ -935,8 +935,8 @@ public class MessageProvider extends ContentProvider {
             for (final LocalMessage message : messages) {
                 final MessageInfoHolder messageInfoHolder = new MessageInfoHolder();
                 final LocalFolder messageFolder = message.getFolder();
+                final Account messageAccount = message.getAccount();
 
-                final Account messageAccount = messageInfoHolder.message.getAccount();
                 helper.populate(messageInfoHolder, message, new FolderInfoHolder(context,
                                 messageFolder, messageAccount), messageAccount);