Handle IMAPInputStream in getMessage to prevent ClassCastException

FixEmailService
Shipped
April 26, 2026 at 4:19 AM UTC
Author
Kamo
Commit
5616354

JavaMail can return an IMAPInputStream instead of a decoded String from part.getContent() when message content has not been pre-fetched. The direct (String) casts in parseMultipart() threw ClassCastException for affected messages, causing fetchFullMessage to fail before mark-as-read was called, so emails never got marked read in classic mode. Add partContentAsString() helper that checks instanceof String first, then falls back to reading an InputStream with the part's charset. Add extractCharset() to parse charset from Content-Type header. Update parseMultipart() to use the helper for all text/* body parts. Also add InputStream branch to top-level getMessage() body parsing for single-part messages whose content arrives as a raw stream.

All changes

Like what you see shipping?

Every one of these updates lands in your workspace automatically. Start free and watch it grow week after week.

Start Free ForeverView Pricing