writeTo Implementation in Multipart is broken.
-----------------------------------------------
Key: MIME4J-38
URL: https://issues.apache.org/jira/browse/MIME4J-38
Project: Mime4j
Issue Type: Bug
Environment: Java 1.6
Reporter: Aljoscha Rittner
This is a typical mixed-buffered/nonbuffered-Stream Bug ;-)
This is the implementation in writeTo:
---------------------------------------------------------------------------
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out,
CharsetUtil.getCharset(getCharset())),8192);
writer.write(getPreamble() + "\r\n");
for (int i = 0; i < bodyParts.size(); i++) {
writer.write(boundary + "\r\n");
((BodyPart) bodyParts.get(i)).writeTo(out);
}
writer.write(getEpilogue() + "\r\n");
writer.write(boundary + "--" + "\r\n");
---------------------------------------------------------------------------
But all writer.write (...) Strings get lost in the buffer. The non buffered
writes throw the OutputStreamWriter are ok. This writeTo method creates
Multipart-Messages without any boundary.
A mix with buffered and non buffered streams is very danger. This is the right
(but ugly) implementation:
---------------------------------------------------------------------------
writer.write(getPreamble() + "\r\n");
writer.flush();
for (int i = 0; i < bodyParts.size(); i++) {
writer.write(boundary + "\r\n");
writer.flush();
((BodyPart) bodyParts.get(i)).writeTo(out);
}
writer.write(getEpilogue() + "\r\n");
writer.write(boundary + "--" + "\r\n");
writer.flush();
---------------------------------------------------------------------------
best regards,
josh.
--
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]