com.mirrorworlds.lifestreams.mail.tnef
Class TnefMessageBuilder

java.lang.Object
  |
  +--com.mirrorworlds.lifestreams.mail.tnef.TnefMessageBuilder

public class TnefMessageBuilder
extends java.lang.Object
implements TnefBuilder

A simple implementation of the TnefBuilder interface. This implementation builds a TnefMessage based on the attribute data bytes passed by the parser. This class ignores some attributes such as attConversationID, attMAPIProps etc., however it tries to build the attachments (eg: files ) sent in a TNEF stream. See the description on setMessageAttribute() and setAttachmentAttribute() methods to see the actual attributes used to build a message. The methods in this class are usually invoked by the parser.

For more information (good luck), search for "Mapping of TNEF Attributes to MAPI Properties", "Mapping of Internet Mail Attributes to MAPI Properties", "TNEF Stream Syntax" and "TNEF Stream Structure" at http://www.microsoft.com

Version:
Feb 20, 2000 Lifestreams 1.5

Field Summary
protected  TnefAttachment attachment
          The current tnef attachment.
protected  TnefContentTypes contentTypes
          MIME content-type manager that translates file extensions to a content-type.
protected  TnefMessage message
          Message object being built.
 
Constructor Summary
TnefMessageBuilder()
          Constructs a basic builder and an empty TnefMessage object.
 
Method Summary
 void addAttachment()
          This method is called by the parser when it encounters a TNEF attachment (start of attachment) sequence.
 void debug(java.lang.String s)
           
protected  int getInt(byte[] d)
           
 TnefMessage getMessage()
          Returns the message build by this builder.
protected  int getShort(byte[] d)
           
protected  java.lang.String getString(byte[] d)
           
 void setAttachmentAttribute(int id, byte[] data)
          Sets the TNEF stream attachment attributes.
 void setContentTypes(TnefContentTypes contentTypes)
          Sets the content-type handler.
 void setKey(int key)
          Sets the TNEF stream message key (16 bits).
 void setMessageAttribute(int id, byte[] data)
          Sets the TNEF stream message attributes.
 void setSignature(int signature)
          Sets the TNEF stream signature (32 bits).
 void setTnefVersion(int version)
          Sets the TNEF stream version (32 bits).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

message

protected TnefMessage message
Message object being built.

attachment

protected TnefAttachment attachment
The current tnef attachment.

contentTypes

protected TnefContentTypes contentTypes
MIME content-type manager that translates file extensions to a content-type.
Constructor Detail

TnefMessageBuilder

public TnefMessageBuilder()
Constructs a basic builder and an empty TnefMessage object.
Method Detail

setContentTypes

public void setContentTypes(TnefContentTypes contentTypes)
Sets the content-type handler. This handler is used to determine the MIME content-type of the attachments (based on the filename extension).
Specified by:
setContentTypes in interface TnefBuilder
Tags copied from interface: TnefBuilder
Parameters:
contentTypes - content-type manager.

setSignature

public void setSignature(int signature)
                  throws java.io.IOException
Sets the TNEF stream signature (32 bits).
Specified by:
setSignature in interface TnefBuilder
Tags copied from interface: TnefBuilder
Parameters:
signature - TNEF stream signature.
Throws:
IO - Exception if the signature is incorrect.

setKey

public void setKey(int key)
Sets the TNEF stream message key (16 bits).
Specified by:
setKey in interface TnefBuilder
Tags copied from interface: TnefBuilder
Parameters:
key - message key.

setTnefVersion

public void setTnefVersion(int version)
Sets the TNEF stream version (32 bits).
Specified by:
setTnefVersion in interface TnefBuilder
Tags copied from interface: TnefBuilder
Parameters:
version - TNEF message stream version.

setMessageAttribute

public void setMessageAttribute(int id,
                                byte[] data)
Sets the TNEF stream message attributes. Note that all of the attributes described in the TnefConstants are not guaranteed to be in the TNEF stream. This implemention sets the following message properties in the TnefMessage object. (other properties are ignored).
 MAPI attDateRecd      = TnefMessage attribute : date-received
 MAPI attDateSent      = TnefMessage attribute : date-sent  (same as msg.getDate())
 MAPI attDateModified  = TnefMessage attribute : date-modified    
 MAPI attSubject       = TnefMesasge attribute : subject
 MAPI attMessageID     = TnefMessage attribute : message-id
 MAPI attPriority      = TnefMessage attribute : message-priority (same asmsg.getPriority())   
 MAPI attFrom          = TBD/ignored.
 MAPI attConversationID= TBD/ignored.     
 MAPI attBody          = TBD/ignored.
 MAPI attMAPIProps     = TBD/ignored.
 MAPI attMessageClass  = TnefMessage attribute : message-class
 
The attributes can be accessed from the TnefMessage's getAttribute(name) method.(for example getAttribute("date-received").

Note that there is no guarantee that the above properties are in the TNEF message stream.

Specified by:
setMessageAttribute in interface TnefBuilder
Parameters:
id - message attribute id
data - message attribute data bytes

setAttachmentAttribute

public void setAttachmentAttribute(int id,
                                   byte[] data)
Sets the TNEF stream attachment attributes. Note that all of the attributes described in the TnefConstants are not guaranteed to be in the TNEF stream. This implemention sets the following attachment properties in the TnefAttachment object. (other properties are ignored).
 MAPI attAttachment        = TBD/ignored.
 MAPI attAttachData        = TnefAttachment : getInputStream() or getContentBytes()
 MAPI attAttachMetaFile    = TBD/ignored.
 MAPI attAttachTitle       = TnefAttachment attribute : title (same as getFilename())
 MAPI attAttachCreateDate  = TnefAttachment attribute : date-created (same as getDate())
 MAPI attAttachRenddata    = TnefAttachment : getRendData()
 
The attributes can be accessed from the TnefAttachment's getAttribute(name) method.(for example getAttribute("filename"). Generally attAttachTitle attribute contains the filename. This implementation of the builder determines the content-type of the attachment based on this filename attribute. (assuming that the TnefContentType is set via setContentTypes() method).

Note that there is no guarantee that the above properties are in the TNEF message stream.

Specified by:
setAttachmentAttribute in interface TnefBuilder
Parameters:
id - attachment attribute id
data - attachment attribute data bytes

addAttachment

public void addAttachment()
Description copied from interface: TnefBuilder
This method is called by the parser when it encounters a TNEF attachment (start of attachment) sequence.
Specified by:
addAttachment in interface TnefBuilder

getMessage

public TnefMessage getMessage()
Description copied from interface: TnefBuilder
Returns the message build by this builder.
Specified by:
getMessage in interface TnefBuilder

getString

protected java.lang.String getString(byte[] d)
Returns:
a String given an array of bytes.

getShort

protected int getShort(byte[] d)
Returns:
a short (16 bit int) given an array of (2) bytes.

getInt

protected int getInt(byte[] d)
Returns:
a int (32 bit) given an array of (4) bytes.

debug

public void debug(java.lang.String s)