Search in sources :

Example 1 with Address

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

the class MessageHeaderTest method createMessage.

private Message createMessage(Address from, Address sender) {
    Message message = new MimeMessage();
    message.setFrom(from);
    message.setSender(sender);
    return message;
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) MimeMessage(com.fsck.k9.mail.internet.MimeMessage)

Example 2 with Address

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

the class MessagingController method addErrorMessage.

private void addErrorMessage(Account account, String subject, String body) {
    if (!K9.isDebug()) {
        return;
    }
    if (!loopCatch.compareAndSet(false, true)) {
        return;
    }
    try {
        if (body == null || body.length() < 1) {
            return;
        }
        Store localStore = account.getLocalStore();
        LocalFolder localFolder = (LocalFolder) localStore.getFolder(account.getErrorFolderName());
        MimeMessage message = new MimeMessage();
        MimeMessageHelper.setBody(message, new TextBody(body));
        message.setFlag(Flag.X_DOWNLOADED_FULL, true);
        message.setSubject(subject);
        long nowTime = System.currentTimeMillis();
        Date nowDate = new Date(nowTime);
        message.setInternalDate(nowDate);
        message.addSentDate(nowDate, K9.hideTimeZone());
        message.setFrom(new Address(account.getEmail(), "K9mail internal"));
        localFolder.appendMessages(Collections.singletonList(message));
        localFolder.clearMessagesOlderThan(nowTime - (15 * 60 * 1000));
    } catch (Throwable it) {
        Timber.e(it, "Could not save error message to %s", account.getErrorFolderName());
    } finally {
        loopCatch.set(false);
    }
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) TextBody(com.fsck.k9.mail.internet.TextBody) Address(com.fsck.k9.mail.Address) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) LocalStore(com.fsck.k9.mailstore.LocalStore) Store(com.fsck.k9.mail.Store) Pop3Store(com.fsck.k9.mail.store.pop3.Pop3Store) Date(java.util.Date)

Example 3 with Address

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

the class MessageListAdapter method bindView.

@Override
public void bindView(View view, Context context, Cursor cursor) {
    Account account = fragment.getAccountFromCursor(cursor);
    String fromList = cursor.getString(SENDER_LIST_COLUMN);
    String toList = cursor.getString(TO_LIST_COLUMN);
    String ccList = cursor.getString(CC_LIST_COLUMN);
    Address[] fromAddrs = Address.unpack(fromList);
    Address[] toAddrs = Address.unpack(toList);
    Address[] ccAddrs = Address.unpack(ccList);
    boolean fromMe = fragment.messageHelper.toMe(account, fromAddrs);
    boolean toMe = fragment.messageHelper.toMe(account, toAddrs);
    boolean ccMe = fragment.messageHelper.toMe(account, ccAddrs);
    CharSequence displayName = fragment.messageHelper.getDisplayName(account, fromAddrs, toAddrs);
    CharSequence displayDate = DateUtils.getRelativeTimeSpanString(context, cursor.getLong(DATE_COLUMN));
    Address counterpartyAddress = fetchCounterPartyAddress(fromMe, toAddrs, ccAddrs, fromAddrs);
    int threadCount = (fragment.showingThreadedList) ? cursor.getInt(THREAD_COUNT_COLUMN) : 0;
    String subject = MlfUtils.buildSubject(cursor.getString(SUBJECT_COLUMN), fragment.getString(R.string.general_no_subject), threadCount);
    boolean read = (cursor.getInt(READ_COLUMN) == 1);
    boolean flagged = (cursor.getInt(FLAGGED_COLUMN) == 1);
    boolean answered = (cursor.getInt(ANSWERED_COLUMN) == 1);
    boolean forwarded = (cursor.getInt(FORWARDED_COLUMN) == 1);
    boolean hasAttachments = (cursor.getInt(ATTACHMENT_COUNT_COLUMN) > 0);
    MessageViewHolder holder = (MessageViewHolder) view.getTag();
    int maybeBoldTypeface = (read) ? Typeface.NORMAL : Typeface.BOLD;
    long uniqueId = cursor.getLong(fragment.uniqueIdColumn);
    boolean selected = fragment.selected.contains(uniqueId);
    holder.chip.setBackgroundColor(account.getChipColor());
    if (fragment.checkboxes) {
        holder.selected.setChecked(selected);
    }
    if (fragment.stars) {
        holder.flagged.setChecked(flagged);
    }
    holder.position = cursor.getPosition();
    if (holder.contactBadge != null) {
        updateContactBadge(holder, counterpartyAddress);
    }
    setBackgroundColor(view, selected, read);
    if (fragment.activeMessage != null) {
        changeBackgroundColorIfActiveMessage(cursor, account, view);
    }
    updateWithThreadCount(holder, threadCount);
    CharSequence beforePreviewText = (fragment.senderAboveSubject) ? subject : displayName;
    String sigil = recipientSigil(toMe, ccMe);
    SpannableStringBuilder messageStringBuilder = new SpannableStringBuilder(sigil).append(beforePreviewText);
    if (fragment.previewLines > 0) {
        String preview = getPreview(cursor);
        messageStringBuilder.append(" ").append(preview);
    }
    holder.preview.setText(messageStringBuilder, TextView.BufferType.SPANNABLE);
    formatPreviewText(holder.preview, beforePreviewText, sigil);
    Drawable statusHolder = buildStatusHolder(forwarded, answered);
    if (holder.from != null) {
        holder.from.setTypeface(Typeface.create(holder.from.getTypeface(), maybeBoldTypeface));
        if (fragment.senderAboveSubject) {
            holder.from.setCompoundDrawablesWithIntrinsicBounds(// left
            statusHolder, // top
            null, // right
            hasAttachments ? mAttachmentIcon : null, // bottom
            null);
            holder.from.setText(displayName);
        } else {
            holder.from.setText(new SpannableStringBuilder(sigil).append(displayName));
        }
    }
    if (holder.subject != null) {
        if (!fragment.senderAboveSubject) {
            holder.subject.setCompoundDrawablesWithIntrinsicBounds(// left
            statusHolder, // top
            null, // right
            hasAttachments ? mAttachmentIcon : null, // bottom
            null);
        }
        holder.subject.setTypeface(Typeface.create(holder.subject.getTypeface(), maybeBoldTypeface));
        holder.subject.setText(subject);
    }
    holder.date.setText(displayDate);
}
Also used : Account(com.fsck.k9.Account) Address(com.fsck.k9.mail.Address) Drawable(android.graphics.drawable.Drawable) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 4 with Address

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

the class Contacts method markAsContacted.

/**
     * Mark contacts with the provided email addresses as contacted.
     *
     * @param addresses Array of {@link Address} objects describing the
     *        contacts to be marked as contacted.
     */
public void markAsContacted(final Address[] addresses) {
    //TODO: Optimize! Potentially a lot of database queries
    for (final Address address : addresses) {
        final Cursor c = getContactByAddress(address.getAddress());
        if (c != null) {
            if (c.getCount() > 0) {
                c.moveToFirst();
                final long personId = c.getLong(CONTACT_ID_INDEX);
                ContactsContract.Contacts.markAsContacted(mContentResolver, personId);
            }
            c.close();
        }
    }
}
Also used : Address(com.fsck.k9.mail.Address) Cursor(android.database.Cursor)

Example 5 with Address

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

the class PgpMessageBuilderTest method createDefaultPgpMessageBuilder.

private static PgpMessageBuilder createDefaultPgpMessageBuilder(OpenPgpApi openPgpApi) {
    PgpMessageBuilder builder = new PgpMessageBuilder(RuntimeEnvironment.application, MessageIdGenerator.getInstance(), BoundaryGenerator.getInstance());
    builder.setOpenPgpApi(openPgpApi);
    Identity identity = new Identity();
    identity.setName("tester");
    identity.setEmail("test@example.org");
    identity.setDescription("test identity");
    identity.setSignatureUse(false);
    builder.setSubject("subject").setSentDate(new Date()).setHideTimeZone(false).setTo(new ArrayList<Address>()).setCc(new ArrayList<Address>()).setBcc(new ArrayList<Address>()).setInReplyTo("inreplyto").setReferences("references").setRequestReadReceipt(false).setIdentity(identity).setMessageFormat(SimpleMessageFormat.TEXT).setText(TEST_MESSAGE_TEXT).setAttachments(new ArrayList<Attachment>()).setSignature("signature").setQuoteStyle(QuoteStyle.PREFIX).setQuotedTextMode(QuotedTextMode.NONE).setQuotedText("quoted text").setQuotedHtmlContent(new InsertableHtmlContent()).setReplyAfterQuote(false).setSignatureBeforeQuotedText(false).setIdentityChanged(false).setSignatureChanged(false).setCursorPosition(0).setMessageReference(null).setDraft(false);
    return builder;
}
Also used : Address(com.fsck.k9.mail.Address) ArrayList(java.util.ArrayList) Attachment(com.fsck.k9.activity.misc.Attachment) InsertableHtmlContent(com.fsck.k9.message.quote.InsertableHtmlContent) Identity(com.fsck.k9.Identity) Date(java.util.Date)

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