public class MsgParser
extends java.lang.Object
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.
MsgParser msgp = new MsgParser();
Message msg = msgp.parseMsg("test.msg");
Modifier and Type | Field and Description |
---|---|
protected static java.util.logging.Logger |
logger |
Constructor and Description |
---|
MsgParser()
Empty constructor.
|
Modifier and Type | Method and Description |
---|---|
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 java.lang.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(java.io.File msgFile)
Parses a .msg file provided in the specified file.
|
Message |
parseMsg(java.io.InputStream msgFileStream)
Parses a .msg file provided by an input stream.
|
Message |
parseMsg(java.io.InputStream msgFileStream,
boolean closeStream)
Parses a .msg file provided by an input stream.
|
Message |
parseMsg(java.lang.String msgFile)
Parses a .msg file provided in the specified file.
|
public Message parseMsg(java.io.File msgFile) throws java.io.IOException, java.lang.UnsupportedOperationException
msgFile
- The .msg file.Message
object representing the .msg file.java.io.IOException
- Thrown if the file could not be loaded or parsed.java.lang.UnsupportedOperationException
- Thrown if the .msg file cannot
be parsed correctly.public Message parseMsg(java.lang.String msgFile) throws java.io.IOException, java.lang.UnsupportedOperationException
msgFile
- The .msg file as a String path.Message
object representing the .msg file.java.io.IOException
- Thrown if the file could not be loaded or parsed.java.lang.UnsupportedOperationException
- Thrown if the .msg file cannot
be parsed correctly.public Message parseMsg(java.io.InputStream msgFileStream) throws java.io.IOException, java.lang.UnsupportedOperationException
msgFileStream
- The .msg file as a InputStream.Message
object representing the .msg file.java.io.IOException
- Thrown if the file could not be loaded or parsed.java.lang.UnsupportedOperationException
- Thrown if the .msg file cannot
be parsed correctly.public Message parseMsg(java.io.InputStream msgFileStream, boolean closeStream) throws java.io.IOException, java.lang.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.java.io.IOException
- Thrown if the file could not be loaded or parsed.java.lang.UnsupportedOperationException
- Thrown if the .msg file cannot
be parsed correctly.protected void checkDirectoryEntry(org.apache.poi.poifs.filesystem.DirectoryEntry dir, Message msg) throws java.io.IOException, java.lang.UnsupportedOperationException
Message
object.dir
- The current node in the .msg file.msg
- The resulting Message
object.java.io.IOException
- Thrown if the .msg file could not
be parsed.java.lang.UnsupportedOperationException
- Thrown if
the .msg file contains unknown data.protected void checkRecipientDirectoryEntry(org.apache.poi.poifs.filesystem.DirectoryEntry dir, Message msg) throws java.io.IOException, java.lang.UnsupportedOperationException
Message
object.dir
- The current node in the .msg file.msg
- The resulting Message
object.java.io.IOException
- Thrown if the .msg file could not
be parsed.java.lang.UnsupportedOperationException
- Thrown if
the .msg file contains unknown data.protected java.lang.Object getData(org.apache.poi.poifs.filesystem.DocumentInputStream dstream, FieldInformation info) throws java.io.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.java.io.IOException
- Thrown if the .msg file could not
be parsed.java.lang.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 java.io.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.java.io.IOException
- Thrown if the attachment could
not be parsed/read.This software is published under the BSD license. Copyright © 2003-${build.year}, CRIXP AG, Switzerland, All rights reserved. Use is subject to license terms.