Search in sources :

Example 21 with MimeType

use of com.fsck.k9.mail.MimeType in project k-9 by k9mail.

the class MessageExtractor method getTextFromPart.

public static String getTextFromPart(Part part, long textSizeLimit) {
    if (part == null) {
        throw new IllegalArgumentException("Argument 'part' must not be null");
    }
    try {
        Body body = part.getBody();
        if (body == null) {
            Timber.v("No body present for this message part");
            return null;
        }
        if (body instanceof TextBody) {
            TextBody textBody = (TextBody) body;
            return textBody.getRawText();
        }
        String mimeType = part.getMimeType();
        if (mimeType != null && MimeUtility.mimeTypeMatches(mimeType, "text/*") || part.isMimeType("application/pgp")) {
            return getTextFromTextPart(part, body, mimeType, textSizeLimit);
        }
        Timber.w("Provided non-text part: %s", mimeType);
    } catch (IOException | MessagingException e) {
        Timber.e(e, "Unable to getTextFromPart");
    }
    return null;
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) IOException(java.io.IOException) Body(com.fsck.k9.mail.Body)

Aggregations

Body (com.fsck.k9.mail.Body)8 Multipart (com.fsck.k9.mail.Multipart)8 BodyPart (com.fsck.k9.mail.BodyPart)6 Part (com.fsck.k9.mail.Part)6 MessagingException (com.fsck.k9.mail.MessagingException)4 IOException (java.io.IOException)4 Message (com.fsck.k9.mail.Message)3 MimeType (com.fsck.k9.mail.MimeType)3 File (java.io.File)3 ContentValues (android.content.ContentValues)2 Uri (android.net.Uri)2 Nullable (androidx.annotation.Nullable)2 Account (com.fsck.k9.Account)2 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)2 MimeHeader (com.fsck.k9.mail.internet.MimeHeader)2 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)2 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)2 Cursor (android.database.Cursor)1 RobolectricTest (com.fsck.k9.RobolectricTest)1 Address (com.fsck.k9.mail.Address)1