public class MapiAttachment extends MapiPropertyContainer
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());
}
}
}
| Modifier and Type | Field and Description |
|---|---|
protected MapiNamedPropertyMappingStorage |
namedPropertyMappingStorage
The named property mapping storage.
|
| Modifier and Type | Method and Description |
|---|---|
com.aspose.email.IMapiNode |
createMapiNode(String key)
Creates the mapi node.
|
byte[] |
getBinaryData()
Gets or sets binary attachment data.
|
Object |
getContent()
Gets the content.
|
String |
getDisplayName()
Gets the display name of the ole object in an attachment.
|
String |
getExtension()
Gets a filename extension that indicates the document type of an attachment.
|
String |
getFileName()
Gets an attachment's base filename and extension, excluding path.
|
String |
getItemId()
The item id, uses with a server
|
String |
getLongFileName()
Gets an attachment's long filename and extension, excluding path.
|
String |
getMimeTag()
Gets formatting information about a
Multipurpose Internet Mail Extensions (MIME) attachment.
|
MapiPropertyCollection |
getNamedProperties()
Gets the named properties of message.
|
MapiObjectProperty |
getObjectData()
Gets an attachment object typically accessed
through the OLE IStorage interface.
|
MapiProperty |
getProperty(PropertyDescriptor pd)
Gets MAPI property by property descriptor.
|
MapiPropertyStream |
getPropertyStream()
Gets the property stream.
|
MapiPropertyCollection |
getSubStorages()
Gets the sub storages.
|
boolean |
isInline()
Gets a value indicating whether the attachment is inline or regular.
|
void |
removeProperty(long tag)
Provides correctly removing property from all collections.
|
void |
save(OutputStream stream)
Save attachment content.
|
void |
save(String filename)
Save attachment content.
|
void |
setBinaryData(byte[] value)
Gets or sets binary attachment data.
|
void |
setDisplayName(String value)
Gets the display name of the ole object in an attachment.
|
void |
setProperty(MapiProperty value)
Sets the property.
|
void |
setProperty(PropertyDescriptor pd,
Object value)
Sets MAPI property.
|
getCodePage, getProperties, getPropertyBoolean, getPropertyBytes, getPropertyDateTime, getPropertyInt32, getPropertyLong, getPropertyShort, getPropertyString, getPropertyString, isStoreUnicodeOk, tryGetPropertyData, tryGetPropertyDateTime, tryGetPropertyInt32, tryGetPropertyLong, tryGetPropertyString, tryGetPropertyString, tryGetPropertyString, tryGetPropertyStringprotected MapiNamedPropertyMappingStorage namedPropertyMappingStorage
The named property mapping storage.
public String getItemId()
The item id, uses with a server
public boolean isInline()
Gets a value indicating whether the attachment is inline or regular. If inline returns true, otherwise false.
public final String getExtension()
Gets a filename extension that indicates the document type of an attachment.
Value: The extension.public final MapiPropertyStream getPropertyStream()
Gets the property stream.
Value: The property stream.public final MapiPropertyCollection getSubStorages()
Gets the sub storages.
Value: The sub storages.public final String getFileName()
Gets an attachment's base filename and extension, excluding path.
Value: The file name.public final String getLongFileName()
Gets an attachment's long filename and extension, excluding path.
Value: The long file name.public final String getDisplayName()
Gets the display name of the ole object in an attachment.
Value: The display name.public final void setDisplayName(String value)
Gets the display name of the ole object in an attachment.
Value: The display name.public final String getMimeTag()
Gets formatting information about a Multipurpose Internet Mail Extensions (MIME) attachment.
Value: The mime tag.public final byte[] getBinaryData()
Gets or sets binary attachment data.
Value: The binary data.public final void setBinaryData(byte[] value)
Gets or sets binary attachment data.
Value: The binary data.public final Object getContent()
Gets the content.
Value: The content.public final MapiObjectProperty getObjectData()
Gets an attachment object typically accessed through the OLE IStorage interface.
Value: The object data.public final MapiPropertyCollection getNamedProperties()
Gets the named properties of message.
Value: The collection of named properties.public final void save(String filename)
Save attachment content.
filename - The file name to save.public final void save(OutputStream stream)
Save attachment content.
stream - The stream to save.public void setProperty(MapiProperty value)
Sets the property.
setProperty in class MapiPropertyContainervalue - The property.ArgumentNullException - If value is null.ArgumentException - If property data is null.InvalidOperationException - If data type is not supported.public final void removeProperty(long tag)
Provides correctly removing property from all collections.
tag - The tag of MapiProperty.public com.aspose.email.IMapiNode createMapiNode(String key)
Creates the mapi node.
createMapiNode in class MapiPropertyContainerkey - The node key.public MapiProperty getProperty(PropertyDescriptor pd)
Gets MAPI property by property descriptor.
getProperty in class MapiPropertyContainerpd - Property descriptor for looked propertypublic void setProperty(PropertyDescriptor pd, Object value)
Sets MAPI property.
setProperty in class MapiPropertyContainerpd - The property descriptor.value - The property data.Copyright (c) 2008-2024 Aspose Pty Ltd. All Rights Reserved.