Search in sources :

Example 1 with Identity

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

the class OpenPgpApiHelperTest method buildUserId_withoutName_shouldCreateOpenPgpAccountName.

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

Example 2 with Identity

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

the class IdentityAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    Object item = mItems.get(position);
    View view = null;
    if (item instanceof Account) {
        if (convertView != null && convertView.getTag() instanceof AccountHolder) {
            view = convertView;
        } else {
            view = mLayoutInflater.inflate(R.layout.choose_account_item, parent, false);
            AccountHolder holder = new AccountHolder();
            holder.name = (TextView) view.findViewById(R.id.name);
            holder.chip = view.findViewById(R.id.chip);
            view.setTag(holder);
        }
        Account account = (Account) item;
        AccountHolder holder = (AccountHolder) view.getTag();
        holder.name.setText(account.getDescription());
        holder.chip.setBackgroundColor(account.getChipColor());
    } else if (item instanceof IdentityContainer) {
        if (convertView != null && convertView.getTag() instanceof IdentityHolder) {
            view = convertView;
        } else {
            view = mLayoutInflater.inflate(R.layout.choose_identity_item, parent, false);
            IdentityHolder holder = new IdentityHolder();
            holder.name = (TextView) view.findViewById(R.id.name);
            holder.description = (TextView) view.findViewById(R.id.description);
            view.setTag(holder);
        }
        IdentityContainer identityContainer = (IdentityContainer) item;
        Identity identity = identityContainer.identity;
        IdentityHolder holder = (IdentityHolder) view.getTag();
        holder.name.setText(identity.getDescription());
        holder.description.setText(getIdentityDescription(identity));
    }
    return view;
}
Also used : Account(com.fsck.k9.Account) TextView(android.widget.TextView) Identity(com.fsck.k9.Identity) TextView(android.widget.TextView) View(android.view.View)

Example 3 with Identity

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

the class RecipientPresenter method getCurrentCryptoStatus.

public ComposeCryptoStatus getCurrentCryptoStatus() {
    if (cachedCryptoStatus == null) {
        ComposeCryptoStatusBuilder builder = new ComposeCryptoStatusBuilder().setCryptoProviderState(cryptoProviderState).setCryptoMode(currentCryptoMode).setEnablePgpInline(cryptoEnablePgpInline).setRecipients(getAllRecipients());
        long accountCryptoKey = account.getCryptoKey();
        if (accountCryptoKey != Account.NO_OPENPGP_KEY) {
            // TODO split these into individual settings? maybe after key is bound to identity
            builder.setSigningKeyId(accountCryptoKey);
            builder.setSelfEncryptId(accountCryptoKey);
        }
        cachedCryptoStatus = builder.build();
    }
    return cachedCryptoStatus;
}
Also used : ComposeCryptoStatusBuilder(com.fsck.k9.activity.compose.ComposeCryptoStatus.ComposeCryptoStatusBuilder)

Example 4 with Identity

use of com.fsck.k9.Identity 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)

Example 5 with Identity

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

the class QuotedMessagePresenter method processDraftMessage.

public void processDraftMessage(MessageViewInfo messageViewInfo, Map<IdentityField, String> k9identity) {
    quoteStyle = k9identity.get(IdentityField.QUOTE_STYLE) != null ? QuoteStyle.valueOf(k9identity.get(IdentityField.QUOTE_STYLE)) : account.getQuoteStyle();
    int cursorPosition = 0;
    if (k9identity.containsKey(IdentityField.CURSOR_POSITION)) {
        try {
            cursorPosition = Integer.parseInt(k9identity.get(IdentityField.CURSOR_POSITION));
        } catch (Exception e) {
            Timber.e(e, "Could not parse cursor position for MessageCompose; continuing.");
        }
    }
    String showQuotedTextMode;
    if (k9identity.containsKey(IdentityField.QUOTED_TEXT_MODE)) {
        showQuotedTextMode = k9identity.get(IdentityField.QUOTED_TEXT_MODE);
    } else {
        showQuotedTextMode = "NONE";
    }
    int bodyLength = k9identity.get(IdentityField.LENGTH) != null ? Integer.valueOf(k9identity.get(IdentityField.LENGTH)) : UNKNOWN_LENGTH;
    int bodyOffset = k9identity.get(IdentityField.OFFSET) != null ? Integer.valueOf(k9identity.get(IdentityField.OFFSET)) : UNKNOWN_LENGTH;
    Integer bodyFooterOffset = k9identity.get(IdentityField.FOOTER_OFFSET) != null ? Integer.valueOf(k9identity.get(IdentityField.FOOTER_OFFSET)) : null;
    Integer bodyPlainLength = k9identity.get(IdentityField.PLAIN_LENGTH) != null ? Integer.valueOf(k9identity.get(IdentityField.PLAIN_LENGTH)) : null;
    Integer bodyPlainOffset = k9identity.get(IdentityField.PLAIN_OFFSET) != null ? Integer.valueOf(k9identity.get(IdentityField.PLAIN_OFFSET)) : null;
    QuotedTextMode quotedMode;
    try {
        quotedMode = QuotedTextMode.valueOf(showQuotedTextMode);
    } catch (Exception e) {
        quotedMode = QuotedTextMode.NONE;
    }
    // Always respect the user's current composition format preference, even if the
    // draft was saved in a different format.
    // TODO - The current implementation doesn't allow a user in HTML mode to edit a draft that wasn't saved with K9mail.
    String messageFormatString = k9identity.get(IdentityField.MESSAGE_FORMAT);
    MessageFormat messageFormat = null;
    if (messageFormatString != null) {
        try {
            messageFormat = MessageFormat.valueOf(messageFormatString);
        } catch (Exception e) {
        /* do nothing */
        }
    }
    if (messageFormat == null) {
        // This message probably wasn't created by us. The exception is legacy
        // drafts created before the advent of HTML composition. In those cases,
        // we'll display the whole message (including the quoted part) in the
        // composition window. If that's the case, try and convert it to text to
        // match the behavior in text mode.
        view.setMessageContentCharacters(BodyTextExtractor.getBodyTextFromMessage(messageViewInfo.message, SimpleMessageFormat.TEXT));
        forcePlainText = true;
        showOrHideQuotedText(quotedMode);
        return;
    }
    if (messageFormat == MessageFormat.HTML) {
        Part part = MimeUtility.findFirstPartByMimeType(messageViewInfo.message, "text/html");
        if (part != null) {
            // Shouldn't happen if we were the one who saved it.
            quotedTextFormat = SimpleMessageFormat.HTML;
            String text = MessageExtractor.getTextFromPart(part);
            Timber.d("Loading message with offset %d, length %d. Text length is %d.", bodyOffset, bodyLength, text.length());
            if (bodyOffset + bodyLength > text.length()) {
                // The draft was edited outside of K-9 Mail?
                Timber.d("The identity field from the draft contains an invalid LENGTH/OFFSET");
                bodyOffset = 0;
                bodyLength = 0;
            }
            // Grab our reply text.
            String bodyText = text.substring(bodyOffset, bodyOffset + bodyLength);
            view.setMessageContentCharacters(HtmlConverter.htmlToText(bodyText));
            // Regenerate the quoted html without our user content in it.
            StringBuilder quotedHTML = new StringBuilder();
            // stuff before the reply
            quotedHTML.append(text.substring(0, bodyOffset));
            quotedHTML.append(text.substring(bodyOffset + bodyLength));
            if (quotedHTML.length() > 0) {
                quotedHtmlContent = new InsertableHtmlContent();
                quotedHtmlContent.setQuotedContent(quotedHTML);
                // We don't know if bodyOffset refers to the header or to the footer
                quotedHtmlContent.setHeaderInsertionPoint(bodyOffset);
                if (bodyFooterOffset != null) {
                    quotedHtmlContent.setFooterInsertionPoint(bodyFooterOffset);
                } else {
                    quotedHtmlContent.setFooterInsertionPoint(bodyOffset);
                }
                // TODO replace with MessageViewInfo data
                view.setQuotedHtml(quotedHtmlContent.getQuotedContent(), AttachmentResolver.createFromPart(messageViewInfo.rootPart));
            }
        }
        if (bodyPlainOffset != null && bodyPlainLength != null) {
            processSourceMessageText(messageViewInfo.rootPart, bodyPlainOffset, bodyPlainLength, false);
        }
    } else if (messageFormat == MessageFormat.TEXT) {
        quotedTextFormat = SimpleMessageFormat.TEXT;
        processSourceMessageText(messageViewInfo.rootPart, bodyOffset, bodyLength, true);
    } else {
        Timber.e("Unhandled message format.");
    }
    // Set the cursor position if we have it.
    try {
        view.setMessageContentCursorPosition(cursorPosition);
    } catch (Exception e) {
        Timber.e(e, "Could not set cursor position in MessageCompose; ignoring.");
    }
    showOrHideQuotedText(quotedMode);
}
Also used : SimpleMessageFormat(com.fsck.k9.message.SimpleMessageFormat) MessageFormat(com.fsck.k9.Account.MessageFormat) Part(com.fsck.k9.mail.Part) QuotedTextMode(com.fsck.k9.message.QuotedTextMode) InsertableHtmlContent(com.fsck.k9.message.quote.InsertableHtmlContent) MessagingException(com.fsck.k9.mail.MessagingException)

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