com.aspose.email

com.aspose.email

Class 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, intformat)
Initializes a new instance of the MapiMessage class.
 
Method Summary
com.aspose.email.IMapiNode
createMapiNode(String tag)
Creates the mapi node.
deepClone()
Creates a new object that is a copy of the current instance.
staticvoid
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.
fromFile(String path)
Create an instance of MapiMessage from the specified file.
fromMailMessage(MailMessage message)
Creates an instance of MapiMessage from the MailMessage.
fromMailMessage(MailMessage message, intformat)
Creates an instance of MapiMessage from the MailMessage.
fromMailMessage(MailMessage message, intformat, booleanpreserveSignature)
Creates an instance of MapiMessage from the MailMessage.
fromMailMessage(String fileName)
Creates an instance of MapiMessage from the MailMessage.
fromProperties(MapiPropertyCollection properties)
Creates an instance of MapiMessage from a collection of Mapi properties.
getAttachments()
Gets the attachments in the message.
getBody()
Gets the message text.
getBodyHtml()
Gets the BodyRtf of the message converted to HTML, if present, otherwise an empty string.
getBodyRtf()
Gets or sets the RTF formatted message text.
int
getBodyType()
Gets the type of the body.
getConversationTopic()
Gets the topic of the first message in a conversation thread.
getDisplayBcc()
Gets a list of the display names of any blind carbon copy (BCC) message recipients, separated by semicolons (;).
getDisplayCc()
Gets a list of the display names of any carbon copy (CC) message recipients, separated by semicolons (;).
getDisplayName()
Gets the display name for the message.
getDisplayNamePrefix()
Gets a prefix of the display name.
getDisplayTo()
Gets a list of the display names of the primary (To) message recipients, separated by semicolons (;).
long
getFlags()
Gets the message flags.
getHeaders()
Gets the transport message headers
getInternetMessageId()
Gets the message id of the message.
getMessageClass()
Gets a case-sensitive string that identifies the sender-defined message class, such as IPM.Note.
getNamedProperties()
Gets the named properties of message.
getNamedPropertyMapping()
Gets the named property mapping.
getNormalizedSubject()
Gets normalized subject of the message.
getPropertyStream()
Gets the property stream.
getRecipients()
Gets the recipients of the message.
getReplyTo()
Gets or sets the reply to names.
getSenderAddressType()
Gets the message sender's e-mail address type.
getSenderEmailAddress()
Gets or sets the message sender's e-mail address.
getSenderName()
Gets or sets the message sender's display name.
getSentRepresentingAddressType()
Gets the address type for the messaging user represented by the sender.
getSentRepresentingEmailAddress()
Gets or sets the e-mail address for the messaging user represented by the sender.
getSentRepresentingName()
Gets or sets the display name for the messaging user represented by the sender.
getSubject()
Gets or sets the subject of the message.
getSubjectPrefix()
Gets a subject prefix that typically indicates some action on a message, such as "FW: " for forwarding.
getSubStorages()
Gets the sub storages.
getTransportMessageHeaders()
Gets the transport-specific message envelope information.
staticboolean
staticboolean
isMsgFormat(String fileName)
Determines whether the specified file has a MSG format.
boolean
isStoreUnicodeOk()
Determines if string properties are Unicode encoded or not.
loadFromTnef(String fileName)
Loads message from Transport Neutral Encapsulation Format (TNEF) data structure
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
void
saveAsTnef(String fileName)
Save message in TNEF format.
void
setBodyContent(String content, intcontentType)
Sets the content of the body.
void
void
void
void
setMessageFlags(longflags)
Sets the message flags.
void
setNamedPropertyMapping(MapiNamedPropertyMappingStorage value)
Sets the named property mapping.
void
setProperty(longvalue, longsigned, longtag)
Sets the property.
void
setProperty(MapiAttachment value, longsigned, longtag)
Sets the attachment.
void
setProperty(MapiProperty property)
Sets the property.
void
setProperty(MapiProperty value, longsigned, longtag)
Sets the property.
void
setProperty(MapiPropertyStream value, longsigned, longtag)
Sets the property stream.
void
setProperty(MapiRecipient value, longsigned, longtag)
Sets the recipient.
void
setPropertySet(MapiProperty value, longsigned, longtag)
Sets the property set.
void
void
void
void
void
void
setStringPropertyValue(longtag, String value)
Sets the string property value.
void
toMapiMessageItem()
Convert MapiMessage to IMapiMessageItem object in dependence with MessageClass.
 
Methods inherited from class com.aspose.email.MapiPropertyContainer
 
Methods inherited from class java.lang.Object
 

    • 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.
      • 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(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(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.
      • 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.
      • 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