com.aspose.email
Class MapiMessage

java.lang.Object
  extended by com.aspose.email.MapiPropertyContainer
      extended by com.aspose.email.MapiMessage
All Implemented Interfaces:
IMapiMessageItem, com.aspose.email.ms.System.ICloneable, com.aspose.email.ms.System.IDisposable

public final class MapiMessage
extends MapiPropertyContainer
implements IMapiMessageItem, com.aspose.email.ms.System.ICloneable, com.aspose.email.ms.System.IDisposable

Represents an Outlook Message format document that can be parsed.


The following exmaple demonstrates how to read Outlook Message files.

[Java]

  //Open Outlook Message files
  MapiMessage msg = MapiMessage.fromFile("outlookmessage.msg");

  //read subject
  System.out.print("Subject:" + msg.getSubject());

  //sender name
  System.out.print("From:" + msg.getSenderName());

  //message body
  System.out.print("Body:" + msg.getBody());

  //Attachments
  for(MapiAttachment att : msg.getAttachments())
  {
      System.out.print("Attachment Name:"+att.getFileName());
      att.save(att.getFileName());
  }
  


Instances of the MapiMessage class are used to represent Microsoft Outlook Message document files that are parsed by MapiMessageReader class. To access the sender, recipient, and contents of an e-mail message, use the associated properties of the MapiMessage class.


Constructor Summary
MapiMessage()
           Initializes a new instance of the MapiMessage class.
MapiMessage(String from, String to, String subject, String body)
           Initializes a new instance of the MapiMessage class.
MapiMessage(String from, String to, String subject, String body, int format)
           Initializes a new instance of the MapiMessage class.
 
Method Summary
 com.aspose.email.IMapiNode createMapiNode(String tag)
           Creates the mapi node.
 Object deepClone()
           Creates a new object that is a copy of the current instance.
static void destroyAttachments(String path)
           Destroies the attachments in the specified Outlook Message files.
 void dispose()
           Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
static MapiMessage fromFile(String path)
           Create an instance of MapiMessage from the specified file.
static MapiMessage fromMailMessage(MailMessage message)
           Creates an instance of MapiMessage from the MailMessage.
static MapiMessage fromMailMessage(MailMessage message, int format)
           Creates an instance of MapiMessage from the MailMessage.
static MapiMessage fromMailMessage(MailMessage message, int format, boolean preserveSignature)
           Creates an instance of MapiMessage from the MailMessage.
static MapiMessage fromMailMessage(String fileName)
           Creates an instance of MapiMessage from the MailMessage.
static MapiMessage fromProperties(MapiPropertyCollection properties)
           Creates an instance of MapiMessage from a collection of Mapi properties.
static MapiMessage fromStream(InputStream stream)
           
 MapiAttachmentCollection getAttachments()
           Gets the attachments in the message.
 String getBody()
           Gets the message text.
 String getBodyHtml()
           Gets the BodyRtf of the message converted to HTML, if present, otherwise an empty string.
 String getBodyRtf()
           Gets or sets the RTF formatted message text.
 int getBodyType()
           Gets the type of the body.
 Date getClientSubmitTime()
           
 String getConversationTopic()
           Gets the topic of the first message in a conversation thread.
 Date getDeliveryTime()
           
 String getDisplayBcc()
           Gets a list of the display names of any blind carbon copy (BCC) message recipients, separated by semicolons (;).
 String getDisplayCc()
           Gets a list of the display names of any carbon copy (CC) message recipients, separated by semicolons (;).
 String getDisplayName()
           Gets the display name for the message.
 String getDisplayNamePrefix()
           Gets a prefix of the display name.
 String getDisplayTo()
           Gets a list of the display names of the primary (To) message recipients, separated by semicolons (;).
 long getFlags()
           Gets the message flags.
 HeaderCollection getHeaders()
           Gets the transport message headers
 String getInternetMessageId()
           Gets the message id of the message.
 String getMessageClass()
           Gets a case-sensitive string that identifies the sender-defined message class, such as IPM.Note.
 MapiPropertyCollection getNamedProperties()
           Gets the named properties of message.
 MapiNamedPropertyMappingStorage getNamedPropertyMapping()
           Gets the named property mapping.
 String getNormalizedSubject()
           Gets normalized subject of the message.
 MapiPropertyStream getPropertyStream()
           Gets the property stream.
 MapiRecipientCollection getRecipients()
           Gets the recipients of the message.
 String getReplyTo()
           Gets or sets the reply to names.
 String getSenderAddressType()
           Gets the message sender's e-mail address type.
 String getSenderEmailAddress()
           Gets or sets the message sender's e-mail address.
 String getSenderName()
           Gets or sets the message sender's display name.
 String getSentRepresentingAddressType()
           Gets the address type for the messaging user represented by the sender.
 String getSentRepresentingEmailAddress()
           Gets or sets the e-mail address for the messaging user represented by the sender.
 String getSentRepresentingName()
           Gets or sets the display name for the messaging user represented by the sender.
 String getSubject()
           Gets or sets the subject of the message.
 String getSubjectPrefix()
           Gets a subject prefix that typically indicates some action on a message, such as "FW: " for forwarding.
 MapiPropertyCollection getSubStorages()
           Gets the sub storages.
 String getTransportMessageHeaders()
           Gets the transport-specific message envelope information.
static boolean isMsgFormat(InputStream stream)
           
static boolean isMsgFormat(String fileName)
           Determines whether the specified file has a MSG format.
 boolean isStoreUnicodeOk()
           Determines if string properties are Unicode encoded or not.
static MapiMessage loadFromTnef(InputStream stream)
           
static MapiMessage loadFromTnef(String fileName)
           Loads message from Transport Neutral Encapsulation Format (TNEF) data structure
static MapiAttachmentCollection removeAttachments(String path)
           Removes all of the attachments from the specified Outlook Message files.
 void save(OutputStream stream)
           
 void save(String fileName)
           Saves the specified file name.
 void saveAsTnef(OutputStream stream)
           
 void saveAsTnef(String fileName)
           Save message in TNEF format.
 void setBodyContent(String content, int contentType)
           Sets the content of the body.
 void setBodyRtf(String value)
           
 void setClientSubmitTime(Date value)
           
 void setDeliveryTime(Date value)
           
 void setMessageFlags(long flags)
           Sets the message flags.
 void setNamedPropertyMapping(MapiNamedPropertyMappingStorage value)
           Sets the named property mapping.
 void setProperty(long value, long signed, long tag)
           Sets the property.
 void setProperty(MapiAttachment value, long signed, long tag)
           Sets the attachment.
 void setProperty(MapiProperty property)
           Sets the property.
 void setProperty(MapiProperty value, long signed, long tag)
           Sets the property.
 void setProperty(MapiPropertyStream value, long signed, long tag)
           Sets the property stream.
 void setProperty(MapiRecipient value, long signed, long tag)
           Sets the recipient.
 void setPropertySet(MapiProperty value, long signed, long tag)
           Sets the property set.
 void setReplyTo(String value)
           
 void setSenderEmailAddress(String value)
           
 void setSenderName(String value)
           
 void setSentRepresentingEmailAddress(String value)
           
 void setSentRepresentingName(String value)
           
 void setStringPropertyValue(long tag, String value)
           Sets the string property value.
 void setSubject(String value)
           
 IMapiMessageItem toMapiMessageItem()
           Convert MapiMessage to IMapiMessageItem object in dependence with MessageClass.
 
Methods inherited from class com.aspose.email.MapiPropertyContainer
getCodePage, getMyProperties, getProperties, getPropertyBoolean, getPropertyBytes, getPropertyDateTime, getPropertyInt32, getPropertyLong, getPropertyShort, getPropertyString, getPropertyString, tryGetPropertyData, tryGetPropertyDateTime, tryGetPropertyInt32, tryGetPropertyLong, tryGetPropertyString, tryGetPropertyString, tryGetPropertyString, tryGetPropertyString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MapiMessage

public MapiMessage()

Initializes a new instance of the MapiMessage class.


MapiMessage

public MapiMessage(String from,
                   String to,
                   String subject,
                   String body,
                   int format)

Initializes a new instance of the MapiMessage class.

Parameters:
from - The From address.
to - The addresses of recipients. Note, that addresses are separated by semicolon.
subject - The message subject.
body - The message body.
format - Defines whether to use Unicode or ASCII encoding for this message.
Throws:
com.aspose.email.ms.System.IllegalArgumentException - Is being thrown if address of recipient is null or empty.
com.aspose.email.ms.System.IllegalArgumentException - Is being thrown if sender or recipient address is not in a recognized format.
com.aspose.email.ms.System.InvalidEnumArgumentException - Is being thrown if format parameter is not a valid enumeration member.

MapiMessage

public MapiMessage(String from,
                   String to,
                   String subject,
                   String body)

Initializes a new instance of the MapiMessage class.

Parameters:
from - The From address.
to - The addresses of recipients. Note, that addresses are separated by semicolon.
subject - The message subject.
body - The message body.
Throws:
com.aspose.email.ms.System.IllegalArgumentException - throws if address of recipient is null or empty.
com.aspose.email.ms.System.IllegalArgumentException - throws if sender or recipient address is not in a recognized format.
Method Detail

getBodyRtf

public String getBodyRtf()

Gets or sets the RTF formatted message text.

Value: The string that represents message body rtf.


When setting a value, the values of PR_RTF_COMPRESSED, PR_RTF_DECOMPRESSES, PR_BODY properties are updated. A string value being set must have RTF format. Thus, if it is necessary to set a value in HTML format, the value must be first to encoded within RTF, according to RTF Extensions Specification. To set the content of the body message in HTML or Plain Text formats quickly, please, use SetBodyContent method. When setting a null value or empty string, the values of BodyRtf and Body properties are set null.


setBodyRtf

public void setBodyRtf(String value)

getBodyHtml

public String getBodyHtml()

Gets the BodyRtf of the message converted to HTML, if present, otherwise an empty string.


getBodyType

public int getBodyType()

Gets the type of the body.

Value: The type of the body.


getReplyTo

public String getReplyTo()

Gets or sets the reply to names.

Throws:
com.aspose.email.ms.System.IllegalArgumentException - throws if reply to address is null.
com.aspose.email.ms.System.IllegalArgumentException - throws if reply to address is not in a recognized format. Value: The reply to names.


Gets or sets the list of ReplyTo addresses separated by semicolon.


setReplyTo

public void setReplyTo(String value)

getBody

public String getBody()

Gets the message text.

Value: The string that represents message body.

Specified by:
getBody in interface IMapiMessageItem

getNormalizedSubject

public String getNormalizedSubject()

Gets normalized subject of the message.

Value: The string that represents normalized subject.


getDisplayTo

public String getDisplayTo()

Gets a list of the display names of the primary (To) message recipients, separated by semicolons (;).

Value: The string that represents display to.


getDisplayNamePrefix

public String getDisplayNamePrefix()

Gets a prefix of the display name.

Value: The string that represents display name prefix.


getDisplayName

public String getDisplayName()

Gets the display name for the message.

Value: The string that represents display name.


getDisplayCc

public String getDisplayCc()

Gets a list of the display names of any carbon copy (CC) message recipients, separated by semicolons (;).

Value: The string that represents display cc.


getDisplayBcc

public String getDisplayBcc()

Gets a list of the display names of any blind carbon copy (BCC) message recipients, separated by semicolons (;).

Value: The string that represents display bcc.


getSenderEmailAddress

public String getSenderEmailAddress()

Gets or sets the message sender's e-mail address.

Throws:
ArgumentException - throws if sender address is not in a recognized format. Value: The string that represents sender email address.


When setting a value, the values of PR_SENDER_SEARCH_KEY and PR_SENDER_ENTRYID properties are updated as well. When setting a null value or empty string, the values of properties are set null.


setSenderEmailAddress

public void setSenderEmailAddress(String value)

getSenderAddressType

public String getSenderAddressType()

Gets the message sender's e-mail address type.

Value: The string that represents sender address type.


getSenderName

public String getSenderName()

Gets or sets the message sender's display name.

Value: The the string that represents sender name.


When setting a null value or empty string, the values of the property get the value equal to SenderEmailAddress.


setSenderName

public void setSenderName(String value)

getTransportMessageHeaders

public String getTransportMessageHeaders()

Gets the transport-specific message envelope information.

Value: The string that represents transport message headers.


getInternetMessageId

public String getInternetMessageId()

Gets the message id of the message.

Value: The string that represents internet message id.


getConversationTopic

public String getConversationTopic()

Gets the topic of the first message in a conversation thread.

Value: The string that represens conversation topic.


getSentRepresentingEmailAddress

public String getSentRepresentingEmailAddress()

Gets or sets the e-mail address for the messaging user represented by the sender.

Throws:
com.aspose.email.ms.System.IllegalArgumentException - throws if email address is not in a recognized format. Value: The string that represents sent representing email address.


When setting a value, the values of PR_SENT_REPRESENTING_SEARCH_KEY and PR_SENT_REPRESENTING_ENTRYID properties are updated as well. When setting a null value or empty string, the values of the property are set null.


setSentRepresentingEmailAddress

public void setSentRepresentingEmailAddress(String value)

getSentRepresentingAddressType

public String getSentRepresentingAddressType()

Gets the address type for the messaging user represented by the sender.

Value: The string that represents sent representing address type.


getSentRepresentingName

public String getSentRepresentingName()

Gets or sets the display name for the messaging user represented by the sender.

Value: The string that represents sent representing name.


When setting a null value or empty string, the values of the property are set in SentRepresentingEmailAddress.


setSentRepresentingName

public void setSentRepresentingName(String value)

getSubjectPrefix

public String getSubjectPrefix()

Gets a subject prefix that typically indicates some action on a message, such as "FW: " for forwarding.

Value: The string that represents subject prefix.


getSubject

public String getSubject()

Gets or sets the subject of the message.

Value: The string that represents message subject.


When setting a value, the values of SubjectPrefix(PR_SUBJECT_PREFIX) and NormalizedSubject(PR_NORMALIZED_SUBJECT) properties are updated as well. If Subject has no prefix, the value of SubjectPrefix property is set null. When setting a null value or empty string, the values of Subject, SubjectPrefix, NormalizedSubject properties are set null.

Specified by:
getSubject in interface IMapiMessageItem

setSubject

public void setSubject(String value)

getMessageClass

public String getMessageClass()

Gets a case-sensitive string that identifies the sender-defined message class, such as IPM.Note. The message class specifies the type, purpose, or content of the message.

Value: The string that represents message class.

Specified by:
getMessageClass in interface IMapiMessageItem

getAttachments

public MapiAttachmentCollection getAttachments()

Gets the attachments in the message.

Value: The attachment collection.


getPropertyStream

public MapiPropertyStream getPropertyStream()

Gets the property stream.

Value: The property stream.


getNamedProperties

public MapiPropertyCollection getNamedProperties()

Gets the named properties of message.

Value: The collection of named properties.


getRecipients

public MapiRecipientCollection getRecipients()

Gets the recipients of the message.

Value: The collection of recipients.


getSubStorages

public MapiPropertyCollection getSubStorages()

Gets the sub storages.

Value: The sub storages.


getNamedPropertyMapping

public MapiNamedPropertyMappingStorage getNamedPropertyMapping()

Gets the named property mapping.

Value: The named property mapping.


getClientSubmitTime

public Date getClientSubmitTime()

setClientSubmitTime

public void setClientSubmitTime(Date value)

getDeliveryTime

public Date getDeliveryTime()

setDeliveryTime

public void setDeliveryTime(Date value)

getHeaders

public HeaderCollection getHeaders()

Gets the transport message headers


getFlags

public long getFlags()

Gets the message flags.

Value: The message flags.


fromFile

public static MapiMessage fromFile(String path)

Create an instance of MapiMessage from the specified file.

Parameters:
path - The name of the file to be loaded.
Returns:
Returns a MapiMessage instance which is loaded from the specified file.

fromStream

public static MapiMessage fromStream(InputStream stream)

fromProperties

public static MapiMessage fromProperties(MapiPropertyCollection properties)

Creates an instance of MapiMessage from a collection of Mapi properties.

Parameters:
properties - A collection of MapiProperty.
Returns:
Returns a MapiMessage instance which is loaded from the specified properties.

fromMailMessage

public static MapiMessage fromMailMessage(String fileName)

Creates an instance of MapiMessage from the MailMessage.

Parameters:
fileName - The file name of MailMessage.
Returns:
Returns a MapiMessage instance which is loaded from the MailMessage.

fromMailMessage

public static MapiMessage fromMailMessage(MailMessage message)

Creates an instance of MapiMessage from the MailMessage.

Parameters:
message - The MailMessage.
Returns:
Returns a MapiMessage instance which is loaded from the MailMessage.

fromMailMessage

public static MapiMessage fromMailMessage(MailMessage message,
                                          int format)

Creates an instance of MapiMessage from the MailMessage.

Parameters:
message - The MailMessage.
format - The message format.
Returns:
MapiMessage that represents Outlook message.

fromMailMessage

public static MapiMessage fromMailMessage(MailMessage message,
                                          int format,
                                          boolean preserveSignature)

Creates an instance of MapiMessage from the MailMessage.

Parameters:
message - The MailMessage.
format - The message format.
preserveSignature - Set to true, if signature is to be preserved.
Returns:
MapiMessage that represents Outlook message.

removeAttachments

public static MapiAttachmentCollection removeAttachments(String path)

Removes all of the attachments from the specified Outlook Message files.


The following exmaple demonstrates how to destroy attachments in Outlook Message files.

[Java]

     //Remove attachments from Outlook Message files
     MapiAttachmentCollection attachments = MapiMessage.removeAttachments("outlookmessage.msg");

     //Attachments
     for(MapiAttachment att : attachments)
     {
        System.out.print("Attachment Name:"+att.getFileName());
        att.save(att.getFileName());
     }
 

Parameters:
path - The name of the Outlook Message file.
Returns:
The attachments collection.

destroyAttachments

public static void destroyAttachments(String path)

Destroies the attachments in the specified Outlook Message files. DestroyAttachments will ignore the attachment parsing.


The following exmaple demonstrates how to destroy attachments in Outlook Message files.

[Java]

     //Destroy attachments from Outlook Message files
     MapiMessage.destroyAttachment("outlookmessage.msg");
 

Parameters:
path - The name of the Outlook Message file.

loadFromTnef

public static MapiMessage loadFromTnef(InputStream stream)

loadFromTnef

public static MapiMessage loadFromTnef(String fileName)

Loads message from Transport Neutral Encapsulation Format (TNEF) data structure

Parameters:
fileName - Name of file containing message data in TNEF format
Returns:
A read MapiMessage
Throws:
com.aspose.email.ms.System.IllegalArgumentException - fileName is null or empty

isMsgFormat

public static boolean isMsgFormat(String fileName)

Determines whether the specified file has a MSG format.

Parameters:
fileName - Name of the file.
Returns:
true if the file is represented in MSG format; otherwise, false.

isMsgFormat

public static boolean isMsgFormat(InputStream stream)

isStoreUnicodeOk

public boolean isStoreUnicodeOk()

Determines if string properties are Unicode encoded or not.

Returns:
True, if string properties are Unicode encoded.

setStringPropertyValue

public void setStringPropertyValue(long tag,
                                   String value)

Sets the string property value.

Parameters:
tag - The property tag.
value - The property value.

setProperty

public void setProperty(MapiProperty property)

Sets the property.

Specified by:
setProperty in class MapiPropertyContainer
Parameters:
property - The property.
Throws:
com.aspose.email.ms.System.IllegalArgumentException - If property is null.
com.aspose.email.ms.System.IllegalArgumentException - If property data is null.
IllegalStateException - If data type is not supported.

toMapiMessageItem

public IMapiMessageItem toMapiMessageItem()

Convert MapiMessage to IMapiMessageItem object in dependence with MessageClass.

Returns:
The IMapiMessageItem interface.
Throws:
UnsupportedOperationException - Thrown when MessageClass doesn't belong to IPM.Note, IPM.StickyNote, IPM.Contact, IPM.Activity, IPM.Appointment, IPM.Schedule.meeting, IPM.Task.


Note, that the following message classes are supported by now: IPM.Note, IPM.StickyNote, IPM.Contact, IPM.Activity, IPM.Appointment, IPM.Schedule.meeting, IPM.Task. If MapiMessage has another class, different from these ones, then NotSupportedException is thrown. If MessageClass is IPM.Note, then MapiMessage copy is returned.


setMessageFlags

public void setMessageFlags(long flags)

Sets the message flags.

Parameters:
flags - The message flags.

saveAsTnef

public void saveAsTnef(OutputStream stream)

saveAsTnef

public void saveAsTnef(String fileName)

Save message in TNEF format.

Parameters:
fileName - Name of the file where a message will be saved to.

save

public void save(String fileName)

Saves the specified file name.

Parameters:
fileName - Name of the file.

save

public void save(OutputStream stream)

setBodyContent

public void setBodyContent(String content,
                           int contentType)

Sets the content of the body.

Parameters:
content - The content.
contentType - Type of the content.


It is provided for setting of the content of the body message in RTF, HTML or Plain Text formats. When setting a value, the values of PR_RTF_COMPRESSED, PR_RTF_DECOMPRESSES, PR_BODY properties are updated as well. Note, after the value in HTML format is set, BodyRtf property returns the value which is encoded within RTF.

Throws:
com.aspose.email.ms.System.IllegalArgumentException - throws if the specified content string is null or empty.

createMapiNode

public com.aspose.email.IMapiNode createMapiNode(String tag)

Creates the mapi node.

Overrides:
createMapiNode in class MapiPropertyContainer
Parameters:
tag - The property tag.
Returns:
The IMapiNode interface.

deepClone

public Object deepClone()

Creates a new object that is a copy of the current instance.

Specified by:
deepClone in interface com.aspose.email.ms.System.ICloneable
Returns:
A new object that is a copy of this instance.

setProperty

public void setProperty(MapiAttachment value,
                        long signed,
                        long tag)

Sets the attachment.

Overrides:
setProperty in class MapiPropertyContainer
Parameters:
value - The property value.
signed - The value, that indicates that the property is signed.
tag - The property tag.

setProperty

public void setProperty(MapiRecipient value,
                        long signed,
                        long tag)

Sets the recipient.

Overrides:
setProperty in class MapiPropertyContainer
Parameters:
value - The property value.
signed - The value, that indicates that the property is signed.
tag - The property tag.

setProperty

public void setProperty(long value,
                        long signed,
                        long tag)

Sets the property.

Overrides:
setProperty in class MapiPropertyContainer
Parameters:
value - The property value.
signed - The value, that indicates that the property is signed.
tag - The property tag.

setPropertySet

public void setPropertySet(MapiProperty value,
                           long signed,
                           long tag)

Sets the property set.

Overrides:
setPropertySet in class MapiPropertyContainer
Parameters:
value - The MapiPropery.
signed - The value, that indicates that the property is signed.
tag - The property tag.

setProperty

public void setProperty(MapiPropertyStream value,
                        long signed,
                        long tag)

Sets the property stream.

Overrides:
setProperty in class MapiPropertyContainer
Parameters:
value - The property stream.
signed - The value, that indicates that the property is signed.
tag - The property tag.

setProperty

public void setProperty(MapiProperty value,
                        long signed,
                        long tag)

Sets the property.

Overrides:
setProperty in class MapiPropertyContainer
Parameters:
value - The MapiProperty.
signed - The value, that indicates that the property is signed.
tag - The property tag.

setNamedPropertyMapping

public void setNamedPropertyMapping(MapiNamedPropertyMappingStorage value)

Sets the named property mapping.

Overrides:
setNamedPropertyMapping in class MapiPropertyContainer
Parameters:
value - The MapiNamedPropertyMappingStorage.

dispose

public void dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Specified by:
dispose in interface com.aspose.email.ms.System.IDisposable


Copyright (c) 2008-2013 Aspose Pty Ltd. All Rights Reserved.