Search in sources :

Example 11 with Identity

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

the class MessageCompose method processMessageToReplyTo.

private void processMessageToReplyTo(MessageViewInfo messageViewInfo) throws MessagingException {
    Message message = messageViewInfo.message;
    if (message.getSubject() != null) {
        final String subject = PREFIX.matcher(message.getSubject()).replaceFirst("");
        if (!subject.toLowerCase(Locale.US).startsWith("re:")) {
            subjectView.setText("Re: " + subject);
        } else {
            subjectView.setText(subject);
        }
    } else {
        subjectView.setText("");
    }
    /*
         * If a reply-to was included with the message use that, otherwise use the from
         * or sender address.
         */
    boolean isReplyAll = action == Action.REPLY_ALL;
    recipientPresenter.initFromReplyToMessage(message, isReplyAll);
    if (message.getMessageId() != null && message.getMessageId().length() > 0) {
        repliedToMessageId = message.getMessageId();
        String[] refs = message.getReferences();
        if (refs != null && refs.length > 0) {
            referencedMessageIds = TextUtils.join("", refs) + " " + repliedToMessageId;
        } else {
            referencedMessageIds = repliedToMessageId;
        }
    } else {
        Timber.d("could not get Message-ID.");
    }
    // Quote the message and setup the UI.
    quotedMessagePresenter.initFromReplyToMessage(messageViewInfo, action);
    if (action == Action.REPLY || action == Action.REPLY_ALL) {
        Identity useIdentity = IdentityHelper.getRecipientIdentityFromMessage(account, message);
        Identity defaultIdentity = account.getIdentity(0);
        if (useIdentity != defaultIdentity) {
            switchToIdentity(useIdentity);
        }
    }
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) Identity(com.fsck.k9.Identity)

Example 12 with Identity

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

the class ManageIdentities method onContextItemSelected.

@Override
public boolean onContextItemSelected(android.view.MenuItem item) {
    AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
    switch(item.getItemId()) {
        case R.id.edit:
            editItem(menuInfo.position);
            break;
        case R.id.up:
            if (menuInfo.position > 0) {
                Identity identity = identities.remove(menuInfo.position);
                identities.add(menuInfo.position - 1, identity);
                mIdentitiesChanged = true;
                refreshView();
            }
            break;
        case R.id.down:
            if (menuInfo.position < identities.size() - 1) {
                Identity identity = identities.remove(menuInfo.position);
                identities.add(menuInfo.position + 1, identity);
                mIdentitiesChanged = true;
                refreshView();
            }
            break;
        case R.id.top:
            Identity identity = identities.remove(menuInfo.position);
            identities.add(0, identity);
            mIdentitiesChanged = true;
            refreshView();
            break;
        case R.id.remove:
            if (identities.size() > 1) {
                identities.remove(menuInfo.position);
                mIdentitiesChanged = true;
                refreshView();
            } else {
                Toast.makeText(this, getString(R.string.no_removable_identity), Toast.LENGTH_LONG).show();
            }
            break;
    }
    return true;
}
Also used : AdapterContextMenuInfo(android.widget.AdapterView.AdapterContextMenuInfo) Identity(com.fsck.k9.Identity)

Example 13 with Identity

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

the class MessageBuilderTest method createIdentity.

private Identity createIdentity() {
    Identity identity = new Identity();
    identity.setName(TEST_IDENTITY_ADDRESS.getPersonal());
    identity.setEmail(TEST_IDENTITY_ADDRESS.getAddress());
    identity.setDescription("test identity");
    identity.setSignatureUse(false);
    return identity;
}
Also used : Identity(com.fsck.k9.Identity)

Example 14 with Identity

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

the class OpenPgpApiHelperTest method buildUserId_withName_shouldCreateOpenPgpAccountName.

@Test
public void buildUserId_withName_shouldCreateOpenPgpAccountName() {
    Identity identity = new Identity();
    identity.setEmail("user@domain.com");
    identity.setName("Name");
    String result = OpenPgpApiHelper.buildUserId(identity);
    assertEquals("Name <user@domain.com>", result);
}
Also used : Identity(com.fsck.k9.Identity) Test(org.junit.Test)

Example 15 with Identity

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

the class MessageBuilder method buildBody.

private void buildBody(MimeMessage message) throws MessagingException {
    // Build the body.
    // TODO FIXME - body can be either an HTML or Text part, depending on whether we're in
    // HTML mode or not.  Should probably fix this so we don't mix up html and text parts.
    TextBody body = buildText(isDraft);
    // text/plain part when messageFormat == MessageFormat.HTML
    TextBody bodyPlain = null;
    final boolean hasAttachments = !attachments.isEmpty();
    if (messageFormat == SimpleMessageFormat.HTML) {
        // HTML message (with alternative text part)
        // This is the compiled MIME part for an HTML message.
        MimeMultipart composedMimeMessage = createMimeMultipart();
        composedMimeMessage.setSubType("alternative");
        // Let the receiver select either the text or the HTML part.
        bodyPlain = buildText(isDraft, SimpleMessageFormat.TEXT);
        composedMimeMessage.addBodyPart(new MimeBodyPart(bodyPlain, "text/plain"));
        composedMimeMessage.addBodyPart(new MimeBodyPart(body, "text/html"));
        if (hasAttachments) {
            // If we're HTML and have attachments, we have a MimeMultipart container to hold the
            // whole message (mp here), of which one part is a MimeMultipart container
            // (composedMimeMessage) with the user's composed messages, and subsequent parts for
            // the attachments.
            MimeMultipart mp = createMimeMultipart();
            mp.addBodyPart(new MimeBodyPart(composedMimeMessage));
            addAttachmentsToMessage(mp);
            MimeMessageHelper.setBody(message, mp);
        } else {
            // If no attachments, our multipart/alternative part is the only one we need.
            MimeMessageHelper.setBody(message, composedMimeMessage);
        }
    } else if (messageFormat == SimpleMessageFormat.TEXT) {
        // Text-only message.
        if (hasAttachments) {
            MimeMultipart mp = createMimeMultipart();
            mp.addBodyPart(new MimeBodyPart(body, "text/plain"));
            addAttachmentsToMessage(mp);
            MimeMessageHelper.setBody(message, mp);
        } else {
            // No attachments to include, just stick the text body in the message and call it good.
            MimeMessageHelper.setBody(message, body);
        }
    }
    // If this is a draft, add metadata for thawing.
    if (isDraft) {
        // Add the identity to the message.
        message.addHeader(K9.IDENTITY_HEADER, buildIdentityHeader(body, bodyPlain));
    }
}
Also used : TextBody(com.fsck.k9.mail.internet.TextBody) MimeMultipart(com.fsck.k9.mail.internet.MimeMultipart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart)

Aggregations

Identity (com.fsck.k9.Identity)10 Account (com.fsck.k9.Account)4 InvalidSettingValueException (com.fsck.k9.preferences.Settings.InvalidSettingValueException)3 Test (org.junit.Test)3 Nullable (android.support.annotation.Nullable)2 View (android.view.View)2 TextView (android.widget.TextView)2 Preferences (com.fsck.k9.Preferences)2 Message (com.fsck.k9.mail.Message)2 Part (com.fsck.k9.mail.Part)2 ServerSettings (com.fsck.k9.mail.ServerSettings)2 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)2 LocalMessage (com.fsck.k9.mailstore.LocalMessage)2 InsertableHtmlContent (com.fsck.k9.message.quote.InsertableHtmlContent)2 SettingsDescription (com.fsck.k9.preferences.Settings.SettingsDescription)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 SuppressLint (android.annotation.SuppressLint)1