Improve profile migration from Eudora experience for Thunderbird.

Bug #3157 --> Eudora importing fails to detect HTML messages.

Bug #242953 --> Migrate the attachment names in messages during Eudora profile migration instead of using the name
"Attachment"

sr=bienvenu
This commit is contained in:
scott%scott-macgregor.org 2004-07-17 04:53:26 +00:00
Родитель 6e0b8971e2
Коммит 84279c9168
8 изменённых файлов: 114 добавлений и 15 удалений

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

@ -649,9 +649,11 @@ nsresult nsEudoraCompose::SendTheMessage( nsIFileSpec *pMsg)
m_pMsgFields->SetReplyTo( headerVal);
// what about all of the other headers?!?!?!?!?!?!
char *pMimeType = nsnull;
char *pMimeType;
if (!bodyType.IsEmpty())
pMimeType = ToNewCString(bodyType);
else
pMimeType = ToNewCString(m_bodyType);
// IMPORT_LOG0( "Outlook compose calling CreateAndSendMessage\n");
nsMsgAttachedFile *pAttach = GetLocalAttachments();

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

@ -132,7 +132,7 @@ public:
nsresult SendTheMessage( nsIFileSpec *pMsg);
void SetBody( const char *pBody, PRInt32 len) { m_pBody = pBody; m_bodyLen = len;}
void SetBody( const char *pBody, PRInt32 len, nsCString &bodyType) { m_pBody = pBody; m_bodyLen = len; m_bodyType = bodyType;}
void SetHeaders( const char *pHeaders, PRInt32 len) { m_pHeaders = pHeaders; m_headerLen = len;}
void SetAttachments( nsVoidArray *pAttachments) { m_pAttachments = pAttachments;}
void SetDefaultDate( nsCString date) { m_defaultDate = date;}
@ -178,6 +178,7 @@ private:
const char * m_pHeaders;
PRInt32 m_bodyLen;
const char * m_pBody;
nsCString m_bodyType;
nsString m_defCharset;
SimpleBufferTonyRCopiedOnce m_readHeaders;
nsCOMPtr<nsIImportService> m_pImportService;

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

@ -956,7 +956,7 @@ void nsEudoraMac::SetSmtpServer( nsIMsgAccountManager *pMgr, nsIMsgAccount *pAcc
}
nsresult nsEudoraMac::GetAttachmentInfo( const char *pFileName, nsIFileSpec *pSpec, nsCString& mimeType)
nsresult nsEudoraMac::GetAttachmentInfo( const char *pFileName, nsIFileSpec *pSpec, nsCString& mimeType, nsCString& aAttachment)
{
mimeType.Truncate();
@ -1039,6 +1039,10 @@ nsresult nsEudoraMac::GetAttachmentInfo( const char *pFileName, nsIFileSpec *pSp
return rv;
}
char *pLeaf = nsnull;
pSpec->GetLeafName( &pLeaf);
aAttachment.Adopt(pLeaf);
nsCOMPtr<nsILocalFileMac> macFile;
rv = NS_FileSpecToILocalFileMac(&tempFileSpec, getter_AddRefs(macFile));
if (NS_FAILED(rv)) {

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

@ -63,7 +63,7 @@ public:
// get a TOC file from a mailbox file
virtual nsresult FindTOCFile( nsIFileSpec *pMailFile, nsIFileSpec **pTOCFile, PRBool *pDeleteToc);
virtual nsresult GetAttachmentInfo( const char *pFileName, nsIFileSpec *pSpec, nsCString& mimeType);
virtual nsresult GetAttachmentInfo( const char *pFileName, nsIFileSpec *pSpec, nsCString& mimeType, nsCString& aAttachment);
// Address book stuff
virtual PRBool FindAddressFolder( nsIFileSpec *pFolder);

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

@ -276,6 +276,7 @@ nsresult nsEudoraMailbox::ImportMailbox( PRUint32 *pBytes, PRBool *pAbort, const
if (NS_SUCCEEDED( rv = NS_NewFileSpec( getter_AddRefs( compositionFile)))) {
nsEudoraCompose compose;
nsCString defaultDate;
nsCAutoString bodyType;
/*
IMPORT_LOG0( "Calling compose.SendMessage\n");
@ -290,13 +291,13 @@ nsresult nsEudoraMailbox::ImportMailbox( PRUint32 *pBytes, PRBool *pAbort, const
IMPORT_LOG0( "Reading first message\n");
while (!*pAbort && NS_SUCCEEDED( rv = ReadNextMessage( &state, readBuffer, headers, body, defaultDate))) {
while (!*pAbort && NS_SUCCEEDED( rv = ReadNextMessage( &state, readBuffer, headers, body, defaultDate, bodyType))) {
if (pBytes) {
*pBytes += (((body.m_writeOffset - 1 + headers.m_writeOffset - 1) / div) * mul);
}
compose.SetBody( body.m_pBuffer, body.m_writeOffset - 1);
compose.SetBody( body.m_pBuffer, body.m_writeOffset - 1, bodyType);
compose.SetHeaders( headers.m_pBuffer, headers.m_writeOffset - 1);
compose.SetAttachments( &m_attachments);
compose.SetDefaultDate(defaultDate);
@ -448,9 +449,7 @@ nsresult nsEudoraMailbox::CompactMailbox( PRUint32 *pBytes, PRBool *pAbort, nsIF
nsresult nsEudoraMailbox::ReadNextMessage( ReadFileState *pState, SimpleBufferTonyRCopiedOnce& copy, SimpleBufferTonyRCopiedOnce& header, SimpleBufferTonyRCopiedOnce& body, nsCString& defaultDate)
nsresult nsEudoraMailbox::ReadNextMessage( ReadFileState *pState, SimpleBufferTonyRCopiedOnce& copy, SimpleBufferTonyRCopiedOnce& header, SimpleBufferTonyRCopiedOnce& body, nsCString& defaultDate, nsCString& bodyType)
{
header.m_writeOffset = 0;
body.m_writeOffset = 0;
@ -556,7 +555,44 @@ nsresult nsEudoraMailbox::ReadNextMessage( ReadFileState *pState, SimpleBufferTo
// Get the body!
// Read one line at a time here and look for the next separator
nsCString tmp;
PRBool insideEudoraTags = PR_FALSE;
// by default we consider the body text to be plain text
bodyType = "text/plain";
while ((lineLen = IsEudoraFromSeparator( copy.m_pBuffer + copy.m_writeOffset, copy.m_bytesInBuf - copy.m_writeOffset, tmp)) == -1) {
if (IsEudoraTag ( copy.m_pBuffer + copy.m_writeOffset, copy.m_bytesInBuf - copy.m_writeOffset, insideEudoraTags, bodyType)) {
// We don't want to keep eudora tags so we remove this line
// let's write the previous text
if (!body.Write( copy.m_pBuffer, copy.m_writeOffset)) {
IMPORT_LOG0( "*** Error writing to message body\n");
return( NS_ERROR_FAILURE);
}
lineLen = -1;
while (copy.m_bytesInBuf && lineLen == -1) {
lineLen = FindStartLine( copy);
if (lineLen == -1)
copy.m_writeOffset = copy.m_bytesInBuf;
else
copy.m_writeOffset += lineLen;
if (NS_FAILED( rv = FillMailBuffer( pState, copy))) {
IMPORT_LOG0( "*** Error reading message body\n");
return( rv);
}
}
if (!copy.m_bytesInBuf)
break;
continue;
}
// Eudora Attachment lines are always outside Eudora Tags
// so we shouldn't try to find one here
if (!insideEudoraTags) {
// Debatable is whether or not to exclude these lines from the
// text of the message, I prefer not to in case the original
// attachment is actually missing.
@ -565,6 +601,8 @@ nsresult nsEudoraMailbox::ReadNextMessage( ReadFileState *pState, SimpleBufferTo
IMPORT_LOG0( "*** Error examining attachment line\n");
return( rv);
}
}
while (((lineLen = FindStartLine( copy)) == -1) && copy.m_bytesInBuf) {
copy.m_writeOffset = copy.m_bytesInBuf;
@ -682,6 +720,56 @@ PRInt32 nsEudoraMailbox::IsEndHeaders( SimpleBufferTonyRCopiedOnce& data)
return( -1);
}
static char *eudoraTag[] = {
"<x-html>",
"</x-html>",
"<x-rich>",
"</x-rich>",
"<x-flowed>",
"</x-flowed>"
};
static PRInt32 eudoraTagLen[] = {
8,
8,
8,
8,
9,
9,
0
};
static const char *TagContentType[] = {
"text/html",
"text/html",
"text/html",
"text/html",
"text/plain",
"text/plain",
};
// Determine if this line contains an eudora special tag
PRBool nsEudoraMailbox::IsEudoraTag( const char *pChar, PRInt32 maxLen, PRBool &insideEudoraTags, nsCString &bodyType)
{
PRInt32 cnt;
PRInt32 idx = 0;
while ((cnt = eudoraTagLen[idx]) != 0) {
if (maxLen >= cnt && !nsCRT::strncmp( eudoraTag[idx], pChar, cnt)) {
insideEudoraTags = (pChar[1] != '/');
bodyType = TagContentType[idx];
return PR_TRUE;
}
idx++;
}
return PR_FALSE;
}
// Determine if this line meets Eudora standards for a separator line
// This logic is based on Eudora 1.3.1's strict requirements for what
// makes a valid separator line. This may need to be relaxed for newer
@ -1052,14 +1140,15 @@ PRBool nsEudoraMailbox::AddAttachment( nsCString& fileName)
return( PR_FALSE);
nsCString mimeType;
if (NS_FAILED( GetAttachmentInfo( fileName.get(), pSpec, mimeType))) {
nsCString attachmentName;
if (NS_FAILED( GetAttachmentInfo( fileName.get(), pSpec, mimeType, attachmentName))) {
NS_RELEASE( pSpec);
return( PR_FALSE);
}
ImportAttachment *a = new ImportAttachment;
a->mimeType = ToNewCString(mimeType);
a->description = nsCRT::strdup( "Attached File");
a->description = !attachmentName.IsEmpty() ? ToNewCString(attachmentName) : nsCRT::strdup( "Attached File");
a->pAttachment = pSpec;
m_attachments.AppendElement( a);

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

@ -64,13 +64,14 @@ public:
// get the toc file corresponding to this mailbox
virtual nsresult FindTOCFile( nsIFileSpec *pMailFile, nsIFileSpec **pTOCFile, PRBool *pDeleteToc) { return( NS_ERROR_FAILURE);}
// interpret the attachment line and return the attached file
virtual nsresult GetAttachmentInfo( const char *pFileName, nsIFileSpec *pSpec, nsCString& mimeType) { return( NS_ERROR_FAILURE);}
virtual nsresult GetAttachmentInfo( const char *pFileName, nsIFileSpec *pSpec, nsCString& mimeType, nsCString& aAttachment) { return( NS_ERROR_FAILURE);}
// Non-platform specific common stuff
// import a mailbox
nsresult ImportMailbox( PRUint32 *pBytes, PRBool *pAbort, const PRUnichar *pName, nsIFileSpec *pSrc, nsIFileSpec *pDst, PRInt32 *pMsgCount);
static PRInt32 IsEudoraFromSeparator( const char *pData, PRInt32 maxLen, nsCString& defaultDate);
static PRBool IsEudoraTag( const char *pChar, PRInt32 maxLen, PRBool &insideEudoraTags, nsCString &bodyType);
protected:
nsresult CreateTempFile( nsIFileSpec **ppSpec);
@ -79,7 +80,7 @@ protected:
private:
nsresult CompactMailbox( PRUint32 *pBytes, PRBool *pAbort, nsIFileSpec *pMail, nsIFileSpec *pToc, nsIFileSpec *pDst);
nsresult ReadNextMessage( ReadFileState *pState, SimpleBufferTonyRCopiedOnce& copy, SimpleBufferTonyRCopiedOnce& header, SimpleBufferTonyRCopiedOnce& body, nsCString& defaultDate);
nsresult ReadNextMessage( ReadFileState *pState, SimpleBufferTonyRCopiedOnce& copy, SimpleBufferTonyRCopiedOnce& header, SimpleBufferTonyRCopiedOnce& body, nsCString& defaultDate, nsCString &defBodyType);
PRInt32 FindStartLine( SimpleBufferTonyRCopiedOnce& data);
PRInt32 FindNextEndLine( SimpleBufferTonyRCopiedOnce& data);
PRInt32 IsEndHeaders( SimpleBufferTonyRCopiedOnce& data);

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

@ -911,7 +911,7 @@ void nsEudoraWin32::SetSmtpServer( nsIMsgAccountManager *pMgr, nsIMsgAccount *pA
}
}
nsresult nsEudoraWin32::GetAttachmentInfo( const char *pFileName, nsIFileSpec *pSpec, nsCString& mimeType)
nsresult nsEudoraWin32::GetAttachmentInfo( const char *pFileName, nsIFileSpec *pSpec, nsCString& mimeType, nsCString& aAttachmentName)
{
mimeType.Truncate();
pSpec->SetNativePath( pFileName);
@ -940,6 +940,8 @@ nsresult nsEudoraWin32::GetAttachmentInfo( const char *pFileName, nsIFileSpec *p
if (mimeType.IsEmpty())
mimeType = "application/octet-stream";
aAttachmentName = name; // use the leaf name of the attachment file url as the attachment name
return( NS_OK);
}

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

@ -65,7 +65,7 @@ public:
// get a TOC file from a mailbox file
virtual nsresult FindTOCFile( nsIFileSpec *pMailFile, nsIFileSpec **pTOCFile, PRBool *pDeleteToc);
virtual nsresult GetAttachmentInfo( const char *pFileName, nsIFileSpec *pSpec, nsCString& mimeType);
virtual nsresult GetAttachmentInfo( const char *pFileName, nsIFileSpec *pSpec, nsCString& mimeType, nsCString& aAttachment);
// Things that must be overridden because they are platform specific.
// retrieve the address book folder