Search in sources :

Example 1 with HtmlSanitizer

use of com.fsck.k9.message.html.HtmlSanitizer in project k-9 by k9mail.

the class MessageViewInfoExtractorTest method setUp.

@Before
public void setUp() throws Exception {
    context = RuntimeEnvironment.application;
    GlobalsHelper.setContext(context);
    HtmlSanitizer dummyHtmlSanitizer = HtmlSanitizerHelper.getDummyHtmlSanitizer();
    messageViewInfoExtractor = new MessageViewInfoExtractor(context, null, dummyHtmlSanitizer);
}
Also used : HtmlSanitizer(com.fsck.k9.message.html.HtmlSanitizer) Before(org.junit.Before)

Example 2 with HtmlSanitizer

use of com.fsck.k9.message.html.HtmlSanitizer in project k-9 by k9mail.

the class MessageViewInfoExtractorTest method testShouldSanitizeOutputHtml.

@Test
public void testShouldSanitizeOutputHtml() throws MessagingException {
    // Create text/plain body
    TextBody body = new TextBody(BODY_TEXT);
    // Create message
    MimeMessage message = new MimeMessage();
    MimeMessageHelper.setBody(message, body);
    message.setHeader(MimeHeader.HEADER_CONTENT_TYPE, "text/plain; format=flowed");
    // Prepare fixture
    HtmlSanitizer htmlSanitizer = mock(HtmlSanitizer.class);
    MessageViewInfoExtractor messageViewInfoExtractor = new MessageViewInfoExtractor(context, null, htmlSanitizer);
    String value = "--sanitized html--";
    when(htmlSanitizer.sanitize(any(String.class))).thenReturn(value);
    // Extract text
    List<Part> outputNonViewableParts = new ArrayList<>();
    ArrayList<Viewable> outputViewableParts = new ArrayList<>();
    MessageExtractor.findViewablesAndAttachments(message, outputViewableParts, outputNonViewableParts);
    ViewableExtractedText viewableExtractedText = messageViewInfoExtractor.extractTextFromViewables(outputViewableParts);
    assertSame(value, viewableExtractedText.html);
}
Also used : TextBody(com.fsck.k9.mail.internet.TextBody) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Part(com.fsck.k9.mail.Part) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) ArrayList(java.util.ArrayList) Viewable(com.fsck.k9.mail.internet.Viewable) ViewableExtractedText(com.fsck.k9.mailstore.MessageViewInfoExtractor.ViewableExtractedText) HtmlSanitizer(com.fsck.k9.message.html.HtmlSanitizer) Test(org.junit.Test)

Example 3 with HtmlSanitizer

use of com.fsck.k9.message.html.HtmlSanitizer in project k-9 by k9mail.

the class MessageViewInfoExtractor method getInstance.

public static MessageViewInfoExtractor getInstance() {
    Context context = Globals.getContext();
    AttachmentInfoExtractor attachmentInfoExtractor = AttachmentInfoExtractor.getInstance();
    HtmlSanitizer htmlSanitizer = HtmlSanitizer.getInstance();
    return new MessageViewInfoExtractor(context, attachmentInfoExtractor, htmlSanitizer);
}
Also used : Context(android.content.Context) AttachmentInfoExtractor(com.fsck.k9.message.extractors.AttachmentInfoExtractor) HtmlSanitizer(com.fsck.k9.message.html.HtmlSanitizer)

Aggregations

HtmlSanitizer (com.fsck.k9.message.html.HtmlSanitizer)3 Context (android.content.Context)1 Part (com.fsck.k9.mail.Part)1 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)1 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)1 TextBody (com.fsck.k9.mail.internet.TextBody)1 Viewable (com.fsck.k9.mail.internet.Viewable)1 ViewableExtractedText (com.fsck.k9.mailstore.MessageViewInfoExtractor.ViewableExtractedText)1 AttachmentInfoExtractor (com.fsck.k9.message.extractors.AttachmentInfoExtractor)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 Test (org.junit.Test)1