CMailMessage::SetPart Method  
 
INT SetPart(
  INT nNewPart  
);

The SetPart method sets the current message part index for the specified message.

Parameters

nNewPart
The new message part index. A value of zero specifies the main message part.

Return Value

If the method succeeds, the return value is the previous message part index. If the method fails, the return value is MIME_ERROR. To get extended error information, call GetLastError.

Remarks

Multipart email messages are structured using the MIME (Multipurpose Internet Mail Extensions) standard, which allows a single email to contain multiple content types, such as plain text, HTML, and file attachments, within a single message body. These components are organized as discrete parts, each with its own headers and body, separated by unique MIME boundaries. In a typical multipart/alternative message, part 0 often contains the message preamble (e.g.: "This is a multipart message in MIME format"), part 1 may contain the plain text version of the message, and part 2 may contain the HTML version. However, multipart messages are not required to include both plain text and HTML content. A message may only include an HTML part and one or more attachments, or any other combination of content types. The structure and ordering of parts depends entirely on how the original sender or mail client composed the message.

To simplify navigating these multipart structures, the SetPart and GetPart methods enable you to iterate through the individual parts of a message. The message parts are zero-based, with index 0 always referring to the top-level message headers and preamble. By calling SetPart, you can change the currently selected message part, enabling functions like GetHeader or GetText to operate on that specific segment. Calling GetPart returns the current part index, which can be useful for saving and restoring state while iterating over a message.

The internal MIME parser flattens multipart messages, meaning that if a message contains nested multipart sections (such as a multipart/mixed part containing a multipart/alternative part), all leaf parts are presented in a linear sequence. This simplifies access and avoids the complexity of recursive traversal. You can determine the total number of parts using GetPartCount, and then iterate from part 0 to part N-1 to examine or extract each segment in order. This approach provides both fine-grained access to MIME message parts and an intuitive model for parsing even complex message structures.

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: csmsgv12.lib
Unicode: Implemented as Unicode and ANSI versions

See Also