com.mirrorworlds.lifestreams.mail.tnef
Class JTnef
java.lang.Object
|
+--com.mirrorworlds.lifestreams.mail.tnef.JTnef
- public class JTnef
- extends java.lang.Object
Creates MS-TNEF Message Objects given a inputstream of TNEF data.
(eg: winmail.dat file). Usage example:
try {
String filename = "winmail.dat";
//create message object using default parser and builder.
TnefMessage msg = JTnef.createTnefMessage(filename);
msg.printInfo(); // print debug info
int count = msg.getCount(); // get number of attachments.
for (int i = 0; i < count; i++) { // loop thru attachments and print
TnefAttachment a = msg.getAttachmentAt(i);
System.out.println(" -- ");
a.printInfo();
// content-type of attachment is a.getContentType();
// filename of attachment is a.getFilename();
// attachment stream is a.getInputStream();
// you can save attachment:
// File f = new File(a.getFilename);
// FileOutputStream fos = new FileOutputStream(f);
// a.writeTo(f); // save attachment.
}
}catch(Exception e) {
e.printStackTrace
}
If you want to, you could specify a TNEF stream parser and builder.
//get parser - this class parses the tnef byte streams
TnefStreamParser = new TnefStreamParserImpl();
// get the builder. The parser will call methods in the builder when
// the parser encounters tnef tokens, attributes, data etc. The builder
// will take this information to build a TnefMessage class.
TnefBuilder builder = new TnefMessageBuilder();
//associate the builder to the parser.
parser.setBuilder(builder);
//get content-type manager (maps file extensions to MIME content-types)
TnefContentType contentTypes = new DefaultContentTypeImpl();
//associate the content-types with the builder.
builder.setContentTypes(contentTypes);
// begin parsing.
parser.parse(tnefStream);
// and finaly grab the message.
TnefMessage msg = builder.getMessage();
- Version:
- Feb 19, 2000 Lifestreams 1.5
Constructor Summary |
JTnef()
|
Method Summary |
static TnefMessage |
createTnefMessage(java.io.File winmailFile)
Parses and returns a TnefMessage message given a TNEF File object. |
static TnefMessage |
createTnefMessage(java.io.InputStream tnefStream)
Parses and returns a TnefMessage message given a TNEF binary
input stream (i.e not a base64 encoded stream). |
static TnefMessage |
createTnefMessage(java.lang.String winmailFilename)
Parses and returns a TnefMessage message given a TNEF filename. |
void |
debug(java.lang.String s)
|
static void |
main(java.lang.String[] args)
|
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
JTnef
public JTnef()
createTnefMessage
public static TnefMessage createTnefMessage(java.io.InputStream tnefStream)
throws java.io.IOException
- Parses and returns a
TnefMessage
message given a TNEF binary
input stream (i.e not a base64 encoded stream).
The client code is responsible for closing the input stream once the parsing
is completed.
- Parameters:
tnefStream
- TNEF raw binary stream.- Returns:
- TnefMessage containing Tnef attachments etc.
- Throws:
- java.io.IOException - if the parsing failed.
- See Also:
TnefMessage
createTnefMessage
public static TnefMessage createTnefMessage(java.lang.String winmailFilename)
throws java.io.IOException
- Parses and returns a
TnefMessage
message given a TNEF filename.
Generally, this is the 'winmail.dat' file.
- Parameters:
winmailFilename
- name of file (winmail.dat)- Returns:
- TnefMessage containing Tnef attachments etc.
- Throws:
- java.io.IOException - if the parsing failed.
- See Also:
TnefMessage
createTnefMessage
public static TnefMessage createTnefMessage(java.io.File winmailFile)
throws java.io.IOException
- Parses and returns a
TnefMessage
message given a TNEF File object.
Generally, this is the File pointing to 'winmail.dat' file.
- Parameters:
winmailFile
- winmail.dat File object.- Returns:
- TnefMessage containing Tnef attachments etc.
- Throws:
- java.io.IOException - if the parsing failed.
- See Also:
TnefMessage
debug
public void debug(java.lang.String s)
main
public static void main(java.lang.String[] args)