bbottema / simple-java-mail

Simple API, Complex Emails (Jakarta Mail smtp wrapper)

Home Page:http://www.simplejavamail.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bugfix: Fix support for reading Calendar attachments with quoted-printable transfer-type

lasombra opened this issue · comments

JDK: AdoptOpenJDK 14.0.1 x86_64

As the title suggests, when parsing a multipart message with the following block:

Content-Type: text/calendar; charset=utf-8; method=REQUEST; name=meeting.ics
Content-Transfer-Encoding: quoted-printable

A ClassCastException is thrown:

java.lang.ClassCastException: class com.sun.mail.util.QPDecoderStream cannot be cast to class javax.mail.util.SharedByteArrayInputStream (com.sun.mail.util.QPDecoderStream and javax.mail.util.SharedByteArrayInputStream are in unnamed module of loader 'app')
	at org.simplejavamail.converter.internal.mimemessage.MimeMessageParser.parseMimePartTree(MimeMessageParser.java:160)
	at org.simplejavamail.converter.internal.mimemessage.MimeMessageParser.parseMimePartTree(MimeMessageParser.java:170)
	at org.simplejavamail.converter.internal.mimemessage.MimeMessageParser.parseMimeMessage(MimeMessageParser.java:141)
	at org.simplejavamail.converter.EmailConverter.mimeMessageToEmailBuilder(EmailConverter.java:118)
	at org.simplejavamail.converter.EmailConverter.emlToEmailBuilder(EmailConverter.java:374)
	at org.simplejavamail.converter.EmailConverter.emlToEmailBuilder(EmailConverter.java:353)
	at org.simplejavamail.converter.EmailConverter.emlToEmail(EmailConverter.java:287)
	at org.simplejavamail.converter.EmailConverter.emlToEmail(EmailConverter.java:279)
	at cx.hoffmann.maildir.Main$1.visitFile(Main.java:47)
	at cx.hoffmann.maildir.Main$1.visitFile(Main.java:43)
	at java.base/java.nio.file.Files.walkFileTree(Files.java:2804)
	at cx.hoffmann.maildir.Main.call(Main.java:43)
	at cx.hoffmann.maildir.Main.call(Main.java:17)
	at picocli.CommandLine.executeUserObject(CommandLine.java:1933)
	at picocli.CommandLine.access$1100(CommandLine.java:145)
	at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2332)
	at picocli.CommandLine$RunLast.handle(CommandLine.java:2326)
	at picocli.CommandLine$RunLast.handle(CommandLine.java:2291)
	at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2159)
	at picocli.CommandLine.execute(CommandLine.java:2058)
	at cx.hoffmann.maildir.Main.main(Main.java:28)

Here's the offending casting:

	public static <T> T parseContent(@NotNull final MimePart currentPart) {
		try {
			return (T) currentPart.getContent();
		} catch (IOException | MessagingException e) {
			throw new MimeMessageParseException(MimeMessageParseException.ERROR_PARSING_CONTENT, e);
		}
	}

Yikes, I just added support for SharedByteArrayInputStream 😅

I'll see what I can do for QPDecoderStream. I'm not familiar with this encoding yet.

ok, I think it's an easy fix. The only thing is I don't have testdata for this.

Are you able to share an sample email I can verify the solution with?

Hey, thanks for keeping looking at this, I really appreciate.

I can send you the file in private. There’s a bunch of encoded data I can’t disclose, I’m afraid. Would that be OK?

Absolutely, that would be much appreciated!

Fix released in 6.4.3. Thanks for your report and trust!

Thank you for the hard work and quick fixes!