Search in sources :

Example 56 with Text

use of com.fsck.k9.mail.internet.Viewable.Text in project k-9 by k9mail.

the class MessageCryptoHelper method extractClearsignedTextReplacementPart.

private static MimeBodyPart extractClearsignedTextReplacementPart(Part part) {
    try {
        String clearsignedText = MessageExtractor.getTextFromPart(part);
        String replacementText = OpenPgpUtils.extractClearsignedMessage(clearsignedText);
        if (replacementText == null) {
            Timber.e("failed to extract clearsigned text for replacement part");
            return NO_REPLACEMENT_PART;
        }
        return new MimeBodyPart(new TextBody(replacementText), "text/plain");
    } catch (MessagingException e) {
        Timber.e(e, "failed to create clearsigned text replacement part");
        return NO_REPLACEMENT_PART;
    }
}
Also used : TextBody(com.fsck.k9.mail.internet.TextBody) MessagingException(com.fsck.k9.mail.MessagingException) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart)

Example 57 with Text

use of com.fsck.k9.mail.internet.Viewable.Text in project k-9 by k9mail.

the class ImapFolderTest method fetchPart_withTextSection_shouldProcessImapResponses.

@Test
public void fetchPart_withTextSection_shouldProcessImapResponses() throws Exception {
    ImapFolder folder = createFolder("Folder");
    prepareImapFolderForOpen(OPEN_MODE_RO);
    folder.open(OPEN_MODE_RO);
    ImapMessage message = createImapMessage("1");
    Part part = createPlainTextPart("1.1");
    setupSingleFetchResponseToCallback();
    folder.fetchPart(message, part, null);
    ArgumentCaptor<Body> bodyArgumentCaptor = ArgumentCaptor.forClass(Body.class);
    verify(part).setBody(bodyArgumentCaptor.capture());
    Body body = bodyArgumentCaptor.getValue();
    Buffer buffer = new Buffer();
    body.writeTo(buffer.outputStream());
    assertEquals("text", buffer.readUtf8());
}
Also used : Buffer(okio.Buffer) Part(com.fsck.k9.mail.Part) Body(com.fsck.k9.mail.Body) BinaryTempFileBody(com.fsck.k9.mail.internet.BinaryTempFileBody) Test(org.junit.Test)

Example 58 with Text

use of com.fsck.k9.mail.internet.Viewable.Text in project k-9 by k9mail.

the class ImapFolderTest method fetchPart_withTextSection_shouldIssueRespectiveCommand.

@Test
public void fetchPart_withTextSection_shouldIssueRespectiveCommand() throws Exception {
    ImapFolder folder = createFolder("Folder");
    prepareImapFolderForOpen(OPEN_MODE_RO);
    when(storeConfig.getMaximumAutoDownloadMessageSize()).thenReturn(4096);
    folder.open(OPEN_MODE_RO);
    ImapMessage message = createImapMessage("1");
    Part part = createPart("TEXT");
    when(imapConnection.readResponse(any(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK"));
    folder.fetchPart(message, part, null);
    verify(imapConnection).sendCommand("UID FETCH 1 (UID BODY.PEEK[TEXT]<0.4096>)", false);
}
Also used : Part(com.fsck.k9.mail.Part) Test(org.junit.Test)

Example 59 with Text

use of com.fsck.k9.mail.internet.Viewable.Text in project k-9 by k9mail.

the class MessageBuilder method buildText.

/**
     * Build the {@link Body} that will contain the text of the message.
     *
     * <p>
     * Draft messages are treated somewhat differently in that signatures are not appended and HTML
     * separators between composed text and quoted text are not added.
     * </p>
     *
     * @param isDraft
     *         If {@code true} we build a message that will be saved as a draft (as opposed to
     *         sent).
     * @param simpleMessageFormat
     *         Specifies what type of message to build ({@code text/plain} vs. {@code text/html}).
     *
     * @return {@link TextBody} instance that contains the entered text and possibly the quoted
     *         original message.
     */
private TextBody buildText(boolean isDraft, SimpleMessageFormat simpleMessageFormat) {
    String messageText = text;
    TextBodyBuilder textBodyBuilder = new TextBodyBuilder(messageText);
    /*
         * Find out if we need to include the original message as quoted text.
         *
         * We include the quoted text in the body if the user didn't choose to
         * hide it. We always include the quoted text when we're saving a draft.
         * That's so the user is able to "un-hide" the quoted text if (s)he
         * opens a saved draft.
         */
    boolean includeQuotedText = (isDraft || quotedTextMode == QuotedTextMode.SHOW);
    boolean isReplyAfterQuote = (quoteStyle == QuoteStyle.PREFIX && this.isReplyAfterQuote);
    textBodyBuilder.setIncludeQuotedText(false);
    if (includeQuotedText) {
        if (simpleMessageFormat == SimpleMessageFormat.HTML && quotedHtmlContent != null) {
            textBodyBuilder.setIncludeQuotedText(true);
            textBodyBuilder.setQuotedTextHtml(quotedHtmlContent);
            textBodyBuilder.setReplyAfterQuote(isReplyAfterQuote);
        }
        if (simpleMessageFormat == SimpleMessageFormat.TEXT && quotedText.length() > 0) {
            textBodyBuilder.setIncludeQuotedText(true);
            textBodyBuilder.setQuotedText(quotedText);
            textBodyBuilder.setReplyAfterQuote(isReplyAfterQuote);
        }
    }
    textBodyBuilder.setInsertSeparator(!isDraft);
    boolean useSignature = (!isDraft && identity.getSignatureUse());
    if (useSignature) {
        textBodyBuilder.setAppendSignature(true);
        textBodyBuilder.setSignature(signature);
        textBodyBuilder.setSignatureBeforeQuotedText(isSignatureBeforeQuotedText);
    } else {
        textBodyBuilder.setAppendSignature(false);
    }
    TextBody body;
    if (simpleMessageFormat == SimpleMessageFormat.HTML) {
        body = textBodyBuilder.buildTextHtml();
    } else {
        body = textBodyBuilder.buildTextPlain();
    }
    return body;
}
Also used : TextBody(com.fsck.k9.mail.internet.TextBody)

Example 60 with Text

use of com.fsck.k9.mail.internet.Viewable.Text in project k-9 by k9mail.

the class PgpMessageBuilder method startOrContinueBuildMessage.

private void startOrContinueBuildMessage(@Nullable Intent pgpApiIntent) {
    try {
        boolean shouldSign = cryptoStatus.isSigningEnabled();
        boolean shouldEncrypt = cryptoStatus.isEncryptionEnabled();
        boolean isPgpInlineMode = cryptoStatus.isPgpInlineModeEnabled();
        if (!shouldSign && !shouldEncrypt) {
            return;
        }
        boolean isSimpleTextMessage = MimeUtility.isSameMimeType("text/plain", currentProcessedMimeMessage.getMimeType());
        if (isPgpInlineMode && !isSimpleTextMessage) {
            throw new MessagingException("Attachments are not supported in PGP/INLINE format!");
        }
        if (pgpApiIntent == null) {
            pgpApiIntent = buildOpenPgpApiIntent(shouldSign, shouldEncrypt, isPgpInlineMode);
        }
        PendingIntent returnedPendingIntent = launchOpenPgpApiIntent(pgpApiIntent, shouldEncrypt || isPgpInlineMode, shouldEncrypt || !isPgpInlineMode, isPgpInlineMode);
        if (returnedPendingIntent != null) {
            queueMessageBuildPendingIntent(returnedPendingIntent, REQUEST_USER_INTERACTION);
            return;
        }
        queueMessageBuildSuccess(currentProcessedMimeMessage);
    } catch (MessagingException me) {
        queueMessageBuildException(me);
    }
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) PendingIntent(android.app.PendingIntent)

Aggregations

Test (org.junit.Test)74 Part (com.fsck.k9.mail.Part)64 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)37 BodyPart (com.fsck.k9.mail.BodyPart)34 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)33 MessageCreationHelper.createTextPart (com.fsck.k9.message.MessageCreationHelper.createTextPart)27 Message (com.fsck.k9.mail.Message)22 TextBody (com.fsck.k9.mail.internet.TextBody)18 MessageCreationHelper.createEmptyPart (com.fsck.k9.message.MessageCreationHelper.createEmptyPart)16 ArrayList (java.util.ArrayList)16 Body (com.fsck.k9.mail.Body)13 MessagingException (com.fsck.k9.mail.MessagingException)13 MessageCreationHelper.createPart (com.fsck.k9.message.MessageCreationHelper.createPart)13 Multipart (com.fsck.k9.mail.Multipart)10 Viewable (com.fsck.k9.mail.internet.Viewable)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)8 Intent (android.content.Intent)6 BinaryMemoryBody (com.fsck.k9.mailstore.BinaryMemoryBody)6 ViewableExtractedText (com.fsck.k9.mailstore.MessageViewInfoExtractor.ViewableExtractedText)6