In my previous article, I described how to read the SMS, MMS, and Emails data from your Windows Mobile device. Now I’m going to tell you how to read the attachments from the emails. I’ll also explain where you can find the attachments to MMS messages.
Content
- Description of IAttach Properties
- Working with e-mail attachments
- MMS attachments – short explanation
- Conclusion
- Useful links
Description of IAttach Properties
Message attachments are one or several additional "blobs" of data, such as a picture, document or sound file attached to the email by a sender. Each individual attachment to a message is supported by the IAttach
interface.
Although the IAttach
interface has no unique methods, it is derived from the IMAPIProp
interface. Below, I describe the properties that are used to configure an attachment.
PR_ATTACH_DATA_BIN
– it’s the IStream interface, which is used to access the attachment. Property type isPT_BINARY
.PR_ATTACH_FILENAME
– it’s the display name for the attachment. The type for this property isPT_TSTRING
.PR_ATTACH_METHOD
– this property must be set to PR_ATTACH_BY_VALUE, it hasPT_LONG
type.PR_ATTACH_NUM
– It’s the number that uniquely identifies the attachment within the message. The type for this property isPT_LONG
.PR_ATTACH_SIZE
– it’s the size, in bytes, of the attachment and all of the attachment properties. The type for this property isPT_LONG
.PR_ENTRYID
– it’s the object's entry identifier. The type for property isPT_BINARY
.PR_LAST_MODIFICATION_TIME
– it’s the last date and time when the object was modified. The type for property isPT_SYSTIME
.PR_NULL
– it’s a NULL value. The type for property isPT_NULL
.PR_OBJECT_TYPE
– it’s the type of object. The type for property isPT_LONG
.PR_PARENT_ENTRYID
– it’s the parent object's entry identifier. The type for property isPT_BINARY
.
Working with e-mail attachments
We have already discussed how to open message, so I omit this part.
We have an already opened message. So, let's go ahead and get the attachments by first getting the attachment table for the message.
In this example, we query the table for the PR_ATTACH_NUM
for the attachment we are interested in.
Then we need to get the properties from the table for the Attachments. For example, we’ll read just three: PR_ATTACH_NUM
, PR_ATTACH_SIZE
, PR_ATTACH_FILENAME
.
Then, in the cycle, we can ask all attachments of the email.
Using the IMessage::OpenAttach()
method with the attachment number, which we found in the query, we can get the IAttach
interface pointer.
After getting an attach interface, we can get the IStream
pointer for the PR_ATTACH_DATA_BIN
property.
When we have the stream pointer, we can copy it to the file or vector of bytes.
And don’t forget to clean up all resources.
MMS attachments – short explanation
We cannot read mms attachments in the same way we read the email ones.
The MMS storage will send us an error when we ask for the properties from the attachment table.
We can find MMS attachments in the raw body of the message. My previous article can tell you about how to read the message body.
The format of MMS message is SMIL (Synchronized Multimedia Integration Language). We can find the attachments looking through the raw message body.
Parsing of the SMIL body of an MMS massage is beyond the scope of this article.
Conclusion
I hope this article helped you to get to know about:
- Work with the e-mail attachments
- The differences between Email and MMS attachments
In this article, I didn’t show how to get the MMS attachments and how to parse SMIL format.
Useful links
SMIL format and MMS:
Download Sample Source (ZIP, 12 KB)
Read another Dev Blog article: How to USB debug Windows.