Help Needed !!
Hi,
I am trying to extract Parsing and Msg convertion ability from this code. My requirement is build a REST api interface to convert .msg file in to .eml file. I am more or less able to convert .msg file to Message object using MsgParser like below
MsgParser parser = new MsgParser(); Message msg = parser.parseMsg(new File("C:\Users\xyz\workspace\projects\demo\xyz.msg"));
However i am facing challenged in converting Message object to eml file using MsgWriter
MsgWriter writer = new MsgWriter(); writer.write(msg, new FileOutputStream("C:\Users\xyz\workspace\projects\demo\xyz.eml"));
These are the contents of my MsgContainer.write() method
public void write(Message msg, OutputStream out) throws IOException {
NPOIFSFileSystem fs = new NPOIFSFileSystem();
DirectoryNode root = fs.getRoot();
MsgContainer cont = new MsgContainer(msg);
cont.write(root);
fs.writeFilesystem(out);
fs.close();
}
Exception i see is
2020-03-03 10:52:37.069 INFO 18036 --- [nio-8080-exec-1] com.example.msgparser.MsgContainer : Msgontainer -> write null 2020-03-03 10:52:37.071 INFO 18036 --- [nio-8080-exec-1] c.example.msgparser.entries.SubstGEntry : SubstGEntry -> 55 - 31 2020-03-03 10:52:37.071 INFO 18036 --- [nio-8080-exec-1] c.example.msgparser.entries.SubstGEntry : __substg1.0_0037001F 2020-03-03 10:52:37.084 ERROR 18036 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: Can't read from a new stream before it has been written to] with root cause
java.lang.IllegalStateException: Can't read from a new stream before it has been written to
Please let me know if this is making sense or if you need more information. Any help is much appreciated.
Do you think you would be able to help me on this ?
Hi @payadav, this is funny, you have the exact same requirement as in #15
MsgWriter's purpose is to write .msg files. You may want to look at class MessageParserFactory, especially around line 63 : https://github.com/lolo101/MsgViewer/blob/01c8db511085eefb8cdd6d13fafeac58592c3ed0/MSGViewer/src/main/java/net/sourceforge/MSGViewer/factory/MessageParserFactory.java
For a hint about how to write a .eml file
Hello @payadav, could you resolve the problem? I intend to close this issue in the next few days if it is no more needed