use of com.fsck.k9.mail.MessagingException in project k-9 by k9mail.
the class PgpMessageBuilder method mimeBuildEncryptedMessage.
private void mimeBuildEncryptedMessage(@NonNull Body encryptedBodyPart) throws MessagingException {
MimeMultipart multipartEncrypted = createMimeMultipart();
multipartEncrypted.setSubType("encrypted");
multipartEncrypted.addBodyPart(MimeBodyPart.create(new TextBody("Version: 1"), "application/pgp-encrypted"));
MimeBodyPart encryptedPart = MimeBodyPart.create(encryptedBodyPart, "application/octet-stream; name=\"encrypted.asc\"");
encryptedPart.addHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, "inline; filename=\"encrypted.asc\"");
multipartEncrypted.addBodyPart(encryptedPart);
MimeMessageHelper.setBody(currentProcessedMimeMessage, multipartEncrypted);
String contentType = String.format("multipart/encrypted; boundary=\"%s\";\r\n protocol=\"application/pgp-encrypted\"", multipartEncrypted.getBoundary());
currentProcessedMimeMessage.setHeader(MimeHeader.HEADER_CONTENT_TYPE, contentType);
}
use of com.fsck.k9.mail.MessagingException in project k-9 by k9mail.
the class PgpMessageBuilder method buildMessageInternal.
@Override
protected void buildMessageInternal() {
if (currentProcessedMimeMessage != null) {
throw new IllegalStateException("message can only be built once!");
}
if (cryptoStatus == null) {
throw new IllegalStateException("PgpMessageBuilder must have cryptoStatus set before building!");
}
Long openPgpKeyId = cryptoStatus.getOpenPgpKeyId();
try {
currentProcessedMimeMessage = build();
} catch (MessagingException me) {
queueMessageBuildException(me);
return;
}
if (openPgpKeyId == null) {
queueMessageBuildSuccess(currentProcessedMimeMessage);
return;
}
if (!cryptoStatus.isProviderStateOk()) {
queueMessageBuildException(new MessagingException("OpenPGP Provider is not ready!"));
return;
}
addAutocryptHeaderIfAvailable(openPgpKeyId);
if (isDraft()) {
addDraftStateHeader();
}
startOrContinueBuildMessage(null);
}
use of com.fsck.k9.mail.MessagingException 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(MimeBodyPart.create(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.mail.MessagingException in project k-9 by k9mail.
the class SimpleMessageBuilder method buildMessageInternal.
@Override
protected void buildMessageInternal() {
try {
MimeMessage message = build();
queueMessageBuildSuccess(message);
} catch (MessagingException me) {
queueMessageBuildException(me);
}
}
use of com.fsck.k9.mail.MessagingException in project k-9 by k9mail.
the class MessageViewInfoExtractor method addMessageHeaderText.
/**
* Extract important header values from a message to display inline (plain text version).
*
* @param text
* The {@link StringBuilder} that will receive the (plain text) output.
* @param message
* The message to extract the header values from.
*
* @throws com.fsck.k9.mail.MessagingException
* In case of an error.
*/
private void addMessageHeaderText(StringBuilder text, Message message) throws MessagingException {
// From: <sender>
Address[] from = message.getFrom();
if (from != null && from.length > 0) {
text.append(resourceProvider.messageHeaderFrom());
text.append(' ');
text.append(Address.toString(from));
text.append("\r\n");
}
// To: <recipients>
Address[] to = message.getRecipients(Message.RecipientType.TO);
if (to != null && to.length > 0) {
text.append(resourceProvider.messageHeaderTo());
text.append(' ');
text.append(Address.toString(to));
text.append("\r\n");
}
// Cc: <recipients>
Address[] cc = message.getRecipients(Message.RecipientType.CC);
if (cc != null && cc.length > 0) {
text.append(resourceProvider.messageHeaderCc());
text.append(' ');
text.append(Address.toString(cc));
text.append("\r\n");
}
// Date: <date>
Date date = message.getSentDate();
if (date != null) {
text.append(resourceProvider.messageHeaderDate());
text.append(' ');
text.append(date.toString());
text.append("\r\n");
}
// Subject: <subject>
String subject = message.getSubject();
text.append(resourceProvider.messageHeaderSubject());
text.append(' ');
if (subject == null) {
text.append(resourceProvider.noSubject());
} else {
text.append(subject);
}
text.append("\r\n\r\n");
}
Aggregations