IMessages Interface
Topic Last Modified: 2007-10-30
The IMessages interface defines methods and properties used to access a collection of Message objects retrieved by a call to GetMessages Method.
Because IMessages is only used for accessing messages on a file system, it is not useful in CDO for Microsoft® Exchange 2000 where messages are saved in the Exchange store.
CLSID
CD000025-8B95-11D1-82DB-00C04FB1625D
Extends
IDispatch
Type Library
Microsoft CDO for Exchange 2000 Library
DLL Implemented In
CDOEX.DLL
Member Summary
The following table lists the properties of the IMessages interface.
Name | Description |
---|---|
Returns an IEnumVARIANT interface on an object that can be used to enumerate the collection. |
|
Returns the number of Message objects contained in the collection. This property is read-only. |
|
Returns the name of the file containing the message on the file system. This property is read-only. |
|
Returns the specified Message object from the collection. This property is read-only. |
The following table lists the methods of the IMessages interface.
Name | Description |
---|---|
Deletes the specified Message object in the collection and from the file system. |
|
Deletes all Message objects in the collection along with all associated files on the file system. |
Remarks
The IDropDirectory.GetMessages method is used to return a collection of messages from a specified file system directory. The object reference returned by this method is of type IMessages. You can use this object to manage the collection of messages returned. You can get the total count of Message objects in the collection, retrieve one of the messages using the IMessages.Item method, and get the name of the file housing the message on the file system using the IMessages.Filename property.
Examples
This hypothetical example demonstrates how you could use the DropDirectory object (exposing the IDropDirectory interface) to enumerate the messages in the SMTP default drop directory and then copy each message addressed to a particular local account into an appropriate account mailbox directory. For example, you could have the local Administrator account's personal mail directory in the "c:\mailboxes\administrator" directory.
[Visual Basic]
Dim iDropDir as New CDO.DropDirectory
Dim iMsgs as CDO.IMessages
Dim iMsg as CDO.Message
Dim iStream as ADODB.Stream
Dim strTo as String
Dim ToRecipients as Variant
Dim strEmailName as String
Dim strAccountName as String
Dim strFileName as String
Dim strMailboxDir as String
Set iMsgs = iDropDir.GetMessages
For Each iMsg in iMsgs
strFileName = iMsgs.FileName(iMsg)
' trim to get the short file name
' from the full path
strFileName = Right(strFileName, Len(strFileName) - InStrRev(strFileName,"\") )
' Get the To recipients...and assume they are all local accounts
strTo = iMsg.To
ToRecipients = Split(strTo,",")
Dim j, lpos, rpos, posdiff
' loop through recipients and get account names for each
' Each address will be in either the "Name" <name@tld> or
' simply <name@tld>
' We get the account name by getting the string
' between "<" and "@"
For j = LBound(ToRecipients) to UBound(ToRecipients)
strEmailName = ToRecipients(j)
lpos = InStr(strEmailName,"<")
rpos = InStr(strEmailName,"@")
posdiff = rpos - lpos - 1
strAccountName = Mid(strEmailName,lpos + 1, posdiff)
' For the purposes of this example,
' each account's mailbox directory resides in the
' directory c:\mailboxes. For user Joe, their account
' directory would be c:\mailboxes\joe
strMailboxDir = "c:\mailboxes\" & strAccountName
' Get the message stream
Set iStream = iMsg.GetStream
' write the stream to the user's mailbox directory
' the file name is the same as the one in the drop directory
iStream.SaveToFile strMailboxDir & "\" & strFileName
iStream.Close
Set iStream = Nothing
Next j
Next iMsg
' delete the picked up messages
' this deletes the files from the file system as well.
iMsgs.DeleteAll
Set iMsgs = Nothing
Set iDropDir = Nothing
[C++,IDL]
#import "d:\program files\common files\system\ado\msado15.dll" no_namespace raw_interfaces_only
#import <cdosys.dll> no_namespace raw_interfaces_only
#include <iostream.h>
#include <assert.h>
#include <wchar.h>
void main(int argc, char* argv[])
{
CoInitialize(NULL);
IDropDirectory* pDropDir = NULL;
IMessages* pMsgs = NULL;
IUnknown* pUnk = NULL;
IEnumVARIANT* pEnum = NULL;
CoCreateInstance(
__uuidof(DropDirectory),
NULL,
CLSCTX_SERVER,
__uuidof(IDropDirectory),
(void**)&pDropDir));
pDropDir->GetMessages(L"",&pMsgs);
long count = 0;
pMsgs->get_Count(&count);
cout << count << endl;
pMsgs->get__NewEnum(&pUnk);
pUnk->QueryInterface(__uuidof(IEnumVARIANT),(void**)&pEnum);
ULONG cFetched = 0;
VARIANT var;
VariantInit(&var);
while (1) {
cFetched = 0;
pEnum->Next(1,&var,&cFetched);
cout << "fetched: " << cFetched << endl;
if(cFetched == 0)
break;
assert(var.vt == VT_DISPATCH);
IMessage* pMsg = NULL;
var.pdispVal->QueryInterface(__uuidof(IMessage),(void**)&pMsg);
var.pdispVal->Release();
VariantClear(&var);
VARIANT varIntf;
VariantInit(&varIntf);
V_VT(&varIntf) = VT_DISPATCH;
varIntf.pdispVal = pMsg;
varIntf.pdispVal->AddRef();
BSTR szFilename;
pMsgs->get_FileName(varIntf,&szFilename);
VariantClear(&varIntf);
cout << _bstr_t(szFilename) << endl;
wchar_t* pwchar;
pwchar = wcsrchr(szFilename,'\\');
_bstr_t mailfilename(pwchar+1);
BSTR to;
pMsg->get_To(&to);
wchar_t* pWChar = to;
wchar_t szbuffer[100];
wchar_t lt = '<';
wchar_t amp = '@';
wchar_t* pFirst;
unsigned int curPos = 0;
_bstr_t mailboxesroot = "c:\\mailboxes\\";
for(unsigned int k = 0;k<wcslen(pWChar);k++){
if(pWChar[k] == lt) {
pFirst = &pWChar[k];
curPos = k;
}
if(pWChar[k] == amp) {
cout << "amp" << endl;
wcsncpy_s(szbuffer,100,pFirst+1,k-curPos-1);
buffer[k-curPos-1] = (wchar_t)'\0';
_bstr_t filen = mailboxesroot + _bstr_t(buffer) + "\\" + _bstr_t(mailfilename);
_Stream* pStrm = NULL;
pMsg->GetStream(&pStrm);
pStrm->SaveToFile(filen,adSaveCreateOverWrite);
pStrm->Release();
}
}
pMsg->Release();
}
CoUninitialize();
}