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);
}
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));
}
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);
}
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);
}
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);
}
Aggregations