Bug #251657 --> Thunderbird profile migration from Eudora.

Re-write the code that parses the windows registry string to properly find eudora.ini so we don't have to prompt the user.
Fix a memory issue with writing to an unallocated nsIFileSpec.
Fix a memory issue by using a nsCOMPtr for the eudora location member variable.
This commit is contained in:
scott%scott-macgregor.org 2004-07-17 04:51:13 +00:00
Родитель e65c24c40b
Коммит 6e0b8971e2
5 изменённых файлов: 44 добавлений и 53 удалений

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

@ -73,7 +73,7 @@
#include "nsIStringBundle.h"
#include "nsEudoraSettings.h"
#include "nsReadableUtils.h"
#include "nsUnicharUtils.h"
#if defined(XP_WIN) || defined(XP_OS2)
#include "nsEudoraWin32.h"
@ -561,6 +561,11 @@ NS_IMETHODIMP ImportEudoraMailImpl::GetImportProgress( PRUint32 *pDoneSoFar)
NS_IMETHODIMP ImportEudoraMailImpl::TranslateFolderName(const nsAString & aFolderName, nsAString & _retval)
{
if (aFolderName.Equals(NS_LITERAL_STRING("Out"), nsCaseInsensitiveStringComparator()))
_retval = NS_LITERAL_STRING(kDestUnsentMessagesFolderName);
else if (aFolderName.Equals(NS_LITERAL_STRING("In"), nsCaseInsensitiveStringComparator()))
_retval = NS_LITERAL_STRING(kDestInboxFolderName);
else
_retval = aFolderName;
return NS_OK;
}

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

@ -73,12 +73,10 @@ nsresult nsEudoraSettings::Create(nsIImportSettings** aImport)
nsEudoraSettings::nsEudoraSettings()
{
m_pLocation = nsnull;
}
nsEudoraSettings::~nsEudoraSettings()
{
NS_IF_RELEASE( m_pLocation);
}
NS_IMPL_ISUPPORTS1(nsEudoraSettings, nsIImportSettings)
@ -93,29 +91,24 @@ NS_IMETHODIMP nsEudoraSettings::AutoLocate(PRUnichar **description, nsIFileSpec
*description = nsnull;
*_retval = PR_FALSE;
*location = nsnull;
nsresult rv;
if (NS_FAILED( rv = NS_NewFileSpec( location)))
return( rv);
if (NS_FAILED( rv = NS_NewFileSpec( getter_AddRefs(m_pLocation))))
return rv;
*description = nsEudoraStringBundle::GetStringByID( EUDORAIMPORT_NAME);
#if defined(XP_WIN) || defined(XP_OS2)
*_retval = nsEudoraWin32::FindSettingsFile( *location);
*_retval = nsEudoraWin32::FindSettingsFile( m_pLocation );
#endif
m_pLocation = *location;
NS_IF_ADDREF( m_pLocation);
return( NS_OK);
NS_IF_ADDREF(*location = m_pLocation);
return NS_OK;
}
NS_IMETHODIMP nsEudoraSettings::SetLocation(nsIFileSpec *location)
{
NS_IF_RELEASE( m_pLocation);
m_pLocation = location;
NS_IF_ADDREF( m_pLocation);
return( NS_OK);
}
@ -129,17 +122,15 @@ NS_IMETHODIMP nsEudoraSettings::Import(nsIMsgAccount **localMailAccount, PRBool
// Get the settings file if it doesn't exist
if (!m_pLocation) {
#if defined(XP_WIN) || defined(XP_OS2)
if (NS_SUCCEEDED( rv = NS_NewFileSpec( &m_pLocation))) {
if (NS_SUCCEEDED( rv = NS_NewFileSpec( getter_AddRefs(m_pLocation)))) {
if (!nsEudoraWin32::FindSettingsFile( m_pLocation)) {
NS_IF_RELEASE( m_pLocation);
m_pLocation = nsnull;
}
}
#endif
#if defined(XP_MAC) || defined(XP_MACOSX)
if (NS_SUCCEEDED( rv = NS_NewFileSpec( &m_pLocation))) {
if (NS_SUCCEEDED( rv = NS_NewFileSpec( getter_AddRefs(m_pLocation)))) {
if (!nsEudoraMac::FindSettingsFile( m_pLocation)) {
NS_IF_RELEASE( m_pLocation);
m_pLocation = nsnull;
}
}

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

@ -41,6 +41,7 @@
#include "nsIImportSettings.h"
#include "nsIFileSpec.h"
#include "nsCOMPtr.h"
class nsEudoraSettings : public nsIImportSettings {
public:
@ -56,7 +57,7 @@ public:
NS_DECL_NSIIMPORTSETTINGS
private:
nsIFileSpec * m_pLocation;
nsCOMPtr<nsIFileSpec> m_pLocation;
};
#endif /* nsEudoraSettings_h___ */

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

@ -106,6 +106,7 @@ PRBool nsEudoraWin32::FindMailFolder( nsIFileSpec *pFolder)
PRBool nsEudoraWin32::FindEudoraLocation( nsIFileSpec *pFolder, PRBool findIni)
{
PRBool result = PR_FALSE;
PRBool exists = PR_FALSE;
// look in the registry to see where eudora is installed?
HKEY sKey;
@ -116,7 +117,30 @@ PRBool nsEudoraWin32::FindEudoraLocation( nsIFileSpec *pFolder, PRBool findIni)
nsCString str((const char *)pBytes);
delete [] pBytes;
str.CompressWhitespace();
// Command line is Eudora mailfolder eudora.ini
if (findIni) {
// find the string coming after the last space
PRInt32 index = str.RFind(" ");
if (index != -1) {
index++; // skip the space
nsCString path;
str.Mid( path, index, str.Length() - index);
pFolder->SetNativePath( path.get());
pFolder->IsFile( &exists);
if (exists)
result = exists;
else // it may just be the mailbox location....guess that there will be a eudora.ini file there
{
pFolder->AppendRelativeUnixPath("eudora.ini");
pFolder->IsFile( &exists);
result = exists;
}
}
} // if findIni
else {
int idx = -1;
if (str.CharAt( 0) == '"') {
idx = str.FindChar( '"', 1);
@ -127,19 +151,6 @@ PRBool nsEudoraWin32::FindEudoraLocation( nsIFileSpec *pFolder, PRBool findIni)
idx = str.FindChar( ' ');
}
if ((idx != -1) && findIni) {
idx++;
while (str.CharAt( idx) == ' ') idx++;
int eIdx = -1;
if (str.CharAt( idx) == '"') {
eIdx = str.FindChar( '"', idx);
}
else {
eIdx = str.FindChar( ' ', idx);
}
idx = eIdx;
}
if (idx != -1) {
idx++;
while (str.CharAt( idx) == ' ') idx++;
@ -154,32 +165,14 @@ PRBool nsEudoraWin32::FindEudoraLocation( nsIFileSpec *pFolder, PRBool findIni)
nsCString path;
str.Mid( path, idx, endIdx - idx);
/*
For some reason, long long ago, it was necessary
to clean up the path to Eudora so that it didn't contain
a mix of short file names and long file names. This is
no longer true.
ConvertPath( path);
IMPORT_LOG1( "** GetShortPath returned: %s\n", path.get());
*/
pFolder->SetNativePath( path.get());
PRBool exists = PR_FALSE;
if (findIni) {
if (NS_SUCCEEDED( pFolder->IsFile( &exists))) {
result = exists;
}
}
else {
if (NS_SUCCEEDED( pFolder->IsDirectory( &exists))) {
if (NS_SUCCEEDED( pFolder->IsDirectory( &exists)))
result = exists;
}
}
}
}
}
} // if pBytes
::RegCloseKey( sKey);
}

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

@ -126,4 +126,5 @@ interface nsIImportMail : nsISupports
#define kDestTrashFolderName "Trash"
#define kDestUnsentMessagesFolderName "Unsent Messages"
#define kDestSentFolderName "Sent"
#define kDestInboxFolderName "Inbox"
%}