Skip to content

Commit

Permalink
[26237] add handling of non String imap mail other text content
Browse files Browse the repository at this point in the history
  • Loading branch information
huthomas committed Mar 26, 2024
1 parent 02a3783 commit b5785d2
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ch.elexis.core.mail;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand All @@ -13,6 +14,7 @@
import javax.mail.internet.InternetAddress;

import org.apache.commons.io.IOUtils;
import org.slf4j.LoggerFactory;

import com.sun.mail.imap.IMAPMessage;

Expand Down Expand Up @@ -67,7 +69,19 @@ private void extractContent() throws MessagingException {

private void extractOtherContent(String contentType, Object content) {
if (contentType.toLowerCase().contains("text/plain")) {
text = (String) content;
if (content instanceof String) {
text = (String) content;
} else if (content instanceof InputStream) {
try {
text = IOUtils.toString((InputStream) content, "ISO-8859-1");
} catch (IOException e) {
LoggerFactory.getLogger(getClass()).warn("Error extraction other content", e);
}
} else {
LoggerFactory.getLogger(getClass()).warn("Unknown other content [" + content + "]");
}
} else {
LoggerFactory.getLogger(getClass()).warn("Unknown other content type [" + contentType + "]");
}
}

Expand Down

0 comments on commit b5785d2

Please sign in to comment.