Search in sources :

Example 61 with Body

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

the class ImapFolderTest method buildImapFetchResponse.

private ImapResponse buildImapFetchResponse(ImapResponseCallback callback) {
    ImapResponse response = ImapResponse.newContinuationRequest(callback);
    response.add("1");
    response.add("FETCH");
    ImapList fetchList = new ImapList();
    fetchList.add("UID");
    fetchList.add("1");
    fetchList.add("BODY");
    fetchList.add("1.1");
    fetchList.add("text");
    response.add(fetchList);
    return response;
}
Also used : ImapResponseHelper.createImapResponse(com.fsck.k9.mail.store.imap.ImapResponseHelper.createImapResponse)

Example 62 with Body

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

the class MessageTest method textBodyPart.

private MimeBodyPart textBodyPart() throws MessagingException {
    TextBody textBody = new TextBody("Testing.\r\n" + "This is a text body with some greek characters.\r\n" + "αβγδεζηθ\r\n" + "End of test.\r\n");
    textBody.setCharset("utf-8");
    MimeBodyPart bodyPart = new MimeBodyPart();
    MimeMessageHelper.setBody(bodyPart, textBody);
    CharsetSupport.setCharset("utf-8", bodyPart);
    return bodyPart;
}
Also used : TextBody(com.fsck.k9.mail.internet.TextBody) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart)

Example 63 with Body

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

the class ReconstructMessageFromDatabaseTest method testAddMissingPart.

public void testAddMissingPart() throws MessagingException, IOException {
    LocalFolder folder = createFolderInDatabase();
    MimeMessage message = new MimeMessage();
    message.addHeader("To", "to@example.com");
    message.addHeader("MIME-Version", "1.0");
    message.addHeader("Content-Type", "text/plain");
    message.setServerExtra("text");
    saveMessageToDatabase(folder, message);
    LocalMessage localMessage = readMessageFromDatabase(folder, message);
    assertEquals("to@example.com", localMessage.getHeader("To")[0]);
    assertEquals("text/plain", localMessage.getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0]);
    assertEquals("text", localMessage.getServerExtra());
    assertNull(localMessage.getBody());
    Body body = new BinaryMemoryBody("Test message body".getBytes(), MimeUtil.ENC_7BIT);
    localMessage.setBody(body);
    folder.addPartToMessage(localMessage, localMessage);
    LocalMessage completeLocalMessage = readMessageFromDatabase(folder, message);
    String reconstructedMessage = writeMessageToString(completeLocalMessage);
    assertEquals("To: to@example.com\r\n" + "MIME-Version: 1.0\r\n" + "Content-Type: text/plain\r\n" + "\r\n" + "Test message body", reconstructedMessage);
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) BinaryTempFileBody(com.fsck.k9.mail.internet.BinaryTempFileBody) Body(com.fsck.k9.mail.Body)

Example 64 with Body

use of com.fsck.k9.mail.Body in project sms-backup-plus by jberkel.

the class Attachment method createPart.

private static MimeBodyPart createPart(Body body, final String filename, final String contentType) throws MessagingException {
    MimeBodyPart part = new MimeBodyPart(body, contentType);
    String contentTypeHeader = TextUtils.isEmpty(contentType) ? "application/octet-stream" : contentType;
    String disposition = "attachment";
    if (!TextUtils.isEmpty(filename)) {
        // should set both name and filename parameters
        // http://www.imc.org/ietf-smtp/mail-archive/msg05023.html
        disposition += encodeRFC2231("filename", filename);
        contentTypeHeader += encodeRFC2231("name", filename);
    }
    part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, contentTypeHeader);
    part.setHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, disposition);
    part.setHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING, "base64");
    return part;
}
Also used : MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart)

Example 65 with Body

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

the class MessageCryptoStructureDetector method findPrimaryPartInMixed.

@Nullable
private static Part findPrimaryPartInMixed(Part part, List<Part> outputExtraParts) {
    Body body = part.getBody();
    boolean isMultipartMixed = part.isMimeType("multipart/mixed") && body instanceof Multipart;
    if (!isMultipartMixed) {
        return null;
    }
    Multipart multipart = (Multipart) body;
    if (multipart.getCount() == 0) {
        return null;
    }
    BodyPart firstBodyPart = multipart.getBodyPart(0);
    Part foundPart;
    if (isPartEncryptedOrSigned(firstBodyPart)) {
        foundPart = firstBodyPart;
    } else {
        foundPart = findPrimaryPartInAlternative(firstBodyPart);
    }
    if (foundPart != null && outputExtraParts != null) {
        for (int i = 1; i < multipart.getCount(); i++) {
            outputExtraParts.add(multipart.getBodyPart(i));
        }
    }
    return foundPart;
}
Also used : BodyPart(com.fsck.k9.mail.BodyPart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) MimeMultipart(com.fsck.k9.mail.internet.MimeMultipart) Multipart(com.fsck.k9.mail.Multipart) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) Body(com.fsck.k9.mail.Body) Nullable(androidx.annotation.Nullable)

Aggregations

Body (com.fsck.k9.mail.Body)44 BodyPart (com.fsck.k9.mail.BodyPart)35 Multipart (com.fsck.k9.mail.Multipart)32 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)32 Part (com.fsck.k9.mail.Part)29 Test (org.junit.Test)29 TextBody (com.fsck.k9.mail.internet.TextBody)23 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)21 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)19 ArrayList (java.util.ArrayList)16 MessagingException (com.fsck.k9.mail.MessagingException)14 BinaryTempFileBody (com.fsck.k9.mail.internet.BinaryTempFileBody)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 Message (com.fsck.k9.mail.Message)9 OutputStream (java.io.OutputStream)9 Stack (java.util.Stack)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 K9RobolectricTest (com.fsck.k9.K9RobolectricTest)7 BinaryMemoryBody (com.fsck.k9.mailstore.BinaryMemoryBody)7 InputStream (java.io.InputStream)7