MimeFindAttachment Function  
 
INT WINAPI MimeFindAttachment(
  HMESSAGE hMessage,  
  LPCTSTR lpszFileName  
);

The MimeFindAttachment function searches the message for an attachment with the specified file name.

Parameters

hMessage
Handle to the message.
lpszFileName
Pointer to a string that specifies the name of the file attachment to search for. This parameter should only specify a base file name; it should not include a file path and cannot be NULL.

Return Value

If the function succeeds, the return value is the message part number that contains an attachment that matches the specified file name. If the message does not contain an attachment with the specified file name, the function will return MIME_ERROR. To get extended error information, call MimeGetLastError.

Remarks

This function will search the message for a attachment that matches the specified file name. The search is not case-sensitive, however it must match the attachment file name completely. This function will not match partial file names or names that include wildcard characters. To obtain a list of all of the files attached to a message, use the MimeEnumAttachments function.

Example

// The name of the file attachment to search for
LPCTSTR lpszFileName = _T("MyProject.docx");

// Search for the attached file and store it on the local system
INT nMessagePart = MimeFindAttachment(hMessage, lpszFileName);
if (nMessagePart != MIME_ERROR)
{
    MimeSetMessagePart(hMessage, nMessagePart);

    if (MimeExtractFile(hMessage, lpszFileName) != MIME_ERROR)
        _tprintf(_T("Saved file attachment %s\n"), lpszFileName);
    else
    {
        _tprintf(_T("Unable to save file attachment %s\n"), lpszFileName);
        return;
    }
}

Requirements

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

See Also

MimeAttachFile, MimeExtractAllFiles, MimeExtractFile, MimeExtractFileEx, MimeGetAttachedFileName