Ejemplo n.º 1
0
LPSPropValue CMapiApi::GetMapiProperty( LPMAPIPROP pProp, ULONG tag)
{
  if (!pProp)
    return( NULL);

  int  sz = CbNewSPropTagArray( 1);
  SPropTagArray *pTag = (SPropTagArray *) new char[sz];
  pTag->cValues = 1;
  pTag->aulPropTag[0] = tag;
  LPSPropValue  lpProp = NULL;
  ULONG  cValues = 0;
  HRESULT hr = pProp->GetProps( pTag, 0, &cValues, &lpProp);
  delete [] pTag;
  if (HR_FAILED( hr) || (cValues != 1)) {
    if (lpProp)
      MAPIFreeBuffer( lpProp);
    return( NULL);
  }
  else {
    if (PROP_TYPE( lpProp->ulPropTag) == PT_ERROR) {
      if (lpProp->Value.l == MAPI_E_NOT_FOUND) {
        MAPIFreeBuffer( lpProp);
        lpProp = NULL;
      }
    }
  }

  return( lpProp);
}
BOOL CExMapi::AreSame(LPMAPIPROP lpMapiProp1,LPMAPIPROP lpMapiProp2)
{
	if(!m_pSession) return FALSE;
	BOOL bResult=FALSE;

	if(lpMapiProp1 != NULL && lpMapiProp2 != NULL)
	{
		ULONG cbEntryId1;
		ULONG cbEntryId2;
		LPENTRYID lpEntryId1 = NULL;	
		LPENTRYID lpEntryId2 = NULL;

		SPropValue * rgprops1 = NULL;
		SPropValue * rgprops2 = NULL;
		ULONG rgTags[] = {1, PR_ENTRYID};
		ULONG cCount1   = 0;
		ULONG cCount2   = 0;
		// Get the message store entryid properties.
		if(SUCCEEDED(lpMapiProp1->GetProps((LPSPropTagArray) rgTags, MAPI_UNICODE, &cCount1, &rgprops1)))
		{
			cbEntryId1 = rgprops1[0].Value.bin.cb;
			lpEntryId1 = (ENTRYID*)rgprops1[0].Value.bin.lpb;
		}

		if(SUCCEEDED(lpMapiProp2->GetProps((LPSPropTagArray) rgTags, MAPI_UNICODE, &cCount2, &rgprops2)))
		{
			cbEntryId2 = rgprops2[0].Value.bin.cb;
			lpEntryId2 = (ENTRYID*)rgprops2[0].Value.bin.lpb;
		}

		if(lpEntryId1 != NULL && lpEntryId2 != NULL)
		{
			ULONG lResult;
			if(SUCCEEDED(m_pSession->CompareEntryIDs(cbEntryId1,lpEntryId1,cbEntryId2,lpEntryId2,0,&lResult)))
			{
				bResult = (BOOL)lResult;
			}			
		}

		MAPIFreeBuffer(rgprops1);
		MAPIFreeBuffer(rgprops2);
	}
	return bResult;
}
Ejemplo n.º 3
0
nsresult nsOutlookMail::CreateList(const PRUnichar * pName,
                                   nsIAddrDatabase *pDb,
                                   LPMAPIPROP pUserList,
                                   nsIImportFieldMap *pFieldMap)
{
  // If no name provided then we're done.
  if (!pName || !(*pName))
    return NS_OK;

  nsresult rv = NS_ERROR_FAILURE;
  // Make sure we have db to work with.
  if (!pDb)
    return rv;

  nsCOMPtr <nsIMdbRow> newListRow;
  rv = pDb->GetNewListRow(getter_AddRefs(newListRow));
  NS_ENSURE_SUCCESS(rv, rv);
  nsAutoCString column;
  LossyCopyUTF16toASCII(nsDependentString(pName), column);
  rv = pDb->AddListName(newListRow, column.get());
  NS_ENSURE_SUCCESS(rv, rv);

  HRESULT             hr;
  LPSPropValue value = NULL;
  ULONG valueCount = 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, &valueCount, &value);
  m_mapi.MAPIFreeBuffer(properties);
  if (HR_FAILED(hr))
    return NS_ERROR_FAILURE;
  if (!value)
    return NS_ERROR_NOT_AVAILABLE;
  // XXX from here out, value must be freed with MAPIFreeBuffer 

  SBinaryArray *sa=(SBinaryArray *)&value->Value.bin;
  if (!sa || !sa->lpbin) {
    m_mapi.MAPIFreeBuffer(value);
    return NS_ERROR_NULL_POINTER;
  }

  LPENTRYID    lpEid;
  ULONG        cbEid;
  int32_t        idx;
  LPMESSAGE        lpMsg;
  nsCString        type;
  LPSPropValue    pVal;
  nsString        subject;
  uint32_t 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);
      m_mapi.MAPIFreeBuffer(value);
      return NS_ERROR_FAILURE;
    }
    // This is a contact, add it to the address book!
    subject.Truncate();
    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);
        pDb->InitCardFromRow(userCard,newRow);

        //add card to db
        bool bl=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),
                                     true, nullptr, nullptr);
      }
    }
  }
  m_mapi.MAPIFreeBuffer(value);

  rv = pDb->AddCardRowToDB(newListRow);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = pDb->SetListAddressTotal(newListRow, total);
  rv = pDb->AddListDirNode(newListRow);
  return rv;
}