CMailMessage::GetTextLength Method  
 
LONG GetTextLength();

Parameters

None.

Return Value

This method returns the number of text characters in the current message part. If the current message part does not contain any text, the method will return zero. If the method fails it will return MIME_ERROR. To retrieve extended error information, call the GetLastError method.

Remarks

The GetTextLength method returns the actual length of the message text in the current message part. This value may be different than what is returned by the GetContentLength method, which returns the value of the content length in bytes, as specified in the message header. The GetTextLength method returns the number of characters (not bytes) in the message text after the contents have been decoded and converted to Unicode.

Example

if (mailMessage.GetContentType(hMessage) == MIME_CONTENT_TEXT)
{
    // Get the size of the decoded/converted message text
    LONG cchMessage = mailMessage.GetTextLength();
    if (cchMessage < 1)
    {
        _tprintf(_T("Message part %d does not contain any text\n"), nMessagePart);
        return;
    }

    // Allocate a buffer for the message text +1 for the null character
    LPTSTR pszMessage = (LPTSTR)malloc((cchMessage + 1) * sizeof(TCHAR));
    if (pszMessage == NULL) // Virtual memory exhausted
        return;

    // Copy the message contents to the buffer
    cchMessage = mailMessage.GetText(pszMessage, cchMessage + 1);
    if (cchMessage > 0)
    {
        // Write the contents of the message part to the console
        fwrite(pszMessage, sizeof(TCHAR), cchMessage, stdout);
        fflush(stdout);
    }

    // Free the memory allocated for our text buffer
    free(pszMessage);
}

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

See Also