[python-win32] getting global addressbook with extended mapi

Jürgen Kareta python at kareta.de
Tue Jun 7 18:32:01 CEST 2005


Hi Mark,

can you please give me some more instructions ?

>  A quick
>google may offer other advice - eg, see if you can find any C++ code that
>references the GAL by any way other than that function.
>
>Mark
>  
>
I found the following on 
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/mapi/html/11b2475b-c6e2-4251-a7a6-0f19a7e560f8.asp

*To open a specific container other than the PAB*

Open the address book's root container by calling the 
IAddrBook::OpenEntry 
<http://msdn.microsoft.com/library/en-us/mapi/html/3d3100da-9ba1-40be-a5b6-01e194b2b3a5.asp> 
method with a NULL entry identifier. The root container is constructed 
by MAPI and contains the top-level containers of all the address book 
providers in the profile.

ok

Get the list of top-level containers by calling the 
IMAPIContainer::GetHierarchyTable 
<http://msdn.microsoft.com/library/en-us/mapi/html/624d2e61-73b5-443b-848c-5a8e8827c38a.asp> 
method

ok

If you want a specific container type such as the global address list, 
restrict the table on PR_DISPLAY_TYPE 
<http://msdn.microsoft.com/library/en-us/mapi/html/b42ecd8d-47fb-43c2-93d8-0d3e55651664.asp>:
Create a property restriction to match PR_DISPLAY_TYPE with the value 
for the particular type of container you want to open. For example, to 
open the global address book, build a property restriction that matches 
PR_DISPLAY_TYPE with the DT_GLOBAL value.     d.    Call the 
IAddrBook::OpenEntry 
<http://msdn.microsoft.com/library/en-us/mapi/html/3d3100da-9ba1-40be-a5b6-01e194b2b3a5.asp> 
method with the PR_ENTRYID 
<http://msdn.microsoft.com/library/en-us/mapi/html/4282197f-6297-46ce-93c8-9002fa97a18e.asp> 
column from the row you want to open the container.
Create an SPropTagArray 
<http://msdn.microsoft.com/library/en-us/mapi/html/af0e208b-e15e-486c-b9a3-c4a2622f7773.asp> 
including PR_ENTRYID 
<http://msdn.microsoft.com/library/en-us/mapi/html/4282197f-6297-46ce-93c8-9002fa97a18e.asp>, 
PR_DISPLAY_TYPE 
<http://msdn.microsoft.com/library/en-us/mapi/html/b42ecd8d-47fb-43c2-93d8-0d3e55651664.asp>, 
and any other columns of interest.
Call the HrQueryAllRows 
<http://msdn.microsoft.com/library/en-us/mapi/html/de5668a0-c9d6-4865-9c1f-df177a7f26dd.asp> 
function passing your property tag array and restriction. Ordinarily, 
there will be a single global address list, but the call can return 
zero, one, or more rows depending on the address book providers in your 
profile. Be prepared to handle all these cases, not just one row.

<my code>
profileName = "Test"
session = mapi.MAPIInitialize(None)
session =mapi.MAPILogonEx(0,'test',None, mapi.MAPI_EXTENDED | 
mapi.MAPI_LOGON_UI |\
                             mapi.MAPI_NO_MAIL |mapi.MAPI_USE_DEFAULT)
hr=session.OpenAddressBook(0,None,mapi.AB_NO_DIALOG)
containers=hr.OpenEntry(None,None,mapi.MAPI_BEST_ACCESS)
con_list=containers.GetHierarchyTable(0)
restriction = (mapi.RES_CONTENT,   # a property restriction
                       (mapi.FL_SUBSTRING | mapi.FL_IGNORECASE | 
mapi.FL_LOOSE, # fuzz level
                        PR_DISPLAY_TYPE,   # of the given prop
                        (PR_DISPLAY_TYPE, 'DT_GLOBAL'))) # with given val
rows = mapi.HrQueryAllRows(con_list,
                                   (PR_ENTRYID, PR_DISPLAY_TYPE),   # 
columns to retrieve
                                   restriction,     # only these rows
                                   None,            # any sort order is fine
                                   0)     
</my code>

results in: TypeError: an integer is required. If I change 'DT_GLOBAL' 
to an integer, rows is empty.

I found some c code on 
http://www.wrconsulting.com/Software/Publications/Exchange/Folders/Client.htm:
// Prepare recipients list...
    ADRLIST * pal = NULL;
    MAPIAllocateBuffer(CbNewADRLIST(1), (LPVOID *) &pal);
    pal->cEntries = 1;

    SPropValue * pPropArray = NULL;
    MAPIAllocateBuffer(3 * sizeof(SPropValue), (LPVOID*) &pPropArray);

    pPropArray[0].ulPropTag = PR_RECIPIENT_TYPE;
    pPropArray[0].Value.l = MAPI_TO;

    pPropArray[1].ulPropTag = PR_DISPLAY_NAME;
    pPropArray[1].Value.lpszA = "Nik Okuntseff";

    pPropArray[2].ulPropTag = PR_ADDRTYPE;
    pPropArray[2].Value.lpszA = "EX";  // Exchange address type

    pal->aEntries[0].ulReserved1 = 0;
    pal->aEntries[0].cValues = 3;   // This "3" is important, otherwise 
the ResolveName fails!
    pal->aEntries[0].rgPropVals = pPropArray;

    // We'll IAddrBook interface to resolve display names to entry IDs.
    LPADRBOOK pAdrBook = NULL;
    hRes = pSession->OpenAddressBook(0, 0, MAPI_ACCESS_MODIFY, &pAdrBook );
    if (FAILED(hRes)) throw -1;
 
    // Call IAdrBook::ResolveName method to resolve display names in our 
list to entry IDs.
    hRes = pAdrBook->ResolveName(0, 0, NULL, pal);
    if (FAILED(hRes)) throw -1;

but I'm unable to adapt that in python.
regards,
Jürgen





More information about the Python-win32 mailing list