Search in sources :

Example 46 with Part

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);
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) Part(com.fsck.k9.mail.Part)

Example 47 with Part

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());
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) MessageCreationHelper.createEmptyPart(com.fsck.k9.message.MessageCreationHelper.createEmptyPart) Part(com.fsck.k9.mail.Part) MessageCreationHelper.createTextPart(com.fsck.k9.message.MessageCreationHelper.createTextPart) Test(org.junit.Test)

Example 48 with Part

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);
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) MessageCreationHelper.createEmptyPart(com.fsck.k9.message.MessageCreationHelper.createEmptyPart) Part(com.fsck.k9.mail.Part) MessageCreationHelper.createTextPart(com.fsck.k9.message.MessageCreationHelper.createTextPart) Test(org.junit.Test)

Example 49 with Part

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());
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) MessageCreationHelper.createEmptyPart(com.fsck.k9.message.MessageCreationHelper.createEmptyPart) Part(com.fsck.k9.mail.Part) MessageCreationHelper.createTextPart(com.fsck.k9.message.MessageCreationHelper.createTextPart) Test(org.junit.Test)

Example 50 with Part

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);
}
Also used : Part(com.fsck.k9.mail.Part) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) MessageCreationHelper.createTextPart(com.fsck.k9.message.MessageCreationHelper.createTextPart) Test(org.junit.Test)

Aggregations

Part (com.fsck.k9.mail.Part)113 Test (org.junit.Test)92 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)78 BodyPart (com.fsck.k9.mail.BodyPart)73 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)39 Message (com.fsck.k9.mail.Message)32 MessageCreationHelper.createTextPart (com.fsck.k9.message.MessageCreationHelper.createTextPart)30 Body (com.fsck.k9.mail.Body)29 Multipart (com.fsck.k9.mail.Multipart)27 ArrayList (java.util.ArrayList)27 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)20 MessageCreationHelper.createEmptyPart (com.fsck.k9.message.MessageCreationHelper.createEmptyPart)19 MessagingException (com.fsck.k9.mail.MessagingException)16 MessageCreationHelper.createPart (com.fsck.k9.message.MessageCreationHelper.createPart)16 TextBody (com.fsck.k9.mail.internet.TextBody)14 AttachmentViewInfo (com.fsck.k9.mailstore.AttachmentViewInfo)13 Viewable (com.fsck.k9.mail.internet.Viewable)10 Uri (android.net.Uri)8 BinaryTempFileBody (com.fsck.k9.mail.internet.BinaryTempFileBody)6 BinaryMemoryBody (com.fsck.k9.mailstore.BinaryMemoryBody)6