From 671ef37186e80d7480462105e015d418ddb90dc2 Mon Sep 17 00:00:00 2001 From: J-N-K Date: Wed, 27 Mar 2024 05:17:45 +0100 Subject: [PATCH] [mail] Fix content processing (#16580) Signed-off-by: Jan N. Klug Signed-off-by: Ciprian Pascu --- .../openhab/binding/mail/internal/POP3IMAPHandler.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bundles/org.openhab.binding.mail/src/main/java/org/openhab/binding/mail/internal/POP3IMAPHandler.java b/bundles/org.openhab.binding.mail/src/main/java/org/openhab/binding/mail/internal/POP3IMAPHandler.java index 984c80387c6..dd9b261117a 100644 --- a/bundles/org.openhab.binding.mail/src/main/java/org/openhab/binding/mail/internal/POP3IMAPHandler.java +++ b/bundles/org.openhab.binding.mail/src/main/java/org/openhab/binding/mail/internal/POP3IMAPHandler.java @@ -52,6 +52,8 @@ import org.openhab.core.types.Command; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.sun.mail.imap.IMAPInputStream; + /** * The {@link POP3IMAPHandler} is responsible for handling commands, which are * sent to one of the channels. @@ -184,6 +186,14 @@ public class POP3IMAPHandler extends BaseThingHandler { mimeMultipart.writeTo(os); contentAsString = os.toString(); } + } else if (rawContent instanceof IMAPInputStream imapInputStream) { + logger.trace("Detected IMAPInputStream message"); + try { + contentAsString = new String(imapInputStream.readAllBytes()); + } catch (IOException e) { + logger.warn("Could not read from stream: {}", e.getMessage(), e); + continue; + } } else { logger.warn( "Failed to convert mail content from '{}' with subject '{}', to String: {}",