Search in sources :

Example 36 with MimeBodyPart

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

the class AttachmentInfoExtractorTest method extractInfoForDb__withTextMimeType__shouldReturnTxtExtension.

@Test
public void extractInfoForDb__withTextMimeType__shouldReturnTxtExtension() throws Exception {
    MimeBodyPart part = new MimeBodyPart();
    part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, "text/plain");
    AttachmentViewInfo attachmentViewInfo = attachmentInfoExtractor.extractAttachmentInfoForDatabase(part);
    // MimeUtility.getExtensionByMimeType("text/plain"); -> "txt"
    assertEquals("noname.txt", attachmentViewInfo.displayName);
    assertEquals("text/plain", attachmentViewInfo.mimeType);
}
Also used : MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) AttachmentViewInfo(com.fsck.k9.mailstore.AttachmentViewInfo) Test(org.junit.Test)

Example 37 with MimeBodyPart

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

the class AttachmentInfoExtractorTest method extractInfoForDb__withDispositionInvalidSizeParam__shouldReturnUnknownSize.

@Test
public void extractInfoForDb__withDispositionInvalidSizeParam__shouldReturnUnknownSize() throws Exception {
    MimeBodyPart part = new MimeBodyPart();
    part.setHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, "attachment" + "; size=\"notanint\"");
    AttachmentViewInfo attachmentViewInfo = attachmentInfoExtractor.extractAttachmentInfoForDatabase(part);
    assertEquals(AttachmentViewInfo.UNKNOWN_SIZE, attachmentViewInfo.size);
}
Also used : MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) AttachmentViewInfo(com.fsck.k9.mailstore.AttachmentViewInfo) Test(org.junit.Test)

Example 38 with MimeBodyPart

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

the class AttachmentInfoExtractorTest method extractInfoForDb__withDispositionSizeParam__shouldReturnThatSize.

@Test
public void extractInfoForDb__withDispositionSizeParam__shouldReturnThatSize() throws Exception {
    MimeBodyPart part = new MimeBodyPart();
    part.setHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, "attachment" + "; size=\"" + TEST_SIZE + "\"");
    AttachmentViewInfo attachmentViewInfo = attachmentInfoExtractor.extractAttachmentInfoForDatabase(part);
    assertEquals(TEST_SIZE, attachmentViewInfo.size);
}
Also used : MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) AttachmentViewInfo(com.fsck.k9.mailstore.AttachmentViewInfo) Test(org.junit.Test)

Example 39 with MimeBodyPart

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

the class PreviewTextExtractorTest method extractPreview_withEmptyBody_shouldThrow.

@Test(expected = PreviewExtractionException.class)
public void extractPreview_withEmptyBody_shouldThrow() throws Exception {
    Part part = new MimeBodyPart(null, "text/plain");
    previewTextExtractor.extractPreview(part);
}
Also used : Part(com.fsck.k9.mail.Part) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) MessageCreationHelper.createTextPart(com.fsck.k9.message.MessageCreationHelper.createTextPart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) Test(org.junit.Test)

Example 40 with MimeBodyPart

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

the class MessageTest method binaryBodyPart.

private MimeBodyPart binaryBodyPart() throws IOException, MessagingException {
    String encodedTestString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz0123456789+/\r\n";
    BinaryTempFileBody tempFileBody = new BinaryTempFileBody(MimeUtil.ENC_BASE64);
    InputStream in = new ByteArrayInputStream(encodedTestString.getBytes("UTF-8"));
    OutputStream out = tempFileBody.getOutputStream();
    try {
        IOUtils.copy(in, out);
    } finally {
        out.close();
    }
    MimeBodyPart bodyPart = new MimeBodyPart(tempFileBody, "application/octet-stream");
    bodyPart.setEncoding(MimeUtil.ENC_BASE64);
    return bodyPart;
}
Also used : BinaryTempFileBody(com.fsck.k9.mail.internet.BinaryTempFileBody) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart)

Aggregations

MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)42 Test (org.junit.Test)22 Part (com.fsck.k9.mail.Part)15 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)15 TextBody (com.fsck.k9.mail.internet.TextBody)11 AttachmentViewInfo (com.fsck.k9.mailstore.AttachmentViewInfo)11 BodyPart (com.fsck.k9.mail.BodyPart)9 MessagingException (com.fsck.k9.mail.MessagingException)7 Uri (android.net.Uri)5 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)5 PendingIntent (android.app.PendingIntent)4 Body (com.fsck.k9.mail.Body)4 Multipart (com.fsck.k9.mail.Multipart)4 CryptoResultAnnotation (com.fsck.k9.mailstore.CryptoResultAnnotation)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 OutputStream (java.io.OutputStream)4 OpenPgpDataSource (org.openintents.openpgp.util.OpenPgpApi.OpenPgpDataSource)4 Intent (android.content.Intent)3 BinaryTempFileBody (com.fsck.k9.mail.internet.BinaryTempFileBody)3 InputStream (java.io.InputStream)3