I am trying to write the raw text of a multi part mime to a stream then break up that stream into 32k chuncks that I will post to a php server.
My problem is I cannot seem to get a handle on the text in the stream.
My print ln shows the content I am trying to retrieve but my file does not get created and I cannot output the stream to the console.
I am so close I can feel it… ![]()
Any idea’s anyone?
iks in advance
Stream stream = session.createStream();
stream.writeText(mime.getHeaders());
System.out.println(mime.getHeaders());
// If multipart MIME entity
if (mime.getContentType().equals("multipart")) {
// Add contents of each child entity to the stream
MIMEEntity child1 = mime.getFirstChildEntity();
while (child1 != null) {
if (child1.getEncoding() != MIMEEntity.ENC_BASE64) {
child1.decodeContent();
child1.encodeContent(MIMEEntity.ENC_BASE64);
}
stream.writeText(child1.getBoundaryStart() +
child1.getContentAsText() +
child1.getBoundaryEnd());
System.out.println(child1.getBoundaryStart() +
child1.getContentAsText() +
child1.getBoundaryEnd());
MIMEEntity child2 = child1.getFirstChildEntity();
if (child2 == null) {
child2 = child1.getNextSibling();
if (child2 == null) {
child2 = child1.getParentEntity();
if (child2 != null)
child2 = child2.getNextSibling();
}
}
child1 = child2;
}
}
// If not multipart, just print content
else {
if (mime.getEncoding() != MIMEEntity.ENC_BASE64) {
mime.decodeContent();
mime.encodeContent(MIMEEntity.ENC_BASE64);
}
stream.writeText(mime.getContentAsText());
System.out.println(mime.getContentAsText());
}
String outPath =
"c:\\StreamFiles\\tmp.txt";
Stream outStream = session.createStream();
if (outStream.open(outPath, "ASCII")) {
if (outStream.getBytes() == 0) {
System.out.println("file...");
outStream.write(stream.read());
outStream.close();
}
else
System.out.println("Output file exists and has content");
}
else
System.out.println("Output file open failed");