public OutgoingMediaMessage getOutgoingMessage(MasterSecret masterSecret, long messageId) throws MmsException, NoSuchMessageException { MmsAddressDatabase addr = DatabaseFactory.getMmsAddressDatabase(context); AttachmentDatabase attachmentDatabase = DatabaseFactory.getAttachmentDatabase(context); Cursor cursor = null; try { cursor = rawQuery(RAW_ID_WHERE, new String[] {String.valueOf(messageId)}); if (cursor != null && cursor.moveToNext()) { long outboxType = cursor.getLong(cursor.getColumnIndexOrThrow(MESSAGE_BOX)); String messageText = cursor.getString(cursor.getColumnIndexOrThrow(BODY)); long timestamp = cursor.getLong(cursor.getColumnIndexOrThrow(NORMALIZED_DATE_SENT)); List<Attachment> attachments = new LinkedList<Attachment>(attachmentDatabase.getAttachmentsForMessage(messageId)); MmsAddresses addresses = addr.getAddressesForId(messageId); List<String> destinations = new LinkedList<>(); String body = getDecryptedBody(masterSecret, messageText, outboxType); destinations.addAll(addresses.getBcc()); destinations.addAll(addresses.getCc()); destinations.addAll(addresses.getTo()); Recipients recipients = RecipientFactory.getRecipientsFromStrings(context, destinations, false); if (body != null && (Types.isGroupQuit(outboxType) || Types.isGroupUpdate(outboxType))) { return new OutgoingGroupMediaMessage(recipients, body, attachments, timestamp); } OutgoingMediaMessage message = new OutgoingMediaMessage( recipients, body, attachments, timestamp, !addresses.getBcc().isEmpty() ? ThreadDatabase.DistributionTypes.BROADCAST : ThreadDatabase.DistributionTypes.DEFAULT); if (Types.isSecureType(outboxType)) { return new OutgoingSecureMediaMessage(message); } return message; } throw new NoSuchMessageException("No record found for id: " + messageId); } catch (IOException e) { throw new MmsException(e); } finally { if (cursor != null) cursor.close(); } }