Search in sources :

Example 91 with MessagingException

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);
}
Also used : TextBody(com.fsck.k9.mail.internet.TextBody) MimeMultipart(com.fsck.k9.mail.internet.MimeMultipart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart)

Example 92 with MessagingException

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);
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException)

Example 93 with MessagingException

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);
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) MimeMultipart(com.fsck.k9.mail.internet.MimeMultipart) BinaryMemoryBody(com.fsck.k9.mailstore.BinaryMemoryBody)

Example 94 with MessagingException

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);
    }
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) MessagingException(com.fsck.k9.mail.MessagingException)

Example 95 with MessagingException

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");
}
Also used : Address(com.fsck.k9.mail.Address) Date(java.util.Date)

Aggregations

MessagingException (com.fsck.k9.mail.MessagingException)159 Test (org.junit.Test)73 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)52 LocalFolder (com.fsck.k9.mailstore.LocalFolder)49 LocalStore (com.fsck.k9.mailstore.LocalStore)49 ArrayList (java.util.ArrayList)49 Message (com.fsck.k9.mail.Message)44 LocalMessage (com.fsck.k9.mailstore.LocalMessage)42 IOException (java.io.IOException)42 FetchProfile (com.fsck.k9.mail.FetchProfile)30 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)28 ByteArrayOutputStream (java.io.ByteArrayOutputStream)27 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)26 BodyPart (com.fsck.k9.mail.BodyPart)23 Part (com.fsck.k9.mail.Part)22 Account (com.fsck.k9.Account)21 Body (com.fsck.k9.mail.Body)21 TextBody (com.fsck.k9.mail.internet.TextBody)21 Date (java.util.Date)20 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)18