Beispiel #1
0
NS_IMETHODIMP ImportOEMailImpl::ImportMailbox(nsIImportMailboxDescriptor *pSource,
                                              nsIFile *pDestination,
                                              PRUnichar **pErrorLog,
                                              PRUnichar **pSuccessLog,
                                              bool *fatalError)
{
  NS_PRECONDITION(pSource != nsnull, "null ptr");
  NS_PRECONDITION(pDestination != nsnull, "null ptr");
  NS_PRECONDITION(fatalError != nsnull, "null ptr");

  nsString success;
  nsString error;
  if (!pSource || !pDestination || !fatalError) {
    nsOEStringBundle::GetStringByID(OEIMPORT_MAILBOX_BADPARAM, error);
    if (fatalError)
      *fatalError = true;
    SetLogs(success, error, pErrorLog, pSuccessLog);
    return NS_ERROR_NULL_POINTER;
  }

  bool abort = false;
  nsString name;
  nsString pName;
  if (NS_SUCCEEDED(pSource->GetDisplayName(getter_Copies(pName))))
    name = pName;

  PRUint32 mailSize = 0;
  pSource->GetSize(&mailSize);
  if (mailSize == 0) {
    ReportSuccess(name, 0, &success);
    SetLogs(success, error, pErrorLog, pSuccessLog);
    return NS_OK;
  }

  nsCOMPtr <nsILocalFile> inFile;
  if (NS_FAILED(pSource->GetFile(getter_AddRefs(inFile)))) {
    ReportError(OEIMPORT_MAILBOX_BADSOURCEFILE, name, &error);
    SetLogs(success, error, pErrorLog, pSuccessLog);
    return NS_ERROR_FAILURE;
  }

  nsCString pPath;
  inFile->GetNativePath(pPath);
  IMPORT_LOG1("Importing Outlook Express mailbox: %s\n", pPath.get());

  m_bytesDone = 0;
  PRUint32 msgCount = 0;
  nsresult rv;
  if (nsOE5File::IsLocalMailFile(inFile)) {
    IMPORT_LOG1("Importing OE5 mailbox: %s!\n", NS_LossyConvertUTF16toASCII(name.get()));
    rv = nsOE5File::ImportMailbox(&m_bytesDone, &abort, name, inFile, pDestination, &msgCount);
  }
  else {
    if (CImportMailbox::ImportMailbox(&m_bytesDone, &abort, name, inFile, pDestination, &msgCount))
      rv = NS_OK;
    else
      rv = NS_ERROR_FAILURE;
  }

  if (NS_SUCCEEDED(rv))
    ReportSuccess(name, msgCount, &success);
  else
    ReportError(OEIMPORT_MAILBOX_CONVERTERROR, name, &error);

  SetLogs(success, error, pErrorLog, pSuccessLog);

  return rv;
}
Beispiel #2
0
NS_IMETHODIMP
ImportEudoraAddressImpl::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");

  nsString success;
  nsString error;
  if (!pSource || !pDestination || !fatalError) {
    IMPORT_LOG0("*** Bad param passed to eudora address import\n");
    nsEudoraStringBundle::GetStringByID(EUDORAIMPORT_ADDRESS_BADPARAM, error);
    if (fatalError)
      *fatalError = true;
    ImportEudoraMailImpl::SetLogs(success, error, pErrorLog, pSuccessLog);
    return NS_ERROR_NULL_POINTER;
  }

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

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


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


#ifdef IMPORT_DEBUG
  nsCString path;
  inFile->GetNativePath(path);
  IMPORT_LOG1("Import address book: %s\n", path.get());
#endif


  nsresult rv = NS_OK;

  m_bytes = 0;
  rv = m_eudora.ImportAddresses(&m_bytes, &abort, name.get(), inFile, pDestination, error);

  if (NS_SUCCEEDED(rv) && error.IsEmpty())
    ReportSuccess(name, &success);
  else
    ImportEudoraMailImpl::ReportError(EUDORAIMPORT_ADDRESS_CONVERTERROR, name, &error);

  ImportEudoraMailImpl::SetLogs(success, error, pErrorLog, pSuccessLog);

  IMPORT_LOG0("*** Returning from eudora address import\n");

  return rv;
}
Beispiel #3
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;
}
Beispiel #4
0
NS_IMETHODIMP
ImportEudoraMailImpl::ImportMailbox(nsIImportMailboxDescriptor *pSource,
                                    nsIMsgFolder *pDstFolder,
                                    PRUnichar **pErrorLog,
                                    PRUnichar **pSuccessLog,
                                    bool *fatalError)
{
  NS_ENSURE_ARG_POINTER(pSource);
  NS_ENSURE_ARG_POINTER(pDstFolder);
  NS_ENSURE_ARG_POINTER(fatalError);

  nsString  success;
  nsString  error;
  bool      abort = false;
  nsString  name;
  PRUnichar *  pName;
  if (NS_SUCCEEDED(pSource->GetDisplayName(&pName)))
  {
    name = pName;
    NS_Free(pName);
  }

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


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

#ifdef IMPORT_DEBUG
  nsCString pPath;
  inFile->GetNativePath(pPath);
  IMPORT_LOG1("Import mailbox: %s\n", pPath.get());
#endif


  PRInt32  msgCount = 0;
  nsresult rv = NS_OK;

  m_bytes = 0;
  rv = m_eudora.ImportMailbox( &m_bytes, &abort, name.get(), inFile, pDstFolder, &msgCount);
  if (NS_SUCCEEDED(rv))
    ReportSuccess(name, msgCount, &success);
  else
    ReportError(EUDORAIMPORT_MAILBOX_CONVERTERROR, name, &error);

  SetLogs(success, error, pErrorLog, pSuccessLog);

  IMPORT_LOG0("*** Returning from eudora mailbox import\n");

  return rv;
}
Beispiel #5
0
NS_IMETHODIMP ImportEudoraMailImpl::ImportMailbox(nsIImportMailboxDescriptor *pSource,
            nsIFile *pDestination,
            PRUnichar **pErrorLog,
            PRUnichar **pSuccessLog,
            bool *fatalError)
{
  NS_PRECONDITION(pSource != nsnull, "null ptr");
  NS_PRECONDITION(pDestination != nsnull, "null ptr");
  NS_PRECONDITION(fatalError != nsnull, "null ptr");

  nsString  success;
  nsString  error;
  if (!pSource || !pDestination || !fatalError)
  {
    IMPORT_LOG0( "*** Bad param passed to eudora mailbox import\n");
    nsEudoraStringBundle::GetStringByID( EUDORAIMPORT_MAILBOX_BADPARAM, error);
    if (fatalError)
      *fatalError = true;
    SetLogs( success, error, pErrorLog, pSuccessLog);
    return NS_ERROR_NULL_POINTER;
  }

  bool      abort = false;
  nsString  name;
  PRUnichar *  pName;
  if (NS_SUCCEEDED( pSource->GetDisplayName( &pName)))
  {
    name = pName;
    NS_Free( pName);
  }

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


  nsCOMPtr <nsILocalFile>  inFile;
  if (NS_FAILED(pSource->GetFile( getter_AddRefs(inFile))))
  {
    ReportError( EUDORAIMPORT_MAILBOX_BADSOURCEFILE, name, &error);
    SetLogs( success, error, pErrorLog, pSuccessLog);
    return( NS_ERROR_FAILURE);
  }

#ifdef IMPORT_DEBUG
  nsCString pPath;
  inFile->GetNativePath(pPath);
  IMPORT_LOG1( "Import mailbox: %s\n", pPath.get());
#endif


  PRInt32  msgCount = 0;
  nsresult rv = NS_OK;

  m_bytes = 0;
  rv = m_eudora.ImportMailbox( &m_bytes, &abort, name.get(), inFile, pDestination, &msgCount);
  if (NS_SUCCEEDED( rv))
    ReportSuccess( name, msgCount, &success);
  else
    ReportError( EUDORAIMPORT_MAILBOX_CONVERTERROR, name, &error);

  SetLogs( success, error, pErrorLog, pSuccessLog);

  IMPORT_LOG0( "*** Returning from eudora mailbox import\n");

  return( rv);
}