private long getThreadIdFor(IncomingMediaMessage retrieved) throws RecipientFormattingException, MmsException { if (retrieved.getGroupId() != null) { Recipients groupRecipients = RecipientFactory.getRecipientsFromString(context, retrieved.getGroupId(), true); return DatabaseFactory.getThreadDatabase(context).getThreadIdFor(groupRecipients); } String localNumber; Set<String> group = new HashSet<>(); if (retrieved.getAddresses().getFrom() == null) { throw new MmsException("FROM value in PduHeaders did not exist."); } group.add(retrieved.getAddresses().getFrom()); if (TextSecurePreferences.isPushRegistered(context)) { localNumber = TextSecurePreferences.getLocalNumber(context); } else { localNumber = ServiceUtil.getTelephonyManager(context).getLine1Number(); } for (String cc : retrieved.getAddresses().getCc()) { PhoneNumberUtil.MatchType match; if (localNumber == null) match = PhoneNumberUtil.MatchType.NO_MATCH; else match = PhoneNumberUtil.getInstance().isNumberMatch(localNumber, cc); if (match == PhoneNumberUtil.MatchType.NO_MATCH || match == PhoneNumberUtil.MatchType.NOT_A_NUMBER) { group.add(cc); } } if (retrieved.getAddresses().getTo().size() > 1) { for (String to : retrieved.getAddresses().getTo()) { PhoneNumberUtil.MatchType match; if (localNumber == null) match = PhoneNumberUtil.MatchType.NO_MATCH; else match = PhoneNumberUtil.getInstance().isNumberMatch(localNumber, to); if (match == PhoneNumberUtil.MatchType.NO_MATCH || match == PhoneNumberUtil.MatchType.NOT_A_NUMBER) { group.add(to); } } } String recipientsList = Util.join(group, ","); Recipients recipients = RecipientFactory.getRecipientsFromString(context, recipientsList, false); return DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients); }
private Pair<Long, Long> insertMessageInbox( MasterSecretUnion masterSecret, IncomingMediaMessage retrieved, String contentLocation, long threadId, long mailbox) throws MmsException { if (threadId == -1 || retrieved.isGroupMessage()) { try { threadId = getThreadIdFor(retrieved); } catch (RecipientFormattingException e) { Log.w("MmsDatabase", e); if (threadId == -1) throw new MmsException(e); } } ContentValues contentValues = new ContentValues(); contentValues.put(DATE_SENT, retrieved.getSentTimeMillis()); contentValues.put(ADDRESS, retrieved.getAddresses().getFrom()); contentValues.put(MESSAGE_BOX, mailbox); contentValues.put(MESSAGE_TYPE, PduHeaders.MESSAGE_TYPE_RETRIEVE_CONF); contentValues.put(THREAD_ID, threadId); contentValues.put(CONTENT_LOCATION, contentLocation); contentValues.put(STATUS, Status.DOWNLOAD_INITIALIZED); contentValues.put(DATE_RECEIVED, generatePduCompatTimestamp()); contentValues.put(PART_COUNT, retrieved.getAttachments().size()); contentValues.put(READ, 0); if (!contentValues.containsKey(DATE_SENT)) { contentValues.put(DATE_SENT, contentValues.getAsLong(DATE_RECEIVED)); } long messageId = insertMediaMessage( masterSecret, retrieved.getAddresses(), retrieved.getBody(), retrieved.getAttachments(), contentValues); DatabaseFactory.getThreadDatabase(context).setUnread(threadId); DatabaseFactory.getThreadDatabase(context).update(threadId); notifyConversationListeners(threadId); jobManager.add(new TrimThreadJob(context, threadId)); return new Pair<>(messageId, threadId); }
public Pair<Long, Long> insertSecureDecryptedMessageInbox( MasterSecretUnion masterSecret, IncomingMediaMessage retrieved, long threadId) throws MmsException { long type = Types.BASE_INBOX_TYPE | Types.SECURE_MESSAGE_BIT; if (masterSecret.getMasterSecret().isPresent()) { type |= Types.ENCRYPTION_SYMMETRIC_BIT; } else { type |= Types.ENCRYPTION_ASYMMETRIC_BIT; } if (retrieved.isPushMessage()) { type |= Types.PUSH_MESSAGE_BIT; } return insertMessageInbox(masterSecret, retrieved, "", threadId, type); }