Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
nsImportGenericMail Class Reference
Inheritance diagram for nsImportGenericMail:
Inheritance graph
[legend]
Collaboration diagram for nsImportGenericMail:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsImportGenericMail ()
virtual ~nsImportGenericMail ()
NS_DECL_ISUPPORTS NS_IMETHOD GetData (const char *dataId, nsISupports **_retval)
NS_IMETHOD SetData (const char *dataId, nsISupports *pData)
NS_IMETHOD GetStatus (const char *statusKind, PRInt32 *_retval)
NS_IMETHOD WantsProgress (PRBool *_retval)
NS_IMETHODIMP BeginImport (nsISupportsString *successLog, nsISupportsString *errorLog, PRBool isAddrLocHome, PRBool *_retval)
NS_IMETHOD ContinueImport (PRBool *_retval)
NS_IMETHOD GetProgress (PRInt32 *_retval)
NS_IMETHOD CancelImport (void)
nsISupports GetData (in string dataId)
void SetData (in string dataId, in nsISupports pData)
long GetStatus (in string statusKind)
boolean WantsProgress ()
boolean BeginImport (in nsISupportsString successLog, in nsISupportsString errorLog, in boolean isAddrLocHome)
boolean ContinueImport ()
long GetProgress ()

Static Public Member Functions

static void SetLogs (nsString &success, nsString &error, nsISupportsString *pSuccess, nsISupportsString *pError)
static void ReportError (PRInt32 id, const PRUnichar *pName, nsString *pStream)

Private Member Functions

PRBool CreateFolder (nsIMsgFolder **ppFolder)
void GetDefaultMailboxes (void)
void GetDefaultLocation (void)
void GetDefaultDestination (void)
void GetMailboxName (PRUint32 index, nsISupportsString *pStr)

Private Attributes

nsString m_pName
nsIMsgFolderm_pDestFolder
PRBool m_deleteDestFolder
PRBool m_createdFolder
nsCOMPtr< nsIFileSpecm_pSrcLocation
PRBool m_gotLocation
PRBool m_found
PRBool m_userVerify
nsIImportMailm_pInterface
nsISupportsArraym_pMailboxes
nsISupportsStringm_pSuccessLog
nsISupportsStringm_pErrorLog
PRUint32 m_totalSize
PRBool m_doImport
ImportThreadDatam_pThreadData
PRBool m_performingMigration

Detailed Description

Definition at line 92 of file nsImportMail.cpp.


Constructor & Destructor Documentation


Member Function Documentation

boolean nsIImportGeneric::BeginImport ( in nsISupportsString  successLog,
in nsISupportsString  errorLog,
in boolean  isAddrLocHome 
) [inherited]
NS_IMETHODIMP nsImportGenericMail::BeginImport ( nsISupportsString successLog,
nsISupportsString errorLog,
PRBool  isAddrLocHome,
PRBool _retval 
)

Definition at line 493 of file nsImportMail.cpp.

{
       NS_PRECONDITION(_retval != nsnull, "null ptr");
    if (!_retval)
        return NS_ERROR_NULL_POINTER;

       nsString      success;
       nsString      error;

       if (!m_doImport) {
              nsImportStringBundle::GetStringByID( IMPORT_NO_MAILBOXES, success);
              SetLogs( success, error, successLog, errorLog);                
              *_retval = PR_TRUE;
              return( NS_OK);             
       }
       
       if (!m_pInterface || !m_pMailboxes) {
    IMPORT_LOG0( "*** BeginImport: Either the interface or source mailbox is not set properly.");
              nsImportStringBundle::GetStringByID( IMPORT_ERROR_MB_NOTINITIALIZED, error);
              SetLogs( success, error, successLog, errorLog);
              *_retval = PR_FALSE;
              return( NS_OK);
       }
       
       if (!m_pDestFolder) {
    IMPORT_LOG0( "*** BeginImport: The destination mailbox is not set properly.");
              nsImportStringBundle::GetStringByID( IMPORT_ERROR_MB_NODESTFOLDER, error);
              SetLogs( success, error, successLog, errorLog);
              *_retval = PR_FALSE;
              return( NS_OK);
       }

       if (m_pThreadData) {
              m_pThreadData->DriverAbort();
              m_pThreadData = nsnull;
       }

       NS_IF_RELEASE( m_pSuccessLog);
       NS_IF_RELEASE( m_pErrorLog);
       m_pSuccessLog = successLog;
       m_pErrorLog = errorLog;
       NS_IF_ADDREF( m_pSuccessLog);
       NS_IF_ADDREF( m_pErrorLog);
       
       
       // kick off the thread to do the import!!!!
       m_pThreadData = new ImportThreadData();
       m_pThreadData->boxes = m_pMailboxes;
       NS_ADDREF( m_pMailboxes);
       m_pThreadData->mailImport = m_pInterface;
       NS_ADDREF( m_pInterface);
       m_pThreadData->errorLog = m_pErrorLog;
       NS_IF_ADDREF( m_pErrorLog);
       m_pThreadData->successLog = m_pSuccessLog;
       NS_IF_ADDREF( m_pSuccessLog);
       
       m_pThreadData->ownsDestRoot = m_deleteDestFolder;
       m_pThreadData->destRoot = m_pDestFolder;
    m_pThreadData->performingMigration = m_performingMigration;
       NS_IF_ADDREF( m_pDestFolder);


       PRThread *pThread = PR_CreateThread( PR_USER_THREAD, &ImportMailThread, m_pThreadData, 
                                                               PR_PRIORITY_NORMAL, 
                                                               PR_LOCAL_THREAD, 
                                                               PR_UNJOINABLE_THREAD,
                                                               0);
       if (!pThread) {
              m_pThreadData->ThreadDelete();
              m_pThreadData->abort = PR_TRUE;
              m_pThreadData->DriverAbort();
              m_pThreadData = nsnull;
              *_retval = PR_FALSE;
              nsImportStringBundle::GetStringByID( IMPORT_ERROR_MB_NOTHREAD, error);
              SetLogs( success, error, successLog, errorLog);
       }
       else
              *_retval = PR_TRUE;
                                   
       return( NS_OK);

}

Here is the call graph for this function:

Implements nsIImportGeneric.

Definition at line 666 of file nsImportMail.cpp.

Here is the call graph for this function:

Definition at line 577 of file nsImportMail.cpp.

{
    NS_PRECONDITION(_retval != nsnull, "null ptr");
    if (!_retval)
        return NS_ERROR_NULL_POINTER;
       
       *_retval = PR_TRUE;
       if (m_pThreadData) {
              if (m_pThreadData->fatalError)
                     *_retval = PR_FALSE;
       }

       return( NS_OK);
}

Definition at line 966 of file nsImportMail.cpp.

{
  nsresult rv;
  *ppFolder = nsnull;

  nsCOMPtr<nsIStringBundle> bundle;
  nsCOMPtr<nsIStringBundleService> bundleService(do_GetService(
                                     NS_STRINGBUNDLE_CONTRACTID, &rv));
  if (NS_FAILED(rv) || !bundleService) 
      return PR_FALSE;
  rv = bundleService->CreateBundle(IMPORT_MSGS_URL, getter_AddRefs(bundle));
  if (NS_FAILED(rv)) 
      return PR_FALSE;
  nsXPIDLString folderName;
  if (!m_pName.IsEmpty()) {
    const PRUnichar *moduleName[] = { m_pName.get() };
    rv = bundle->FormatStringFromName(NS_LITERAL_STRING("ModuleFolderName").get(),
                                      moduleName, 1,
                                      getter_Copies(folderName));
  }
  else {
    rv = bundle->GetStringFromName(NS_LITERAL_STRING("DefaultFolderName").get(),
                                   getter_Copies(folderName));
  }
  if (NS_FAILED(rv)) {
      IMPORT_LOG0( "*** Failed to get Folder Name!\n");
      return PR_FALSE;
  }
  nsCOMPtr <nsIMsgAccountManager> accMgr = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
  if (NS_FAILED(rv)) {
    IMPORT_LOG0( "*** Failed to create account manager!\n");
    return PR_FALSE;
  }

  nsCOMPtr <nsIMsgIncomingServer> server;
  rv = accMgr->GetLocalFoldersServer(getter_AddRefs(server)); 
  // if Local Folders does not exist already, create it
  if (NS_FAILED(rv) || !server)
  {
    nsCOMPtr <nsIMessengerMigrator> messengerMigrator = do_GetService(NS_MESSENGERMIGRATOR_CONTRACTID, &rv);
    if (NS_FAILED(rv)) {
      IMPORT_LOG0( "*** Failed to create messenger migrator!\n");
      return PR_FALSE;
    }
    rv = messengerMigrator->CreateLocalMailAccount(PR_FALSE);
    if (NS_FAILED(rv)) {
      IMPORT_LOG0( "*** Failed to create Local Folders!\n");
      return PR_FALSE;
    }
    
    rv = accMgr->GetLocalFoldersServer(getter_AddRefs(server)); 
  }

  if (NS_SUCCEEDED(rv) && server) {
    nsCOMPtr <nsIMsgFolder> localRootFolder;
    rv = server->GetRootMsgFolder(getter_AddRefs(localRootFolder)); 
    if (localRootFolder) {
      // we need to call GetSubFolders() so that the folders get initialized 
      // if they are not initialized yet. 
      nsCOMPtr <nsIEnumerator> aEnumerator;
      rv = localRootFolder->GetSubFolders(getter_AddRefs(aEnumerator));
      if (NS_SUCCEEDED(rv)) {
        // check if the folder name we picked already exists.
        PRBool exists = PR_FALSE;
        rv = localRootFolder->ContainsChildNamed(folderName.get(), &exists);
        if (exists) {
          nsXPIDLString name;
          localRootFolder->GenerateUniqueSubfolderName(folderName.get(), nsnull, getter_Copies(name));
          if (!name.IsEmpty())
            folderName.Assign(name);
          else {
            IMPORT_LOG0( "*** Failed to find a unique folder name!\n");
            return PR_FALSE;
          }
        }
        IMPORT_LOG1( "Creating folder for importing mail: '%s'\n", NS_ConvertUCS2toUTF8(folderName).get());

        // if we are doing migration, don't bother putting the local folders we are importing as a 
        // sub folder of local folders.
        if (m_performingMigration)       
        {
          NS_IF_ADDREF(*ppFolder = localRootFolder);
          return PR_TRUE;
        }
        else
        {
        rv = localRootFolder->CreateSubfolder(folderName.get(), nsnull);
        if (NS_SUCCEEDED(rv)) {
          nsCOMPtr<nsISupports> subFolder;
          rv = localRootFolder->GetChildNamed(folderName.get(), getter_AddRefs(subFolder));
          if (subFolder) {
            subFolder->QueryInterface(NS_GET_IID(nsIMsgFolder), (void **) ppFolder);
            if (*ppFolder) {
              IMPORT_LOG1("Folder '%s' created successfully\n", NS_ConvertUCS2toUTF8(folderName).get());
              return PR_TRUE;
            }
          } // if subFolder
        }
        } // if not performing migration
      }
    } // if localRootFolder
  } // if server
  IMPORT_LOG0("****** FAILED TO CREATE FOLDER FOR IMPORT\n");
  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsISupports nsIImportGeneric::GetData ( in string  dataId) [inherited]
NS_IMETHODIMP nsImportGenericMail::GetData ( const char *  dataId,
nsISupports **  _retval 
)

Definition at line 239 of file nsImportMail.cpp.

{
       nsresult rv = NS_OK;

    NS_PRECONDITION(_retval != nsnull, "null ptr");
       if (!_retval)
              return NS_ERROR_NULL_POINTER;
       
       *_retval = nsnull;
       if (!nsCRT::strcasecmp( dataId, "mailInterface")) {
              *_retval = m_pInterface;
              NS_IF_ADDREF( m_pInterface);
       }
       
       if (!nsCRT::strcasecmp( dataId, "mailBoxes")) {
              if (!m_pMailboxes)
                     GetDefaultMailboxes();
              *_retval = m_pMailboxes;
              NS_IF_ADDREF( m_pMailboxes);
       }

       if (!nsCRT::strcasecmp( dataId, "mailLocation")) {
              if (!m_pSrcLocation)
                     GetDefaultLocation();
              NS_IF_ADDREF(*_retval = m_pSrcLocation);
       }
       
       if (!nsCRT::strcasecmp( dataId, "mailDestination")) {
              if (!m_pDestFolder)
                     GetDefaultDestination();
              *_retval = m_pDestFolder;
              NS_IF_ADDREF( m_pDestFolder);
       }
       
       if (!nsCRT::strcasecmp( dataId, "migration")) {
        nsCOMPtr<nsISupportsPRBool> migrationString = do_CreateInstance(NS_SUPPORTS_PRBOOL_CONTRACTID, &rv);
        NS_ENSURE_SUCCESS(rv, rv);
        migrationString->SetData(m_performingMigration);
        NS_IF_ADDREF( *_retval = migrationString);
       }
       
       if (!nsCRT::strcasecmp( dataId, "currentMailbox")) {
              // create an nsISupportsString, get the current mailbox
              // name being imported and put it in the string
              nsCOMPtr<nsISupportsString> data = do_CreateInstance( kSupportsWStringCID, &rv);
              if (NS_FAILED( rv))
                     return( rv);
              if (m_pThreadData) {
                     GetMailboxName( m_pThreadData->currentMailbox, data);
              }
              *_retval = data;
              NS_ADDREF( *_retval);
       }

       return( rv);
}

Here is the call graph for this function:

Definition at line 403 of file nsImportMail.cpp.

{
       if (m_pDestFolder)
              return;
       if (!m_pInterface)
              return;

       nsIMsgFolder *       rootFolder;
       m_deleteDestFolder = PR_FALSE;
       m_createdFolder = PR_FALSE;
       if (CreateFolder( &rootFolder)) {
              m_pDestFolder = rootFolder;
              m_deleteDestFolder = PR_TRUE;
              m_createdFolder = PR_TRUE;
              return;
       }
  IMPORT_LOG0("*** GetDefaultDestination: Failed to create a default import destination folder.");
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 376 of file nsImportMail.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 395 of file nsImportMail.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 479 of file nsImportMail.cpp.

{
       if (m_pMailboxes) {
              nsCOMPtr<nsIImportMailboxDescriptor> box(do_QueryElementAt(m_pMailboxes, index));
              if (box) {
                     nsXPIDLString name;
                     box->GetDisplayName(getter_Copies(name));
                     if (!name.IsEmpty()) {
                            pStr->SetData(name);
                     }
              }
       }
}

Here is the call graph for this function:

Definition at line 593 of file nsImportMail.cpp.

{
       // This returns the progress from the the currently
       // running import mail or import address book thread.
    NS_PRECONDITION(_retval != nsnull, "null ptr");
    if (!_retval)
        return NS_ERROR_NULL_POINTER;

       if (!m_pThreadData || !(m_pThreadData->threadAlive)) {
              *_retval = 100;                           
              return( NS_OK);      
       }
       
       PRUint32 sz = 0;
       if (m_pThreadData->currentSize && m_pInterface) {
              if (NS_FAILED( m_pInterface->GetImportProgress( &sz)))
                     sz = 0;
       }
       

       // *_retval = (PRInt32) (((PRUint32)(m_pThreadData->currentTotal + sz) * (PRUint32)100) / m_totalSize);

       if (m_totalSize) {
              PRFloat64     perc;
              perc = (PRFloat64) m_pThreadData->currentTotal;
              perc += sz;
              perc *= 100;
              perc /= m_totalSize;
              *_retval = (PRInt32) perc;
              if (*_retval > 100)
                     *_retval = 100;
       }
       else
              *_retval = 0;
       
       // never return 100% while the thread is still alive
       if (*_retval > 99)
              *_retval = 99;

       return( NS_OK);
}

Here is the call graph for this function:

long nsIImportGeneric::GetStatus ( in string  statusKind) [inherited]
NS_IMETHODIMP nsImportGenericMail::GetStatus ( const char *  statusKind,
PRInt32 _retval 
)

Definition at line 353 of file nsImportMail.cpp.

{
       NS_PRECONDITION(statusKind != nsnull, "null ptr");
       NS_PRECONDITION(_retval != nsnull, "null ptr");
       if (!statusKind || !_retval)
              return( NS_ERROR_NULL_POINTER);
       
       *_retval = 0;

       if (!nsCRT::strcasecmp( statusKind, "isInstalled")) {
              GetDefaultLocation();
              *_retval = (PRInt32) m_found;
       }

       if (!nsCRT::strcasecmp( statusKind, "canUserSetLocation")) {
              GetDefaultLocation();
              *_retval = (PRInt32) m_userVerify;
       }

       return( NS_OK);
}

Here is the call graph for this function:

void nsImportGenericMail::ReportError ( PRInt32  id,
const PRUnichar pName,
nsString pStream 
) [static]

Definition at line 635 of file nsImportMail.cpp.

{
       if (!pStream)
              return;
       // load the error string
       nsIStringBundle *pBundle = nsImportStringBundle::GetStringBundleProxy();
       PRUnichar *pFmt = nsImportStringBundle::GetStringByID( id, pBundle);
       PRUnichar *pText = nsTextFormatter::smprintf( pFmt, pName);
       pStream->Append( pText);
       nsTextFormatter::smprintf_free( pText);
       nsImportStringBundle::FreeString( pFmt);
       pStream->AppendWithConversion( NS_LINEBREAK);
       NS_IF_RELEASE( pBundle);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIImportGeneric::SetData ( in string  dataId,
in nsISupports  pData 
) [inherited]
NS_IMETHODIMP nsImportGenericMail::SetData ( const char *  dataId,
nsISupports *  pData 
)

Definition at line 296 of file nsImportMail.cpp.

{
    nsresult rv = NS_OK;
       NS_PRECONDITION(dataId != nsnull, "null ptr");
    if (!dataId)
        return NS_ERROR_NULL_POINTER;

       if (!nsCRT::strcasecmp( dataId, "mailInterface")) {
              NS_IF_RELEASE( m_pInterface);
              if (item)
                     item->QueryInterface( NS_GET_IID(nsIImportMail), (void **) &m_pInterface);
       }
       if (!nsCRT::strcasecmp( dataId, "mailBoxes")) {
              NS_IF_RELEASE( m_pMailboxes);
              if (item)
                     item->QueryInterface( NS_GET_IID(nsISupportsArray), (void **) &m_pMailboxes);
       }
       
       if (!nsCRT::strcasecmp( dataId, "mailLocation")) {
              NS_IF_RELEASE( m_pMailboxes);
    m_pSrcLocation = nsnull;
    if (item) {
      nsresult rv;
      nsCOMPtr <nsILocalFile> location = do_QueryInterface(item, &rv);
      NS_ENSURE_SUCCESS(rv,rv);
      
      rv = NS_NewFileSpecFromIFile(location, getter_AddRefs(m_pSrcLocation));
      NS_ENSURE_SUCCESS(rv,rv);
    }
       }
       
       if (!nsCRT::strcasecmp( dataId, "mailDestination")) {
              NS_IF_RELEASE( m_pDestFolder);
              if (item)
                     item->QueryInterface( NS_GET_IID(nsIMsgFolder), (void **) &m_pDestFolder);
              m_deleteDestFolder = PR_FALSE;
       }
       
       if (!nsCRT::strcasecmp( dataId, "name")) {
              nsCOMPtr<nsISupportsString> nameString;
              if (item) {
                     item->QueryInterface( NS_GET_IID(nsISupportsString), getter_AddRefs(nameString));
                     rv = nameString->GetData(m_pName);
              }
       }

  if (!nsCRT::strcasecmp( dataId, "migration")) {
              nsCOMPtr<nsISupportsPRBool> migrationString;
              if (item) {
                     item->QueryInterface( NS_GET_IID(nsISupportsPRBool), getter_AddRefs(migrationString));
                     rv = migrationString->GetData(&m_performingMigration);
              }
       }

       return rv;
}

Here is the call graph for this function:

void nsImportGenericMail::SetLogs ( nsString success,
nsString error,
nsISupportsString pSuccess,
nsISupportsString pError 
) [static]

Definition at line 651 of file nsImportMail.cpp.

{
    nsAutoString str;
    if (pSuccess) {
        pSuccess->GetData(str);
        str.Append(success);
        pSuccess->SetData(str);
    }
    if (pError) {
        pError->GetData(str);
        str.Append(error);
        pError->SetData(str);
    }
}

Here is the caller graph for this function:

Definition at line 422 of file nsImportMail.cpp.

{
       NS_PRECONDITION(_retval != nsnull, "null ptr");
    if (!_retval)
        return NS_ERROR_NULL_POINTER;
       
       if (m_pThreadData) {
              m_pThreadData->DriverAbort();
              m_pThreadData = nsnull;
       }

       if (!m_pMailboxes) {
              GetDefaultLocation();
              GetDefaultMailboxes();
       }

       if (!m_pDestFolder) {
              GetDefaultDestination();
       }

       PRUint32             totalSize = 0;
       PRBool               result = PR_FALSE;

       if (m_pMailboxes) {
              PRUint32             i;
              PRBool               import;
              PRUint32             count = 0;
              nsresult             rv;
              PRUint32             size;

              rv = m_pMailboxes->Count( &count);
              
              for (i = 0; i < count; i++) {
                     nsCOMPtr<nsIImportMailboxDescriptor> box =
                            do_QueryElementAt(m_pMailboxes, i);
                     if (box) {
                            import = PR_FALSE;
                            size = 0;
                            rv = box->GetImport( &import);
                            if (import) {
                                   rv = box->GetSize( &size);
                                   result = PR_TRUE;
                            }
                            totalSize += size;
                     }
              }

              m_totalSize = totalSize;
       }
       
       m_doImport = result;

       *_retval = result;   

       return( NS_OK);
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 138 of file nsImportMail.cpp.

Definition at line 137 of file nsImportMail.cpp.

Definition at line 148 of file nsImportMail.cpp.

Definition at line 141 of file nsImportMail.cpp.

Definition at line 140 of file nsImportMail.cpp.

Definition at line 136 of file nsImportMail.cpp.

Definition at line 150 of file nsImportMail.cpp.

Definition at line 146 of file nsImportMail.cpp.

Definition at line 143 of file nsImportMail.cpp.

Definition at line 144 of file nsImportMail.cpp.

Definition at line 135 of file nsImportMail.cpp.

Definition at line 139 of file nsImportMail.cpp.

Definition at line 145 of file nsImportMail.cpp.

Definition at line 149 of file nsImportMail.cpp.

Definition at line 147 of file nsImportMail.cpp.

Definition at line 142 of file nsImportMail.cpp.


The documentation for this class was generated from the following file: