Search in sources :

Example 1 with BinaryMemoryBody

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

the class PgpMessageBuilder method mimeBuildSignedMessage.

private void mimeBuildSignedMessage(@NonNull BodyPart signedBodyPart, Intent result) throws MessagingException {
    if (!cryptoStatus.isSigningEnabled()) {
        throw new IllegalStateException("call to mimeBuildSignedMessage while signing isn't enabled!");
    }
    byte[] signedData = result.getByteArrayExtra(OpenPgpApi.RESULT_DETACHED_SIGNATURE);
    if (signedData == null) {
        throw new MessagingException("didn't find expected RESULT_DETACHED_SIGNATURE in api call result");
    }
    MimeMultipart multipartSigned = createMimeMultipart();
    multipartSigned.setSubType("signed");
    multipartSigned.addBodyPart(signedBodyPart);
    multipartSigned.addBodyPart(new MimeBodyPart(new BinaryMemoryBody(signedData, MimeUtil.ENC_7BIT), "application/pgp-signature; name=\"signature.asc\""));
    MimeMessageHelper.setBody(currentProcessedMimeMessage, multipartSigned);
    String contentType = String.format("multipart/signed; boundary=\"%s\";\r\n  protocol=\"application/pgp-signature\"", multipartSigned.getBoundary());
    if (result.hasExtra(OpenPgpApi.RESULT_SIGNATURE_MICALG)) {
        String micAlgParameter = result.getStringExtra(OpenPgpApi.RESULT_SIGNATURE_MICALG);
        contentType += String.format("; micalg=\"%s\"", micAlgParameter);
    } else {
        Timber.e("missing micalg parameter for pgp multipart/signed!");
    }
    currentProcessedMimeMessage.setHeader(MimeHeader.HEADER_CONTENT_TYPE, contentType);
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) MimeMultipart(com.fsck.k9.mail.internet.MimeMultipart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) BinaryMemoryBody(com.fsck.k9.mailstore.BinaryMemoryBody)

Example 2 with BinaryMemoryBody

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

the class MigrationTest method migratePgpInlineEncryptedMessage.

@Test
public void migratePgpInlineEncryptedMessage() throws Exception {
    SQLiteDatabase db = createV50Database();
    insertPgpInlineEncryptedMessage(db);
    db.close();
    LocalStore localStore = LocalStore.getInstance(account, RuntimeEnvironment.application);
    LocalMessage msg = localStore.getFolder("dev").getMessage("7");
    FetchProfile fp = new FetchProfile();
    fp.add(FetchProfile.Item.BODY);
    localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null);
    Assert.assertEquals(6, msg.getId());
    Assert.assertEquals(12, msg.getHeaderNames().size());
    Assert.assertEquals("text/plain", msg.getMimeType());
    Assert.assertEquals(0, msg.getAttachmentCount());
    Assert.assertTrue(msg.getBody() instanceof BinaryMemoryBody);
    String msgTextContent = MessageExtractor.getTextFromPart(msg);
    Assert.assertEquals(OpenPgpUtils.PARSE_RESULT_MESSAGE, OpenPgpUtils.parseMessage(msgTextContent));
}
Also used : FetchProfile(com.fsck.k9.mail.FetchProfile) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Test(org.junit.Test)

Example 3 with BinaryMemoryBody

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

the class MessageExtractorTest method getTextFromPart_withTextBody_shouldReturnText.

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

Example 4 with BinaryMemoryBody

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

the class MessageExtractorTest method getTextFromPart_withUnknownEncoding_shouldReturnUnmodifiedBodyContents.

@Test
public void getTextFromPart_withUnknownEncoding_shouldReturnUnmodifiedBodyContents() throws Exception {
    part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, "text/plain");
    String bodyText = "Sample text body";
    BinaryMemoryBody body = new BinaryMemoryBody(bodyText.getBytes(), "unknown encoding");
    part.setBody(body);
    String result = MessageExtractor.getTextFromPart(part);
    assertEquals(bodyText, result);
}
Also used : BinaryMemoryBody(com.fsck.k9.mailstore.BinaryMemoryBody) Test(org.junit.Test)

Example 5 with BinaryMemoryBody

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

the class MessageExtractorTest method getTextFromPart_withRawDataBodyWithNonText_shouldReturnNull.

@Test
public void getTextFromPart_withRawDataBodyWithNonText_shouldReturnNull() throws Exception {
    part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, "image/jpeg");
    BinaryMemoryBody body = new BinaryMemoryBody("Sample text body".getBytes(), MimeUtil.ENC_8BIT);
    part.setBody(body);
    String result = MessageExtractor.getTextFromPart(part);
    assertNull(result);
}
Also used : BinaryMemoryBody(com.fsck.k9.mailstore.BinaryMemoryBody) Test(org.junit.Test)

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