Search in sources :

Example 31 with Attachment

use of com.fsck.k9.activity.misc.Attachment in project k-9 by k9mail.

the class MessageBuilderTest method build_withAttachment_nonAscii_shouldSucceed.

@Test
public void build_withAttachment_nonAscii_shouldSucceed() throws Exception {
    MessageBuilder messageBuilder = createSimpleMessageBuilder();
    Attachment attachment = createAttachmentWithContent("text/plain", ATTACHMENT_FILENAME_NON_ASCII, TEST_ATTACHMENT_TEXT);
    messageBuilder.setAttachments(Collections.singletonList(attachment));
    messageBuilder.buildAsync(callback);
    MimeMessage message = getMessageFromCallback();
    assertEquals(MESSAGE_HEADERS + MESSAGE_CONTENT_WITH_ATTACH_NON_ASCII_FILENAME, getMessageContents(message));
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) RobolectricTest(com.fsck.k9.RobolectricTest) Test(org.junit.Test)

Example 32 with Attachment

use of com.fsck.k9.activity.misc.Attachment in project k-9 by k9mail.

the class MessageBuilderTest method build_withAttachment_longFileName.

@Test
public void build_withAttachment_longFileName() throws Exception {
    MessageBuilder messageBuilder = createSimpleMessageBuilder();
    Attachment attachment = createAttachmentWithContent("text/plain", "~~~~~~~~~1~~~~~~~~~2~~~~~~~~~3~~~~~~~~~4~~~~~~~~~5~~~~~~~~~6~~~~~~~~~7.txt", TEST_ATTACHMENT_TEXT);
    messageBuilder.setAttachments(Collections.singletonList(attachment));
    messageBuilder.buildAsync(callback);
    MimeMessage message = getMessageFromCallback();
    assertEquals(MESSAGE_HEADERS + MESSAGE_CONTENT_WITH_LONG_FILE_NAME, getMessageContents(message));
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) RobolectricTest(com.fsck.k9.RobolectricTest) Test(org.junit.Test)

Example 33 with Attachment

use of com.fsck.k9.activity.misc.Attachment in project k-9 by k9mail.

the class AttachmentPresenter method addAttachment.

private void addAttachment(Uri uri, String contentType, boolean allowMessageType, boolean internalAttachment) {
    if (attachments.containsKey(uri)) {
        return;
    }
    int loaderId = getNextFreeLoaderId();
    Attachment attachment = Attachment.createAttachment(uri, loaderId, contentType, allowMessageType, internalAttachment);
    addAttachmentAndStartLoader(attachment);
}
Also used : Attachment(com.fsck.k9.activity.misc.Attachment) InlineAttachment(com.fsck.k9.activity.misc.InlineAttachment)

Example 34 with Attachment

use of com.fsck.k9.activity.misc.Attachment 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) RobolectricTest(com.fsck.k9.RobolectricTest) Test(org.junit.Test)

Example 35 with Attachment

use of com.fsck.k9.activity.misc.Attachment 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) RobolectricTest(com.fsck.k9.RobolectricTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)12 Attachment (com.fsck.k9.activity.misc.Attachment)9 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)9 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)9 RobolectricTest (com.fsck.k9.RobolectricTest)8 MessagingException (com.fsck.k9.mail.MessagingException)7 Body (com.fsck.k9.mail.Body)6 BodyPart (com.fsck.k9.mail.BodyPart)6 Part (com.fsck.k9.mail.Part)6 InlineAttachment (com.fsck.k9.activity.misc.InlineAttachment)5 Multipart (com.fsck.k9.mail.Multipart)4 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)4 AttachmentViewInfo (com.fsck.k9.mailstore.AttachmentViewInfo)4 File (java.io.File)4 ArrayList (java.util.ArrayList)4 TextBody (com.fsck.k9.mail.internet.TextBody)3 SQLiteException (android.database.sqlite.SQLiteException)2 Uri (android.net.Uri)2 Address (com.fsck.k9.mail.Address)2 Html (com.fsck.k9.mail.internet.Viewable.Html)2