Prevent NPE

Email's code can create a notification if the email message hasn't
finished syncing, and the message cursor will not be populated.

Bug: 8361360
Change-Id: I0511a2e7f099c53079cb1e61427387cbda5982e4
diff --git a/src/com/android/mail/utils/NotificationUtils.java b/src/com/android/mail/utils/NotificationUtils.java
index 7ad83d1..2f72e44 100644
--- a/src/com/android/mail/utils/NotificationUtils.java
+++ b/src/com/android/mail/utils/NotificationUtils.java
@@ -836,19 +836,26 @@
                             new NotificationCompat.BigTextStyle(notification);
 
                     // Seek the message cursor to the first unread message
-                    messageCursor.moveToPosition(firstUnseenMessagePos);
-                    final Message message = messageCursor.getMessage();
-                    bigText.bigText(getSingleMessageBigText(context,
-                            conversation.subject, message));
+                    final Message message;
+                    if (messageCursor.moveToPosition(firstUnseenMessagePos)) {
+                        message = messageCursor.getMessage();
+                        bigText.bigText(getSingleMessageBigText(context,
+                                conversation.subject, message));
+                    } else {
+                        LogUtils.e(LOG_TAG, "Failed to load message");
+                        message = null;
+                    }
 
-                    final Set<String> notificationActions =
-                            folderPreferences.getNotificationActions();
+                    if (message != null) {
+                        final Set<String> notificationActions =
+                                folderPreferences.getNotificationActions();
 
-                    final int notificationId = getNotificationId(notificationAccount, folder);
+                        final int notificationId = getNotificationId(notificationAccount, folder);
 
-                    NotificationActionUtils.addNotificationActions(context, notificationIntent,
-                            notification, account, conversation, message, folder,
-                            notificationId, when, notificationActions);
+                        NotificationActionUtils.addNotificationActions(context, notificationIntent,
+                                notification, account, conversation, message, folder,
+                                notificationId, when, notificationActions);
+                    }
                 } else {
                     // For an old-style notification