Search in sources :

Example 26 with Address

use of com.fsck.k9.mail.Address in project k-9 by k9mail.

the class ListHeadersTest method getListPostAddresses_withMailtoWithSubject_shouldReturnCorrectAddress.

@Test
public void getListPostAddresses_withMailtoWithSubject_shouldReturnCorrectAddress() throws Exception {
    for (String emailAddress : TEST_EMAIL_ADDRESSES) {
        String headerValue = "<mailto:" + emailAddress + "?subject=list%20posting>";
        Message message = buildMimeMessageWithListPostValue(headerValue);
        Address[] result = ListHeaders.getListPostAddresses(message);
        assertExtractedAddressMatchesEmail(emailAddress, result);
    }
}
Also used : Message(com.fsck.k9.mail.Message) Address(com.fsck.k9.mail.Address) Test(org.junit.Test)

Example 27 with Address

use of com.fsck.k9.mail.Address in project k-9 by k9mail.

the class MimeMessageParseTest method getRecipients_withXEnvelopeTo.

@Test
public void getRecipients_withXEnvelopeTo() throws Exception {
    MimeMessage msg = parseWithoutRecurse(toStream("From: <adam@example.org>\r\n" + "To: <eva@example.org>\r\n" + "X-Envelope-To: <test@mail.com>\r\n" + "Subject: Testmail\r\n" + "MIME-Version: 1.0\r\n" + "Content-type: text/plain\r\n" + "Content-Transfer-Encoding: 7bit\r\n" + "\r\n" + "this is some test text."));
    Address[] xEnvelopeToAddresses = msg.getRecipients(RecipientType.X_ENVELOPE_TO);
    assertEquals(1, xEnvelopeToAddresses.length);
    assertEquals(new Address("<test@mail.com>"), xEnvelopeToAddresses[0]);
}
Also used : Address(com.fsck.k9.mail.Address) Test(org.junit.Test)

Example 28 with Address

use of com.fsck.k9.mail.Address in project k-9 by k9mail.

the class PgpMessageBuilder method addAutocryptHeaderIfAvailable.

private void addAutocryptHeaderIfAvailable(long openPgpKeyId) {
    Address address = currentProcessedMimeMessage.getFrom()[0];
    byte[] keyData = autocryptOpenPgpApiInteractor.getKeyMaterialForKeyId(openPgpApi, openPgpKeyId, address.getAddress());
    if (keyData != null) {
        autocryptOperations.addAutocryptHeaderToMessage(currentProcessedMimeMessage, keyData, address.getAddress(), cryptoStatus.isSenderPreferEncryptMutual());
    }
}
Also used : Address(com.fsck.k9.mail.Address)

Example 29 with Address

use of com.fsck.k9.mail.Address in project k-9 by k9mail.

the class MessageViewInfoExtractor method addMessageHeaderText.

/**
 * Extract important header values from a message to display inline (plain text version).
 *
 * @param text
 *         The {@link StringBuilder} that will receive the (plain text) output.
 * @param message
 *         The message to extract the header values from.
 *
 * @throws com.fsck.k9.mail.MessagingException
 *          In case of an error.
 */
private void addMessageHeaderText(StringBuilder text, Message message) throws MessagingException {
    // From: <sender>
    Address[] from = message.getFrom();
    if (from != null && from.length > 0) {
        text.append(resourceProvider.messageHeaderFrom());
        text.append(' ');
        text.append(Address.toString(from));
        text.append("\r\n");
    }
    // To: <recipients>
    Address[] to = message.getRecipients(Message.RecipientType.TO);
    if (to != null && to.length > 0) {
        text.append(resourceProvider.messageHeaderTo());
        text.append(' ');
        text.append(Address.toString(to));
        text.append("\r\n");
    }
    // Cc: <recipients>
    Address[] cc = message.getRecipients(Message.RecipientType.CC);
    if (cc != null && cc.length > 0) {
        text.append(resourceProvider.messageHeaderCc());
        text.append(' ');
        text.append(Address.toString(cc));
        text.append("\r\n");
    }
    // Date: <date>
    Date date = message.getSentDate();
    if (date != null) {
        text.append(resourceProvider.messageHeaderDate());
        text.append(' ');
        text.append(date.toString());
        text.append("\r\n");
    }
    // Subject: <subject>
    String subject = message.getSubject();
    text.append(resourceProvider.messageHeaderSubject());
    text.append(' ');
    if (subject == null) {
        text.append(resourceProvider.noSubject());
    } else {
        text.append(subject);
    }
    text.append("\r\n\r\n");
}
Also used : Address(com.fsck.k9.mail.Address) Date(java.util.Date)

Example 30 with Address

use of com.fsck.k9.mail.Address in project k-9 by k9mail.

the class LocalMessage method populateFromGetMessageCursor.

void populateFromGetMessageCursor(Cursor cursor) throws MessagingException {
    final String subject = cursor.getString(LocalStore.MSG_INDEX_SUBJECT);
    this.setSubject(subject == null ? "" : subject);
    Address[] from = Address.unpack(cursor.getString(LocalStore.MSG_INDEX_SENDER_LIST));
    if (from.length > 0) {
        this.setFrom(from[0]);
    }
    this.setInternalSentDate(new Date(cursor.getLong(LocalStore.MSG_INDEX_DATE)));
    this.setUid(cursor.getString(LocalStore.MSG_INDEX_UID));
    String flagList = cursor.getString(LocalStore.MSG_INDEX_FLAGS);
    if (flagList != null && flagList.length() > 0) {
        String[] flags = flagList.split(",");
        for (String flag : flags) {
            try {
                this.setFlagInternal(Flag.valueOf(flag), true);
            } catch (Exception e) {
                if (!"X_BAD_FLAG".equals(flag)) {
                    Timber.w("Unable to parse flag %s", flag);
                }
            }
        }
    }
    this.databaseId = cursor.getLong(LocalStore.MSG_INDEX_ID);
    mTo = getAddressesOrNull(Address.unpack(cursor.getString(LocalStore.MSG_INDEX_TO)));
    mCc = getAddressesOrNull(Address.unpack(cursor.getString(LocalStore.MSG_INDEX_CC)));
    mBcc = getAddressesOrNull(Address.unpack(cursor.getString(LocalStore.MSG_INDEX_BCC)));
    headerNeedsUpdating = true;
    this.setReplyTo(Address.unpack(cursor.getString(LocalStore.MSG_INDEX_REPLY_TO)));
    this.attachmentCount = cursor.getInt(LocalStore.MSG_INDEX_ATTACHMENT_COUNT);
    this.setInternalDate(new Date(cursor.getLong(LocalStore.MSG_INDEX_INTERNAL_DATE)));
    this.setMessageId(cursor.getString(LocalStore.MSG_INDEX_MESSAGE_ID_HEADER));
    String previewTypeString = cursor.getString(LocalStore.MSG_INDEX_PREVIEW_TYPE);
    DatabasePreviewType databasePreviewType = DatabasePreviewType.fromDatabaseValue(previewTypeString);
    previewType = databasePreviewType.getPreviewType();
    if (previewType == PreviewType.TEXT) {
        preview = cursor.getString(LocalStore.MSG_INDEX_PREVIEW);
    } else {
        preview = "";
    }
    if (this.mFolder == null) {
        LocalFolder f = new LocalFolder(this.localStore, cursor.getInt(LocalStore.MSG_INDEX_FOLDER_ID));
        f.open();
        this.mFolder = f;
    }
    threadId = (cursor.isNull(LocalStore.MSG_INDEX_THREAD_ID)) ? -1 : cursor.getLong(LocalStore.MSG_INDEX_THREAD_ID);
    rootId = (cursor.isNull(LocalStore.MSG_INDEX_THREAD_ROOT_ID)) ? -1 : cursor.getLong(LocalStore.MSG_INDEX_THREAD_ROOT_ID);
    boolean deleted = (cursor.getInt(LocalStore.MSG_INDEX_FLAG_DELETED) == 1);
    boolean read = (cursor.getInt(LocalStore.MSG_INDEX_FLAG_READ) == 1);
    boolean flagged = (cursor.getInt(LocalStore.MSG_INDEX_FLAG_FLAGGED) == 1);
    boolean answered = (cursor.getInt(LocalStore.MSG_INDEX_FLAG_ANSWERED) == 1);
    boolean forwarded = (cursor.getInt(LocalStore.MSG_INDEX_FLAG_FORWARDED) == 1);
    setFlagInternal(Flag.DELETED, deleted);
    setFlagInternal(Flag.SEEN, read);
    setFlagInternal(Flag.FLAGGED, flagged);
    setFlagInternal(Flag.ANSWERED, answered);
    setFlagInternal(Flag.FORWARDED, forwarded);
    setMessagePartId(cursor.getLong(LocalStore.MSG_INDEX_MESSAGE_PART_ID));
    MimeType mimeType = MimeType.parseOrNull(cursor.getString(LocalStore.MSG_INDEX_MIME_TYPE));
    this.mimeType = mimeType != null ? mimeType.toString() : DEFAULT_MIME_TYPE;
    byte[] header = cursor.getBlob(LocalStore.MSG_INDEX_HEADER_DATA);
    if (header != null) {
        MessageHeaderParser.parse(new ByteArrayInputStream(header), this::addRawHeader);
    } else {
        Timber.d("No headers available for this message!");
    }
    headerNeedsUpdating = false;
}
Also used : Address(com.fsck.k9.mail.Address) ByteArrayInputStream(java.io.ByteArrayInputStream) Date(java.util.Date) IOException(java.io.IOException) MessagingException(com.fsck.k9.mail.MessagingException) MimeType(com.fsck.k9.mail.MimeType)

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