use of com.fsck.k9.mail.Part in project k-9 by k9mail.
the class MessagingController method downloadPartial.
private void downloadPartial(Folder remoteFolder, LocalFolder localFolder, Message message) throws MessagingException {
/*
* We have a structure to deal with, from which
* we can pull down the parts we want to actually store.
* Build a list of parts we are interested in. Text parts will be downloaded
* right now, attachments will be left for later.
*/
Set<Part> viewables = MessageExtractor.collectTextParts(message);
/*
* Now download the parts we're interested in storing.
*/
for (Part part : viewables) {
remoteFolder.fetchPart(message, part, null);
}
// Store the updated message locally
localFolder.appendMessages(Collections.singletonList(message));
Message localMessage = localFolder.getMessage(message.getUid());
// Set a flag indicating this message has been fully downloaded and can be
// viewed.
localMessage.setFlag(Flag.X_DOWNLOADED_PARTIAL, true);
}
use of com.fsck.k9.mail.Part in project k-9 by k9mail.
the class MessagePreviewCreatorTest method createPreview_withTextPart.
@Test
public void createPreview_withTextPart() throws Exception {
Message message = createDummyMessage();
Part textPart = createTextPart("text/plain");
when(encryptionDetector.isEncrypted(message)).thenReturn(false);
when(textPartFinder.findFirstTextPart(message)).thenReturn(textPart);
when(previewTextExtractor.extractPreview(textPart)).thenReturn("expected");
PreviewResult result = previewCreator.createPreview(message);
assertTrue(result.isPreviewTextAvailable());
assertEquals(PreviewType.TEXT, result.getPreviewType());
assertEquals("expected", result.getPreviewText());
}
use of com.fsck.k9.mail.Part in project k-9 by k9mail.
the class MessagePreviewCreatorTest method createPreview_withEmptyTextPart.
@Test
public void createPreview_withEmptyTextPart() throws Exception {
Message message = createDummyMessage();
Part textPart = createEmptyPart("text/plain");
when(encryptionDetector.isEncrypted(message)).thenReturn(false);
when(textPartFinder.findFirstTextPart(message)).thenReturn(textPart);
PreviewResult result = previewCreator.createPreview(message);
assertFalse(result.isPreviewTextAvailable());
assertEquals(PreviewType.NONE, result.getPreviewType());
verifyNoMoreInteractions(previewTextExtractor);
}
use of com.fsck.k9.mail.Part in project k-9 by k9mail.
the class MessagePreviewCreatorTest method createPreview_withPreviewTextExtractorThrowing.
@Test
public void createPreview_withPreviewTextExtractorThrowing() throws Exception {
Message message = createDummyMessage();
Part textPart = createTextPart("text/plain");
when(encryptionDetector.isEncrypted(message)).thenReturn(false);
when(textPartFinder.findFirstTextPart(message)).thenReturn(textPart);
when(previewTextExtractor.extractPreview(textPart)).thenThrow(new PreviewExtractionException(""));
PreviewResult result = previewCreator.createPreview(message);
assertFalse(result.isPreviewTextAvailable());
assertEquals(PreviewType.ERROR, result.getPreviewType());
}
use of com.fsck.k9.mail.Part in project k-9 by k9mail.
the class PreviewTextExtractorTest method extractPreview_shouldStripHorizontalRules.
@Test
public void extractPreview_shouldStripHorizontalRules() throws Exception {
String text = "line 1" + "------------------------------\r\n" + "line 2";
Part part = createTextPart("text/plain", text);
String preview = previewTextExtractor.extractPreview(part);
assertEquals("line 1 line 2", preview);
}
Aggregations