use of app.k9mail.html.cleaner.HtmlProcessor in project k-9 by k9mail.
the class MessageViewInfoExtractorTest method setUp.
@Before
public void setUp() throws Exception {
context = RuntimeEnvironment.application;
HtmlProcessor htmlProcessor = createFakeHtmlProcessor();
attachmentInfoExtractor = spy(DI.get(AttachmentInfoExtractor.class));
messageViewInfoExtractor = new MessageViewInfoExtractor(attachmentInfoExtractor, htmlProcessor, new TestCoreResourceProvider());
}
use of app.k9mail.html.cleaner.HtmlProcessor 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
HtmlProcessor htmlProcessor = mock(HtmlProcessor.class);
MessageViewInfoExtractor messageViewInfoExtractor = new MessageViewInfoExtractor(null, htmlProcessor, new TestCoreResourceProvider());
String value = "--sanitized html--";
when(htmlProcessor.processForDisplay(anyString())).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);
}
use of app.k9mail.html.cleaner.HtmlProcessor in project k-9 by k9mail.
the class MessageViewInfoExtractorTest method createFakeHtmlProcessor.
HtmlProcessor createFakeHtmlProcessor() {
HtmlProcessor htmlProcessor = mock(HtmlProcessor.class);
when(htmlProcessor.processForDisplay(anyString())).thenAnswer(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
return (String) invocation.getArguments()[0];
}
});
return htmlProcessor;
}
Aggregations