Search in sources :

Example 1 with Html

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

the class MessageFulltextCreator method extractText.

private String extractText(Message message) {
    Part textPart = textPartFinder.findFirstTextPart(message);
    if (textPart == null || hasEmptyBody(textPart)) {
        return null;
    }
    String text = MessageExtractor.getTextFromPart(textPart, MAX_CHARACTERS_CHECKED_FOR_FTS);
    String mimeType = textPart.getMimeType();
    if (!MimeUtility.isSameMimeType(mimeType, "text/html")) {
        return text;
    }
    return HtmlConverter.htmlToText(text);
}
Also used : Part(com.fsck.k9.mail.Part)

Example 2 with Html

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

the class MessageDecryptVerifierTest method findPrimaryCryptoPart_withMultipartMixedContainingMultipartAlternativeContainingPgpInline.

@Test
public void findPrimaryCryptoPart_withMultipartMixedContainingMultipartAlternativeContainingPgpInline() throws Exception {
    List<Part> outputExtraParts = new ArrayList<>();
    BodyPart pgpInlinePart = bodypart("text/plain", PGP_INLINE_DATA);
    Message message = messageFromBody(multipart("mixed", multipart("alternative", pgpInlinePart, bodypart("text/html")), bodypart("application/octet-stream")));
    Part cryptoPart = MessageDecryptVerifier.findPrimaryEncryptedOrSignedPart(message, outputExtraParts);
    assertSame(pgpInlinePart, cryptoPart);
}
Also used : BodyPart(com.fsck.k9.mail.BodyPart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with Html

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

the class MessageDecryptVerifierTest method findPrimaryCryptoPart_withMultipartAlternativeContainingPgpInline.

@Test
public void findPrimaryCryptoPart_withMultipartAlternativeContainingPgpInline() throws Exception {
    List<Part> outputExtraParts = new ArrayList<>();
    BodyPart pgpInlinePart = bodypart("text/plain", PGP_INLINE_DATA);
    Message message = messageFromBody(multipart("alternative", pgpInlinePart, bodypart("text/html")));
    Part cryptoPart = MessageDecryptVerifier.findPrimaryEncryptedOrSignedPart(message, outputExtraParts);
    assertSame(pgpInlinePart, cryptoPart);
}
Also used : BodyPart(com.fsck.k9.mail.BodyPart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with Html

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

the class MessageCompose method updateMessageFormat.

public void updateMessageFormat() {
    MessageFormat origMessageFormat = account.getMessageFormat();
    SimpleMessageFormat messageFormat;
    if (origMessageFormat == MessageFormat.TEXT) {
        // The user wants to send text/plain messages. We don't override that choice under
        // any circumstances.
        messageFormat = SimpleMessageFormat.TEXT;
    } else if (quotedMessagePresenter.isForcePlainText() && quotedMessagePresenter.includeQuotedText()) {
        // Right now we send a text/plain-only message when the quoted text was edited, no
        // matter what the user selected for the message format.
        messageFormat = SimpleMessageFormat.TEXT;
    } else if (recipientPresenter.isForceTextMessageFormat()) {
        // Right now we only support PGP inline which doesn't play well with HTML. So force
        // plain text in those cases.
        messageFormat = SimpleMessageFormat.TEXT;
    } else if (origMessageFormat == MessageFormat.AUTO) {
        if (action == Action.COMPOSE || quotedMessagePresenter.isQuotedTextText() || !quotedMessagePresenter.includeQuotedText()) {
            // If the message format is set to "AUTO" we use text/plain whenever possible. That
            // is, when composing new messages and replying to or forwarding text/plain
            // messages.
            messageFormat = SimpleMessageFormat.TEXT;
        } else {
            messageFormat = SimpleMessageFormat.HTML;
        }
    } else {
        // In all other cases use HTML
        messageFormat = SimpleMessageFormat.HTML;
    }
    setCurrentMessageFormat(messageFormat);
}
Also used : MessageFormat(com.fsck.k9.Account.MessageFormat) SimpleMessageFormat(com.fsck.k9.message.SimpleMessageFormat) SimpleMessageFormat(com.fsck.k9.message.SimpleMessageFormat)

Example 5 with Html

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

the class MessageExtractorTest method getTextFromPart_withExceptionThrownGettingInputStream_shouldReturnNull.

@Test
public void getTextFromPart_withExceptionThrownGettingInputStream_shouldReturnNull() throws Exception {
    part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, "text/html");
    Body body = mock(Body.class);
    when(body.getInputStream()).thenThrow(new MessagingException("Test"));
    part.setBody(body);
    String result = MessageExtractor.getTextFromPart(part);
    assertNull(result);
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) Body(com.fsck.k9.mail.Body) BinaryMemoryBody(com.fsck.k9.mailstore.BinaryMemoryBody) Test(org.junit.Test)

Aggregations

Part (com.fsck.k9.mail.Part)31 BodyPart (com.fsck.k9.mail.BodyPart)24 Test (org.junit.Test)24 MessageCreationHelper.createTextPart (com.fsck.k9.message.MessageCreationHelper.createTextPart)12 MessageCreationHelper.createEmptyPart (com.fsck.k9.message.MessageCreationHelper.createEmptyPart)11 MessageCreationHelper.createPart (com.fsck.k9.message.MessageCreationHelper.createPart)11 ArrayList (java.util.ArrayList)11 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)9 Body (com.fsck.k9.mail.Body)7 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)7 Message (com.fsck.k9.mail.Message)6 Multipart (com.fsck.k9.mail.Multipart)6 TextBody (com.fsck.k9.mail.internet.TextBody)6 Viewable (com.fsck.k9.mail.internet.Viewable)6 Alternative (com.fsck.k9.mail.internet.Viewable.Alternative)4 Html (com.fsck.k9.mail.internet.Viewable.Html)4 Text (com.fsck.k9.mail.internet.Viewable.Text)4 MessageFormat (com.fsck.k9.Account.MessageFormat)3 K9RobolectricTest (com.fsck.k9.K9RobolectricTest)3 MessagingException (com.fsck.k9.mail.MessagingException)3