|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.opencrx.application.uses.com.auxilii.msgparser.MsgParser
public class MsgParser
Main parser class that does the actual
parsing of the Outlook .msg file. It uses the
POI
library for parsing the .msg container file
and is based on a description posted by
Peter Fiskerstrand at
fileformat.info.
It parses the .msg file and stores the information
in a Message
object. Attachments are
put into an FileAttachment
object. Hence, please
keep in mind that the complete mail is held in the memory!
If an attachment is another .msg file, this
attachment is not processed as a normal attachment
but rather included as a MsgAttachment
. This
attached mail is, again, a Message
object
and may have further attachments and so on.
Note: this code has not been tested on a wide
range of .msg files. Use in production level
(as in any other level) at your own risk.
Usage:
MsgParser msgp = new MsgParser();
Message msg = msgp.parseMsg("test.msg");
Field Summary | |
---|---|
protected static Logger |
logger
|
Constructor Summary | |
---|---|
MsgParser()
Empty constructor. |
Method Summary | |
---|---|
protected FieldInformation |
analyzeDocumentEntry(org.apache.poi.poifs.filesystem.DocumentEntry de)
Analyzes the DocumentEntry and returns
a FieldInformation object containing the
class (the field name, so to say) and type of
the entry. |
protected void |
checkDirectoryEntry(org.apache.poi.poifs.filesystem.DirectoryEntry dir,
Message msg)
Recursively parses the complete .msg file with the help of the POI library. |
protected void |
checkRecipientDirectoryEntry(org.apache.poi.poifs.filesystem.DirectoryEntry dir,
Message msg)
Parses a recipient directory entry which holds informations about one of possibly multiple recipients. |
protected Object |
getData(org.apache.poi.poifs.filesystem.DocumentInputStream dstream,
FieldInformation info)
Reads the information from the InputStream and creates, based on the information in the FieldInformation object, either a String
or a byte[] (e.g., for attachments) Object
containing this data. |
protected void |
parseAttachment(org.apache.poi.poifs.filesystem.DirectoryEntry dir,
Message msg)
Creates an Attachment object based on
the given directory entry. |
Message |
parseMsg(File msgFile)
Parses a .msg file provided in the specified file. |
Message |
parseMsg(InputStream msgFileStream)
Parses a .msg file provided by an input stream. |
Message |
parseMsg(InputStream msgFileStream,
boolean closeStream)
Parses a .msg file provided by an input stream. |
Message |
parseMsg(String msgFile)
Parses a .msg file provided in the specified file. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final Logger logger
Constructor Detail |
---|
public MsgParser()
Method Detail |
---|
public Message parseMsg(File msgFile) throws IOException, UnsupportedOperationException
msgFile
- The .msg file.
Message
object representing the .msg file.
IOException
- Thrown if the file could not be loaded or parsed.
UnsupportedOperationException
- Thrown if the .msg file cannot
be parsed correctly.public Message parseMsg(String msgFile) throws IOException, UnsupportedOperationException
msgFile
- The .msg file as a String path.
Message
object representing the .msg file.
IOException
- Thrown if the file could not be loaded or parsed.
UnsupportedOperationException
- Thrown if the .msg file cannot
be parsed correctly.public Message parseMsg(InputStream msgFileStream) throws IOException, UnsupportedOperationException
msgFileStream
- The .msg file as a InputStream.
Message
object representing the .msg file.
IOException
- Thrown if the file could not be loaded or parsed.
UnsupportedOperationException
- Thrown if the .msg file cannot
be parsed correctly.public Message parseMsg(InputStream msgFileStream, boolean closeStream) throws IOException, UnsupportedOperationException
msgFileStream
- The .msg file as a InputStream.closeStream
- Indicates whether the provided stream should
be closed after the message has been read.
Message
object representing the .msg file.
IOException
- Thrown if the file could not be loaded or parsed.
UnsupportedOperationException
- Thrown if the .msg file cannot
be parsed correctly.protected void checkDirectoryEntry(org.apache.poi.poifs.filesystem.DirectoryEntry dir, Message msg) throws IOException, UnsupportedOperationException
Message
object.
dir
- The current node in the .msg file.msg
- The resulting Message
object.
IOException
- Thrown if the .msg file could not
be parsed.
UnsupportedOperationException
- Thrown if
the .msg file contains unknown data.protected void checkRecipientDirectoryEntry(org.apache.poi.poifs.filesystem.DirectoryEntry dir, Message msg) throws IOException, UnsupportedOperationException
Message
object.
dir
- The current node in the .msg file.msg
- The resulting Message
object.
IOException
- Thrown if the .msg file could not
be parsed.
UnsupportedOperationException
- Thrown if
the .msg file contains unknown data.protected Object getData(org.apache.poi.poifs.filesystem.DocumentInputStream dstream, FieldInformation info) throws IOException
FieldInformation
object, either a String
or a byte[] (e.g., for attachments) Object
containing this data.
dstream
- The InputStream of the Document Entry.info
- The field information that is needed to
determine the data type of the input stream.
IOException
- Thrown if the .msg file could not
be parsed.
UnsupportedOperationException
- Thrown if
the .msg file contains unknown data.protected FieldInformation analyzeDocumentEntry(org.apache.poi.poifs.filesystem.DocumentEntry de)
DocumentEntry
and returns
a FieldInformation
object containing the
class (the field name, so to say) and type of
the entry.
de
- The DocumentEntry
that should be examined.
FieldInformation
object containing class
and type of the document entry or, if the entry is
not an interesting field, an empty FieldInformation
object containing FieldInformation.UNKNOWN
class
and type.protected void parseAttachment(org.apache.poi.poifs.filesystem.DirectoryEntry dir, Message msg) throws IOException
Attachment
object based on
the given directory entry. The entry may either
point to an attached file or to an
attached .msg file, which will be added
as a MsgAttachment
object instead.
dir
- The directory entry containing the attachment
document entry and some other document entries
describing the attachment (name, extension, mime type, ...)msg
- The Message
object that this
attachment should be added to.
IOException
- Thrown if the attachment could
not be parsed/read.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |