Search in sources :

Example 26 with Attachment

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

the class AttachmentPresenter method addAttachment.

private void addAttachment(AttachmentViewInfo attachmentViewInfo) {
    if (attachments.containsKey(attachmentViewInfo.internalUri)) {
        throw new IllegalStateException("Received the same attachmentViewInfo twice!");
    }
    int loaderId = getNextFreeLoaderId();
    Attachment attachment = Attachment.createAttachment(attachmentViewInfo.internalUri, loaderId, attachmentViewInfo.mimeType);
    attachment = attachment.deriveWithMetadataLoaded(attachmentViewInfo.mimeType, attachmentViewInfo.displayName, attachmentViewInfo.size);
    addAttachmentAndStartLoader(attachment);
}
Also used : Attachment(com.fsck.k9.activity.misc.Attachment)

Example 27 with Attachment

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

the class MessageTest method nestedMessage.

private MimeMessage nestedMessage(MimeMessage subMessage) throws MessagingException, IOException {
    BinaryTempFileMessageBody tempMessageBody = new BinaryTempFileMessageBody(MimeUtil.ENC_8BIT);
    OutputStream out = tempMessageBody.getOutputStream();
    try {
        subMessage.writeTo(out);
    } finally {
        out.close();
    }
    MimeBodyPart bodyPart = new MimeBodyPart(tempMessageBody, "message/rfc822");
    bodyPart.setHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, "attachment");
    bodyPart.setEncoding(MimeUtil.ENC_7BIT);
    MimeMessage parentMessage = sampleMessage();
    ((Multipart) parentMessage.getBody()).addBodyPart(bodyPart);
    return parentMessage;
}
Also used : MimeMultipart(com.fsck.k9.mail.internet.MimeMultipart) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) BinaryTempFileMessageBody(com.fsck.k9.mail.internet.BinaryTempFileMessageBody) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart)

Example 28 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) Test(org.junit.Test)

Example 29 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) Test(org.junit.Test)

Aggregations

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