use of com.fsck.k9.mail.Address in project k-9 by k9mail.
the class MessageCryptoHelper method getDecryptionIntent.
@NonNull
private Intent getDecryptionIntent() {
Intent decryptIntent = new Intent(OpenPgpApi.ACTION_DECRYPT_VERIFY);
Address[] from = currentMessage.getFrom();
if (from.length > 0) {
decryptIntent.putExtra(OpenPgpApi.EXTRA_SENDER_ADDRESS, from[0].getAddress());
}
decryptIntent.putExtra(OpenPgpApi.EXTRA_DECRYPTION_RESULT, cachedDecryptionResult);
return decryptIntent;
}
use of com.fsck.k9.mail.Address in project sms-backup-plus by jberkel.
the class MessageGenerator method messageFromMapCallLog.
@Nullable
private Message messageFromMapCallLog(Map<String, String> msgMap) throws MessagingException {
final String address = msgMap.get(CallLog.Calls.NUMBER);
final int callType = toInt(msgMap.get(CallLog.Calls.TYPE));
if (!callLogTypes.isTypeEnabled(callType)) {
if (LOCAL_LOGV)
Log.v(TAG, "ignoring call log entry: " + msgMap);
return null;
}
PersonRecord record = personLookup.lookupPerson(address);
if (!includePersonInBackup(record, DataType.CALLLOG))
return null;
final Message msg = new MimeMessage();
msg.setSubject(getSubject(DataType.CALLLOG, record));
switch(callType) {
case CallLog.Calls.OUTGOING_TYPE:
msg.setFrom(userAddress);
msg.setRecipient(Message.RecipientType.TO, record.getAddress(addressStyle));
break;
case CallLog.Calls.MISSED_TYPE:
case CallLog.Calls.INCOMING_TYPE:
case CallLog.Calls.REJECTED_TYPE:
case CallLog.Calls.VOICEMAIL_TYPE:
msg.setFrom(record.getAddress(addressStyle));
msg.setRecipient(Message.RecipientType.TO, userAddress);
break;
default:
// some weird phones seem to have SMS in their call logs, which is
// not part of the official API.
Log.w(TAG, "ignoring unknown call type: " + callType);
return null;
}
final int duration = msgMap.get(CallLog.Calls.DURATION) == null ? 0 : toInt(msgMap.get(CallLog.Calls.DURATION));
setBody(msg, new TextBody(callFormatter.format(callType, record.getNumber(), duration)));
Date sentDate;
try {
sentDate = new Date(Long.valueOf(msgMap.get(CallLog.Calls.DATE)));
} catch (NumberFormatException n) {
Log.e(TAG, ERROR_PARSING_DATE, n);
sentDate = new Date();
}
headerGenerator.setHeaders(msg, msgMap, DataType.CALLLOG, address, record, sentDate, callType);
return msg;
}
use of com.fsck.k9.mail.Address in project sms-backup-plus by jberkel.
the class MessageConverterTest method testConvertMessagesSeenFlagFromMessageStatusWithSMS.
@Test
public void testConvertMessagesSeenFlagFromMessageStatusWithSMS() throws Exception {
MatrixCursor cursor = new MatrixCursor(new String[] { Telephony.TextBasedSmsColumns.ADDRESS, Telephony.TextBasedSmsColumns.READ });
cursor.addRow(new Object[] { "foo", "0" });
cursor.addRow(new Object[] { "foo", "1" });
cursor.moveToFirst();
PersonRecord record = mock(PersonRecord.class);
when(personLookup.lookupPerson(any(String.class))).thenReturn(record);
when(record.getAddress(any(AddressStyle.class))).thenReturn(new Address("foo"));
when(preferences.getMarkAsReadType()).thenReturn(MarkAsReadTypes.MESSAGE_STATUS);
messageConverter = new MessageConverter(RuntimeEnvironment.application, preferences, "foo@example.com", personLookup, contactAccessor);
ConversionResult res = messageConverter.convertMessages(cursor, DataType.SMS);
assertThat(res.getMessages().get(0).isSet(Flag.SEEN)).isFalse();
cursor.moveToNext();
res = messageConverter.convertMessages(cursor, DataType.SMS);
assertThat(res.getMessages().get(0).isSet(Flag.SEEN)).isTrue();
}
use of com.fsck.k9.mail.Address in project sms-backup-plus by jberkel.
the class MessageConverterTest method testConvertMessagesSeenFlagUnreadWithSMS.
@Test
public void testConvertMessagesSeenFlagUnreadWithSMS() throws Exception {
MatrixCursor cursor = new MatrixCursor(new String[] { Telephony.TextBasedSmsColumns.ADDRESS, Telephony.TextBasedSmsColumns.READ });
cursor.addRow(new Object[] { "foo", "0" });
cursor.addRow(new Object[] { "foo", "1" });
cursor.moveToFirst();
PersonRecord record = mock(PersonRecord.class);
when(personLookup.lookupPerson(any(String.class))).thenReturn(record);
when(record.getAddress(any(AddressStyle.class))).thenReturn(new Address("foo"));
when(preferences.getMarkAsReadType()).thenReturn(MarkAsReadTypes.UNREAD);
messageConverter = new MessageConverter(RuntimeEnvironment.application, preferences, "foo@example.com", personLookup, contactAccessor);
ConversionResult res = messageConverter.convertMessages(cursor, DataType.SMS);
assertThat(res.getMessages().get(0).isSet(Flag.SEEN)).isFalse();
cursor.moveToNext();
res = messageConverter.convertMessages(cursor, DataType.SMS);
assertThat(res.getMessages().get(0).isSet(Flag.SEEN)).isFalse();
}
use of com.fsck.k9.mail.Address in project sms-backup-plus by jberkel.
the class MessageGeneratorTest method testShouldGenerateMMSMessageWithCorrectEncoding.
@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 });
}
Aggregations