BOOL GetMessage( |
|
LONG nMessageId, |
|
|
CMailMessage& mailMessage |
|
); |
HMESSAGE GetMessage( |
|
LONG nMessageId, |
|
|
DWORD dwOptions |
|
); |
The GetMessage method retrieves a message from the current
message store.
Parameters
- nMessageId
- An integer value which specifies the message number that should
be retrieved. The first message in the message store has a value of
one.
- mailMessage
- A CMailMessage object which will reference the message
that is retrieved from the message store.
- 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 |
0 |
A shared message handle returned by the function. The
contents of this message will be overwritten each time this
function is called. |
MIME_COPY_STORED_MESSAGE |
A message handle is allocated for a copy of the message
that is retrieved from the message store. |
Return Value
If the first form of the method succeeds the return value is
non-zero, otherwise the return value is zero. If the second form of
the message succeeds it returns a message handle, otherwise it
returns INVALID_MESSAGE. To get extended error information, call
GetLastError.
Remarks
The second form of the GetMessage method returns a message
handle for the specified message in the message store. If no options
are specified, a temporary message handle is returned that is only
valid until the next message is retrieved. If a multithreaded
application changes the contents of the temporary message, it will
change for all other threads that have obtained a message handle
using this function.
If the application must have a unique copy of the message, the
MIME_COPY_STORED_MESSAGE option should be specified. Instead of
returning a handle to a shared message, the message is duplicated and
a handle to that copy of the message is returned. If a reference to a
CMailMessage object is passed to the first form of this
method, this option is used to create a copy of the message.
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
See Also
CMailMessage,
DeleteMessage,
FindMessage,
GetMessageCount,
StoreMessage
|