Search in sources :

Example 51 with Address

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;
}
Also used : Address(com.fsck.k9.mail.Address) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) NonNull(android.support.annotation.NonNull)

Example 52 with Address

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;
}
Also used : TextBody(com.fsck.k9.mail.internet.TextBody) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Date(java.util.Date) Nullable(android.support.annotation.Nullable)

Example 53 with Address

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();
}
Also used : Address(com.fsck.k9.mail.Address) MatrixCursor(android.database.MatrixCursor) AddressStyle(com.zegoggles.smssync.preferences.AddressStyle) Test(org.junit.Test)

Example 54 with Address

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();
}
Also used : Address(com.fsck.k9.mail.Address) MatrixCursor(android.database.MatrixCursor) AddressStyle(com.zegoggles.smssync.preferences.AddressStyle) Test(org.junit.Test)

Example 55 with Address

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 });
}
Also used : Address(com.fsck.k9.mail.Address) Message(com.fsck.k9.mail.Message) Uri(android.net.Uri) AddressStyle(com.zegoggles.smssync.preferences.AddressStyle) Test(org.junit.Test)

Aggregations

Address (com.fsck.k9.mail.Address)72 Test (org.junit.Test)40 Uri (android.net.Uri)13 RobolectricTest (com.fsck.k9.RobolectricTest)12 Message (com.fsck.k9.mail.Message)10 Date (java.util.Date)8 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)7 ArrayList (java.util.ArrayList)7 MessagingException (com.fsck.k9.mail.MessagingException)6 Contacts (com.fsck.k9.helper.Contacts)5 Recipient (com.fsck.k9.view.RecipientSelectView.Recipient)5 AddressStyle (com.zegoggles.smssync.preferences.AddressStyle)5 IOException (java.io.IOException)5 Intent (android.content.Intent)4 Cursor (android.database.Cursor)4 MatrixCursor (android.database.MatrixCursor)4 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)4 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)4 TextBody (com.fsck.k9.mail.internet.TextBody)4 SpannableString (android.text.SpannableString)3