Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lasombra opened this issue Aug 5, 2020 · 6 comments

Comments

@lasombra
Copy link

lasombra commented Aug 5, 2020

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);
		}
	}
@bbottema
Copy link
Owner

bbottema commented Aug 5, 2020

Yikes, I just added support for SharedByteArrayInputStream 😅

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

@bbottema bbottema added this to the 6.4.3 milestone Aug 5, 2020
@bbottema
Copy link
Owner

bbottema commented Aug 5, 2020

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?

@lasombra
Copy link
Author

lasombra commented Aug 5, 2020

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?

@bbottema
Copy link
Owner

bbottema commented Aug 5, 2020

Absolutely, that would be much appreciated!

@bbottema
Copy link
Owner

bbottema commented Aug 6, 2020

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

@bbottema bbottema closed this as completed Aug 6, 2020
@lasombra
Copy link
Author

lasombra commented Aug 6, 2020

Thank you for the hard work and quick fixes!

@bbottema bbottema changed the title ClassCastException when parsing "text/calendar" with Content-Transfer-Encoding: quoted-printable Bugfix: Fix support for reading Calendar attachments with quoted-printable transfer-type Oct 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants