Creating Message Text
Although some messages are made up of nothing more than a recipient list and a subject line, the content of most messages, specifically IPM.Note messages, includes text. Message text can be plain or formatted and is stored in two properties: PR_BODY and PR_RTF_COMPRESSED. If your client is plain text-based, set PR_BODY. If you support formatted text in the Rich Text Format (RTF), set either PR_RTF_COMPRESSED only or both PR_RTF_COMPRESSED and PR_BODY, depending on the message store provider that you are using. When an RTF-aware client is using an RTF-aware message store, it sets PR_RTF_COMPRESSED only. When an RTF-aware client is using a non-RTF-aware message store, it sets both properties.
Note Clients can use other types of formatted text in addition to RTF, but MAPI has not defined properties for managing types other than RTF.
To determine whether or not your message store supports Rich Text Format
-
Call the message store's IMAPIProp::GetProps method to retrieve the PR_STORE_SUPPORT_MASK property.
-
Check for the STORE_RTF_OK bit. If STORE_RTF_OK is set, the message store provider supports RTF text. If it is not set, the message store provider supports plain text only.
To set PR_RTF_COMPRESSED
-
Call the message's IMAPIProp::OpenProperty method to open the PR_RTF_COMPRESSED property, specifying IID_IStream as the interface identifier and setting the MAPI_CREATE flag.
-
Call the WrapCompressedRTFStream function, passing the STORE_UNCOMPRESSED_RTF flag if the STORE_UNCOMPRESSED_RTF bit is set in the message store's PR_STORE_SUPPORT_MASK property.
-
Release the original stream by calling its IUnknown::Release method.
-
Call either IStream::Write or IStream::CopyTo to write the message text to the stream returned from WrapCompressedRTFStream.
-
Call the Commit and Release methods on the stream returned from the OpenProperty method.
At this point, if the message store provider supports RTF, you have done all that is required. You can depend on the message store provider to handle synchronizing the message content and formatting and to create the PR_BODY property if necessary. RTF-aware message stores call RTFSync to handle the synchronization. If the RTF_SYNC_BODY_CHANGED flag is set to TRUE, the provider will recompute the PR_BODY property.
If your message store provider does not support RTF, you must also add non-RTF message content by setting the PR_BODY property.
To set PR_BODY
-
Call the IMAPIProp::OpenProperty method to open the PR_BODY property with the IStream interface.
-
Call IStream::Write to write the message text data to the stream returned from OpenProperty.
-
Call the RTFSync function to synchronize the text with the formatting. Because this is a new message, set both the RTF_SYNC_RTF_CHANGED and RTF_SYNC_BODY_CHANGED flags to indicate that both the RTF and plain text version of the message text has changed. RTFSync will set several related properties that the message store provider requires, such as PR_RTF_IN_SYNC, and write them to the message.
-
Call IStream::Commit and IUnknown::Release on the stream to commit the changes and free its memory.