|
LONG FindMessage( |
|
LONG nMessageId, |
|
|
LPCTSTR lpszHeaderName, |
|
|
LPCTSTR lpszHeaderValue, |
|
|
DWORD dwOptions |
|
); |
The FindMessage method searches for a message in the
current message store.
Parameters
- nMessageId
- An integer value which specifies the message number that should
be used when starting the search. The first message in the message
store has a value of one.
- lpszHeaderField
- A pointer to the string which specifies the name of the header
field that should be searched. The header field name is not case
sensitive. This parameter cannot be NULL.
- lpszHeaderValue
- A pointer to the string which specifies the header value that
should be searched for. The search options can be used to specify
if the search is case-sensitive, and whether the search should
return partial matches to the string. This parameter cannot be
NULL.
- dwOptions
- A value which specifies one or more options. This parameter is
constructed by using a bitwise operator with any of the following
values:
Constant |
Description |
MIME_SEARCH_DEFAULT |
Perform a complete match against the specified header
value. The comparison is not case-sensitive. |
MIME_SEARCH_CASE_SENSITIVE |
The header field value comparison will be case-sensitive.
Note that this does not affect header field names. Matches for
header names are always case-insensitive. |
MIME_SEARCH_PARTIAL_MATCH |
Perform a partial match against the specified header value.
It recommended that this option be used when searching for
matches to email addresses. |
MIME_SEARCH_DECODE_HEADERS |
Decode any encoded message headers before comparing them to
the specified value. This option can increase the amount of
time required to search the message store and should only be
used when necessary. |
Return Value
If the method succeeds, the return value is the number for the
message which matches the search criteria. If the method fails, the
return value is MIME_ERROR. To get extended error information, call
GetLastError.
Remarks
The FindMessage method is used to search the message store
for a message which matches a specific header field value. For
example, it can be used to find every message which is addressed to a
specific recipient or has a subject which matches a particular string
value.
Example
CMessageStore mailStorage;
LPCTSTR lpszHeader = _T("From");
LPCTSTR lpszAddress = _T("jsmith@example.com");
LONG nMessageId = 1;
if (! mailStorage.OpenFile(lpszFileName))
{
// Unable to open the storage file
return;
}
// Begin searching for messages from the specified sender
while (nMessageId != MIME_ERROR)
{
nMessageId = mailStorage.FindMessage(nMessageId,
lpszHeader,
lpszAddress,
MIME_SEARCH_PARTIAL_MATCH);
if (nMessageId != MIME_ERROR)
{
CMailMessage mailMessage;
// Get a copy of the message that was found
if (mailStorage.GetMessage(nMessageId, mailMessage))
{
// Store the message in a file
TCHAR szFileName[MAX_PATH];
BOOL bExported;
// Create a filename based on the message number
wsprintf(szFileName, _T("msg%05ld.tmp"), nMessageId);
// Export the message to a file
bExported = mailMessage.ExportMessage(szFileName);
}
// Increase the message ID to resume the search at the next message
nMessageId++;
}
}
mailStorage.CloseFile();
Requirements
Minimum Desktop Platform: Windows 7 (Service Pack 1)
Minimum Server Platform: Windows Server 2008 R2 (Service Pack 1)
Header File: cstools10.h
Import Library: csmsgv10.lib
Unicode: Implemented as Unicode and ANSI versions.
See Also
DeleteMessage,
GetMessage,
GetMessageCount
|
|