Scrub recipients for MMS messages so they'll be valid PLMN.

This commit is contained in:
Moxie Marlinspike 2013-03-14 15:59:28 -07:00
parent 0a769da9de
commit 5df88cc0a7
2 changed files with 12 additions and 4 deletions

View File

@ -19,6 +19,7 @@ package org.thoughtcrime.securesms.recipients;
import android.content.Context; import android.content.Context;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.util.Patterns;
import org.thoughtcrime.securesms.crypto.KeyUtil; import org.thoughtcrime.securesms.crypto.KeyUtil;
import org.thoughtcrime.securesms.recipients.Recipient.RecipientModifiedListener; import org.thoughtcrime.securesms.recipients.Recipient.RecipientModifiedListener;
@ -133,13 +134,20 @@ public class Recipients implements Parcelable {
return this.recipients; return this.recipients;
} }
public String[] toNumberStringArray() { public String[] toNumberStringArray(boolean scrub) {
String[] recipientsArray = new String[recipients.size()]; String[] recipientsArray = new String[recipients.size()];
Iterator<Recipient> iterator = recipients.iterator(); Iterator<Recipient> iterator = recipients.iterator();
int i = 0; int i = 0;
while (iterator.hasNext()) while (iterator.hasNext()) {
recipientsArray[i++] = iterator.next().getNumber(); String number = iterator.next().getNumber();
if (scrub && number != null && !Patterns.EMAIL_ADDRESS.matcher(number).matches()) {
number = number.replaceAll("[^0-9+]", "");
}
recipientsArray[i++] = number;
}
return recipientsArray; return recipientsArray;
} }

View File

@ -110,7 +110,7 @@ public class MessageSender {
SendReq sendRequest, long threadId, boolean secure) SendReq sendRequest, long threadId, boolean secure)
throws MmsException throws MmsException
{ {
String[] recipientsArray = recipients.toNumberStringArray(); String[] recipientsArray = recipients.toNumberStringArray(true);
EncodedStringValue[] encodedNumbers = EncodedStringValue.encodeStrings(recipientsArray); EncodedStringValue[] encodedNumbers = EncodedStringValue.encodeStrings(recipientsArray);
sendRequest.setTo(encodedNumbers); sendRequest.setTo(encodedNumbers);