Back to index

lightning-sunbird  0.9+nobinonly
WabObject.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "nscore.h"
00039 #include "nsCRT.h"
00040 #include "wabobject.h"
00041 
00042 
00043 
00044 enum {
00045     ieidPR_DISPLAY_NAME = 0,
00046     ieidPR_ENTRYID,
00047        ieidPR_OBJECT_TYPE,
00048     ieidMax
00049 };
00050 
00051 static const SizedSPropTagArray(ieidMax, ptaEid)=
00052 {
00053     ieidMax,
00054     {
00055         PR_DISPLAY_NAME,
00056         PR_ENTRYID,
00057               PR_OBJECT_TYPE,
00058     }
00059 };
00060 
00061 
00062 enum {
00063     iemailPR_DISPLAY_NAME = 0,
00064     iemailPR_ENTRYID,
00065     iemailPR_EMAIL_ADDRESS,
00066     iemailPR_OBJECT_TYPE,
00067     iemailMax
00068 };
00069 static const SizedSPropTagArray(iemailMax, ptaEmail)=
00070 {
00071     iemailMax,
00072     {
00073         PR_DISPLAY_NAME,
00074         PR_ENTRYID,
00075         PR_EMAIL_ADDRESS,
00076         PR_OBJECT_TYPE
00077     }
00078 };
00079 
00080 typedef struct {
00081        PRBool        multiLine;
00082        ULONG         tag;
00083        char *        pLDIF;
00084 } AddrImportField;
00085 
00086 #define       kExtraUserFields     10
00087 AddrImportField             extraUserFields[kExtraUserFields] = {
00088        {PR_TRUE, PR_COMMENT, "description:"},
00089        {PR_FALSE, PR_BUSINESS_TELEPHONE_NUMBER, "telephonenumber:"},
00090        {PR_FALSE, PR_HOME_TELEPHONE_NUMBER, "homephone:"},
00091        {PR_FALSE, PR_COMPANY_NAME, "o:"},
00092        {PR_FALSE, PR_TITLE, "title:"},
00093        {PR_FALSE, PR_BUSINESS_FAX_NUMBER, "facsimiletelephonenumber:"},
00094        {PR_FALSE, PR_LOCALITY, "locality:"},
00095        {PR_FALSE, PR_STATE_OR_PROVINCE, "st:"},
00096        {PR_TRUE, PR_STREET_ADDRESS, "streetaddress:"},
00097        {PR_FALSE, PR_POSTAL_CODE, "postalcode:"}
00098 };
00099 
00100 #define       kWhitespace   " \t\b\r\n"
00101 
00102 #define TR_OUTPUT_EOL       "\r\n"
00103 
00104 #define       kLDIFPerson          "objectclass: top" TR_OUTPUT_EOL "objectclass: person" TR_OUTPUT_EOL
00105 #define kLDIFGroup          "objectclass: top" TR_OUTPUT_EOL "objectclass: groupOfNames" TR_OUTPUT_EOL
00106 
00107 /*********************************************************************************/
00108 
00109 
00110 // contructor for CWAB object
00111 //
00112 // pszFileName - FileName of WAB file to open
00113 //          if no file name is specified, opens the default
00114 //
00115 CWAB::CWAB(nsIFileSpec *file)
00116 {
00117     // Here we load the WAB Object and initialize it
00118     m_pUniBuff = NULL;
00119        m_uniBuffLen = 0;
00120 
00121        m_bInitialized = PR_FALSE;
00122        m_lpAdrBook = NULL;
00123        m_lpWABObject = NULL;
00124        m_hinstWAB = NULL;
00125 
00126     {
00127         TCHAR  szWABDllPath[MAX_PATH];
00128         DWORD  dwType = 0;
00129         ULONG  cbData = sizeof(szWABDllPath);
00130         HKEY hKey = NULL;
00131 
00132         *szWABDllPath = '\0';
00133         
00134         // First we look under the default WAB DLL path location in the
00135         // Registry. 
00136         // WAB_DLL_PATH_KEY is defined in wabapi.h
00137         //
00138         if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, WAB_DLL_PATH_KEY, 0, KEY_READ, &hKey))
00139             RegQueryValueEx( hKey, "", NULL, &dwType, (LPBYTE) szWABDllPath, &cbData);
00140 
00141         if(hKey) RegCloseKey(hKey);
00142 
00143         // if the Registry came up blank, we do a loadlibrary on the wab32.dll
00144         // WAB_DLL_NAME is defined in wabapi.h
00145         //
00146         m_hinstWAB = LoadLibrary( (lstrlen(szWABDllPath)) ? szWABDllPath : WAB_DLL_NAME );
00147     }
00148 
00149     if(m_hinstWAB)
00150     {
00151         // if we loaded the dll, get the entry point 
00152         //
00153         m_lpfnWABOpen = (LPWABOPEN) GetProcAddress(m_hinstWAB, "WABOpen");
00154 
00155         if(m_lpfnWABOpen)
00156         {
00157               char          fName[2] = {0, 0};
00158               char *        pPath = nsnull;
00159             HRESULT hr = E_FAIL;
00160             WAB_PARAM wp = {0};
00161             wp.cbSize = sizeof(WAB_PARAM);
00162             if (file != nsnull) {
00163               file->GetNativePath( &pPath);      
00164               wp.szFileName = (LPTSTR) pPath;
00165             }
00166             else
00167               wp.szFileName = (LPTSTR) fName;
00168         
00169             // if we choose not to pass in a WAB_PARAM object, 
00170             // the default WAB file will be opened up
00171             //
00172             hr = m_lpfnWABOpen(&m_lpAdrBook,&m_lpWABObject,&wp,0);
00173 
00174             if(!hr)
00175                 m_bInitialized = TRUE;
00176             
00177             if (pPath)
00178               nsCRT::free( pPath);
00179         }
00180     }
00181 
00182 }
00183 
00184 
00185 // Destructor
00186 //
00187 CWAB::~CWAB()
00188 {
00189        if (m_pUniBuff)
00190               delete [] m_pUniBuff;
00191 
00192     if(m_bInitialized)
00193     {
00194         if(m_lpAdrBook)
00195             m_lpAdrBook->Release();
00196 
00197         if(m_lpWABObject)
00198             m_lpWABObject->Release();
00199 
00200         if(m_hinstWAB)
00201             FreeLibrary(m_hinstWAB);
00202     }
00203 }
00204 
00205 
00206 HRESULT CWAB::IterateWABContents(CWabIterator *pIter, int *pDone)
00207 {
00208   if (!m_bInitialized || !m_lpAdrBook)
00209     return( E_FAIL);
00210   
00211   ULONG                     ulObjType =   0;
00212   LPMAPITABLE        lpAB =  NULL;
00213   ULONG                     cRows =       0;
00214   LPSRowSet          lpRowAB = NULL;
00215   LPABCONT           lpContainer = NULL;
00216   int                       cNumRows = 0;
00217   nsresult                  keepGoing;
00218   
00219   HRESULT                   hr = E_FAIL;
00220   
00221   ULONG                     lpcbEID = 0;
00222   LPENTRYID          lpEID = NULL;
00223   ULONG                     rowCount = 0;
00224   ULONG                     curCount = 0;
00225   
00226   nsString           uniStr;
00227   
00228   // Get the entryid of the root PAB container
00229   //
00230   hr = m_lpAdrBook->GetPAB( &lpcbEID, &lpEID);
00231   
00232   if (HR_FAILED( hr))
00233     goto exit;
00234   
00235   ulObjType = 0;
00236   
00237   // Open the root PAB container
00238   // This is where all the WAB contents reside
00239   //
00240   hr = m_lpAdrBook->OpenEntry(lpcbEID,
00241     (LPENTRYID)lpEID,
00242     NULL,
00243     0,
00244     &ulObjType,
00245     (LPUNKNOWN *)&lpContainer);
00246   
00247   m_lpWABObject->FreeBuffer(lpEID);
00248   
00249   lpEID = NULL;
00250   
00251   if(HR_FAILED(hr))
00252     goto exit;
00253   
00254   // Get a contents table of all the contents in the
00255   // WABs root container
00256   //
00257   hr = lpContainer->GetContentsTable( 0,
00258     &lpAB);
00259   
00260   if(HR_FAILED(hr))
00261     goto exit;
00262   
00263   hr = lpAB->GetRowCount( 0, &rowCount);
00264   if (HR_FAILED(hr))
00265     rowCount = 100;
00266   if (rowCount == 0)
00267     rowCount = 1;
00268   
00269   // Order the columns in the ContentsTable to conform to the
00270   // ones we want - which are mainly DisplayName, EntryID and
00271   // ObjectType
00272   // The table is gauranteed to set the columns in the order 
00273   // requested
00274   //
00275   hr =lpAB->SetColumns( (LPSPropTagArray)&ptaEid, 0 );
00276   
00277   if(HR_FAILED(hr))
00278     goto exit;
00279   
00280   
00281   // Reset to the beginning of the table
00282   //
00283   hr = lpAB->SeekRow( BOOKMARK_BEGINNING, 0, NULL );
00284   
00285   if(HR_FAILED(hr))
00286     goto exit;
00287   
00288   // Read all the rows of the table one by one
00289   //
00290   
00291   do {
00292     
00293     hr = lpAB->QueryRows(1, 0, &lpRowAB);
00294     
00295     if(HR_FAILED(hr))
00296       break;
00297     
00298     if(lpRowAB)
00299     {
00300       cNumRows = lpRowAB->cRows;
00301       
00302       if (cNumRows)
00303       {
00304         LPTSTR lpsz = lpRowAB->aRow[0].lpProps[ieidPR_DISPLAY_NAME].Value.lpszA;
00305         LPENTRYID lpEID = (LPENTRYID) lpRowAB->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.lpb;
00306         ULONG cbEID = lpRowAB->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.cb;
00307         
00308         // There are 2 kinds of objects - the MAPI_MAILUSER contact object
00309         // and the MAPI_DISTLIST contact object
00310         // For the purposes of this sample, we will only consider MAILUSER
00311         // objects
00312         //
00313         if(lpRowAB->aRow[0].lpProps[ieidPR_OBJECT_TYPE].Value.l == MAPI_MAILUSER)
00314         {
00315           // We will now take the entry-id of each object and cache it
00316           // on the listview item representing that object. This enables
00317           // us to uniquely identify the object later if we need to
00318           //
00319           CStrToUnicode( lpsz, uniStr);
00320           keepGoing = pIter->EnumUser( uniStr.get(), lpEID, cbEID);
00321           curCount++;
00322           if (pDone) {
00323             *pDone = (curCount * 100) / rowCount;
00324             if (*pDone > 100)
00325               *pDone = 100;
00326           }
00327         }
00328       }
00329       FreeProws(lpRowAB );         
00330     }
00331     
00332     
00333   } while ( SUCCEEDED(hr) && cNumRows && lpRowAB && NS_SUCCEEDED(keepGoing) )  ;
00334   
00335   hr = lpAB->SeekRow( BOOKMARK_BEGINNING, 0, NULL );
00336   
00337   if(HR_FAILED(hr))
00338     goto exit;
00339   
00340   // Read all the rows of the table one by one
00341   //
00342   keepGoing = TRUE;
00343   do {
00344     
00345     hr = lpAB->QueryRows(1, 0, &lpRowAB);
00346     
00347     if(HR_FAILED(hr))
00348       break;
00349     
00350     if(lpRowAB)
00351     {
00352       cNumRows = lpRowAB->cRows;
00353       
00354       if (cNumRows)
00355       {
00356         LPTSTR lpsz = lpRowAB->aRow[0].lpProps[ieidPR_DISPLAY_NAME].Value.lpszA;
00357         LPENTRYID lpEID = (LPENTRYID) lpRowAB->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.lpb;
00358         ULONG cbEID = lpRowAB->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.cb;
00359         
00360         // There are 2 kinds of objects - the MAPI_MAILUSER contact object
00361         // and the MAPI_DISTLIST contact object
00362         // For the purposes of this sample, we will only consider MAILUSER
00363         // objects
00364         //
00365         if(lpRowAB->aRow[0].lpProps[ieidPR_OBJECT_TYPE].Value.l == MAPI_DISTLIST)
00366         {
00367           LPABCONT distListContainer = NULL;
00368           // We will now take the entry-id of each object and cache it
00369           // on the listview item representing that object. This enables
00370           // us to uniquely identify the object later if we need to
00371           //
00372           hr = m_lpAdrBook->OpenEntry(cbEID, lpEID, NULL,
00373             0,&ulObjType,(LPUNKNOWN *)&distListContainer);
00374           
00375           LPMAPITABLE              distListTable =  NULL;
00376 
00377 
00378           // Get a contents table of the dist list
00379           //
00380           hr = distListContainer->GetContentsTable( 0, &distListTable);
00381           if (lpAB) 
00382           {
00383             hr = distListTable->GetRowCount( 0, &rowCount);
00384             if (HR_FAILED(hr))
00385               rowCount = 100;
00386             if (rowCount == 0)
00387               rowCount = 1;
00388   
00389             // Order the columns in the ContentsTable to conform to the
00390             // ones we want - which are mainly DisplayName, EntryID and
00391             // ObjectType
00392             // The table is gauranteed to set the columns in the order 
00393             // requested
00394             //
00395             hr = distListTable->SetColumns( (LPSPropTagArray)&ptaEid, 0 );
00396             CStrToUnicode( lpsz, uniStr);
00397             keepGoing = pIter->EnumList( uniStr.get(), lpEID, cbEID, distListTable);
00398             curCount++;
00399             if (pDone) {
00400               *pDone = (curCount * 100) / rowCount;
00401               if (*pDone > 100)
00402                 *pDone = 100;
00403             }
00404           }
00405           if (distListContainer)
00406             distListContainer->Release();
00407           if (distListTable)
00408             distListTable->Release();
00409         }
00410       }
00411       FreeProws(lpRowAB );         
00412     }
00413     
00414   } while ( SUCCEEDED(hr) && cNumRows && lpRowAB && NS_SUCCEEDED(keepGoing) )  ;
00415   
00416   
00417 exit:
00418   
00419   if ( lpContainer )
00420     lpContainer->Release();
00421   
00422   if ( lpAB )
00423     lpAB->Release();
00424   
00425   return hr;
00426 }
00427 
00428 
00429 
00430 
00431 
00432 
00433 void CWAB::FreeProws(LPSRowSet prows)
00434 {
00435        ULONG         irow;
00436        if (!prows)
00437               return;
00438        for (irow = 0; irow < prows->cRows; ++irow)
00439               m_lpWABObject->FreeBuffer(prows->aRow[irow].lpProps);
00440        m_lpWABObject->FreeBuffer(prows);
00441 }
00442 
00443 
00444 LPDISTLIST CWAB::GetDistList( ULONG cbEid, LPENTRYID pEid)
00445 {
00446        if (!m_bInitialized || !m_lpAdrBook)
00447               return( NULL);
00448        
00449        LPDISTLIST    lpDistList = NULL;
00450        ULONG         ulObjType;
00451 
00452        m_lpAdrBook->OpenEntry( cbEid, pEid, NULL, 0, &ulObjType, (LPUNKNOWN *)&lpDistList);
00453        return( lpDistList);
00454 }
00455 
00456 LPSPropValue CWAB::GetListProperty( LPDISTLIST pUser, ULONG tag)
00457 {
00458        if (!pUser)
00459               return( NULL);
00460 
00461        int    sz = CbNewSPropTagArray( 1);
00462        SPropTagArray *pTag = (SPropTagArray *) new char[sz];
00463        pTag->cValues = 1;
00464        pTag->aulPropTag[0] = tag;
00465        LPSPropValue  lpProp = NULL;
00466        ULONG  cValues = 0;
00467        HRESULT hr = pUser->GetProps( pTag, 0, &cValues, &lpProp);
00468        delete [] pTag;
00469        if (HR_FAILED( hr) || (cValues != 1)) {
00470               if (lpProp)
00471                      m_lpWABObject->FreeBuffer( lpProp);
00472               return( NULL);
00473        }
00474        return( lpProp);
00475 }
00476 
00477 LPMAILUSER CWAB::GetUser( ULONG cbEid, LPENTRYID pEid)
00478 {
00479        if (!m_bInitialized || !m_lpAdrBook)
00480               return( NULL);
00481        
00482        LPMAILUSER    lpMailUser = NULL;
00483        ULONG         ulObjType;
00484 
00485        m_lpAdrBook->OpenEntry( cbEid, pEid, NULL, 0, &ulObjType, (LPUNKNOWN *)&lpMailUser);
00486        return( lpMailUser);
00487 }
00488 
00489 LPSPropValue CWAB::GetUserProperty( LPMAILUSER pUser, ULONG tag)
00490 {
00491        if (!pUser)
00492               return( NULL);
00493 
00494        ULONG  uTag = tag;
00495        /* 
00496               Getting Unicode does not help with getting the right
00497               international charset.  Windoze bloze.
00498        */
00499        /*
00500        if (PROP_TYPE( uTag) == PT_STRING8) {
00501               uTag = CHANGE_PROP_TYPE( tag, PT_UNICODE);
00502        }
00503        */
00504 
00505        int    sz = CbNewSPropTagArray( 1);
00506        SPropTagArray *pTag = (SPropTagArray *) new char[sz];
00507        pTag->cValues = 1;
00508        pTag->aulPropTag[0] = uTag;
00509        LPSPropValue  lpProp = NULL;
00510        ULONG  cValues = 0;
00511        HRESULT hr = pUser->GetProps( pTag, 0, &cValues, &lpProp);
00512        if (HR_FAILED( hr) || (cValues != 1)) {
00513               if (lpProp)
00514                      m_lpWABObject->FreeBuffer( lpProp);
00515               lpProp = NULL;
00516               if (uTag != tag) {
00517                      pTag->cValues = 1;
00518                      pTag->aulPropTag[0] = tag;
00519                      cValues = 0;
00520                      hr = pUser->GetProps( pTag, 0, &cValues, &lpProp);
00521                      if (HR_FAILED( hr) || (cValues != 1)) {
00522                             if (lpProp)
00523                                    m_lpWABObject->FreeBuffer( lpProp);
00524                             lpProp = NULL;
00525                      }
00526               }
00527        }
00528        delete [] pTag;
00529        return( lpProp);
00530 }
00531 
00532 void CWAB::CStrToUnicode( const char *pStr, nsString& result)
00533 {
00534        result.Truncate( 0);
00535        int wLen = MultiByteToWideChar( CP_ACP, 0, pStr, -1, m_pUniBuff, 0);
00536        if (wLen >= m_uniBuffLen) {
00537               if (m_pUniBuff)
00538                      delete [] m_pUniBuff;
00539               m_pUniBuff = new PRUnichar[wLen + 64];
00540               m_uniBuffLen = wLen + 64;
00541        }
00542        if (wLen) {
00543               MultiByteToWideChar( CP_ACP, 0, pStr, -1, m_pUniBuff, m_uniBuffLen);
00544               result = m_pUniBuff;
00545        }
00546 }
00547 
00548 // If the value is a string, get it...
00549 void CWAB::GetValueString( LPSPropValue pVal, nsString& val)
00550 {
00551        val.Truncate( 0);
00552        
00553        if (!pVal)
00554               return;
00555 
00556     switch( PROP_TYPE( pVal->ulPropTag)) {
00557        case PT_STRING8: {
00558                      CStrToUnicode( (const char *) (pVal->Value.lpszA), val);
00559               }
00560         break;
00561               case PT_UNICODE:
00562                      val = (PRUnichar *) (pVal->Value.lpszW);
00563               break;
00564               case PT_MV_STRING8: {
00565                      nsString      tmp;
00566             ULONG    j;
00567             for(j = 0; j < pVal->Value.MVszA.cValues; j++) {
00568                             CStrToUnicode( (const char *) (pVal->Value.MVszA.lppszA[j]), tmp);
00569                 val += tmp;
00570                 val.AppendWithConversion(TR_OUTPUT_EOL);
00571             }
00572         }
00573         break;
00574               case PT_MV_UNICODE: {
00575             ULONG    j;
00576             for(j = 0; j < pVal->Value.MVszW.cValues; j++) {
00577                 val += (PRUnichar *) (pVal->Value.MVszW.lppszW[j]);
00578                 val.AppendWithConversion(TR_OUTPUT_EOL);
00579             }
00580         }
00581         break;
00582 
00583               case PT_I2:
00584               case PT_LONG:
00585               case PT_R4:
00586               case PT_DOUBLE:
00587               case PT_BOOLEAN: {    
00588                      /*
00589                      TCHAR sz[256];
00590             wsprintf(sz,"%d", pVal->Value.l);
00591             val = sz;
00592                      */
00593         }
00594         break;
00595 
00596               case PT_BINARY:
00597               break;
00598 
00599               default:
00600         break;
00601     }
00602 
00603        val.Trim( kWhitespace, PR_TRUE, PR_TRUE);
00604 }
00605 
00606 
00607 
00608 
00609 
00610 /*
00611 BOOL CWabIterateProcess::SanitizeMultiLine( CString& val)
00612 {
00613        val.TrimLeft();
00614        val.TrimRight();
00615        int idx = val.FindOneOf( "\x0D\x0A");
00616        if (idx == -1)
00617               return( FALSE);
00618 
00619        // needs encoding
00620        U32 bufSz = UMimeEncode::GetBufferSize( val.GetLength());
00621        P_U8 pBuf = new U8[bufSz];
00622        U32 len = UMimeEncode::ConvertBuffer( (PC_U8)((PC_S8)val), val.GetLength(), pBuf, 66, 52, "\x0D\x0A ");
00623        pBuf[len] = 0;
00624        val = pBuf;
00625        delete pBuf;
00626        return( TRUE);
00627 }
00628 
00629 BOOL CWabIterateProcess::EnumUser( LPCTSTR pName, LPENTRYID pEid, ULONG cbEid)
00630 {
00631        TRACE1( "User: %s\n", pName);
00632 
00633        LPMAILUSER    pUser = m_pWab->GetUser( cbEid, pEid);
00634        
00635        // Get the "required" strings first
00636        CString              lastName;
00637        CString              firstName;
00638        CString              eMail;
00639        CString              nickName;
00640        CString              middleName;
00641 
00642        if (!pUser) {
00643               UDialogs::ErrMessage1( IDS_ENTRY_ERROR, pName);
00644               return( FALSE);
00645        }
00646 
00647        LPSPropValue  pProp = m_pWab->GetUserProperty( pUser, PR_EMAIL_ADDRESS);
00648        if (pProp) {
00649               m_pWab->GetValueString( pProp, eMail);
00650               SanitizeValue( eMail);
00651               m_pWab->FreeProperty( pProp);
00652        }
00653        pProp = m_pWab->GetUserProperty( pUser, PR_GIVEN_NAME);
00654        if (pProp) {
00655               m_pWab->GetValueString( pProp, firstName);
00656               SanitizeValue( firstName);
00657               m_pWab->FreeProperty( pProp);
00658        }
00659        pProp = m_pWab->GetUserProperty( pUser, PR_SURNAME);
00660        if (pProp) {
00661               m_pWab->GetValueString( pProp, lastName);
00662               SanitizeValue( lastName);
00663               m_pWab->FreeProperty( pProp);
00664        }
00665        pProp = m_pWab->GetUserProperty( pUser, PR_MIDDLE_NAME);
00666        if (pProp) {
00667               m_pWab->GetValueString( pProp, middleName);
00668               SanitizeValue( middleName);
00669               m_pWab->FreeProperty( pProp);
00670        }
00671        pProp = m_pWab->GetUserProperty( pUser, PR_NICKNAME);
00672        if (pProp) {
00673               m_pWab->GetValueString( pProp, nickName);
00674               SanitizeValue( nickName);
00675               m_pWab->FreeProperty( pProp);
00676        }
00677        if (nickName.IsEmpty())
00678               nickName = pName;
00679        if (firstName.IsEmpty()) {
00680               firstName = nickName;
00681               middleName.Empty();
00682               lastName.Empty();
00683        }
00684        if (lastName.IsEmpty())
00685               middleName.Empty();
00686 
00687        if (eMail.IsEmpty())
00688               eMail = nickName;
00689 
00690 
00691        // We now have the required fields
00692        // write them out followed by any optional fields!
00693        BOOL   result = TRUE;
00694 
00695        if (m_recordsDone)
00696               result = m_out.WriteEol();
00697 
00698        CString              line;
00699        CString              header;
00700        line.LoadString( IDS_LDIF_DN_START);
00701        line += firstName;
00702        if (!middleName.IsEmpty()) {
00703               line += ' ';
00704               line += middleName;
00705        }
00706        if (!lastName.IsEmpty()) {
00707               line += ' ';
00708               line += lastName;
00709        }
00710        header.LoadString( IDS_LDIF_DN_MIDDLE);
00711        line += header;
00712        line += eMail;
00713        result = result && m_out.WriteStr( line);
00714        result = result && m_out.WriteEol();
00715 
00716        line.LoadString( IDS_FIELD_LDIF_FULLNAME);
00717        line += ' ';
00718        line += firstName;
00719        if (!middleName.IsEmpty()) {
00720               line += ' ';
00721               line += middleName;
00722        }
00723        if (!lastName.IsEmpty()) {
00724               line += ' ';
00725               line += lastName;
00726        }
00727        result = result && m_out.WriteStr( line);
00728        result = result && m_out.WriteEol();
00729 
00730 
00731        line.LoadString( IDS_FIELD_LDIF_GIVENNAME);
00732        line += ' ';
00733        line += firstName;
00734        result = result && m_out.WriteStr( line);
00735        result = result && m_out.WriteEol();
00736 
00737        if (!lastName.IsEmpty()) {
00738               line.LoadString( IDS_FIELD_LDIF_LASTNAME);
00739               if (!middleName.IsEmpty()) {
00740                      line += ' ';
00741                      line += middleName;
00742               }
00743               line += ' ';
00744               line += lastName;
00745               result = result && m_out.WriteStr( line);
00746               result = result && m_out.WriteEol();
00747        }
00748 
00749        result = result && m_out.WriteStr( kLDIFPerson);
00750        
00751        line.LoadString( IDS_FIELD_LDIF_EMAIL);
00752        line += ' ';
00753        line += eMail;
00754        result = result && m_out.WriteStr( line);
00755        result = result && m_out.WriteEol();
00756 
00757        line.LoadString( IDS_FIELD_LDIF_NICKNAME);
00758        line += ' ';
00759        line += nickName;
00760        result = result && m_out.WriteStr( line);
00761        result = result && m_out.WriteEol();
00762 
00763        // Do all of the extra fields!
00764        CString       value;
00765        BOOL   encoded = FALSE;
00766        for (int i = 0; i < kExtraUserFields; i++) {
00767               value.Empty();
00768               pProp = m_pWab->GetUserProperty( pUser, extraUserFields[i].tag);
00769               if (pProp) {
00770                      m_pWab->GetValueString( pProp, value);
00771                      m_pWab->FreeProperty( pProp);
00772               }
00773               if (extraUserFields[i].multiLine) {
00774                      encoded = SanitizeMultiLine( value);
00775               }
00776               else
00777                      SanitizeValue( value);
00778               if (!value.IsEmpty()) {
00779                      line = extraUserFields[i].pLDIF;
00780                      if (encoded) {
00781                             line += ": ";
00782                             encoded = FALSE;
00783                      }
00784                      else
00785                             line += ' ';
00786                      line += value;
00787                      result = result && m_out.WriteStr( line);
00788                      result = result && m_out.WriteEol();
00789               }
00790        }
00791 
00792        m_pWab->ReleaseUser( pUser);
00793 
00794        if (!result) {
00795               UDialogs::ErrMessage0( IDS_ADDRESS_SAVE_ERROR);
00796        }
00797 
00798        m_totalDone += kValuePerUser;
00799        m_recordsDone++;
00800 
00801        return( result);
00802 }
00803 */
00804 
00805 
00806  
00807 
00808 /*
00809 BOOL CWabIterateProcess::EnumList( LPCTSTR pName, LPENTRYID pEid, ULONG cbEid)
00810 {
00811        TRACE1( "List: %s\n", pName);
00812 
00813        LPDISTLIST           pList = m_pWab->GetDistList( cbEid, pEid);
00814        if (!pList) {
00815               UDialogs::ErrMessage1( IDS_ENTRY_ERROR, pName);
00816               return( FALSE);
00817        }
00818 
00819        // Find out if this is just a regular entry or a true list...
00820        CString                     eMail;
00821        LPSPropValue  pProp = m_pWab->GetListProperty( pList, PR_EMAIL_ADDRESS);
00822        if (pProp) {
00823               m_pWab->GetValueString( pProp, eMail);
00824               SanitizeValue( eMail);
00825               m_pWab->FreeProperty( pProp);
00826               // Treat this like a regular entry...
00827               if (!eMail.IsEmpty()) {
00828                      m_pWab->ReleaseDistList( pList);
00829                      return( WriteListUserEntry( pName, eMail));
00830               }
00831        }
00832 
00833        // This may very well be a list, find the entries...
00834        m_pListTable = OpenDistList( pList);
00835        if (m_pListTable) {
00836               m_pList = pList;
00837               m_listName = pName;
00838               m_listDone = 0;
00839               m_listHeaderDone = FALSE;
00840               m_state = kEnumListState;
00841        }
00842        else {
00843               m_pWab->ReleaseDistList( pList);
00844               m_recordsDone++;
00845               m_totalDone += kValuePerUser;
00846        }
00847 
00848        return( TRUE);
00849 }
00850 
00851 BOOL CWabIterateProcess::EnumNextListUser( BOOL *pDone)
00852 {
00853        HRESULT                     hr;
00854        int                         cNumRows = 0;
00855        LPSRowSet            lpRowAB = NULL;
00856        BOOL                 keepGoing = TRUE;
00857 
00858        if (!m_pListTable)
00859               return( FALSE);
00860 
00861        hr = m_pListTable->QueryRows( 1, 0, &lpRowAB);
00862 
00863        if(HR_FAILED(hr)) {
00864               UDialogs::ErrMessage0( IDS_ERROR_READING_WAB);
00865               return( FALSE);
00866        }
00867 
00868        if(lpRowAB) {
00869               cNumRows = lpRowAB->cRows;
00870 
00871               if (cNumRows) {
00872                      LPTSTR lpsz = lpRowAB->aRow[0].lpProps[ieidPR_DISPLAY_NAME].Value.lpszA;
00873                      LPENTRYID lpEID = (LPENTRYID) lpRowAB->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.lpb;
00874                      ULONG cbEID = lpRowAB->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.cb;
00875             if(lpRowAB->aRow[0].lpProps[ieidPR_OBJECT_TYPE].Value.l == MAPI_DISTLIST) {
00876                             keepGoing = HandleListList( lpsz, lpEID, cbEID);     
00877                   }
00878                      else if (lpRowAB->aRow[0].lpProps[ieidPR_OBJECT_TYPE].Value.l == MAPI_MAILUSER) {
00879                             keepGoing = HandleListUser( lpsz, lpEID, cbEID);     
00880                      }
00881               }
00882               m_pWab->FreeProws( lpRowAB);              
00883        }
00884 
00885        if (!cNumRows || !lpRowAB) {
00886               *pDone = TRUE;
00887               m_pListTable->Release();
00888               m_pListTable = NULL;
00889               if (m_pList)
00890                      m_pWab->ReleaseDistList( m_pList);
00891               m_pList = NULL;
00892               if (m_listDone < kValuePerUser)
00893                      m_totalDone += (kValuePerUser - m_listDone);
00894               m_recordsDone++;
00895               return( keepGoing);
00896        }
00897 
00898        if (!keepGoing)
00899               return( FALSE);
00900 
00901        if (m_listDone < kValuePerUser) {
00902               m_listDone++;
00903               m_totalDone++;
00904        }
00905 
00906        return( TRUE);
00907 }
00908 
00909 BOOL CWabIterateProcess::HandleListList( LPCTSTR pName, LPENTRYID lpEid, ULONG cbEid)
00910 {
00911        BOOL                 result;
00912        LPDISTLIST           pList = m_pWab->GetDistList( cbEid, lpEid);
00913        if (!pList) {
00914               UDialogs::ErrMessage1( IDS_ENTRY_ERROR, pName);
00915               return( FALSE);
00916        }
00917 
00918        CString                     eMail;
00919        LPSPropValue  pProp = m_pWab->GetListProperty( pList, PR_EMAIL_ADDRESS);
00920        if (pProp) {
00921               m_pWab->GetValueString( pProp, eMail);
00922               SanitizeValue( eMail);
00923               m_pWab->FreeProperty( pProp);
00924               // Treat this like a regular entry...
00925               if (!eMail.IsEmpty()) {
00926                      // write out a member based on pName and eMail
00927                      result = WriteGroupMember( pName, eMail);
00928                      m_pWab->ReleaseDistList( pList);
00929                      return( result);
00930               }
00931        }
00932 
00933        // iterate the list and add each member to the top level list
00934        LPMAPITABLE   pTable = OpenDistList( pList);
00935        if (!pTable) {
00936               TRACE0( "Error opening table for list\n");
00937               m_pWab->ReleaseDistList( pList);
00938               UDialogs::ErrMessage1( IDS_ENTRY_ERROR, pName);
00939               return( FALSE);
00940        }
00941 
00942        int                         cNumRows = 0;
00943        LPSRowSet            lpRowAB = NULL;
00944        HRESULT                     hr;
00945        BOOL                 keepGoing = TRUE;
00946 
00947        do {
00948               hr = pTable->QueryRows( 1, 0, &lpRowAB);
00949 
00950               if(HR_FAILED(hr)) {
00951                      UDialogs::ErrMessage0( IDS_ERROR_READING_WAB);
00952                      pTable->Release();
00953                      m_pWab->ReleaseDistList( pList);
00954                      return( FALSE);
00955               }
00956 
00957               if(lpRowAB) {
00958                      cNumRows = lpRowAB->cRows;
00959 
00960                      if (cNumRows) {
00961                             LPTSTR lpsz = lpRowAB->aRow[0].lpProps[ieidPR_DISPLAY_NAME].Value.lpszA;
00962                             LPENTRYID lpEID = (LPENTRYID) lpRowAB->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.lpb;
00963                             ULONG cbEID = lpRowAB->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.cb;
00964                             if(lpRowAB->aRow[0].lpProps[ieidPR_OBJECT_TYPE].Value.l == MAPI_DISTLIST) {
00965                                    keepGoing = HandleListList( lpsz, lpEID, cbEID);     
00966                             }
00967                             else if (lpRowAB->aRow[0].lpProps[ieidPR_OBJECT_TYPE].Value.l == MAPI_MAILUSER) {
00968                                    keepGoing = HandleListUser( lpsz, lpEID, cbEID);     
00969                             }
00970                      }
00971                      m_pWab->FreeProws( lpRowAB);              
00972               }
00973        }
00974        while (keepGoing && cNumRows && lpRowAB);
00975 
00976        pTable->Release();
00977        m_pWab->ReleaseDistList( pList);
00978        return( keepGoing);
00979 }
00980 
00981 BOOL CWabIterateProcess::HandleListUser( LPCTSTR pName, LPENTRYID lpEid, ULONG cbEid)
00982 {
00983        // Get the basic properties for building the member line
00984        LPMAILUSER    pUser = m_pWab->GetUser( cbEid, lpEid);
00985        
00986        // Get the "required" strings first
00987        CString              lastName;
00988        CString              firstName;
00989        CString              eMail;
00990        CString              nickName;
00991        CString              middleName;
00992 
00993        if (!pUser) {
00994               UDialogs::ErrMessage1( IDS_ENTRY_ERROR, pName);
00995               return( FALSE);
00996        }
00997 
00998        LPSPropValue  pProp = m_pWab->GetUserProperty( pUser, PR_EMAIL_ADDRESS);
00999        if (pProp) {
01000               m_pWab->GetValueString( pProp, eMail);
01001               SanitizeValue( eMail);
01002               m_pWab->FreeProperty( pProp);
01003        }
01004        pProp = m_pWab->GetUserProperty( pUser, PR_GIVEN_NAME);
01005        if (pProp) {
01006               m_pWab->GetValueString( pProp, firstName);
01007               SanitizeValue( firstName);
01008               m_pWab->FreeProperty( pProp);
01009        }
01010        pProp = m_pWab->GetUserProperty( pUser, PR_SURNAME);
01011        if (pProp) {
01012               m_pWab->GetValueString( pProp, lastName);
01013               SanitizeValue( lastName);
01014               m_pWab->FreeProperty( pProp);
01015        }
01016        pProp = m_pWab->GetUserProperty( pUser, PR_MIDDLE_NAME);
01017        if (pProp) {
01018               m_pWab->GetValueString( pProp, middleName);
01019               SanitizeValue( middleName);
01020               m_pWab->FreeProperty( pProp);
01021        }
01022        pProp = m_pWab->GetUserProperty( pUser, PR_NICKNAME);
01023        if (pProp) {
01024               m_pWab->GetValueString( pProp, nickName);
01025               SanitizeValue( nickName);
01026               m_pWab->FreeProperty( pProp);
01027        }
01028        if (nickName.IsEmpty())
01029               nickName = pName;
01030        if (firstName.IsEmpty()) {
01031               firstName = nickName;
01032               middleName.Empty();
01033               lastName.Empty();
01034        }
01035        if (lastName.IsEmpty())
01036               middleName.Empty();
01037 
01038        if (eMail.IsEmpty())
01039               eMail = nickName;
01040 
01041        m_pWab->ReleaseUser( pUser);
01042 
01043        CString       name = firstName;
01044        if (!middleName.IsEmpty()) {
01045               name += ' ';
01046               name += middleName;
01047        }
01048        if (!lastName.IsEmpty()) {
01049               name += ' ';
01050               name += lastName;
01051        }
01052        return( WriteGroupMember( name, eMail));
01053 }
01054 
01055 BOOL CWabIterateProcess::WriteGroupMember( const char *pName, const char *pEmail)
01056 {
01057        CString              middle;
01058        CString              line;
01059        BOOL          result;
01060 
01061        // Check for the header first
01062        if (!m_listHeaderDone) {
01063               if (m_recordsDone)
01064                      result = m_out.WriteEol();
01065               else
01066                      result = TRUE;
01067               line.LoadString( IDS_LDIF_DN_START);
01068               line += m_listName;
01069               line += TR_OUTPUT_EOL;
01070               middle.LoadString( IDS_FIELD_LDIF_FULLNAME);
01071               line += middle;
01072               line += m_listName;
01073               line += TR_OUTPUT_EOL;
01074               if (!result || !m_out.WriteStr( line) || !m_out.WriteStr( kLDIFGroup)) {
01075                      UDialogs::ErrMessage0( IDS_ADDRESS_SAVE_ERROR);
01076                      return( FALSE);
01077               }
01078               m_listHeaderDone = TRUE;
01079        }
01080 
01081        
01082        line.LoadString( IDS_FIELD_LDIF_MEMBER_START);
01083        line += pName;
01084        middle.LoadString( IDS_LDIF_DN_MIDDLE);
01085        line += middle;
01086        line += pEmail;
01087        line += TR_OUTPUT_EOL;
01088        if (!m_out.WriteStr( line)) {
01089               UDialogs::ErrMessage0( IDS_ADDRESS_SAVE_ERROR);
01090               return( FALSE);
01091        }
01092 
01093        if (m_listDone < kValuePerUser) {
01094               m_listDone++;
01095               m_totalDone++;
01096        }
01097 
01098        return( TRUE);
01099 }
01100 */
01101