[
https://issues.apache.org/jira/browse/MIME4J-48?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12612775#action_12612775
]
Niklas Therning commented on MIME4J-48:
---------------------------------------
After some debugging I've figured out that the InputBuffer passed to the new
MimeEntity in nextMessage() also needs to read from the
QuotedPrintableInputStream. I've changed nextMessage() into this:
private EntityStateMachine nextMessage() {
String transferEncoding = body.getTransferEncoding();
InputStream instream;
InputBuffer buffer;
if (MimeUtil.isBase64Encoding(transferEncoding)) {
log.debug("base64 encoded message/rfc822 detected");
instream = new Base64InputStream(dataStream);
buffer = new InputBuffer(instream, 4 * 1024);
} else if (MimeUtil.isQuotedPrintableEncoded(transferEncoding)) {
log.debug("quoted-printable encoded message/rfc822 detected");
instream = new QuotedPrintableInputStream(dataStream);
buffer = new InputBuffer(instream, 4 * 1024);
} else {
instream = dataStream;
buffer = inbuffer;
}
if (recursionMode == RecursionMode.M_RAW) {
RawEntity message = new RawEntity(instream);
return message;
} else {
MimeEntity message = new MimeEntity(
rootStream,
instream,
buffer,
body,
EntityStates.T_START_MESSAGE,
EntityStates.T_END_MESSAGE,
maximalBodyDescriptor,
strictParsing);
message.setRecursionMode(recursionMode);
return message;
}
}
This seems to work as expected. Oleg, can you confirm that this is a proper fix
for the problem?
> NPE when parsing embedded quoted printable encoded message
> ----------------------------------------------------------
>
> Key: MIME4J-48
> URL: https://issues.apache.org/jira/browse/MIME4J-48
> Project: Mime4j
> Issue Type: Bug
> Affects Versions: 0.4
> Reporter: Niklas Therning
> Fix For: 0.4
>
> Attachments: 36442979.msg
>
>
> When trying to parse a message which contains an embedded quoted printable
> message I received a NullPointerException:
> Exception in thread "main" java.lang.NullPointerException
> at
> org.apache.james.mime4j.decoder.QuotedPrintableInputStream.populatePushbackQueue(QuotedPrintableInputStream.java:85)
> at
> org.apache.james.mime4j.decoder.QuotedPrintableInputStream.fillBuffer(QuotedPrintableInputStream.java:119)
> at
> org.apache.james.mime4j.decoder.QuotedPrintableInputStream.read(QuotedPrintableInputStream.java:57)
> at
> org.apache.james.mime4j.BufferingInputStreamAdaptor.doReadLine(BufferingInputStreamAdaptor.java:78)
> at
> org.apache.james.mime4j.BufferingInputStreamAdaptor.readLine(BufferingInputStreamAdaptor.java:68)
> at
> org.apache.james.mime4j.AbstractEntity.fillFieldBuffer(AbstractEntity.java:129)
> at
> org.apache.james.mime4j.AbstractEntity.parseField(AbstractEntity.java:162)
> at org.apache.james.mime4j.MimeEntity.advance(MimeEntity.java:97)
> at
> org.apache.james.mime4j.MimeTokenStream.next(MimeTokenStream.java:363)
> at Mime4jTest.main(Mime4jTest.java:83)
> I've figured out that it is the following code in MimeEntity which passes the
> null stream when creating the QuotedPrintableInputStream:
> private EntityStateMachine nextMessage() {
> String transferEncoding = body.getTransferEncoding();
> InputStream instream;
> if (MimeUtil.isBase64Encoding(transferEncoding)) {
> log.debug("base64 encoded message/rfc822 detected");
> instream = new Base64InputStream(mimeStream);
> } else if (MimeUtil.isQuotedPrintableEncoded(transferEncoding)) {
> log.debug("quoted-printable encoded message/rfc822 detected");
> instream = new QuotedPrintableInputStream(mimeStream);
>
> } else {
> instream = dataStream;
> }
> mimeStream seems to be null in this situation. I've tried to use dataStream
> instead of mimeStream. This seems to work better but when I do that I get an
> infinite loop when trying to parse an embedded multipart message which has
> =3D in its boundary. I'll attach such a message.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]