Incorporating Formatted Text and Attachments

A client application can send or receive a message that includes formatted text and attachments. Clients that want to work with formatted text must use the MAPI client interface. CMC, Simple MAPI, and the Active Messaging Library do not support formatted text in messages.

Design Tasks

  1. Decide on a mechanism for displaying formatted text. You can use the Rich Text Format (RTF) supported by Microsoft or your own customized format. See Formatted Text in MAPI.
  2. Decide on the types of attachments that your client will handle. See Attachments.
  3. Decide if and how your client will activate and save its attachments. See Creating a Message Attachment.

Implementation Tasks

    To send a message with formatted text
  1. Call the IMAPIProp::OpenProperty method to open the PR_RTF_COMPRESSED property, setting both the MAPI_CREATE and MAPI_MODIFY flags. MAPI_CREATE ensures that any new data replaces any old data and MAPI_MODIFY enables your client to make those replacements.
  2. Call the WrapCompressedRTFStream function, passing STORE_UNCOMPRESSED_RTF if the message store sets the STORE_UNCOMPRESSED_RTF bit in its PR_STORE_SUPPORT_MASK property, to get an uncompressed version of the PR_RTF_COMPRESSED stream returned from OpenProperty.
  3. Write the message text data to the uncompressed stream returned from WrapCompressedRTFStream.
  4. If the message data is an attachment, write the character token "\objattph" followed by a space to the stream instead of the attachment.
  5. Set the PR_RENDERING_POSITION property of the attachment to a value that will increase with each attachment. For example, the first attachment could be assigned 1 as its PR_RENDERING_POSITION, the second one 2, and so on.
  6. Commit and release both the uncompressed and compressed streams.
  7. If the message store does not support RTF as indicated by the absence of the STORE_RTF_OK setting in the PR_STORE_SUPPORT_MASK property, call the RTFSync function and pass the RTF_SYNC_RTF_CHANGED flag.

For more information, see Supporting Formatted Text in Outgoing Messages: Client Responsibilities.

    To read a message with formatted text
  1. Call RTFSync to synchronize the message text with the formatting if the message store is not RTF-aware and the PR_RTF_IN_SYNC property is missing or set to FALSE. The RTF_SYNC_BODY_CHANGED flag should be passed in the ulFlags parameter. Clients working with RTF-aware message stores need not make the RTFSync call because the message store takes care of it.
  2. Call IMAPIProp::SaveChanges if the message has been updated.
  3. Call IMAPIProp::OpenProperty to open the PR_RTF_COMPRESSED property.
  4. Call the WrapCompressedRTFStream function, passing the STORE_UNCOMPRESSED_RTF flag if the message store sets the STORE_UNCOMPRESSED_RTF flag in its PR_STORE_SUPPORT_MASK property, to create an uncompressed version of the compressed RTF data.
  5. Display the uncompressed RTF data.

If there are attachments in the message, perform the following tasks in addition to the preceding steps:

  1. Before reading from the uncompressed RTF stream, sort the message's attachment table on the value of the PR_RENDERING_POSITION property. The attachments will now be in order by how they appear in the message.
  2. As your client scans through the RTF stream, check for the token "\objattph". The character following the token is the place to put the next attachment from the sorted table. Handle attachments that have set their PR_RENDERING_POSITION property to -1 separately.

For more information, see Supporting Formatted Text in Incoming Messages: Client Responsibilities.

About Sample Source Code

See the following topic:

Sample RTF Utility