MapiAttachment

Inheritance: java.lang.Object, com.aspose.email.MapiPropertyContainer

public class MapiAttachment extends MapiPropertyContainer

Represents a message attachment.

This class encapsulates an attachment, providing methods to access and manipulate its properties.

Example:

// This code example loads a message from a file and iterates over each attachment.
 // If an attachment is inline, it prints its display name.
 // If not, it checks if the attachment is an embedded message.
 // If so, it saves the attachment to a memory stream.
 // If not, it saves to a specified path.

 // Load the MAPI message from the specified file
 MapiMessage msg = MapiMessage.load("source.msg");

 // Iterate over each attachment in the MAPI message
 for (MapiAttachment mapiAttachment : msg.getAttachments()) {
     // Check if the attachment is inline
     if (mapiAttachment.isInline()) {
         // If inline, print its display name
         System.out.println("Inline: " + mapiAttachment.getDisplayName());
     } else {
         // If not inline
         // Check if the attachment contains an embedded message
         if (mapiAttachment.getObjectData() != null && mapiAttachment.getObjectData().isOutlookMessage()) {
             // If it's an embedded message
             // Save the attachment to a memory stream
             try (ByteArrayOutputStream ms = new ByteArrayOutputStream()) {
                 mapiAttachment.save(ms);
                 byte[] bytes = ms.toByteArray();
                 try (ByteArrayInputStream msInput = new ByteArrayInputStream(bytes)) {
                     // Load the embedded message from the memory stream
                     MapiMessage embeddedMessage = MapiMessage.load(msInput);
                 }
             } catch (IOException e) {
                 e.printStackTrace();
             }
         } else {
             // If it's not an embedded message
             // Save the attachment to the specified path
             mapiAttachment.save(Paths.get(path, mapiAttachment.getLongFileName()).toString());
         }
     }
 }

Methods

MethodDescription
createMapiNode(String key)Creates the mapi node.
equals(Object arg0)
getBinaryData()Gets or sets binary attachment data.
getClass()
getCodePage()Gets the code page.
getContent()Gets the content.
getDisplayName()Gets the display name of the ole object in an attachment.
getExtension()Gets a filename extension that indicates the document type of an attachment.
getFileName()Gets an attachment’s base filename and extension, excluding path.
getItemId()The item id, uses with a server
getLongFileName()Gets an attachment’s long filename and extension, excluding path.
getMimeTag()Gets formatting information about a Multipurpose Internet Mail Extensions (MIME) attachment.
getNamedProperties()Gets the named properties of message.
getObjectData()Gets an attachment object typically accessed through the OLE IStorage interface.
getProperties()Gets the collection of properties.
getProperty(PropertyDescriptor pd)Gets MAPI property by property descriptor.
getPropertyBoolean(long tag)Gets the value of the property specified by tag as Boolean type.
getPropertyBytes(long tag)Gets the string value of the property specified by tag.
getPropertyDateTime(long key)Gets the value of the property specified by tag as DateTime type.
getPropertyInt32(long tag)Gets the int32 value of the property specified by tag.
getPropertyLong(long tag)Gets the value of the property specified by tag as Long (int64) type.
getPropertyShort(long tag)Gets the value of the property specified by tag as Short type.
getPropertyStream()Gets the property stream.
getPropertyString(long tag)Gets the string value of the property specified by tag.
getPropertyString(long tag, int codepage)Gets the string value of the property specified by tag.
getSubStorages()Gets the sub storages.
hashCode()
isInline()Gets a value indicating whether the attachment is inline or regular.
isStoreUnicodeOk()Determines if string properties are Unicode encoded or not.
notify()
notifyAll()
removeProperty(long tag)Provides correctly removing property from all collections.
save(OutputStream stream)Save attachment content.
save(String filename)Save attachment content.
setBinaryData(byte[] value)Gets or sets binary attachment data.
setDisplayName(String value)Gets the display name of the ole object in an attachment.
setProperty(MapiProperty value)Sets the property.
setProperty(PropertyDescriptor pd, Object value)Sets MAPI property.
toString()
tryGetPropertyData(long tag)Try to get the property data with specified tag key.
tryGetPropertyDateTime(long tag, Date[] value)Gets the value of the specified property as DateTime type.
tryGetPropertyInt32(long tag, int[] value)Gets the value of the specified property as Int32 type.
tryGetPropertyLong(long tag, long[] value)Gets the value of the specified property as Long type.
tryGetPropertyString(long tag)Try to get a property data as string with specified tag.
tryGetPropertyString(long tag, int codepage)Try to get a property data as string with specified tag and code page.
tryGetPropertyString(long tag, String[] value)Gets the value of the specified property as String type.
tryGetPropertyString(long tag, String[] value, int codepage)Gets the value of the specified property as String type.
wait()
wait(long arg0)
wait(long arg0, int arg1)

createMapiNode(String key)

public IMapiNode createMapiNode(String key)

Creates the mapi node.

Parameters:

ParameterTypeDescription
keyjava.lang.StringThe node key.

Returns: com.aspose.email.IMapiNode - The IMapiNode interface.

equals(Object arg0)

public boolean equals(Object arg0)

Parameters:

ParameterTypeDescription
arg0java.lang.Object

Returns: boolean

getBinaryData()

public final byte[] getBinaryData()

Gets or sets binary attachment data.

Value: The binary data.

Returns: byte[]

getClass()

public final native Class<?> getClass()

Returns: java.lang.Class

getCodePage()

public int getCodePage()

Gets the code page.

Value: The code page.

Returns: int

getContent()

public final Object getContent()

Gets the content.

Value: The content.

Returns: java.lang.Object

getDisplayName()

public final String getDisplayName()

Gets the display name of the ole object in an attachment.

Value: The display name.

Returns: java.lang.String

getExtension()

public final String getExtension()

Gets a filename extension that indicates the document type of an attachment.

Value: The extension.

Returns: java.lang.String

getFileName()

public final String getFileName()

Gets an attachment’s base filename and extension, excluding path.

Value: The file name.

Returns: java.lang.String

getItemId()

public String getItemId()

The item id, uses with a server

Returns: java.lang.String

getLongFileName()

public final String getLongFileName()

Gets an attachment’s long filename and extension, excluding path.

Value: The long file name.

Returns: java.lang.String

getMimeTag()

public final String getMimeTag()

Gets formatting information about a Multipurpose Internet Mail Extensions (MIME) attachment.

Value: The mime tag.

Returns: java.lang.String

getNamedProperties()

public final MapiPropertyCollection getNamedProperties()

Gets the named properties of message.

Value: The collection of named properties.

Returns: MapiPropertyCollection

getObjectData()

public final MapiObjectProperty getObjectData()

Gets an attachment object typically accessed through the OLE IStorage interface.

Value: The object data.

Returns: MapiObjectProperty

getProperties()

public MapiPropertyCollection getProperties()

Gets the collection of properties.

Value: The properties.

Returns: MapiPropertyCollection

getProperty(PropertyDescriptor pd)

public MapiProperty getProperty(PropertyDescriptor pd)

Gets MAPI property by property descriptor.

Parameters:

ParameterTypeDescription
pdPropertyDescriptorProperty descriptor for looked property

Returns: MapiProperty - Mapi property if it is found, otherwise null.

getPropertyBoolean(long tag)

public final Boolean getPropertyBoolean(long tag)

Gets the value of the property specified by tag as Boolean type.

Parameters:

ParameterTypeDescription
taglongThe MAPI property tag.

Returns: java.lang.Boolean - The value of the property. If the property does not exist, returns NULL; otherwise, returns the value.

getPropertyBytes(long tag)

public final byte[] getPropertyBytes(long tag)

Gets the string value of the property specified by tag.

Parameters:

ParameterTypeDescription
taglongThe MAPI property tag.

Returns: byte[] - The value of the property. If the property does not exist, returns NULL; otherwise, returns the value.

getPropertyDateTime(long key)

public final Date getPropertyDateTime(long key)

Gets the value of the property specified by tag as DateTime type.

Parameters:

ParameterTypeDescription
keylongThe MAPI property tag.

Returns: java.util.Date - The value of the property. If the property does not exist, returns NULL; otherwise, returns the value.

getPropertyInt32(long tag)

public final Integer getPropertyInt32(long tag)

Gets the int32 value of the property specified by tag.

Parameters:

ParameterTypeDescription
taglongThe MAPI property tag.

Returns: java.lang.Integer - The value of the property. If the property does not exist, returns NULL; otherwise, returns the value.

getPropertyLong(long tag)

public final Long getPropertyLong(long tag)

Gets the value of the property specified by tag as Long (int64) type.

Parameters:

ParameterTypeDescription
taglongThe MAPI property tag.

Returns: java.lang.Long - The value of the property. If the property does not exist, returns NULL; otherwise, returns the value.

getPropertyShort(long tag)

public final Short getPropertyShort(long tag)

Gets the value of the property specified by tag as Short type.

Parameters:

ParameterTypeDescription
taglongThe MAPI property tag.

Returns: java.lang.Short - The value of the property. If the property does not exist, returns NULL; otherwise, returns the value.

getPropertyStream()

public final MapiPropertyStream getPropertyStream()

Gets the property stream.

Value: The property stream.

Returns: MapiPropertyStream

getPropertyString(long tag)

public final String getPropertyString(long tag)

Gets the string value of the property specified by tag.

Parameters:

ParameterTypeDescription
taglongThe MAPI property tag.

Returns: java.lang.String - The value of the property. If the property does not exist, returns NULL; otherwise, returns the value.

getPropertyString(long tag, int codepage)

public final String getPropertyString(long tag, int codepage)

Gets the string value of the property specified by tag.

Parameters:

ParameterTypeDescription
taglongThe MAPI property tag.
codepageintThe specified codepage used to get string value.

Returns: java.lang.String - The value of the property. If the property does not exist, returns NULL; otherwise, returns the value.

getSubStorages()

public final MapiPropertyCollection getSubStorages()

Gets the sub storages.

Value: The sub storages.

Returns: MapiPropertyCollection

hashCode()

public native int hashCode()

Returns: int

isInline()

public boolean isInline()

Gets a value indicating whether the attachment is inline or regular. If inline returns true, otherwise false.

Returns: boolean

isStoreUnicodeOk()

public final boolean isStoreUnicodeOk()

Determines if string properties are Unicode encoded or not.

Returns: boolean - True, if string properties are Unicode encoded.

notify()

public final native void notify()

notifyAll()

public final native void notifyAll()

removeProperty(long tag)

public final void removeProperty(long tag)

Provides correctly removing property from all collections.

Parameters:

ParameterTypeDescription
taglongThe tag of MapiProperty.

save(OutputStream stream)

public final void save(OutputStream stream)

Save attachment content.

Parameters:

ParameterTypeDescription
streamjava.io.OutputStreamThe stream to save.

save(String filename)

public final void save(String filename)

Save attachment content.

Parameters:

ParameterTypeDescription
filenamejava.lang.StringThe file name to save.

setBinaryData(byte[] value)

public final void setBinaryData(byte[] value)

Gets or sets binary attachment data.

Value: The binary data.

Parameters:

ParameterTypeDescription
valuebyte[]

setDisplayName(String value)

public final void setDisplayName(String value)

Gets the display name of the ole object in an attachment.

Value: The display name.

Parameters:

ParameterTypeDescription
valuejava.lang.String

setProperty(MapiProperty value)

public void setProperty(MapiProperty value)

Sets the property.

Parameters:

ParameterTypeDescription
valueMapiPropertyThe property.

setProperty(PropertyDescriptor pd, Object value)

public void setProperty(PropertyDescriptor pd, Object value)

Sets MAPI property.

Parameters:

ParameterTypeDescription
pdPropertyDescriptorThe property descriptor.
valuejava.lang.ObjectThe property data.

toString()

public String toString()

Returns: java.lang.String

tryGetPropertyData(long tag)

public final byte[] tryGetPropertyData(long tag)

Try to get the property data with specified tag key.

Parameters:

ParameterTypeDescription
taglongThe tag key.

Returns: byte[] - The property data.

tryGetPropertyDateTime(long tag, Date[] value)

public final boolean tryGetPropertyDateTime(long tag, Date[] value)

Gets the value of the specified property as DateTime type. A return value indicates whether the operation succeeded.

Parameters:

ParameterTypeDescription
taglongThe MAPI property tag.
valuejava.util.Date[]When this method returns, contains the value of the specified property, if the property exists. This parameter is passed uninitialized.

Returns: boolean - true if s was converted successfully; otherwise, false.

tryGetPropertyInt32(long tag, int[] value)

public final boolean tryGetPropertyInt32(long tag, int[] value)

Gets the value of the specified property as Int32 type. A return value indicates whether the operation succeeded.

Parameters:

ParameterTypeDescription
taglongThe MAPI property tag.
valueint[]When this method returns, contains the value of the specified property, if the property exists. This parameter is passed uninitialized.

Returns: boolean - true if s was converted successfully; otherwise, false.

tryGetPropertyLong(long tag, long[] value)

public final boolean tryGetPropertyLong(long tag, long[] value)

Gets the value of the specified property as Long type. A return value indicates whether the operation succeeded.

Parameters:

ParameterTypeDescription
taglongThe MAPI property tag.
valuelong[]When this method returns, contains the value of the specified property, if the property exists. This parameter is passed uninitialized.

Returns: boolean - true if s was converted successfully; otherwise, false.

tryGetPropertyString(long tag)

public final String tryGetPropertyString(long tag)

Try to get a property data as string with specified tag.

Parameters:

ParameterTypeDescription
taglongThe property tag key.

Returns: java.lang.String - String that contains the contents of property data.

tryGetPropertyString(long tag, int codepage)

public final String tryGetPropertyString(long tag, int codepage)

Try to get a property data as string with specified tag and code page.

Parameters:

ParameterTypeDescription
taglongThe property tag key.
codepageintThe code page.

Returns: java.lang.String - String that contains the contents of property data.

tryGetPropertyString(long tag, String[] value)

public final boolean tryGetPropertyString(long tag, String[] value)

Gets the value of the specified property as String type. A return value indicates whether the operation succeeded.

Parameters:

ParameterTypeDescription
taglongThe MAPI property tag.
valuejava.lang.String[]When this method returns, contains the value of the specified property, if the property exists. This parameter is passed uninitialized.

Returns: boolean - true if s was converted successfully; otherwise, false.

tryGetPropertyString(long tag, String[] value, int codepage)

public final boolean tryGetPropertyString(long tag, String[] value, int codepage)

Gets the value of the specified property as String type. A return value indicates whether the operation succeeded.

Parameters:

ParameterTypeDescription
taglongThe MAPI property tag.
valuejava.lang.String[]When this method returns, contains the value of the specified property, if the property exists. This parameter is passed uninitialized.
codepageintThe specified codepage used to get string value.

Returns: boolean - true if s was converted successfully; otherwise, false.

wait()

public final void wait()

wait(long arg0)

public final native void wait(long arg0)

Parameters:

ParameterTypeDescription
arg0long

wait(long arg0, int arg1)

public final void wait(long arg0, int arg1)

Parameters:

ParameterTypeDescription
arg0long
arg1int