public MmsDetails getDetails(Uri mmsUri, AddressStyle style) { Cursor cursor = resolver.query(Uri.withAppendedPath(mmsUri, "addr"), null, null, null, null); // TODO: this is probably not the best way to determine if a message is inbound or outbound boolean inbound = true; final List<String> recipients = new ArrayList<String>(); while (cursor != null && cursor.moveToNext()) { final String address = cursor.getString(cursor.getColumnIndex("address")); //final int type = addresses.getInt(addresses.getColumnIndex("type")); if (MmsConsts.INSERT_ADDRESS_TOKEN.equals(address)) { inbound = false; } else { recipients.add(address); } } if (cursor != null) cursor.close(); List<PersonRecord> records = new ArrayList<PersonRecord>(recipients.size()); List<Address> addresses = new ArrayList<Address>(recipients.size()); if (!recipients.isEmpty()) { for (String s : recipients) { PersonRecord record = personLookup.lookupPerson(s); records.add(record); addresses.add(record.getAddress(style)); } } return new MmsDetails(inbound, recipients, records, addresses); }
@Test public void testShouldGenerateSubjectWithNameForMMS() throws Exception { PersonRecord personRecord = new PersonRecord(1, "Foo Bar", "foo@bar.com", "1234"); MmsSupport.MmsDetails details = new MmsSupport.MmsDetails(true, "foo", personRecord, new Address("foo@bar.com")); when(mmsSupport.getDetails(any(Uri.class), any(AddressStyle.class))).thenReturn(details); Message msg = generator.messageForDataType(mockMessage("1234", personRecord), DataType.MMS); assertThat(msg).isNotNull(); assertThat(msg.getSubject()).isEqualTo("SMS with Foo Bar"); }
@Test public void testShouldGenerateMMSMessageWithCorrectEncoding() throws Exception { PersonRecord personRecord = new PersonRecord(1, "Foo Bar", "foo@bar.com", "1234"); MmsSupport.MmsDetails details = new MmsSupport.MmsDetails(true, "foo", personRecord, new Address("foo@bar.com")); when(mmsSupport.getDetails(any(Uri.class), any(AddressStyle.class))).thenReturn(details); Message msg = generator.messageForDataType(mockMessage("1234", personRecord), DataType.MMS); assertThat(msg.getHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING)).isEqualTo(new String[] { MimeUtil.ENC_7BIT }); }