Search in sources :

Example 1 with MimeUtility.isSameMimeType

use of com.fsck.k9.mail.internet.MimeUtility.isSameMimeType in project k-9 by k9mail.

the class MessageFulltextCreator method extractText.

private String extractText(Message message) {
    Part textPart = textPartFinder.findFirstTextPart(message);
    if (textPart == null || hasEmptyBody(textPart)) {
        return null;
    }
    String text = MessageExtractor.getTextFromPart(textPart, MAX_CHARACTERS_CHECKED_FOR_FTS);
    String mimeType = textPart.getMimeType();
    if (!MimeUtility.isSameMimeType(mimeType, "text/html")) {
        return text;
    }
    return HtmlConverter.htmlToText(text);
}
Also used : Part(com.fsck.k9.mail.Part)

Example 2 with MimeUtility.isSameMimeType

use of com.fsck.k9.mail.internet.MimeUtility.isSameMimeType in project k-9 by k9mail.

the class PgpMessageBuilder method startOrContinueBuildMessage.

private void startOrContinueBuildMessage(@Nullable Intent pgpApiIntent) {
    try {
        boolean shouldSign = cryptoStatus.isSigningEnabled() && !isDraft();
        boolean shouldEncrypt = cryptoStatus.isEncryptionEnabled() || (isDraft() && cryptoStatus.isEncryptAllDrafts());
        boolean isPgpInlineMode = cryptoStatus.isPgpInlineModeEnabled() && !isDraft();
        if (!shouldSign && !shouldEncrypt) {
            queueMessageBuildSuccess(currentProcessedMimeMessage);
            return;
        }
        boolean isSimpleTextMessage = MimeUtility.isSameMimeType("text/plain", currentProcessedMimeMessage.getMimeType());
        if (isPgpInlineMode && !isSimpleTextMessage) {
            throw new MessagingException("Attachments are not supported in PGP/INLINE format!");
        }
        if (shouldEncrypt && !isDraft() && !cryptoStatus.hasRecipients()) {
            throw new MessagingException("Must have recipients to build message!");
        }
        if (messageContentBodyPart == null) {
            messageContentBodyPart = createBodyPartFromMessageContent();
            boolean payloadSupportsMimeHeaders = !isPgpInlineMode;
            if (payloadSupportsMimeHeaders) {
                if (cryptoStatus.isEncryptSubject() && shouldEncrypt) {
                    moveSubjectIntoEncryptedPayload();
                }
                maybeAddGossipHeadersToBodyPart();
            // unfortuntately, we can't store the Autocrypt-Draft-State header in the payload
            // see https://github.com/autocrypt/autocrypt/pull/376#issuecomment-384293480
            }
        }
        if (pgpApiIntent == null) {
            boolean encryptToSelfOnly = isDraft();
            pgpApiIntent = buildOpenPgpApiIntent(shouldSign, shouldEncrypt, encryptToSelfOnly, isPgpInlineMode);
        }
        PendingIntent returnedPendingIntent = launchOpenPgpApiIntent(pgpApiIntent, messageContentBodyPart, shouldEncrypt || isPgpInlineMode, shouldEncrypt || !isPgpInlineMode, isPgpInlineMode);
        if (returnedPendingIntent != null) {
            queueMessageBuildPendingIntent(returnedPendingIntent, REQUEST_USER_INTERACTION);
            return;
        }
        queueMessageBuildSuccess(currentProcessedMimeMessage);
    } catch (MessagingException me) {
        queueMessageBuildException(me);
    }
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) PendingIntent(android.app.PendingIntent)

Example 3 with MimeUtility.isSameMimeType

use of com.fsck.k9.mail.internet.MimeUtility.isSameMimeType in project k-9 by k9mail.

the class MessageFulltextCreator method createFulltext.

public String createFulltext(@NonNull Message message) {
    Part textPart = textPartFinder.findFirstTextPart(message);
    if (textPart == null || hasEmptyBody(textPart)) {
        return null;
    }
    String text = MessageExtractor.getTextFromPart(textPart, MAX_CHARACTERS_CHECKED_FOR_FTS);
    String mimeType = textPart.getMimeType();
    if (!MimeUtility.isSameMimeType(mimeType, "text/html")) {
        return text;
    }
    return HtmlConverter.htmlToText(text);
}
Also used : Part(com.fsck.k9.mail.Part)

Aggregations

Part (com.fsck.k9.mail.Part)2 PendingIntent (android.app.PendingIntent)1 MessagingException (com.fsck.k9.mail.MessagingException)1