Exemplo n.º 1
0
NS_IMETHODIMP
ImportAddressImpl::ImportAddressBook(nsIImportABDescriptor *pSource,
                                     nsIAddrDatabase *pDestination,
                                     nsIImportFieldMap *fieldMap,
                                     nsISupports *aSupportService,
                                     PRUnichar ** pErrorLog,
                                     PRUnichar ** pSuccessLog,
                                     bool * fatalError)
{
  NS_PRECONDITION(pSource != nsnull, "null ptr");
  NS_PRECONDITION(pDestination != nsnull, "null ptr");
  NS_PRECONDITION(fatalError != nsnull, "null ptr");

  m_bytesImported = 0;

  nsString success, error;
  if (!pSource || !pDestination || !fatalError) {
    IMPORT_LOG0("*** Bad param passed to text address import\n");
    nsImportStringBundle::GetStringByID(TEXTIMPORT_ADDRESS_BADPARAM,
                                        m_notProxyBundle,
                                        error);

    SetLogs(success, error, pErrorLog, pSuccessLog);

    if (fatalError)
      *fatalError = true;

    return NS_ERROR_NULL_POINTER;
  }

  ClearSampleFile();

  bool addrAbort = false;
  nsString name;
  pSource->GetPreferredName(name);

  PRUint32 addressSize = 0;
  pSource->GetSize(&addressSize);
  if (addressSize == 0) {
    IMPORT_LOG0("Address book size is 0, skipping import.\n");
    ReportSuccess(name, &success, m_notProxyBundle);
    SetLogs(success, error, pErrorLog, pSuccessLog);
    return NS_OK;
  }

  nsCOMPtr<nsIFile> inFile;
  if (NS_FAILED(pSource->GetAbFile(getter_AddRefs(inFile)))) {
    ReportError(TEXTIMPORT_ADDRESS_BADSOURCEFILE, name, &error, m_notProxyBundle);
    SetLogs(success, error, pErrorLog, pSuccessLog);
    return NS_ERROR_FAILURE;
  }

  if (!aSupportService) {
    IMPORT_LOG0("Missing support service to import call");
    return NS_ERROR_FAILURE;
  }

  bool isLDIF = false;
  nsresult rv;
  nsCOMPtr<nsIAbLDIFService> ldifService(do_QueryInterface(aSupportService, &rv));

    if (NS_SUCCEEDED(rv)) {
      rv = ldifService->IsLDIFFile(inFile, &isLDIF);
      if (NS_FAILED(rv)) {
        IMPORT_LOG0("*** Error reading address file\n");
      }
    }

  if (NS_FAILED(rv)) {
    ReportError(TEXTIMPORT_ADDRESS_CONVERTERROR, name, &error, m_notProxyBundle);
    SetLogs(success, error, pErrorLog, pSuccessLog);
    return rv;
  }

  if (isLDIF) {
    if (ldifService)
      rv = ldifService->ImportLDIFFile(pDestination, inFile, false, &m_bytesImported);
    else
      return NS_ERROR_FAILURE;
  }
  else {
    rv = m_text.ImportAddresses(&addrAbort, name.get(), inFile, pDestination, fieldMap, error, &m_bytesImported);
    SaveFieldMap(fieldMap);
  }

  if (NS_SUCCEEDED(rv) && error.IsEmpty()) {
    ReportSuccess(name, &success, m_notProxyBundle);
    SetLogs(success, error, pErrorLog, pSuccessLog);
  }
  else {
    ReportError(TEXTIMPORT_ADDRESS_CONVERTERROR, name, &error, m_notProxyBundle);
    SetLogs(success, error, pErrorLog, pSuccessLog);
  }

  IMPORT_LOG0("*** Text address import done\n");
  return rv;
}
Exemplo n.º 2
0
NS_IMETHODIMP ImportAddressImpl::ImportAddressBook(	nsIImportABDescriptor *pSource,
        nsIAddrDatabase *	pDestination,
        nsIImportFieldMap *	fieldMap,
        PRBool isAddrLocHome,
        PRUnichar **		pErrorLog,
        PRUnichar **		pSuccessLog,
        PRBool *			fatalError)
{
    NS_PRECONDITION(pSource != nsnull, "null ptr");
    NS_PRECONDITION(pDestination != nsnull, "null ptr");
    NS_PRECONDITION(fatalError != nsnull, "null ptr");

    nsCOMPtr<nsIStringBundle>	bundle( dont_AddRef( nsTextStringBundle::GetStringBundleProxy()));
    m_bytesImported = 0;

    nsString	success;
    nsString	error;
    if (!pSource || !pDestination || !fatalError) {
        IMPORT_LOG0( "*** Bad param passed to text address import\n");
        nsTextStringBundle::GetStringByID( TEXTIMPORT_ADDRESS_BADPARAM, error, bundle);
        if (fatalError)
            *fatalError = PR_TRUE;
        SetLogs( success, error, pErrorLog, pSuccessLog);
        return( NS_ERROR_NULL_POINTER);
    }

    ClearSampleFile();

    PRBool		addrAbort = PR_FALSE;
    nsString	name;
    PRUnichar *	pName;
    if (NS_SUCCEEDED( pSource->GetPreferredName( &pName))) {
        name = pName;
        nsCRT::free( pName);
    }

    PRUint32 addressSize = 0;
    pSource->GetSize( &addressSize);
    if (addressSize == 0) {
        IMPORT_LOG0( "Address book size is 0, skipping import.\n");
        ReportSuccess( name, &success);
        SetLogs( success, error, pErrorLog, pSuccessLog);
        return( NS_OK);
    }


    nsIFileSpec	*	inFile;
    if (NS_FAILED( pSource->GetFileSpec( &inFile))) {
        ReportError( TEXTIMPORT_ADDRESS_BADSOURCEFILE, name, &error);
        SetLogs( success, error, pErrorLog, pSuccessLog);
        return( NS_ERROR_FAILURE);
    }

    nsXPIDLCString pPath;
    inFile->GetNativePath(getter_Copies(pPath));
    IMPORT_LOG1( "Importing address book: %s\n", pPath.get());

    nsresult rv = NS_OK;
    PRBool	isLDIF = PR_FALSE;

    nsCOMPtr<nsIAbLDIFService> ldifService = do_GetService(NS_ABLDIFSERVICE_CONTRACTID, &rv);

    if (NS_SUCCEEDED(rv)) {
        rv = ldifService->IsLDIFFile(inFile, &isLDIF);
        if (NS_FAILED(rv)) {
            IMPORT_LOG0( "*** Error reading address file\n");
        }
    }

    if (NS_FAILED( rv)) {
        inFile->Release();
        ReportError( TEXTIMPORT_ADDRESS_CONVERTERROR, name, &error);
        SetLogs( success, error, pErrorLog, pSuccessLog);
        return( rv);
    }

    if (isLDIF) {
        if (ldifService)
            rv = ldifService->ImportLDIFFile(pDestination, inFile, PR_FALSE, &m_bytesImported);
        else
            return NS_ERROR_FAILURE;
    }
    else {
        rv = m_text.ImportAddresses( &addrAbort, name.get(), inFile, pDestination, fieldMap, error, &m_bytesImported);
        SaveFieldMap( fieldMap);
    }

    inFile->Release();


    if (NS_SUCCEEDED( rv) && error.IsEmpty()) {
        ReportSuccess( name, &success);
    }
    else {
        ReportError( TEXTIMPORT_ADDRESS_CONVERTERROR, name, &error);
    }

    SetLogs( success, error, pErrorLog, pSuccessLog);

    IMPORT_LOG0( "*** Text address import done\n");
    return rv;
}