From c8b56bd74b291ae7931797472c065b287e6c2a71 Mon Sep 17 00:00:00 2001 From: "bugzilla%standard8.demon.co.uk" Date: Sat, 10 Feb 2007 09:45:31 +0000 Subject: [PATCH] Bug 182128 Edit Card, Notes on several lines appear on one after export/import in text format (txt, tab, csv). r=Neil,sr=bienvenu --- mailnews/addrbook/src/nsAddressBook.cpp | 25 +++++----------------- mailnews/import/text/src/nsTextAddress.cpp | 13 +++++------ mailnews/import/text/src/nsTextAddress.h | 1 - 3 files changed, 10 insertions(+), 29 deletions(-) diff --git a/mailnews/addrbook/src/nsAddressBook.cpp b/mailnews/addrbook/src/nsAddressBook.cpp index 13dc4dcd39f2..492a465107bf 100644 --- a/mailnews/addrbook/src/nsAddressBook.cpp +++ b/mailnews/addrbook/src/nsAddressBook.cpp @@ -607,32 +607,17 @@ nsAddressBook::ExportDirectoryToDelimitedText(nsIAbDirectory *aDirectory, const if (!needsQuotes && (newValue.FindChar(',') != kNotFound || newValue.FindChar('\x09') != kNotFound)) needsQuotes = PR_TRUE; + // Make sure we quote if containing CR/LF. + if (newValue.FindChar(nsCRT::CR) != kNotFound || + newValue.FindChar(nsCRT::LF) != kNotFound) + needsQuotes = PR_TRUE; + if (needsQuotes) { newValue.Insert(NS_LITERAL_STRING("\""), 0); newValue.AppendLiteral("\""); } - // For notes, make sure CR/LF is converted to spaces - // to avoid creating multiple lines for a single card. - // - // the import code expects .txt, .tab, .csv files to - // have non-ASCII data in the system charset - // - // note, this means if you machine is set to US-ASCII - // but you have cards with Japanese characters - // you will lose data when exporting. - // - // the solution is to export / import as LDIF. - // non-ASCII data is treated as base64 encoded UTF-8 in LDIF - if (!strcmp(EXPORT_ATTRIBUTES_TABLE[i].abColName, kNotesColumn)) - { - if (!newValue.IsEmpty()) - { - newValue.ReplaceChar(nsCRT::CR, ' '); - newValue.ReplaceChar(nsCRT::LF, ' '); - } - } rv = importService->SystemStringFromUnicode(newValue.get(), valueCStr); if (NS_FAILED(rv)) { diff --git a/mailnews/import/text/src/nsTextAddress.cpp b/mailnews/import/text/src/nsTextAddress.cpp index 3ce44c9a1e5d..8b6bb37ba75a 100644 --- a/mailnews/import/text/src/nsTextAddress.cpp +++ b/mailnews/import/text/src/nsTextAddress.cpp @@ -47,6 +47,7 @@ #include "TextDebugLog.h" #include "plstr.h" +#include "nsCRT.h" #define kWhitespace " \t\b\r\n" @@ -163,7 +164,10 @@ nsresult nsTextAddress::ReadRecord(nsILineInputStream *aLineStream, nsCString &a // Read the line and append it rv = aLineStream->ReadLine(line, &more); if (NS_SUCCEEDED(rv)) { - aLine += line; + if (!aLine.IsEmpty()) + aLine.AppendLiteral(NS_LINEBREAK); + aLine.Append(line); + numQuotes += line.CountChar('"'); } } @@ -360,13 +364,6 @@ PRBool nsTextAddress::GetField( const char *pLine, PRInt32 maxLen, PRInt32 index return( result); } -void nsTextAddress::SanitizeSingleLine( nsCString& val) -{ - val.ReplaceSubstring( "\x0D\x0A", ", "); - val.ReplaceChar( 13, ' '); - val.ReplaceChar( 10, ' '); -} - nsresult nsTextAddress::DetermineDelim(nsIFile *aSrc) { nsCOMPtr inputStream; diff --git a/mailnews/import/text/src/nsTextAddress.h b/mailnews/import/text/src/nsTextAddress.h index 97926f6f99b7..6cb301fff2dc 100644 --- a/mailnews/import/text/src/nsTextAddress.h +++ b/mailnews/import/text/src/nsTextAddress.h @@ -71,7 +71,6 @@ private: nsresult ProcessLine(const char *pLine, PRInt32 len, nsString& errors); static PRInt32 CountFields(const char *pLine, PRInt32 maxLen, char delim); - static void SanitizeSingleLine( nsCString& val); static nsresult ReadRecord(nsILineInputStream *pSrc, nsCString &aLine, char delim, PRBool *aMore); char m_delim;