Improve logging in MessageExtractor.getTextFromPart()

This commit is contained in:
cketti 2021-06-02 00:34:38 +02:00
parent 63e6c61368
commit 4a65c5b4a0

View file

@ -44,27 +44,33 @@ public class MessageExtractor {
} }
public static String getTextFromPart(Part part, long textSizeLimit) { public static String getTextFromPart(Part part, long textSizeLimit) {
try { if (part == null) {
if ((part != null) && (part.getBody() != null)) { throw new IllegalArgumentException("Argument 'part' must not be null");
final Body body = part.getBody();
if (body instanceof TextBody) {
return ((TextBody) body).getRawText();
}
final String mimeType = part.getMimeType();
if (mimeType != null && MimeUtility.mimeTypeMatches(mimeType, "text/*") ||
part.isMimeType("application/pgp")) {
return getTextFromTextPart(part, body, mimeType, textSizeLimit);
} else {
throw new MessagingException("Provided non-text part: " + mimeType);
}
} else {
throw new MessagingException("Provided invalid part");
}
} catch (IOException e) {
Timber.e(e, "Unable to getTextFromPart");
} catch (MessagingException e) {
Timber.e("Unable to getTextFromPart");
} }
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; return null;
} }