Search in sources :

Example 11 with BinaryMemoryBody

use of com.fsck.k9.mailstore.BinaryMemoryBody in project k-9 by k9mail.

the class MessageExtractorTest method getTextFromPart_withHtmlWithCharsetInContentTypeRawDataBody_shouldReturnHtmlText.

@Test
public void getTextFromPart_withHtmlWithCharsetInContentTypeRawDataBody_shouldReturnHtmlText() throws Exception {
    part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, "text/html; charset=UTF-8");
    BinaryMemoryBody body = new BinaryMemoryBody("<html><body>Sample text body</body></html>".getBytes(), MimeUtil.ENC_8BIT);
    part.setBody(body);
    String result = MessageExtractor.getTextFromPart(part);
    assertEquals("<html><body>Sample text body</body></html>", result);
}
Also used : BinaryMemoryBody(com.fsck.k9.mailstore.BinaryMemoryBody) Test(org.junit.Test)

Example 12 with BinaryMemoryBody

use of com.fsck.k9.mailstore.BinaryMemoryBody 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)

Aggregations

Test (org.junit.Test)9 BinaryMemoryBody (com.fsck.k9.mailstore.BinaryMemoryBody)7 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)3 FetchProfile (com.fsck.k9.mail.FetchProfile)3 Body (com.fsck.k9.mail.Body)2 BinaryTempFileBody (com.fsck.k9.mail.internet.BinaryTempFileBody)2 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)2 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)2 BodyPart (com.fsck.k9.mail.BodyPart)1 Message (com.fsck.k9.mail.Message)1 MessagingException (com.fsck.k9.mail.MessagingException)1 Multipart (com.fsck.k9.mail.Multipart)1 Part (com.fsck.k9.mail.Part)1 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)1 File (java.io.File)1