fix problem importing mailing lists from outlook, patch by wind.li@sun.com, r=me, sr=mscott 149961

This commit is contained in:
bienvenu%nventure.com 2003-11-04 22:46:40 +00:00
Родитель f4cc4a66e9
Коммит f051a570f3
6 изменённых файлов: 163 добавлений и 56 удалений

Просмотреть файл

@ -257,4 +257,14 @@ interface nsIAddrDatabase : nsIAddrDBAnnouncer {
* The column value (example: jabroni316)
*/
[noscript] void addRowValue(in nsIMdbRow aRow, in ACString aLDIFAttributeName, in AString aColValue);
void AddListCardColumnsToRow(in nsIAbCard aPCard,
in nsIMdbRow aPListRow,
in unsigned long aPos,
out nsIAbCard aPNewCard,
in boolean aInMailingList);
void InitCardFromRow(in nsIAbCard aNewCard,in nsIMdbRow aCardRow);
void SetListAddressTotal(in nsIMdbRow aListRow, in PRUint32 aTotal);
nsIMdbRow FindRowByCard(in nsIAbCard aCard);
};

Просмотреть файл

@ -1618,7 +1618,7 @@ NS_IMETHODIMP nsAddrDatabase::CreateNewListCardAndAddToDB(nsIAbDirectory *aList,
return rv;
}
nsresult nsAddrDatabase::AddListCardColumnsToRow
NS_IMETHODIMP nsAddrDatabase::AddListCardColumnsToRow
(nsIAbCard *pCard, nsIMdbRow *pListRow, PRUint32 pos, nsIAbCard** pNewCard, PRBool aInMailingList)
{
if (!pCard && !pListRow )
@ -1782,11 +1782,17 @@ PRUint32 nsAddrDatabase::GetListAddressTotal(nsIMdbRow* listRow)
return count;
}
nsresult nsAddrDatabase::SetListAddressTotal(nsIMdbRow* listRow, PRUint32 total)
NS_IMETHODIMP nsAddrDatabase::SetListAddressTotal(nsIMdbRow* aListRow, PRUint32 aTotal)
{
return AddIntColumn(listRow, m_ListTotalColumnToken, total);
return AddIntColumn(aListRow, m_ListTotalColumnToken, aTotal);
}
NS_IMETHODIMP nsAddrDatabase::FindRowByCard(nsIAbCard * aCard,nsIMdbRow **aRow)
{
nsXPIDLString primaryEmail;
aCard->GetPrimaryEmail(getter_Copies(primaryEmail));
return GetRowForCharColumn(primaryEmail, m_PriEmailColumnToken, PR_TRUE, aRow);
}
nsresult nsAddrDatabase::GetAddressRowByPos(nsIMdbRow* listRow, PRUint16 pos, nsIMdbRow** cardRow)
{
@ -2607,7 +2613,7 @@ nsresult nsAddrDatabase::AddLowercaseColumn
return rv;
}
nsresult nsAddrDatabase::GetCardFromDB(nsIAbCard *newCard, nsIMdbRow* cardRow)
NS_IMETHODIMP nsAddrDatabase::InitCardFromRow(nsIAbCard *newCard, nsIMdbRow* cardRow)
{
nsresult err = NS_OK;
if (!newCard || !cardRow)
@ -3348,7 +3354,7 @@ nsresult nsAddrDatabase::CreateCardFromDeletedCardsTable(nsIMdbRow* cardRow, mdb
if (NS_SUCCEEDED(rv) && dbpersonCard)
{
GetCardFromDB(personCard, cardRow);
InitCardFromRow(personCard, cardRow);
mdbOid tableOid;
m_mdbDeletedCardsTable->GetOid(GetEnv(), &tableOid);
@ -3383,7 +3389,7 @@ nsresult nsAddrDatabase::CreateCard(nsIMdbRow* cardRow, mdb_id listRowID, nsIAbC
if (NS_SUCCEEDED(rv) && dbpersonCard)
{
GetCardFromDB(personCard, cardRow);
InitCardFromRow(personCard, cardRow);
mdbOid tableOid;
m_mdbPabTable->GetOid(GetEnv(), &tableOid);

Просмотреть файл

@ -322,6 +322,12 @@ public:
static void PRTime2Seconds(PRTime prTime, PRUint32 *seconds);
NS_IMETHOD AddListCardColumnsToRow(nsIAbCard *aPCard, nsIMdbRow *aPListRow, PRUint32 aPos, nsIAbCard** aPNewCard, PRBool aInMailingList);
NS_IMETHOD InitCardFromRow(nsIAbCard *aNewCard, nsIMdbRow* aCardRow);
NS_IMETHOD SetListAddressTotal(nsIMdbRow* aListRow, PRUint32 aTotal);
NS_IMETHOD FindRowByCard(nsIAbCard * card,nsIMdbRow **aRow);
protected:
static void AddToCache(nsAddrDatabase* pAddrDB) {GetDBCache()->AppendElement(pAddrDB);}
@ -346,16 +352,13 @@ protected:
nsresult GetIntColumn(nsIMdbRow *cardRow, mdb_token outToken,
PRUint32* pValue, PRUint32 defaultValue);
nsresult GetBoolColumn(nsIMdbRow *cardRow, mdb_token outToken, PRBool* pValue);
nsresult GetCardFromDB(nsIAbCard *newCard, nsIMdbRow* cardRow);
nsresult GetListCardFromDB(nsIAbCard *listCard, nsIMdbRow* listRow);
nsresult GetListFromDB(nsIAbDirectory *newCard, nsIMdbRow* listRow);
nsresult AddRecordKeyColumnToRow(nsIMdbRow *pRow);
nsresult AddAttributeColumnsToRow(nsIAbCard *card, nsIMdbRow *cardRow);
nsresult AddListCardColumnsToRow(nsIAbCard *pCard, nsIMdbRow *pListRow, PRUint32 pos, nsIAbCard** pNewCard, PRBool aInMailingList);
nsresult AddListAttributeColumnsToRow(nsIAbDirectory *list, nsIMdbRow *listRow);
nsresult CreateCard(nsIMdbRow* cardRow, mdb_id listRowID, nsIAbCard **result);
nsresult CreateCardFromDeletedCardsTable(nsIMdbRow* cardRow, mdb_id listRowID, nsIAbCard **result);
nsresult SetListAddressTotal(nsIMdbRow* listRow, PRUint32 total);
nsresult DeleteCardFromListRow(nsIMdbRow* pListRow, mdb_id cardRowID);
void DeleteCardFromAllMailLists(mdb_id cardRowID);
nsresult NotifyListEntryChange(PRUint32 abCode, nsIAbDirectory *dir, nsIAddrDBListener *instigator);

Просмотреть файл

@ -505,13 +505,12 @@ BOOL CMapiApi::OpenMdbEntry( LPMDB lpMdb, ULONG cbEntry, LPENTRYID pEntryId, LPU
{
ULONG ulObjType;
HRESULT hr;
hr = lpMdb->OpenEntry( cbEntry,
hr = m_lpSession->OpenEntry(cbEntry,
pEntryId,
NULL,
0,
&ulObjType,
(LPUNKNOWN *) ppOpen);
if (FAILED(hr)) {
MAPI_TRACE2( "OpenMdbEntry failed: 0x%lx, %d\n", (long)hr, (int)hr);
return( FALSE);

Просмотреть файл

@ -1005,7 +1005,7 @@ nsresult nsOutlookMail::ImportAddresses( PRUint32 *pCount, PRUint32 *pTotal, con
pVal = m_mapi.GetMapiProperty( lpMsg, PR_SUBJECT);
if (pVal)
m_mapi.GetStringFromProp( pVal, subject);
CreateList(subject.get(), pDb);
CreateList(subject.get(), pDb, lpMsg, pFieldMap);
}
}
@ -1017,8 +1017,10 @@ nsresult nsOutlookMail::ImportAddresses( PRUint32 *pCount, PRUint32 *pTotal, con
rv = pDb->Commit(nsAddrDBCommitType::kLargeCommit);
return rv;
}
nsresult nsOutlookMail::CreateList( const PRUnichar * pName, nsIAddrDatabase *pDb)
nsresult nsOutlookMail::CreateList( const PRUnichar * pName,
nsIAddrDatabase *pDb,
LPMAPIPROP pUserList,
nsIImportFieldMap *pFieldMap)
{
// If no name provided then we're done.
if (!pName || !(*pName))
@ -1029,18 +1031,105 @@ nsresult nsOutlookMail::CreateList( const PRUnichar * pName, nsIAddrDatabase *pD
if (!pDb)
return rv;
nsCOMPtr <nsIMdbRow> newRow;
rv = pDb->GetNewListRow(getter_AddRefs(newRow));
nsCOMPtr <nsIMdbRow> newListRow;
rv = pDb->GetNewListRow(getter_AddRefs(newListRow));
NS_ENSURE_SUCCESS(rv, rv);
nsCAutoString column;
column.AssignWithConversion(pName);
rv = pDb->AddListName(newListRow, column.get());
NS_ENSURE_SUCCESS(rv, rv);
rv = pDb->AddListName(newRow, NS_ConvertUCS2toUTF8(pName).get());
HRESULT hr;
LPSPropValue aValue = NULL ;
ULONG aValueCount = 0 ;
LPSPropTagArray properties = NULL ;
m_mapi.MAPIAllocateBuffer(CbNewSPropTagArray(1),
(void **)&properties) ;
properties->cValues = 1;
properties->aulPropTag [0] = m_mapi.GetEmailPropertyTag(pUserList, 0x8054);
hr = pUserList->GetProps(properties, 0, &aValueCount, &aValue) ;
SBinaryArray *sa=(SBinaryArray *)&aValue->Value.bin;
LPENTRYID lpEid;
ULONG cbEid;
PRInt32 idx;
LPMESSAGE lpMsg;
nsCString type;
LPSPropValue pVal;
nsString subject;
PRUint32 total;
total=sa->cValues;
for (idx=0;idx<sa->cValues ;idx++)
{
lpEid= (LPENTRYID) sa->lpbin[idx].lpb;
cbEid = sa->lpbin[idx].cb;
if (!m_mapi.OpenEntry(cbEid, lpEid, (LPUNKNOWN *) &lpMsg))
{
IMPORT_LOG1( "*** Error opening messages in mailbox: %S\n", pName);
return( NS_ERROR_FAILURE);
}
{
{
// This is a contact, add it to the address book!
subject.Truncate( 0);
pVal = m_mapi.GetMapiProperty( lpMsg, PR_SUBJECT);
if (pVal)
m_mapi.GetStringFromProp( pVal, subject);
nsCOMPtr <nsIMdbRow> newRow;
nsCOMPtr <nsIMdbRow> oldRow;
pDb->GetNewRow( getter_AddRefs(newRow));
if (newRow) {
if (BuildCard( subject.get(), pDb, newRow, lpMsg, pFieldMap))
{
nsCOMPtr <nsIAbCard> userCard;
nsCOMPtr <nsIAbCard> newCard;
userCard = do_CreateInstance(NS_ABMDBCARD_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = pDb->AddCardRowToDB(newRow);
pDb->InitCardFromRow(userCard,newRow);
//add card to db
PRBool bl=PR_FALSE;
pDb->FindRowByCard(userCard,getter_AddRefs(oldRow));
if (oldRow)
{
newRow = oldRow;
}
else
{
pDb->AddCardRowToDB( newRow);
}
//add card list
pDb->AddListCardColumnsToRow(userCard,
newListRow,idx+1,
getter_AddRefs(newCard),PR_TRUE);
}
}
}
}
}
rv = pDb->AddCardRowToDB(newListRow);
NS_ENSURE_SUCCESS(rv, rv);
rv = pDb->AddListDirNode(newRow);
rv = pDb->SetListAddressTotal(newListRow, total);
rv = pDb->AddListDirNode(newListRow);
return rv;
}
void nsOutlookMail::SanitizeValue( nsString& val)
{
val.ReplaceSubstring(NS_LITERAL_STRING("\x0D\x0A").get(),

Просмотреть файл

@ -51,46 +51,46 @@ class nsIImportFieldMap;
class nsOutlookMail {
public:
nsOutlookMail();
~nsOutlookMail();
nsresult GetMailFolders( nsISupportsArray **pArray);
nsresult GetAddressBooks( nsISupportsArray **pArray);
nsresult ImportMailbox( PRUint32 *pDoneSoFar, PRBool *pAbort, PRInt32 index, const PRUnichar *pName, nsIFileSpec *pDest, PRInt32 *pMsgCount);
nsresult ImportAddresses( PRUint32 *pCount, PRUint32 *pTotal, const PRUnichar *pName, PRUint32 id, nsIAddrDatabase *pDb, nsString& errors);
nsOutlookMail();
~nsOutlookMail();
nsresult GetMailFolders( nsISupportsArray **pArray);
nsresult GetAddressBooks( nsISupportsArray **pArray);
nsresult ImportMailbox( PRUint32 *pDoneSoFar, PRBool *pAbort, PRInt32 index, const PRUnichar *pName, nsIFileSpec *pDest, PRInt32 *pMsgCount);
nsresult ImportAddresses( PRUint32 *pCount, PRUint32 *pTotal, const PRUnichar *pName, PRUint32 id, nsIAddrDatabase *pDb, nsString& errors);
private:
void OpenMessageStore( CMapiFolder *pNextFolder);
BOOL WriteData( nsIFileSpec *pDest, const char *pData, PRInt32 len);
BOOL WriteMessage( nsIFileSpec *pDest, CMapiMessage *pMsg, int& attachCount, BOOL *pTerminate);
BOOL WriteStr( nsIFileSpec *pDest, const char *pStr);
BOOL WriteMimeMsgHeader( nsIFileSpec *pDest, CMapiMessage *pMsg);
BOOL WriteMimeBoundary( nsIFileSpec *pDest, CMapiMessage *pMsg, BOOL terminate);
nsresult DeleteFile( nsIFileSpec *pSpec);
void EmptyAttachments( void);
void BuildAttachments( CMapiMessage& msg, int count);
void DumpAttachments( void);
PRBool IsAddressBookNameUnique( nsString& name, nsString& list);
void MakeAddressBookNameUnique( nsString& name, nsString& list);
void SanitizeValue( nsString& val);
void SplitString( nsString& val1, nsString& val2);
PRBool BuildCard( const PRUnichar *pName, nsIAddrDatabase *pDb, nsIMdbRow *newRow, LPMAPIPROP pUser, nsIImportFieldMap *pFieldMap);
nsresult CreateList( const PRUnichar * pName, nsIAddrDatabase *pDb);
void OpenMessageStore( CMapiFolder *pNextFolder);
BOOL WriteData( nsIFileSpec *pDest, const char *pData, PRInt32 len);
BOOL WriteMessage( nsIFileSpec *pDest, CMapiMessage *pMsg, int& attachCount, BOOL *pTerminate);
BOOL WriteStr( nsIFileSpec *pDest, const char *pStr);
BOOL WriteMimeMsgHeader( nsIFileSpec *pDest, CMapiMessage *pMsg);
BOOL WriteMimeBoundary( nsIFileSpec *pDest, CMapiMessage *pMsg, BOOL terminate);
nsresult DeleteFile( nsIFileSpec *pSpec);
void EmptyAttachments( void);
void BuildAttachments( CMapiMessage& msg, int count);
void DumpAttachments( void);
PRBool IsAddressBookNameUnique( nsString& name, nsString& list);
void MakeAddressBookNameUnique( nsString& name, nsString& list);
void SanitizeValue( nsString& val);
void SplitString( nsString& val1, nsString& val2);
PRBool BuildCard( const PRUnichar *pName, nsIAddrDatabase *pDb, nsIMdbRow *newRow, LPMAPIPROP pUser, nsIImportFieldMap *pFieldMap);
nsresult CreateList( const PRUnichar * pName, nsIAddrDatabase *pDb, LPMAPIPROP pUserList, nsIImportFieldMap *pFieldMap);
void SetDefaultContentType(CMapiMessage &msg, nsCString &cType);
private:
PRBool m_gotFolders;
PRBool m_gotAddresses;
PRBool m_haveMapi;
CMapiApi m_mapi;
CMapiFolderList m_folderList;
CMapiFolderList m_addressList;
CMapiFolderList m_storeList;
LPMDB m_lpMdb;
nsVoidArray m_attachments;
PRBool m_gotFolders;
PRBool m_gotAddresses;
PRBool m_haveMapi;
CMapiApi m_mapi;
CMapiFolderList m_folderList;
CMapiFolderList m_addressList;
CMapiFolderList m_storeList;
LPMDB m_lpMdb;
nsVoidArray m_attachments;
};
#endif /* nsOutlookMail_h___ */