diff --git a/mozilla/mailnews/base/public/nsIMsgFolder.idl b/mozilla/mailnews/base/public/nsIMsgFolder.idl index e3a13752d6e..126d40b28f2 100644 --- a/mozilla/mailnews/base/public/nsIMsgFolder.idl +++ b/mozilla/mailnews/base/public/nsIMsgFolder.idl @@ -82,10 +82,10 @@ const nsMsgBiffState nsMsgBiffState_Unknown = 2; // We dunno whether there is ne void startFolderLoading(); void endFolderLoading(); - /* get new headers for db */ - void updateFolder(in nsIMsgWindow aWindow); + /* get new headers for db */ + void updateFolder(in nsIMsgWindow aWindow); - readonly attribute wstring prettiestName; + readonly attribute wstring prettiestName; /** * URL for this folder @@ -95,7 +95,7 @@ const nsMsgBiffState nsMsgBiffState_Unknown = 2; // We dunno whether there is ne /** * should probably move to the server */ - readonly attribute boolean showDeletedMessages; + readonly attribute boolean showDeletedMessages; /** * this folder's parent server @@ -131,7 +131,7 @@ const nsMsgBiffState nsMsgBiffState_Unknown = 2; // We dunno whether there is ne /** * the phantom server folder */ - readonly attribute nsIMsgFolder rootFolder; + readonly attribute nsIMsgFolder rootFolder; /** * function to get the filter list on folder's server @@ -140,25 +140,29 @@ const nsMsgBiffState nsMsgBiffState_Unknown = 2; // We dunno whether there is ne nsIMsgFilterList getFilterList(in nsIMsgWindow msgWindow); void setFilterList(in nsIMsgFilterList filterList); - void ForceDBClosed (); - void Delete (); + void ForceDBClosed (); + void Delete (); - void deleteSubFolders(in nsISupportsArray folders, in nsIMsgWindow msgWindow); - void propagateDelete(in nsIMsgFolder folder, in boolean deleteStorage, in nsIMsgWindow msgWindow); - void recursiveDelete(in boolean deleteStorage, in nsIMsgWindow msgWindow); + void deleteSubFolders(in nsISupportsArray folders, in nsIMsgWindow msgWindow); + void propagateDelete(in nsIMsgFolder folder, in boolean deleteStorage, + in nsIMsgWindow msgWindow); + void recursiveDelete(in boolean deleteStorage, in nsIMsgWindow msgWindow); - void createSubfolder(in wstring folderName, in nsIMsgWindow msgWindow); - [noscript] nsIMsgFolder addSubfolder(in nsAutoString folderName); - /* this method ensures the storage for the folder exists. - For local folders, it creates the berkeley mailbox if missing. - For imap folders, it subscribes to the folder if it exists, - or creates it if it doesn't exist - */ - void createStorageIfMissing(in nsIUrlListener urlListener); + void createSubfolder(in wstring folderName, in nsIMsgWindow msgWindow); + nsIMsgFolder addSubfolder(in AString folderName); + /* this method ensures the storage for the folder exists. + For local folders, it creates the berkeley mailbox if missing. + For imap folders, it subscribes to the folder if it exists, + or creates it if it doesn't exist + */ + void createStorageIfMissing(in nsIUrlListener urlListener); void compact(in nsIUrlListener aListener, in nsIMsgWindow aMsgWindow); - void compactAll(in nsIUrlListener aListener, in nsIMsgWindow aMsgWindow, in nsISupportsArray aFolderArray, in boolean aCompactOfflineAlso, in nsISupportsArray aOfflineFolderArray); - void compactAllOfflineStores(in nsIMsgWindow aMsgWindow, in nsISupportsArray aOfflineFolderArray); + void compactAll(in nsIUrlListener aListener, in nsIMsgWindow aMsgWindow, + in nsISupportsArray aFolderArray, in boolean aCompactOfflineAlso, + in nsISupportsArray aOfflineFolderArray); + void compactAllOfflineStores(in nsIMsgWindow aMsgWindow, + in nsISupportsArray aOfflineFolderArray); void emptyTrash(in nsIMsgWindow aMsgWindow, in nsIUrlListener aListener); /** @@ -166,28 +170,28 @@ const nsMsgBiffState nsMsgBiffState_Unknown = 2; // We dunno whether there is ne * * @param name the new name of the folder */ - void rename(in wstring name, in nsIMsgWindow msgWindow); + void rename(in wstring name, in nsIMsgWindow msgWindow); void renameSubFolders( in nsIMsgWindow msgWindow, in nsIMsgFolder oldFolder); /** * looks in immediate children of this folder for the given name * * @param name the name of the target subfolder */ - boolean containsChildNamed(in wstring name); - boolean isAncestorOf(in nsIMsgFolder folder); + boolean containsChildNamed(in wstring name); + boolean isAncestorOf(in nsIMsgFolder folder); - wstring generateUniqueSubfolderName(in wstring prefix, - in nsIMsgFolder otherFolder); + wstring generateUniqueSubfolderName(in wstring prefix, + in nsIMsgFolder otherFolder); - void updateSummaryTotals(in boolean force); - void summaryChanged(); + void updateSummaryTotals(in boolean force); + void summaryChanged(); /** * get the total number of unread messages in this folder, * or in all subfolders * * @param deep if true, descends into all subfolders and gets a grand total */ - long getNumUnread(in boolean deep); + long getNumUnread(in boolean deep); /** * get the total number of messages in this folder, @@ -195,101 +199,102 @@ const nsMsgBiffState nsMsgBiffState_Unknown = 2; // We dunno whether there is ne * * @param deep if true, descends into all subfolders and gets a grand total */ - long getTotalMessages(in boolean deep); + long getTotalMessages(in boolean deep); /** * does this folder have new messages * */ - //boolean hasNewMessages(); - attribute boolean hasNewMessages; + //boolean hasNewMessages(); + attribute boolean hasNewMessages; /** * return the first new message in the folder * */ - readonly attribute nsIMsgDBHdr firstNewMessage; + readonly attribute nsIMsgDBHdr firstNewMessage; /** * clear new status flag of all of the new messages * */ - void clearNewMessages(); + void clearNewMessages(); - readonly attribute unsigned long expungedBytes; + readonly attribute unsigned long expungedBytes; /** * can this folder be deleted? * for example, special folders cannot be deleted */ - readonly attribute boolean deletable; + readonly attribute boolean deletable; /** * should we be displaying recipients instead of the sender? * for example, in the Sent folder, recipients are more relevant * than the sender */ - readonly attribute boolean displayRecipients; + readonly attribute boolean displayRecipients; /** * used to determine if it will take a long time to download all * the headers in this folder - so that we can do folder notifications * synchronously instead of asynchronously */ - readonly attribute boolean manyHeadersToDownload; + readonly attribute boolean manyHeadersToDownload; - readonly attribute boolean requiresCleanup; - void clearRequiresCleanup(); + readonly attribute boolean requiresCleanup; + void clearRequiresCleanup(); /** * this should go into a news-specific interface */ - readonly attribute boolean knowsSearchNntpExtension; + readonly attribute boolean knowsSearchNntpExtension; /** * this should go into a news-specific interface */ - readonly attribute boolean allowsPosting; + readonly attribute boolean allowsPosting; - readonly attribute string relativePathName; + readonly attribute string relativePathName; /** * size of this folder on disk (not including .msf file) * for imap, it's the sum of the size of the messages */ - attribute unsigned long sizeOnDisk; + attribute unsigned long sizeOnDisk; - readonly attribute string username; - readonly attribute string hostname; + readonly attribute string username; + readonly attribute string hostname; - void setFlag(in unsigned long flag); - void clearFlag(in unsigned long flag); - boolean getFlag(in unsigned long flag); + void setFlag(in unsigned long flag); + void clearFlag(in unsigned long flag); + boolean getFlag(in unsigned long flag); void setPrefFlag(); - void toggleFlag (in unsigned long flag); - void onFlagChange (in unsigned long flag); + void toggleFlag (in unsigned long flag); + void onFlagChange (in unsigned long flag); - attribute unsigned long flags; + attribute unsigned long flags; - nsIMsgFolder getFoldersWithFlag(in unsigned long flags, - in unsigned long resultsize, out unsigned long numFolders); + nsIMsgFolder getFoldersWithFlag(in unsigned long flags, + in unsigned long resultsize, + out unsigned long numFolders); - void getExpansionArray(in nsISupportsArray expansionArray); + void getExpansionArray(in nsISupportsArray expansionArray); string getUriForMsg(in nsIMsgDBHdr msgHdr); - void deleteMessages(in nsISupportsArray messages, + void deleteMessages(in nsISupportsArray messages, in nsIMsgWindow msgWindow, in boolean deleteStorage, in boolean isMove, in nsIMsgCopyServiceListener listener, in boolean allowUndo); void copyMessages(in nsIMsgFolder srcFolder, in nsISupportsArray messages, in boolean isMove, in nsIMsgWindow msgWindow, - in nsIMsgCopyServiceListener listener, in boolean isFolder, - in boolean allowUndo); + in nsIMsgCopyServiceListener listener, in boolean isFolder, + in boolean allowUndo); void copyFolder(in nsIMsgFolder srcFolder, in boolean isMoveFolder, in nsIMsgWindow msgWindow, in nsIMsgCopyServiceListener listener ); @@ -303,20 +308,20 @@ const nsMsgBiffState nsMsgBiffState_Unknown = 2; // We dunno whether there is ne boolean testSemaphore (in nsISupports semHolder); readonly attribute boolean locked; - void getNewMessages(in nsIMsgWindow aWindow, in nsIUrlListener aListener); + void getNewMessages(in nsIMsgWindow aWindow, in nsIUrlListener aListener); /** * write out summary data for this folder * to the given folder cache (i.e. panacea.dat) */ - void writeToFolderCache(in nsIMsgFolderCache folderCache, in boolean deep); + void writeToFolderCache(in nsIMsgFolderCache folderCache, in boolean deep); /** * the charset of this folder */ - attribute string charset; - attribute boolean charsetOverride; - attribute unsigned long biffState; + attribute string charset; + attribute boolean charsetOverride; + attribute unsigned long biffState; /** * the number of new messages since this folder was last visited @@ -343,8 +348,9 @@ const nsMsgBiffState nsMsgBiffState_Unknown = 2; // We dunno whether there is ne string generateMessageURI(in nsMsgKey msgKey); const nsMsgDispositionState nsMsgDispositionState_Replied = 0; - const nsMsgDispositionState nsMsgDispositionState_Forwarded = 1; - void addMessageDispositionState(in nsIMsgDBHdr aMessage, in nsMsgDispositionState aDispositionFlag); + const nsMsgDispositionState nsMsgDispositionState_Forwarded = 1; + void addMessageDispositionState(in nsIMsgDBHdr aMessage, + in nsMsgDispositionState aDispositionFlag); void markMessagesRead(in nsISupportsArray messages, in boolean markRead); void markAllMessagesRead(); @@ -360,20 +366,26 @@ const nsMsgBiffState nsMsgBiffState_Unknown = 2; // We dunno whether there is ne boolean shouldStoreMsgOffline(in nsMsgKey msgKey); boolean hasMsgOffline(in nsMsgKey msgKey); - nsIInputStream getOfflineFileStream(in nsMsgKey msgKey, out PRUint32 offset, out PRUint32 size); + nsIInputStream getOfflineFileStream(in nsMsgKey msgKey, out PRUint32 offset, + out PRUint32 size); readonly attribute nsIOutputStream offlineStoreOutputStream; readonly attribute nsIInputStream offlineStoreInputStream; - void DownloadMessagesForOffline(in nsISupportsArray messages, in nsIMsgWindow window); - nsIMsgFolder getChildWithURI(in string uri, in boolean deep, in boolean caseInsensitive); + void DownloadMessagesForOffline(in nsISupportsArray messages, + in nsIMsgWindow window); + nsIMsgFolder getChildWithURI(in string uri, in boolean deep, + in boolean caseInsensitive); void downloadAllForOffline(in nsIUrlListener listener, in nsIMsgWindow window); /** - * Turn notifications on/off for various notification types. Currently only supporting - * allMessageCountNotifications which refers to both total and unread message counts. + * Turn notifications on/off for various notification types. Currently only + * supporting allMessageCountNotifications which refers to both total and + * unread message counts. */ const unsigned long allMessageCountNotifications = 0; - void enableNotifications(in long notificationType, in boolean enable, in boolean dbBatching); + void enableNotifications(in long notificationType, in boolean enable, + in boolean dbBatching); boolean isCommandEnabled(in string command); - boolean matchOrChangeFilterDestination(in nsIMsgFolder folder, in boolean caseInsensitive); + boolean matchOrChangeFilterDestination(in nsIMsgFolder folder, + in boolean caseInsensitive); boolean confirmFolderDeletionForFilter(in nsIMsgWindow msgWindow); void alertFilterChanged(in nsIMsgWindow msgWindow); void throwAlertMsg(in string msgName, in nsIMsgWindow msgWindow); @@ -420,7 +432,7 @@ const nsMsgBiffState nsMsgBiffState_Unknown = 2; // We dunno whether there is ne void AddFolderListener(in nsIFolderListener listener); void RemoveFolderListener(in nsIFolderListener listener); - nsIMsgFolder FindSubFolder(in string escapedSubFolderName); + nsIMsgFolder FindSubFolder(in ACString escapedSubFolderName); void NotifyPropertyChanged(in nsIAtom property, in string oldValue, diff --git a/mozilla/mailnews/base/public/nsIMsgHdr.idl b/mozilla/mailnews/base/public/nsIMsgHdr.idl index af55b89926d..bc8e1c27811 100644 --- a/mozilla/mailnews/base/public/nsIMsgHdr.idl +++ b/mozilla/mailnews/base/public/nsIMsgHdr.idl @@ -43,10 +43,6 @@ #include "MailNewsTypes2.idl" -[ptr] native nsString(nsString); -[ptr] native nsCString(nsCString); -[ref] native nsStringRef(nsString); -[ref] native nsCStringRef(nsCString); [ptr] native octetPtr(PRUint8); interface nsIMsgFolder; @@ -56,8 +52,8 @@ interface nsIMsgHdr : nsISupports { /* general property routines - I think this can retrieve any header in the db */ - [noscript] void getProperty(in string propertyName, in nsStringRef propertyValue); - [noscript] void setProperty(in string propertyName, in nsStringRef propertyStr); + AString getProperty(in string propertyName); + void setProperty(in string propertyName, in AString propertyStr); void setStringProperty(in string propertyName, in string propertyValue); string getStringProperty(in string propertyName); unsigned long getUint32Property(in string propertyName); @@ -68,7 +64,7 @@ interface nsIMsgHdr : nsISupports readonly attribute boolean isRead; readonly attribute boolean isFlagged; - // Mark message routines + // Mark message routines void markRead(in boolean read); void markFlagged(in boolean flagged); void markHasAttachments(in boolean hasAttachments); @@ -104,9 +100,9 @@ interface nsIMsgHdr : nsISupports /* anything below here still has to be fixed */ void setReferences(in string references); readonly attribute unsigned short numReferences; - [noscript] void getStringReference(in long refNum, in nsCStringRef ref); + ACString getStringReference(in long refNum); - void setRecipientsArray(in string names, in string addresses, + void setRecipientsArray(in string names, in string addresses, in unsigned long numAddresses); void setCCListArray(in string names, in string addresses, in unsigned long numAddresses); @@ -119,9 +115,9 @@ interface nsIMsgHdr : nsISupports [noscript] void getSubjectCollationKey(out octetPtr key, out unsigned long len); [noscript] void getRecipientsCollationKey(out octetPtr key, out unsigned long len); - attribute string Charset; - attribute nsMsgLabelValue label; - readonly attribute nsIMsgFolder folder; + attribute string Charset; + attribute nsMsgLabelValue label; + readonly attribute nsIMsgFolder folder; }; [scriptable, uuid(B5212A60-F93F-11d2-951C-006097222B83)] diff --git a/mozilla/mailnews/base/search/src/nsMsgFilter.cpp b/mozilla/mailnews/base/search/src/nsMsgFilter.cpp index d59e748b763..74f0d4c8014 100644 --- a/mozilla/mailnews/base/search/src/nsMsgFilter.cpp +++ b/mozilla/mailnews/base/search/src/nsMsgFilter.cpp @@ -55,7 +55,7 @@ #include "nsMsgSearchValue.h" #include "nsReadableUtils.h" #include "nsEscape.h" -#include "nsMsgUtf7Utils.h" +#include "nsMsgI18N.h" #include "nsIImportService.h" #include "nsISupportsObsolete.h" #include "nsIOutputStream.h" @@ -510,15 +510,14 @@ nsresult nsMsgFilter::ConvertMoveToFolderValue(nsIMsgRuleAction *filterAction, n { nsAutoString unicodeStr; impSvc->SystemStringToUnicode(originalServerPath.get(), unicodeStr); - char *utfNewName = CreateUtf7ConvertedStringFromUnicode(unicodeStr.get()); - originalServerPath.Assign(utfNewName); - nsCRT::free(utfNewName); + nsresult rv = CopyUTF16toMUTF7(unicodeStr, originalServerPath); + NS_ENSURE_SUCCESS(rv, rv); } nsCOMPtr destIFolder; if (rootFolder) { - rootFolder->FindSubFolder(originalServerPath.get(), getter_AddRefs(destIFolder)); + rootFolder->FindSubFolder(originalServerPath, getter_AddRefs(destIFolder)); if (destIFolder) { destIFolder->GetURI(getter_Copies(folderUri)); @@ -576,10 +575,7 @@ nsresult nsMsgFilter::ConvertMoveToFolderValue(nsIMsgRuleAction *filterAction, n { nsAutoString unicodeStr; impSvc->SystemStringToUnicode(moveValue.get(), unicodeStr); - nsXPIDLCString escapedName; - rv = NS_MsgEscapeEncodeURLPath(unicodeStr.get(), getter_Copies(escapedName)); - if (NS_SUCCEEDED(rv) && escapedName) - moveValue.Assign(escapedName.get()); + rv = NS_MsgEscapeEncodeURLPath(unicodeStr, moveValue); } destFolderUri.Append(moveValue); localMailRootMsgFolder->GetChildWithURI (destFolderUri.get(), PR_TRUE, PR_FALSE /*caseInsensitive*/, getter_AddRefs(destIMsgFolder)); diff --git a/mozilla/mailnews/base/search/src/nsMsgSearchAdapter.cpp b/mozilla/mailnews/base/search/src/nsMsgSearchAdapter.cpp index cb479ec689d..914e98e2330 100644 --- a/mozilla/mailnews/base/search/src/nsMsgSearchAdapter.cpp +++ b/mozilla/mailnews/base/search/src/nsMsgSearchAdapter.cpp @@ -49,6 +49,7 @@ #include "nsIIOService.h" #include "nsNetCID.h" #include "prprf.h" +#include "nsAutoPtr.h" // This stuff lives in the base class because the IMAP search syntax // is used by the Dredd SEARCH command as well as IMAP itself @@ -601,35 +602,35 @@ nsresult nsMsgSearchAdapter::EncodeImapTerm (nsIMsgSearchTerm *term, PRBool real #endif // do all sorts of crazy escaping - convertedValue = reallyDredd ? EscapeSearchUrl (searchTermValue) : + convertedValue = reallyDredd ? EscapeSearchUrl (searchTermValue) : EscapeImapSearchProtocol(searchTermValue); - useQuotes = !reallyDredd || - (nsAutoString(convertedValue).FindChar((PRUnichar)' ') != -1); - // now convert to char* and escape quoted_specials - nsresult rv = ConvertFromUnicode(NS_ConvertUCS2toUTF8(destCharset).get(), nsAutoString(convertedValue), &value); - if (NS_SUCCEEDED(rv) && value) - { - char *oldValue = value; - // max escaped length is one extra character for every character in the cmd. - char *newValue = (char*)PR_Malloc(sizeof(char) * (2*strlen(value) + 1)); - if (newValue) - { - char *p = newValue; - while (1) - { - char ch = *value++; - if (!ch) - break; - if ((useQuotes ? ch == '"' : 0) || ch == '\\') - *p++ = '\\'; - *p++ = ch; - } - *p = '\0'; - value = nsCRT::strdup(newValue); // realloc down to smaller size - nsCRT::free(newValue); - nsCRT::free(oldValue); - } - } + useQuotes = !reallyDredd || + (nsDependentString(convertedValue).FindChar(PRUnichar(' ')) != -1); + // now convert to char* and escape quoted_specials + nsCAutoString valueStr; + nsresult rv = ConvertFromUnicode(NS_LossyConvertUTF16toASCII(destCharset).get(), + nsDependentString(convertedValue), valueStr); + if (NS_SUCCEEDED(rv)) + { + const char *vptr = valueStr.get(); + // max escaped length is one extra character for every character in the cmd. + nsAutoArrayPtr newValue(new char[2*strlen(vptr) + 1]); + if (newValue) + { + char *p = newValue; + while (1) + { + char ch = *vptr++; + if (!ch) + break; + if ((useQuotes ? ch == '"' : 0) || ch == '\\') + *p++ = '\\'; + *p++ = ch; + } + *p = '\0'; + value = nsCRT::strdup(newValue); // realloc down to smaller size + } + } else value = nsCRT::strdup(""); nsCRT::free(convertedValue); diff --git a/mozilla/mailnews/base/search/src/nsMsgSearchTerm.cpp b/mozilla/mailnews/base/search/src/nsMsgSearchTerm.cpp index 5a27907068e..31e129f70d2 100644 --- a/mozilla/mailnews/base/search/src/nsMsgSearchTerm.cpp +++ b/mozilla/mailnews/base/search/src/nsMsgSearchTerm.cpp @@ -938,7 +938,7 @@ nsresult nsMsgSearchTerm::MatchString (const char *stringToMatch, n_str = m_value.string; if (charset != nsnull) { - nsString out; + nsAutoString out; ConvertToUnicode(charset, stringToMatch ? stringToMatch : "", out); utf8 = ToNewUTF8String(out); } diff --git a/mozilla/mailnews/base/src/nsMessenger.cpp b/mozilla/mailnews/base/src/nsMessenger.cpp index 3c065ceb955..4d3ad8ba644 100644 --- a/mozilla/mailnews/base/src/nsMessenger.cpp +++ b/mozilla/mailnews/base/src/nsMessenger.cpp @@ -59,6 +59,7 @@ #include "MoreFilesX.h" #endif #endif +#include "nsNativeCharsetUtils.h" // necko #include "nsMimeTypes.h" @@ -228,8 +229,11 @@ nsresult ConvertAndSanitizeFileName(const char * displayName, PRUnichar ** unico // replace platform specific path separator and illegale characters to avoid any confusion ucs2Str.ReplaceChar(FILE_PATH_SEPARATOR FILE_ILLEGAL_CHARACTERS, '-'); - if (result) - rv = ConvertFromUnicode(nsMsgI18NFileSystemCharset(), ucs2Str, result); + if (result) { + nsCAutoString nativeStr; + rv = nsMsgI18NCopyUTF16ToNative(ucs2Str, nativeStr); + *result = ToNewCString(nativeStr); + } if (unicodeResult) *unicodeResult = ToNewUnicode(ucs2Str); @@ -491,11 +495,11 @@ nsMessenger::PromptIfFileExists(nsFileSpec &fileSpec) { nsCOMPtr dialog(do_GetInterface(mDocShell)); if (!dialog) return rv; - nsString path; + nsAutoString path; PRBool dialogResult = PR_FALSE; nsXPIDLString errorMessage; - nsMsgGetNativePathString(fileSpec.GetNativePathCString(),path); + nsMsgI18NCopyNativeToUTF16(fileSpec.GetNativePathCString(), path); const PRUnichar *pathFormatStrings[] = { path.get() }; if (!mStringBundle) @@ -802,7 +806,6 @@ nsMessenger::SaveAttachment(const char * contentType, const char * url, nsCOMPtr lastSaveDir; nsCOMPtr fileSpec; nsXPIDLCString filePath; - nsXPIDLString defaultDisplayString; unescapedUrl = PL_strdup(url); if (!unescapedUrl) @@ -810,6 +813,7 @@ nsMessenger::SaveAttachment(const char * contentType, const char * url, nsUnescape(unescapedUrl); + nsXPIDLString defaultDisplayString; rv = ConvertAndSanitizeFileName(displayName, getter_Copies(defaultDisplayString), nsnull); if (NS_FAILED(rv)) goto done; @@ -857,9 +861,9 @@ nsMessenger::SaveAllAttachments(PRUint32 count, nsCOMPtr lastSaveDir; nsCOMPtr fileSpec; nsXPIDLCString dirName; - char *unescapedUrl = nsnull, *unescapedName = nsnull; nsSaveAllAttachmentsState *saveState = nsnull; PRInt16 dialogResult; + char *unescapedUrl = nsnull; if (NS_FAILED(rv)) goto done; @@ -899,22 +903,21 @@ nsMessenger::SaveAllAttachments(PRUint32 count, unescapedUrl = PL_strdup(urlArray[0]); nsUnescape(unescapedUrl); - rv = ConvertAndSanitizeFileName(displayNameArray[0], nsnull, &unescapedName); + nsXPIDLCString unescapedName; + rv = ConvertAndSanitizeFileName(displayNameArray[0], nsnull, getter_Copies(unescapedName)); if (NS_FAILED(rv)) goto done; - aFileSpec += unescapedName; + aFileSpec += unescapedName.get(); rv = PromptIfFileExists(aFileSpec); if (NS_FAILED(rv)) return rv; fileSpec->SetFromFileSpec(aFileSpec); rv = SaveAttachment(fileSpec, unescapedUrl, messageUriArray[0], contentTypeArray[0], (void *)saveState); - if (NS_FAILED(rv)) goto done; } done: PR_FREEIF (unescapedUrl); - PR_FREEIF (unescapedName); return rv; } @@ -989,11 +992,12 @@ nsMessenger::SaveAs(const char *aURI, PRBool aAsFile, nsIMsgIdentity *aIdentity, filePicker->SetDisplayDirectory(lastSaveDir); } + nsCOMPtr localFile; + nsAutoString fileName; rv = filePicker->Show(&dialogResult); if (NS_FAILED(rv) || dialogResult == nsIFilePicker::returnCancel) goto done; - nsCOMPtr localFile; rv = filePicker->GetFile(getter_AddRefs(localFile)); if (NS_FAILED(rv)) goto done; @@ -1016,7 +1020,6 @@ nsMessenger::SaveAs(const char *aURI, PRBool aAsFile, nsIMsgIdentity *aIdentity, if (NS_FAILED(rv)) goto done; - nsAutoString fileName; rv = localFile->GetLeafName(fileName); NS_ENSURE_SUCCESS(rv, rv); @@ -1952,18 +1955,20 @@ nsSaveMsgListener::OnStopRequest(nsIRequest* request, nsISupports* aSupport, if (m_saveAllAttachmentsState->m_curIndex < m_saveAllAttachmentsState->m_count) { - char * unescapedUrl = nsnull, * unescapedName = nsnull; nsSaveAllAttachmentsState *state = m_saveAllAttachmentsState; PRUint32 i = state->m_curIndex; nsCOMPtr fileSpec; nsFileSpec aFileSpec ((const char *) state->m_directoryName); + char * unescapedUrl = nsnull; + nsXPIDLCString unescapedName; rv = NS_NewFileSpec(getter_AddRefs(fileSpec)); if (NS_FAILED(rv)) goto done; unescapedUrl = PL_strdup(state->m_urlArray[i]); nsUnescape(unescapedUrl); - rv = ConvertAndSanitizeFileName(state->m_displayNameArray[i], nsnull, &unescapedName); + rv = ConvertAndSanitizeFileName(state->m_displayNameArray[i], nsnull, + getter_Copies(unescapedName)); if (NS_FAILED(rv)) goto done; @@ -1983,7 +1988,6 @@ nsSaveMsgListener::OnStopRequest(nsIRequest* request, nsISupports* aSupport, m_saveAllAttachmentsState = nsnull; } PR_FREEIF(unescapedUrl); - PR_FREEIF(unescapedName); } else { diff --git a/mozilla/mailnews/base/src/nsSubscribableServer.cpp b/mozilla/mailnews/base/src/nsSubscribableServer.cpp index dc19006f8c8..333bcb59108 100644 --- a/mozilla/mailnews/base/src/nsSubscribableServer.cpp +++ b/mozilla/mailnews/base/src/nsSubscribableServer.cpp @@ -53,7 +53,7 @@ #include "nsIRDFLiteral.h" #include "nsIServiceManager.h" -#include "nsMsgUtf7Utils.h" +#include "nsMsgI18N.h" #include "nsMsgUtils.h" static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); @@ -739,13 +739,17 @@ nsSubscribableServer::GetLeafName(const char *path, PRUnichar **aLeafName) // for news, the path is escaped UTF8 // // when we switch to using the tree, this hack will go away. + nsAutoString leafName; if (mShowFullName) { - rv = NS_MsgDecodeUnescapeURLPath(path, aLeafName); + rv = NS_MsgDecodeUnescapeURLPath(nsDependentCString(path), leafName); } else { - rv = CreateUnicodeStringFromUtf7(node->name, aLeafName); + rv = CopyMUTF7toUTF16(nsDependentCString(node->name), leafName); + } + if (NS_SUCCEEDED(rv)) { + *aLeafName = ToNewUnicode(leafName); + NS_ENSURE_TRUE(*aLeafName, NS_ERROR_OUT_OF_MEMORY); } - NS_ENSURE_SUCCESS(rv,rv); return rv; } diff --git a/mozilla/mailnews/base/util/Makefile.in b/mozilla/mailnews/base/util/Makefile.in index 90443311e4c..94e5c063e81 100644 --- a/mozilla/mailnews/base/util/Makefile.in +++ b/mozilla/mailnews/base/util/Makefile.in @@ -89,7 +89,6 @@ CPPSRCS = \ nsMsgMailNewsUrl.cpp \ nsMsgTxn.cpp \ nsMsgI18N.cpp \ - nsMsgUtf7Utils.cpp \ nsAdapterEnumerator.cpp \ $(NULL) @@ -110,7 +109,6 @@ EXPORTS = \ nsMsgMailNewsUrl.h \ nsMsgTxn.h \ nsMsgI18N.h \ - nsMsgUtf7Utils.h \ nsAdapterEnumerator.h \ $(NULL) diff --git a/mozilla/mailnews/base/util/nsMsgDBFolder.cpp b/mozilla/mailnews/base/util/nsMsgDBFolder.cpp index 6fd8300da6b..e996ee8fee8 100644 --- a/mozilla/mailnews/base/util/nsMsgDBFolder.cpp +++ b/mozilla/mailnews/base/util/nsMsgDBFolder.cpp @@ -339,7 +339,7 @@ NS_IMETHODIMP nsMsgDBFolder::SetCharset(const char * aCharset) rv = GetDBFolderInfoAndDB(getter_AddRefs(folderInfo), getter_AddRefs(db)); if(NS_SUCCEEDED(rv)) { - rv = folderInfo->SetCharacterSet(NS_ConvertASCIItoUCS2(aCharset).get()); + rv = folderInfo->SetCharacterSet(NS_ConvertASCIItoUTF16(aCharset).get()); db->Commit(nsMsgDBCommitType::kLargeCommit); mCharset.AssignWithConversion(aCharset); // synchronize member variable } @@ -533,7 +533,7 @@ nsresult nsMsgDBFolder::ReadDBFolderInfo(PRBool force) //folderInfo->GetImapUnreadPendingMessages(&mNumPendingUnreadMessages); PRBool defaultUsed; - folderInfo->GetCharacterSet(&mCharset, &defaultUsed); + folderInfo->GetCharacterSet(mCharset, &defaultUsed); if (defaultUsed) mCharset.Truncate(); folderInfo->GetCharacterSetOverride(&mCharsetOverride); @@ -2188,7 +2188,7 @@ nsMsgDBFolder::GetSubFolders(nsIEnumerator* *result) } NS_IMETHODIMP -nsMsgDBFolder::FindSubFolder(const char *aEscapedSubFolderName, nsIMsgFolder **aFolder) +nsMsgDBFolder::FindSubFolder(const nsACString& aEscapedSubFolderName, nsIMsgFolder **aFolder) { nsresult rv = NS_OK; nsCOMPtr rdf(do_GetService(kRDFServiceCID, &rv)); @@ -2958,7 +2958,7 @@ NS_IMETHODIMP nsMsgDBFolder::CreateSubfolder(const PRUnichar *folderName, nsIMsg return NS_ERROR_NOT_IMPLEMENTED; } -nsresult nsMsgDBFolder::AddSubfolder(nsAutoString *folderName, +nsresult nsMsgDBFolder::AddSubfolder(const nsAString& folderName, nsIMsgFolder** newFolder) { return NS_ERROR_NOT_IMPLEMENTED; diff --git a/mozilla/mailnews/base/util/nsMsgI18N.cpp b/mozilla/mailnews/base/util/nsMsgI18N.cpp index e9f8346a6c9..f199a202794 100644 --- a/mozilla/mailnews/base/util/nsMsgI18N.cpp +++ b/mozilla/mailnews/base/util/nsMsgI18N.cpp @@ -62,7 +62,7 @@ #include "nsReadableUtils.h" #include "prmem.h" #include "nsFileSpec.h" -#include "nsUnicharUtils.h" +#include "plstr.h" static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID); static NS_DEFINE_CID(kEntityConverterCID, NS_ENTITYCONVERTER_CID); @@ -71,262 +71,128 @@ static NS_DEFINE_CID(kEntityConverterCID, NS_ENTITYCONVERTER_CID); // International functions necessary for composition // -nsresult nsMsgI18NConvertFromUnicode(const nsAFlatCString& aCharset, +nsresult nsMsgI18NConvertFromUnicode(const char* aCharset, const nsAFlatString& inString, - nsACString& outString) + nsACString& outString, + PRBool aIsCharsetCanonical) { if (inString.IsEmpty()) { - outString.Truncate(0); + outString.Truncate(); return NS_OK; } // Note: this will hide a possible error when the unicode text may contain more than one charset. // (e.g. Latin1 + Japanese). Use nsMsgI18NSaveAsCharset instead to avoid that problem. - else if (aCharset.IsEmpty() || - aCharset.Equals("us-ascii", nsCaseInsensitiveCStringComparator()) || - aCharset.Equals("ISO-8859-1", nsCaseInsensitiveCStringComparator())) { + else if (!*aCharset || !PL_strcasecmp(aCharset, "us-ascii") || + !PL_strcasecmp(aCharset, "ISO-8859-1")) { LossyCopyUTF16toASCII(inString, outString); return NS_OK; } - else if (aCharset.Equals("UTF-8", nsCaseInsensitiveCStringComparator())) { + else if (!PL_strcasecmp(aCharset, "UTF-8")) { CopyUTF16toUTF8(inString, outString); return NS_OK; } - nsresult res; - nsCOMPtr ccm = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &res); - if(NS_SUCCEEDED(res)) { - nsCOMPtr encoder; + nsresult rv; + nsCOMPtr ccm = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr encoder; - // get an unicode converter - res = ccm->GetUnicodeEncoder(aCharset.get(), getter_AddRefs(encoder)); - if(NS_SUCCEEDED(res)) { - res = encoder->SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace, nsnull, '?'); - if (NS_SUCCEEDED(res)) { + // get an unicode converter + if (aIsCharsetCanonical) // optimize for modified UTF-7 used by IMAP + rv = ccm->GetUnicodeEncoderRaw(aCharset, getter_AddRefs(encoder)); + else + rv = ccm->GetUnicodeEncoder(aCharset, getter_AddRefs(encoder)); + NS_ENSURE_SUCCESS(rv, rv); + rv = encoder->SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace, nsnull, '?'); + NS_ENSURE_SUCCESS(rv, rv); - const PRUnichar *originalSrcPtr = inString.get(); - const PRUnichar *currentSrcPtr = originalSrcPtr; - PRInt32 originalUnicharLength = inString.Length(); - PRInt32 srcLength; - PRInt32 dstLength; - char localbuf[512]; - PRInt32 consumedLen = 0; + const PRUnichar *originalSrcPtr = inString.get(); + const PRUnichar *currentSrcPtr = originalSrcPtr; + PRInt32 originalUnicharLength = inString.Length(); + PRInt32 srcLength; + PRInt32 dstLength; + char localbuf[512]; + PRInt32 consumedLen = 0; - outString.Truncate(); + outString.Truncate(); + // convert + while (consumedLen < originalUnicharLength) { + srcLength = originalUnicharLength - consumedLen; + dstLength = 512; + rv = encoder->Convert(currentSrcPtr, &srcLength, localbuf, &dstLength); + if (NS_FAILED(rv) || dstLength == 0) + break; + outString.Append(localbuf, dstLength); - // convert - while (consumedLen < originalUnicharLength) { - srcLength = originalUnicharLength - consumedLen; - dstLength = 512; - res = encoder->Convert(currentSrcPtr, &srcLength, localbuf, &dstLength); - if (NS_FAILED(res) || dstLength == 0) - break; - outString.Append(localbuf, dstLength); - - currentSrcPtr += srcLength; - consumedLen = currentSrcPtr - originalSrcPtr; // src length used so far - } - res = encoder->Finish(localbuf, &dstLength); - if (NS_SUCCEEDED(res)) - outString.Append(localbuf, dstLength); - } - } + currentSrcPtr += srcLength; + consumedLen = currentSrcPtr - originalSrcPtr; // src length used so far } - return res; + rv = encoder->Finish(localbuf, &dstLength); + if (NS_SUCCEEDED(rv)) + outString.Append(localbuf, dstLength); + return rv; } -nsresult nsMsgI18NConvertToUnicode(const nsAFlatCString& aCharset, +nsresult nsMsgI18NConvertToUnicode(const char* aCharset, const nsAFlatCString& inString, - nsAString& outString) + nsAString& outString, + PRBool aIsCharsetCanonical) { if (inString.IsEmpty()) { outString.Truncate(); return NS_OK; } - else if (aCharset.IsEmpty() || - aCharset.Equals("us-ascii", nsCaseInsensitiveCStringComparator()) || - aCharset.Equals("ISO-8859-1", nsCaseInsensitiveCStringComparator())) { + else if (!*aCharset || !PL_strcasecmp(aCharset, "us-ascii") || + !PL_strcasecmp(aCharset, "ISO-8859-1")) { // Despite its name, it also works for Latin-1. CopyASCIItoUTF16(inString, outString); return NS_OK; } - else if (aCharset.Equals("UTF-8", nsCaseInsensitiveCStringComparator())) { - CopyUTF8toUTF16(inString, outString); - return NS_OK; - } - - nsresult res; - nsCOMPtr ccm = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &res); - - if(NS_SUCCEEDED(res)) { - nsCOMPtr decoder; - - // get an unicode converter - res = ccm->GetUnicodeDecoder(aCharset.get(), getter_AddRefs(decoder)); - if(NS_SUCCEEDED(res)) { - - const char *originalSrcPtr = inString.get(); - const char *currentSrcPtr = originalSrcPtr; - PRInt32 originalLength = inString.Length(); - PRInt32 srcLength; - PRInt32 dstLength; - PRUnichar localbuf[512]; - PRInt32 consumedLen = 0; - - outString.Truncate(); - - // convert - while (consumedLen < originalLength) { - srcLength = originalLength - consumedLen; - dstLength = 512; - res = decoder->Convert(currentSrcPtr, &srcLength, localbuf, &dstLength); - if (NS_FAILED(res) || dstLength == 0) - break; - outString.Append(localbuf, dstLength); - - currentSrcPtr += srcLength; - consumedLen = currentSrcPtr - originalSrcPtr; // src length used so far - } - } - } - return res; -} - -// Convert an unicode string to a C string with a given charset. -nsresult ConvertFromUnicode(const char* aCharset, - const nsString& inString, - char** outCString) -{ - NS_ENSURE_ARG_POINTER(aCharset); - NS_ENSURE_ARG_POINTER(outCString); - - *outCString = NULL; - - if (inString.IsEmpty()) { - *outCString = nsCRT::strdup(""); - return (NULL == *outCString) ? NS_ERROR_OUT_OF_MEMORY : NS_OK; - } - // Note: this will hide a possible error when the unicode text may contain more than one charset. - // (e.g. Latin1 + Japanese). Use nsMsgI18NSaveAsCharset instead to avoid that problem. - else if (!*aCharset || - !nsCRT::strcasecmp("us-ascii", aCharset) || - !nsCRT::strcasecmp("ISO-8859-1", aCharset)) { - *outCString = ToNewCString(inString); - return *outCString ? NS_OK : NS_ERROR_OUT_OF_MEMORY; - } - else if (!nsCRT::strcasecmp("UTF-8", aCharset)) { - *outCString = ToNewUTF8String(inString); - return *outCString ? NS_OK : NS_ERROR_OUT_OF_MEMORY; - } - - nsresult res; - - nsCOMPtr ccm = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &res); - NS_ENSURE_SUCCESS(res, res); - - // get an unicode converter - nsCOMPtr encoder; - res = ccm->GetUnicodeEncoder(aCharset, getter_AddRefs(encoder)); - NS_ENSURE_SUCCESS(res, res); - - - PRUnichar *unichars = (PRUnichar *) inString.get(); - PRInt32 unicharLength = inString.Length(); - PRInt32 dstLength; - - res = encoder->GetMaxLength(unichars, unicharLength, &dstLength); - NS_ENSURE_SUCCESS(res, res); - - res = encoder->SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace, nsnull, '?'); - NS_ENSURE_SUCCESS(res, res); - - // allocale an output buffer - *outCString = (char *) PR_Malloc(dstLength + 1); - NS_ENSURE_TRUE(*outCString, NS_ERROR_OUT_OF_MEMORY); - - PRInt32 buffLength = dstLength; - **outCString = '\0'; - res = encoder->Convert(unichars, &unicharLength, *outCString, &dstLength); - if (NS_SUCCEEDED(res)) { - PRInt32 finLen = buffLength - dstLength; - res = encoder->Finish((char *)(*outCString+dstLength), &finLen); - if (NS_SUCCEEDED(res)) { - dstLength += finLen; + else if (!PL_strcasecmp(aCharset, "UTF-8")) { + if (IsUTF8(inString)) { + CopyUTF8toUTF16(inString, outString); + return NS_OK; } - (*outCString)[dstLength] = '\0'; + NS_WARNING("Invalid UTF-8 string"); + return NS_ERROR_UNEXPECTED; } - return res; -} + nsresult rv; + nsCOMPtr ccm = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); -// Convert a C string to an unicode string. -nsresult ConvertToUnicode(const char* aCharset, - const char* inCString, - nsString& outString) -{ - NS_ENSURE_ARG_POINTER(aCharset); - NS_ENSURE_ARG_POINTER(inCString); - - if ('\0' == *inCString) { - outString.Truncate(); - return NS_OK; - } - else if ((!*aCharset || - !nsCRT::strcasecmp("us-ascii", aCharset) || - !nsCRT::strcasecmp("ISO-8859-1", aCharset)) && - nsCRT::IsAscii(inCString)) { - outString.AssignWithConversion(inCString); - return NS_OK; - } - - nsresult res; - - nsCOMPtr ccm = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &res); - NS_ENSURE_SUCCESS(res, res); + nsCOMPtr decoder; // get an unicode converter - nsCOMPtr decoder; - res = ccm->GetUnicodeDecoder(aCharset, getter_AddRefs(decoder)); - NS_ENSURE_SUCCESS(res, res); + if (aIsCharsetCanonical) // optimize for modified UTF-7 used by IMAP + rv = ccm->GetUnicodeDecoderRaw(aCharset, getter_AddRefs(decoder)); + else + rv = ccm->GetUnicodeDecoder(aCharset, getter_AddRefs(decoder)); + NS_ENSURE_SUCCESS(rv, rv); - PRUnichar *unichars; - PRInt32 unicharLength; - PRInt32 srcLen = PL_strlen(inCString); + const char *originalSrcPtr = inString.get(); + const char *currentSrcPtr = originalSrcPtr; + PRInt32 originalLength = inString.Length(); + PRInt32 srcLength; + PRInt32 dstLength; + PRUnichar localbuf[512]; + PRInt32 consumedLen = 0; - // buffer size 144 = - // 72 (default line len for compose) - // times 2 (converted byte len might be larger) - const int klocalbufsize = 144; - PRUnichar localbuf[klocalbufsize+1]; - PRBool usedlocalbuf; + outString.Truncate(); - if (srcLen > klocalbufsize) { - res = decoder->GetMaxLength(inCString, srcLen, &unicharLength); - NS_ENSURE_SUCCESS(res, res); - unichars = (PRUnichar *) nsMemory::Alloc(unicharLength * sizeof(PRUnichar)); - NS_ENSURE_TRUE(unichars, NS_ERROR_OUT_OF_MEMORY); - usedlocalbuf = PR_FALSE; + // convert + while (consumedLen < originalLength) { + srcLength = originalLength - consumedLen; + dstLength = 512; + rv = decoder->Convert(currentSrcPtr, &srcLength, localbuf, &dstLength); + if (NS_FAILED(rv) || dstLength == 0) + break; + outString.Append(localbuf, dstLength); + + currentSrcPtr += srcLength; + consumedLen = currentSrcPtr - originalSrcPtr; // src length used so far } - else { - unichars = localbuf; - unicharLength = klocalbufsize+1; - usedlocalbuf = PR_TRUE; - } - - // convert to unicode - res = decoder->Convert(inCString, &srcLen, unichars, &unicharLength); - outString.Assign(unichars, unicharLength); - if (!usedlocalbuf) - nsMemory::Free(unichars); - - return res; -} - -// Charset to be used for the internatl processing. -const char *msgCompHeaderInternalCharset() -{ - // UTF-8 is a super set of us-ascii. - // We can use the same string manipulation methods as us-ascii without breaking non us-ascii characters. - return "UTF-8"; + return rv; } // Charset used by the file system. @@ -351,13 +217,15 @@ const char * nsMsgI18NFileSystemCharset() } // MIME encoder, output string should be freed by PR_FREE +// XXX : fix callers later to avoid allocation and copy char * nsMsgI18NEncodeMimePartIIStr(const char *header, PRBool structured, const char *charset, PRInt32 fieldnamelen, PRBool usemime) { // No MIME, convert to the outgoing mail charset. if (PR_FALSE == usemime) { - char *convertedStr; - if (NS_SUCCEEDED(ConvertFromUnicode(charset, NS_ConvertUTF8toUCS2(header), &convertedStr))) - return (convertedStr); + nsCAutoString convertedStr; + if (NS_SUCCEEDED(ConvertFromUnicode(charset, NS_ConvertUTF8toUTF16(header), + convertedStr))) + return PL_strdup(convertedStr.get()); else return PL_strdup(header); } @@ -547,7 +415,7 @@ nsresult nsMsgI18NSaveAsCharset(const char* contentType, const char *charset, if (nsCRT::IsAscii(inString)) { if (isAsciiOnly) *isAsciiOnly = PR_TRUE; - *outString = nsCRT::strdup(NS_LossyConvertUCS2toASCII(inString).get()); + *outString = nsCRT::strdup(NS_LossyConvertUTF16toASCII(inString).get()); return (nsnull != *outString) ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } if (isAsciiOnly) @@ -690,7 +558,7 @@ nsMsgI18NGetAcceptLanguage(void) if (!ucsval.IsEmpty()) { static nsCAutoString acceptLang; - acceptLang.Assign(NS_LossyConvertUCS2toASCII(ucsval)); + LossyCopyUTF16toASCII(ucsval, acceptLang); return acceptLang.get(); } } @@ -700,18 +568,3 @@ nsMsgI18NGetAcceptLanguage(void) return "en"; } - -// taken from nsFileSpec::GetNativePathString() -void -nsMsgGetNativePathString(const char *aPath, nsString& aResult) -{ - if (!aPath) { - aResult.Truncate(); - return; - } - if (nsCRT::IsAscii(aPath)) - aResult.AssignWithConversion(aPath); - else - ConvertToUnicode(nsMsgI18NFileSystemCharset(), aPath, aResult); -} - diff --git a/mozilla/mailnews/base/util/nsMsgI18N.h b/mozilla/mailnews/base/util/nsMsgI18N.h index 80064550e91..8c4d9856954 100644 --- a/mozilla/mailnews/base/util/nsMsgI18N.h +++ b/mozilla/mailnews/base/util/nsMsgI18N.h @@ -98,13 +98,6 @@ NS_MSG_BASE PRBool nsMsgI18Ncheck_data_in_charset_range(const char *charset, */ NS_MSG_BASE const char *nsMsgI18NGetAcceptLanguage(void); -/** - * Return charset name internally used in messsage compose. - * - * @return Charset name. - */ -NS_MSG_BASE const char *msgCompHeaderInternalCharset(void); - /** * Return charset name of file system (OS dependent). * @@ -120,10 +113,11 @@ NS_MSG_BASE const char * nsMsgI18NFileSystemCharset(void); * @param outString [OUT] Converted output string. * @return nsresult. */ -NS_MSG_BASE nsresult nsMsgI18NConvertFromUnicode(const nsAFlatCString& aCharset, - const nsAFlatString& inString, - nsACString& outString); - +NS_MSG_BASE nsresult nsMsgI18NConvertFromUnicode(const char* aCharset, + const nsAFlatString& inString, + nsACString& outString, + PRBool aIsCharsetCanonical = + PR_FALSE); /** * Convert from charset to unicode. * @@ -132,34 +126,11 @@ NS_MSG_BASE nsresult nsMsgI18NConvertFromUnicode(const nsAFlatCString& aCharset, * @param outString [OUT] Output unicode string. * @return nsresult. */ -NS_MSG_BASE nsresult nsMsgI18NConvertToUnicode(const nsAFlatCString& aCharset, - const nsAFlatCString& inString, - nsAString& outString); - -/** - * Convert from unicode to target charset. - * - * @param charset [IN] Charset name. - * @param inString [IN] Unicode string to convert. - * @param outCString [OUT] Output C string, need PR_FREE. - * @return nsresult. - */ -NS_MSG_BASE nsresult ConvertFromUnicode(const char* aCharset, - const nsString& inString, - char** outCString); - -/** - * Convert from charset to unicode. - * - * @param charset [IN] Charset name. - * @param inCString [IN] C string to convert. - * @param outString [OUT] Output unicode string. - * @return nsresult. - */ -NS_MSG_BASE nsresult ConvertToUnicode(const char* aCharset, - const char* inCString, - nsString& outString); - +NS_MSG_BASE nsresult nsMsgI18NConvertToUnicode(const char* aCharset, + const nsAFlatCString& inString, + nsAString& outString, + PRBool aIsCharsetCanonical = + PR_FALSE); /** * Parse for META charset. * @@ -210,11 +181,59 @@ NS_MSG_BASE nsresult nsMsgI18NSaveAsCharset(const char* contentType, const char* */ NS_MSG_BASE nsresult nsMsgI18NFormatNNTPXPATInNonRFC1522Format(const nsCString& aCharset, const nsString& inString, nsCString& outString); -/** - * convert a path in the native filesystem charset - */ -NS_MSG_BASE -void -nsMsgGetNativePathString(const char *aPath, nsString& aResult); +// inline forwarders to avoid littering with 'x-imap4-.....' +inline nsresult CopyUTF16toMUTF7(const nsAFlatString &aSrc, nsACString& aDest) +{ + return nsMsgI18NConvertFromUnicode("x-imap4-modified-utf7", aSrc, + aDest, PR_TRUE); +} + +inline nsresult CopyMUTF7toUTF16(const nsAFlatCString& aSrc, nsAString& aDest) +{ + return nsMsgI18NConvertToUnicode("x-imap4-modified-utf7", aSrc, + aDest, PR_TRUE); +} + +inline nsresult ConvertToUnicode(const char* charset, + const nsAFlatCString &aSrc, nsAString& aDest) +{ + return nsMsgI18NConvertToUnicode(charset, aSrc, aDest); +} + +inline nsresult ConvertToUnicode(const char* charset, + const char* aSrc, nsAString& aDest) +{ + return nsMsgI18NConvertToUnicode(charset, nsDependentCString(aSrc), aDest); +} + +inline nsresult ConvertFromUnicode(const char* charset, + const nsAFlatString &aSrc, nsACString& aDest) +{ + return nsMsgI18NConvertFromUnicode(charset, aSrc, aDest); +} + +// XXX to be replaced by NS_CopyNativeToUnicode +inline nsresult nsMsgI18NCopyNativeToUTF16(const nsAFlatCString &aSrc, + nsAString &aDest) +{ + return nsMsgI18NConvertToUnicode(nsMsgI18NFileSystemCharset(), aSrc, aDest); +} + +inline nsresult nsMsgI18NCopyNativeToUTF16(const char* aSrc, nsAString &aDest) +{ + return nsMsgI18NCopyNativeToUTF16(nsDependentCString(aSrc), aDest); +} + +// XXX to be replaced by NS_CopyUnicodeToNative +inline nsresult nsMsgI18NCopyUTF16ToNative(const nsAFlatString &aSrc, + nsACString &aDest) +{ + return nsMsgI18NConvertFromUnicode(nsMsgI18NFileSystemCharset(), aSrc, aDest); +} +inline nsresult nsMsgI18NCopyUTF16ToNative(const PRUnichar* aSrc, + nsACString &aDest) +{ + return nsMsgI18NCopyUTF16ToNative(nsDependentString(aSrc), aDest); +} #endif /* _nsMsgI18N_H_ */ diff --git a/mozilla/mailnews/base/util/nsMsgUtils.cpp b/mozilla/mailnews/base/util/nsMsgUtils.cpp index 1a70c3f2561..3253229cd15 100644 --- a/mozilla/mailnews/base/util/nsMsgUtils.cpp +++ b/mozilla/mailnews/base/util/nsMsgUtils.cpp @@ -295,16 +295,11 @@ nsresult NS_MsgCreatePathStringFromFolderURI(const char *folderURI, nsCString& p nsCAutoString oldPath; if (nsCRT::IsAscii(folderURI)) oldPath.Assign(folderURI); - else - { - char *nativeString = nsnull; - nsresult rv = ConvertFromUnicode(nsMsgI18NFileSystemCharset(), - nsAutoString(NS_ConvertUTF8toUCS2(folderURI)), &nativeString); - if (NS_SUCCEEDED(rv) && nativeString && nativeString[0]) - oldPath.Assign(nativeString); - else + else { + nsresult rv = nsMsgI18NCopyUTF16ToNative(NS_ConvertUTF8toUTF16(folderURI), + oldPath); + if (NS_FAILED(rv)) oldPath.Assign(folderURI); - PR_FREEIF(nativeString); } nsCAutoString pathPiece; @@ -500,28 +495,20 @@ char * NS_MsgSACat (char **destination, const char *source) return *destination; } -nsresult NS_MsgEscapeEncodeURLPath(const PRUnichar *str, char **result) +nsresult NS_MsgEscapeEncodeURLPath(const nsAString& str, nsACString& result) { - NS_ENSURE_ARG_POINTER(str); - NS_ENSURE_ARG_POINTER(result); - - *result = nsEscape(NS_ConvertUCS2toUTF8(str).get(), url_Path); - if (!*result) return NS_ERROR_OUT_OF_MEMORY; + NS_EscapeURL(NS_ConvertUTF16toUTF8(str), + esc_FileBaseName|esc_Forced|esc_AlwaysCopy, + result); return NS_OK; } -nsresult NS_MsgDecodeUnescapeURLPath(const char *path, PRUnichar **result) +nsresult NS_MsgDecodeUnescapeURLPath(const nsASingleFragmentCString& path, nsAString& result) { - NS_ENSURE_ARG_POINTER(path); - NS_ENSURE_ARG_POINTER(result); - - char *unescapedName = nsCRT::strdup(path); - if (!unescapedName) return NS_ERROR_OUT_OF_MEMORY; - nsUnescape(unescapedName); - nsAutoString resultStr; - resultStr = NS_ConvertUTF8toUCS2(unescapedName); - *result = ToNewUnicode(resultStr); - if (!*result) return NS_ERROR_OUT_OF_MEMORY; + nsCAutoString unescapedName; + NS_UnescapeURL(path, esc_FileBaseName|esc_Forced|esc_AlwaysCopy, + unescapedName); + CopyUTF8toUTF16(unescapedName, result); return NS_OK; } diff --git a/mozilla/mailnews/base/util/nsMsgUtils.h b/mozilla/mailnews/base/util/nsMsgUtils.h index 0e5bbcd7cab..8335fac5e49 100644 --- a/mozilla/mailnews/base/util/nsMsgUtils.h +++ b/mozilla/mailnews/base/util/nsMsgUtils.h @@ -72,9 +72,9 @@ NS_MSG_BASE char * NS_MsgSACopy(char **destination, const char *source); NS_MSG_BASE char * NS_MsgSACat(char **destination, const char *source); -NS_MSG_BASE nsresult NS_MsgEscapeEncodeURLPath(const PRUnichar *str, char **result); +NS_MSG_BASE nsresult NS_MsgEscapeEncodeURLPath(const nsAString& str, nsACString& result); -NS_MSG_BASE nsresult NS_MsgDecodeUnescapeURLPath(const char *path, PRUnichar **result); +NS_MSG_BASE nsresult NS_MsgDecodeUnescapeURLPath(const nsASingleFragmentCString& path, nsAString& result); NS_MSG_BASE PRBool WeAreOffline(); diff --git a/mozilla/mailnews/compose/public/nsIMsgCompFields.idl b/mozilla/mailnews/compose/public/nsIMsgCompFields.idl index fd0659997aa..c9ba1277268 100644 --- a/mozilla/mailnews/compose/public/nsIMsgCompFields.idl +++ b/mozilla/mailnews/compose/public/nsIMsgCompFields.idl @@ -44,21 +44,21 @@ [scriptable, uuid(3E89CAE3-BD2D-11d2-8293-000000000000)] interface nsIMsgCompFields : nsISupports { - attribute wstring from; - attribute wstring replyTo; - attribute wstring to; - attribute wstring cc; - attribute wstring bcc; + attribute AString from; + attribute AString replyTo; + attribute AString to; + attribute AString cc; + attribute AString bcc; - attribute wstring fcc; - attribute wstring fcc2; + attribute AString fcc; + attribute AString fcc2; attribute string newsgroups; attribute string newshost; attribute string newspostUrl; attribute string followupTo; - attribute wstring subject; + attribute AString subject; /** * attachments @@ -67,14 +67,14 @@ interface nsIMsgCompFields : nsISupports { */ attribute string attachments; - attribute wstring organization; + attribute AString organization; attribute string references; attribute string priority; attribute string messageId; attribute string characterSet; readonly attribute string defaultCharacterSet; - attribute wstring templateName; + attribute AString templateName; attribute string draftId; attribute boolean returnReceipt; @@ -85,9 +85,9 @@ interface nsIMsgCompFields : nsISupports { attribute boolean uuEncodeAttachments; attribute boolean bodyIsAsciiOnly; - attribute wstring otherRandomHeaders; + attribute AString otherRandomHeaders; - attribute wstring body; + attribute AString body; /** * temporaryFiles diff --git a/mozilla/mailnews/compose/public/nsIMsgComposeService.idl b/mozilla/mailnews/compose/public/nsIMsgComposeService.idl index db28b3f7d54..1fae2296cf3 100644 --- a/mozilla/mailnews/compose/public/nsIMsgComposeService.idl +++ b/mozilla/mailnews/compose/public/nsIMsgComposeService.idl @@ -60,25 +60,6 @@ interface nsIMsgComposeService : nsISupports { the compose window */ void OpenComposeWindowWithURI(in string msgComposeWindowURL, in nsIURI aURI); - /** - * OpenComposeWindowWithValues - * - * @NOT SUPPORTED ANYMORE, USE OpenComposeWindowWithParams INSTEAD. - * @THIS API WILL BE REMOVED - */ - void OpenComposeWindowWithValues(in string msgComposeWindowURL, in MSG_ComposeType type, in MSG_ComposeFormat format, - in wstring to, in wstring cc, in wstring bcc, in string newsgroups, - in wstring subject, in wstring body, in string attachment, in nsIMsgIdentity identity); - - /** - * OpenComposeWindowWithCompFields - * - * @NOT SUPPORTED ANYMORE, USE OpenComposeWindowWithParams INSTEAD. - * @THIS API WILL BE REMOVED - */ - void OpenComposeWindowWithCompFields(in string msgComposeWindowURL, in MSG_ComposeType type, in MSG_ComposeFormat format, - in nsIMsgCompFields compFields, in nsIMsgIdentity identity); - /* ... */ void OpenComposeWindowWithParams(in string msgComposeWindowURL, in nsIMsgComposeParams params); diff --git a/mozilla/mailnews/compose/src/nsMsgAttachmentHandler.cpp b/mozilla/mailnews/compose/src/nsMsgAttachmentHandler.cpp index 04fb84574a6..1259f99e23f 100644 --- a/mozilla/mailnews/compose/src/nsMsgAttachmentHandler.cpp +++ b/mozilla/mailnews/compose/src/nsMsgAttachmentHandler.cpp @@ -65,6 +65,7 @@ #include "nsIMimeStreamConverter.h" #include "nsMsgMimeCID.h" #include "nsNetUtil.h" +#include "nsNativeCharsetUtils.h" /////////////////////////////////////////////////////////////////////////// @@ -519,7 +520,8 @@ nsMsgAttachmentHandler::SnarfMsgAttachment(nsMsgCompFields *compFields) { nsAutoString error_msg; nsAutoString path; - nsMsgGetNativePathString(mFileSpec->GetNativePathCString(),path); + NS_CopyNativeToUnicode( + nsDependentCString(mFileSpec->GetNativePathCString()), path); nsMsgBuildErrorMessageByID(NS_MSG_UNABLE_TO_OPEN_TMP_FILE, error_msg, &path, nsnull); sendReport->SetMessage(nsIMsgSendReport::process_Current, error_msg.get(), PR_FALSE); } @@ -655,7 +657,8 @@ nsMsgAttachmentHandler::SnarfAttachment(nsMsgCompFields *compFields) { nsAutoString error_msg; nsAutoString path; - nsMsgGetNativePathString(mFileSpec->GetNativePathCString(),path); + NS_CopyNativeToUnicode( + nsDependentCString(mFileSpec->GetNativePathCString()), path); nsMsgBuildErrorMessageByID(NS_MSG_UNABLE_TO_OPEN_TMP_FILE, error_msg, &path, nsnull); sendReport->SetMessage(nsIMsgSendReport::process_Current, error_msg.get(), PR_FALSE); } @@ -969,11 +972,11 @@ nsMsgAttachmentHandler::LoadDataFromFile(nsFileSpec& fSpec, nsString &sigData, P if (charsetConversion) { - if (NS_FAILED(ConvertToUnicode(m_charset, readBuf, sigData))) - sigData.AssignWithConversion(readBuf); + if (NS_FAILED(ConvertToUnicode(m_charset, nsDependentCString(readBuf), sigData))) + CopyASCIItoUTF16(readBuf, sigData); } else - sigData.AssignWithConversion(readBuf); + CopyASCIItoUTF16(readBuf, sigData); PR_FREEIF(readBuf); return NS_OK; @@ -1126,7 +1129,7 @@ nsMsgAttachmentHandler::UrlExit(nsresult status, const PRUnichar* aMsg) // Now use the converter service here to do the right // thing and convert this data to plain text for us! // - nsString conData; + nsAutoString conData; if (NS_SUCCEEDED(LoadDataFromFile(*mFileSpec, conData, PR_TRUE))) { @@ -1138,13 +1141,12 @@ nsMsgAttachmentHandler::UrlExit(nsresult status, const PRUnichar* aMsg) nsOutputFileStream tempfile(*mFileSpec, PR_WRONLY | PR_CREATE_FILE, 00600); if (tempfile.is_open()) { - char *tData = nsnull; - if (NS_FAILED(ConvertFromUnicode(m_charset, conData, &tData))) - tData = ToNewCString(conData); - if (tData) + nsCAutoString tData; + if (NS_FAILED(ConvertFromUnicode(m_charset, conData, tData))) + LossyCopyUTF16toASCII(conData, tData); + if (!tData.IsEmpty()) { - (void) tempfile.write(tData, strlen(tData)); - PR_FREEIF(tData); + (void) tempfile.write(tData.get(), tData.Length()); } tempfile.close(); } diff --git a/mozilla/mailnews/compose/src/nsMsgCompFields.cpp b/mozilla/mailnews/compose/src/nsMsgCompFields.cpp index 5de00d0de05..9bb06e7594e 100644 --- a/mozilla/mailnews/compose/src/nsMsgCompFields.cpp +++ b/mozilla/mailnews/compose/src/nsMsgCompFields.cpp @@ -58,7 +58,7 @@ nsMsgCompFields::nsMsgCompFields() for (i = 0; i < MSG_MAX_HEADERS; i ++) m_headers[i] = nsnull; - m_body = nsnull; + m_body.Truncate(); NS_NewISupportsArray(getter_AddRefs(m_attachments)); @@ -82,7 +82,6 @@ nsMsgCompFields::nsMsgCompFields() m_DefaultCharacterSet.AssignWithConversion(charset); SetCharacterSet(m_DefaultCharacterSet.get()); } - m_internalCharSet.Assign(msgCompHeaderInternalCharset()); } nsMsgCompFields::~nsMsgCompFields() @@ -90,8 +89,6 @@ nsMsgCompFields::~nsMsgCompFields() PRInt16 i; for (i = 0; i < MSG_MAX_HEADERS; i ++) PR_FREEIF(m_headers[i]); - - PR_FREEIF(m_body); } nsresult nsMsgCompFields::SetAsciiHeader(MsgHeaderID header, const char *value) @@ -130,91 +127,84 @@ const char* nsMsgCompFields::GetAsciiHeader(MsgHeaderID header) return m_headers[header] ? m_headers[header] : ""; } -nsresult nsMsgCompFields::SetUnicodeHeader(MsgHeaderID header, const PRUnichar *value) +nsresult nsMsgCompFields::SetUnicodeHeader(MsgHeaderID header, const nsAString& value) { - char* cString; - ConvertFromUnicode(m_internalCharSet.get(), nsAutoString(value), &cString); - nsresult rv = SetAsciiHeader(header, cString); - PR_Free(cString); - - return rv; + return SetAsciiHeader(header, NS_ConvertUTF16toUTF8(value).get()); } -nsresult nsMsgCompFields::GetUnicodeHeader(MsgHeaderID header, PRUnichar **_retval) +nsresult nsMsgCompFields::GetUnicodeHeader(MsgHeaderID header, nsAString& aResult) { - nsString unicodeStr; - ConvertToUnicode(m_internalCharSet.get(), GetAsciiHeader(header), unicodeStr); - *_retval = ToNewUnicode(unicodeStr); + CopyUTF8toUTF16(GetAsciiHeader(header), aResult); return NS_OK; } -NS_IMETHODIMP nsMsgCompFields::SetFrom(const PRUnichar *value) +NS_IMETHODIMP nsMsgCompFields::SetFrom(const nsAString &value) { return SetUnicodeHeader(MSG_FROM_HEADER_ID, value); } -NS_IMETHODIMP nsMsgCompFields::GetFrom(PRUnichar **_retval) +NS_IMETHODIMP nsMsgCompFields::GetFrom(nsAString &_retval) { return GetUnicodeHeader(MSG_FROM_HEADER_ID, _retval); } -NS_IMETHODIMP nsMsgCompFields::SetReplyTo(const PRUnichar *value) +NS_IMETHODIMP nsMsgCompFields::SetReplyTo(const nsAString &value) { return SetUnicodeHeader(MSG_REPLY_TO_HEADER_ID, value); } -NS_IMETHODIMP nsMsgCompFields::GetReplyTo(PRUnichar **_retval) +NS_IMETHODIMP nsMsgCompFields::GetReplyTo(nsAString &_retval) { return GetUnicodeHeader(MSG_REPLY_TO_HEADER_ID, _retval); } -NS_IMETHODIMP nsMsgCompFields::SetTo(const PRUnichar *value) +NS_IMETHODIMP nsMsgCompFields::SetTo(const nsAString &value) { return SetUnicodeHeader(MSG_TO_HEADER_ID, value); } -NS_IMETHODIMP nsMsgCompFields::GetTo(PRUnichar **_retval) +NS_IMETHODIMP nsMsgCompFields::GetTo(nsAString &_retval) { return GetUnicodeHeader(MSG_TO_HEADER_ID, _retval); } -NS_IMETHODIMP nsMsgCompFields::SetCc(const PRUnichar *value) +NS_IMETHODIMP nsMsgCompFields::SetCc(const nsAString &value) { return SetUnicodeHeader(MSG_CC_HEADER_ID, value); } -NS_IMETHODIMP nsMsgCompFields::GetCc(PRUnichar **_retval) +NS_IMETHODIMP nsMsgCompFields::GetCc(nsAString &_retval) { return GetUnicodeHeader(MSG_CC_HEADER_ID, _retval); } -NS_IMETHODIMP nsMsgCompFields::SetBcc(const PRUnichar *value) +NS_IMETHODIMP nsMsgCompFields::SetBcc(const nsAString &value) { return SetUnicodeHeader(MSG_BCC_HEADER_ID, value); } -NS_IMETHODIMP nsMsgCompFields::GetBcc(PRUnichar **_retval) +NS_IMETHODIMP nsMsgCompFields::GetBcc(nsAString &_retval) { return GetUnicodeHeader(MSG_BCC_HEADER_ID, _retval); } -NS_IMETHODIMP nsMsgCompFields::SetFcc(const PRUnichar *value) +NS_IMETHODIMP nsMsgCompFields::SetFcc(const nsAString &value) { return SetUnicodeHeader(MSG_FCC_HEADER_ID, value); } -NS_IMETHODIMP nsMsgCompFields::GetFcc(PRUnichar **_retval) +NS_IMETHODIMP nsMsgCompFields::GetFcc(nsAString &_retval) { return GetUnicodeHeader(MSG_FCC_HEADER_ID, _retval); } -NS_IMETHODIMP nsMsgCompFields::SetFcc2(const PRUnichar *value) +NS_IMETHODIMP nsMsgCompFields::SetFcc2(const nsAString &value) { return SetUnicodeHeader(MSG_FCC2_HEADER_ID, value); } -NS_IMETHODIMP nsMsgCompFields::GetFcc2(PRUnichar **_retval) +NS_IMETHODIMP nsMsgCompFields::GetFcc2(nsAString &_retval) { return GetUnicodeHeader(MSG_FCC2_HEADER_ID, _retval); } @@ -252,12 +242,12 @@ NS_IMETHODIMP nsMsgCompFields::GetFollowupTo(char **_retval) return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } -NS_IMETHODIMP nsMsgCompFields::SetSubject(const PRUnichar *value) +NS_IMETHODIMP nsMsgCompFields::SetSubject(const nsAString &value) { return SetUnicodeHeader(MSG_SUBJECT_HEADER_ID, value); } -NS_IMETHODIMP nsMsgCompFields::GetSubject(PRUnichar **_retval) +NS_IMETHODIMP nsMsgCompFields::GetSubject(nsAString &_retval) { return GetUnicodeHeader(MSG_SUBJECT_HEADER_ID, _retval); } @@ -287,12 +277,12 @@ NS_IMETHODIMP nsMsgCompFields::GetTemporaryFiles(char **_retval) return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } -NS_IMETHODIMP nsMsgCompFields::SetOrganization(const PRUnichar *value) +NS_IMETHODIMP nsMsgCompFields::SetOrganization(const nsAString &value) { return SetUnicodeHeader(MSG_ORGANIZATION_HEADER_ID, value); } -NS_IMETHODIMP nsMsgCompFields::GetOrganization(PRUnichar **_retval) +NS_IMETHODIMP nsMsgCompFields::GetOrganization(nsAString &_retval) { return GetUnicodeHeader(MSG_ORGANIZATION_HEADER_ID, _retval); } @@ -308,12 +298,12 @@ NS_IMETHODIMP nsMsgCompFields::GetReferences(char **_retval) return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } -NS_IMETHODIMP nsMsgCompFields::SetOtherRandomHeaders(const PRUnichar *value) +NS_IMETHODIMP nsMsgCompFields::SetOtherRandomHeaders(const nsAString &value) { return SetUnicodeHeader(MSG_OTHERRANDOMHEADERS_HEADER_ID, value); } -NS_IMETHODIMP nsMsgCompFields::GetOtherRandomHeaders(PRUnichar **_retval) +NS_IMETHODIMP nsMsgCompFields::GetOtherRandomHeaders(nsAString &_retval) { return GetUnicodeHeader(MSG_OTHERRANDOMHEADERS_HEADER_ID, _retval); } @@ -362,12 +352,12 @@ NS_IMETHODIMP nsMsgCompFields::GetMessageId(char **_retval) return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } -NS_IMETHODIMP nsMsgCompFields::SetTemplateName(const PRUnichar *value) +NS_IMETHODIMP nsMsgCompFields::SetTemplateName(const nsAString &value) { return SetUnicodeHeader(MSG_X_TEMPLATE_HEADER_ID, value); } -NS_IMETHODIMP nsMsgCompFields::GetTemplateName(PRUnichar **_retval) +NS_IMETHODIMP nsMsgCompFields::GetTemplateName(nsAString &_retval) { return GetUnicodeHeader(MSG_X_TEMPLATE_HEADER_ID, _retval); } @@ -469,45 +459,30 @@ NS_IMETHODIMP nsMsgCompFields::GetBodyIsAsciiOnly(PRBool *_retval) return NS_OK; } -NS_IMETHODIMP nsMsgCompFields::SetBody(const PRUnichar *value) +NS_IMETHODIMP nsMsgCompFields::SetBody(const nsAString &value) { - PR_FREEIF(m_body); - if (value) - { - char* cString; - ConvertFromUnicode(m_internalCharSet.get(), nsAutoString(value), &cString); - m_body = cString; - if (!m_body) - return NS_ERROR_OUT_OF_MEMORY; - } + CopyUTF16toUTF8(value, m_body); return NS_OK; } -NS_IMETHODIMP nsMsgCompFields::GetBody(PRUnichar **_retval) +NS_IMETHODIMP nsMsgCompFields::GetBody(nsAString &_retval) { - nsString unicodeStr; - const char* cString = GetBody(); - ConvertToUnicode(m_internalCharSet.get(), cString, unicodeStr); - *_retval = ToNewUnicode(unicodeStr); - + CopyUTF8toUTF16(m_body, _retval); return NS_OK; } nsresult nsMsgCompFields::SetBody(const char *value) { - PR_FREEIF(m_body); if (value) - { - m_body = nsCRT::strdup(value); - if (!m_body) - return NS_ERROR_OUT_OF_MEMORY; - } + m_body = value; + else + m_body.Truncate(); return NS_OK; } const char* nsMsgCompFields::GetBody() { - return m_body ? m_body : ""; + return m_body.get(); } /* readonly attribute nsISupportsArray attachmentsArray; */ @@ -604,46 +579,41 @@ NS_IMETHODIMP nsMsgCompFields::SplitRecipients(const PRUnichar *recipients, PRBo nsCOMPtr parser = do_GetService(NS_MAILNEWS_MIME_HEADER_PARSER_CONTRACTID); if (parser) { - char * recipientsStr; + nsCAutoString recipientsStr; char * names; char * addresses; PRUint32 numAddresses; - if (NS_FAILED(ConvertFromUnicode(msgCompHeaderInternalCharset(), nsAutoString(recipients), &recipientsStr))) - { - recipientsStr = ToNewCString(nsDependentString(recipients)); - } + CopyUTF16toUTF8(recipients, recipientsStr); - if (! recipientsStr) - return NS_ERROR_OUT_OF_MEMORY; - - rv= parser->ParseHeaderAddresses(msgCompHeaderInternalCharset(), recipientsStr, &names, &addresses, &numAddresses); + rv= parser->ParseHeaderAddresses("UTF-8", recipientsStr.get(), &names, + &addresses, &numAddresses); if (NS_SUCCEEDED(rv)) { PRUint32 i=0; char * pNames = names; char * pAddresses = addresses; - char * fullAddress; - nsString aRecipient; PRBool aBool; - for (i = 0; i < numAddresses; i ++) - { - if (!emailAddressOnly) - rv = parser->MakeFullAddress(msgCompHeaderInternalCharset(), pNames, pAddresses, &fullAddress); - if (NS_SUCCEEDED(rv) && !emailAddressOnly) - { - rv = ConvertToUnicode(msgCompHeaderInternalCharset(), fullAddress, aRecipient); - PR_FREEIF(fullAddress); - } - else - rv = ConvertToUnicode(msgCompHeaderInternalCharset(), pAddresses, aRecipient); - if (NS_FAILED(rv)) - break; + for (i = 0; i < numAddresses; i ++) + { + nsXPIDLCString fullAddress; + nsAutoString recipient; + if (!emailAddressOnly) + rv = parser->MakeFullAddress("UTF-8", pNames, + pAddresses, getter_Copies(fullAddress)); + if (NS_SUCCEEDED(rv) && !emailAddressOnly) + { + rv = ConvertToUnicode("UTF-8", fullAddress, recipient); + } + else + rv = ConvertToUnicode("UTF-8", nsDependentCString(pAddresses), recipient); + if (NS_FAILED(rv)) + break; - rv = pAddrArray->AppendString(aRecipient.get(), &aBool); - if (NS_FAILED(rv)) - break; + rv = pAddrArray->AppendString(recipient.get(), &aBool); + if (NS_FAILED(rv)) + break; pNames += PL_strlen(pNames) + 1; pAddresses += PL_strlen(pAddresses) + 1; @@ -652,8 +622,6 @@ NS_IMETHODIMP nsMsgCompFields::SplitRecipients(const PRUnichar *recipients, PRBo PR_FREEIF(names); PR_FREEIF(addresses); } - - PR_Free(recipientsStr); } else rv = NS_ERROR_FAILURE; @@ -699,55 +667,49 @@ nsresult nsMsgCompFields::SplitRecipientsEx(const PRUnichar *recipients, nsIMsgR nsCOMPtr parser = do_GetService(NS_MAILNEWS_MIME_HEADER_PARSER_CONTRACTID); if (parser) { - char * recipientsStr; + nsCAutoString recipientsStr; char * names; - char * addresses; + char *addresses; PRUint32 numAddresses; - if (NS_FAILED(ConvertFromUnicode(msgCompHeaderInternalCharset(), nsAutoString(recipients), &recipientsStr))) - { - recipientsStr = ToNewCString(nsDependentString(recipients)); - } - - if (! recipientsStr) - return NS_ERROR_OUT_OF_MEMORY; - - rv= parser->ParseHeaderAddresses(msgCompHeaderInternalCharset(), recipientsStr, &names, &addresses, &numAddresses); + CopyUTF16toUTF8(recipients, recipientsStr); + rv= parser->ParseHeaderAddresses("UTF-8", recipientsStr.get(), &names, + &addresses, &numAddresses); if (NS_SUCCEEDED(rv)) { PRUint32 i=0; char * pNames = names; char * pAddresses = addresses; - char * fullAddress; - nsString aRecipient; + nsAutoString recipient; PRBool aBool; for (i = 0; i < numAddresses; i ++) { + nsXPIDLCString fullAddress; if (pAddrsArray) { - rv = parser->MakeFullAddress(msgCompHeaderInternalCharset(), pNames, pAddresses, &fullAddress); + rv = parser->MakeFullAddress("UTF-8", pNames, pAddresses, + getter_Copies(fullAddress)); if (NS_SUCCEEDED(rv)) { - rv = ConvertToUnicode(msgCompHeaderInternalCharset(), fullAddress, aRecipient); - PR_FREEIF(fullAddress); + rv = ConvertToUnicode("UTF-8", fullAddress, recipient); } else - rv = ConvertToUnicode(msgCompHeaderInternalCharset(), pAddresses, aRecipient); + rv = ConvertToUnicode("UTF-8", pAddresses, recipient); if (NS_FAILED(rv)) return rv; - rv = pAddrsArray->AppendString(aRecipient.get(), &aBool); + rv = pAddrsArray->AppendString(recipient.get(), &aBool); if (NS_FAILED(rv)) return rv; } if (pEmailsArray) { - rv = ConvertToUnicode(msgCompHeaderInternalCharset(), pAddresses, aRecipient); + rv = ConvertToUnicode("UTF-8", pAddresses, recipient); if (NS_FAILED(rv)) return rv; - rv = pEmailsArray->AppendString(aRecipient.get(), &aBool); + rv = pEmailsArray->AppendString(recipient.get(), &aBool); if (NS_FAILED(rv)) return rv; } @@ -756,11 +718,9 @@ nsresult nsMsgCompFields::SplitRecipientsEx(const PRUnichar *recipients, nsIMsgR pAddresses += PL_strlen(pAddresses) + 1; } - PR_FREEIF(names); - PR_FREEIF(addresses); + PR_FREEIF(names); + PR_FREEIF(addresses); } - - PR_Free(recipientsStr); } else rv = NS_ERROR_FAILURE; @@ -773,17 +733,15 @@ NS_IMETHODIMP nsMsgCompFields::ConvertBodyToPlainText() { nsresult rv = NS_OK; - if (m_body && *m_body != 0) + if (!m_body.IsEmpty()) { - PRUnichar * ubody; - rv = GetBody(&ubody); + nsAutoString body; + rv = GetBody(body); if (NS_SUCCEEDED(rv)) { - nsString body(ubody); - PR_Free(ubody); rv = ConvertBufToPlainText(body, UseFormatFlowed(GetCharacterSet())); if (NS_SUCCEEDED(rv)) - rv = SetBody(body.get()); + rv = SetBody(body); } } return rv; diff --git a/mozilla/mailnews/compose/src/nsMsgCompFields.h b/mozilla/mailnews/compose/src/nsMsgCompFields.h index 27471d7b178..d372ffc7248 100644 --- a/mozilla/mailnews/compose/src/nsMsgCompFields.h +++ b/mozilla/mailnews/compose/src/nsMsgCompFields.h @@ -85,8 +85,8 @@ public: nsresult SetAsciiHeader(MsgHeaderID header, const char *value); const char* GetAsciiHeader(MsgHeaderID header); //just return the address of the internal header variable, don't dispose it - nsresult SetUnicodeHeader(MsgHeaderID header, const PRUnichar *value); - nsresult GetUnicodeHeader(MsgHeaderID header, PRUnichar **_retval); //Will return a copy of the header, must be free using PR_Free() + nsresult SetUnicodeHeader(MsgHeaderID header, const nsAString &value); + nsresult GetUnicodeHeader(MsgHeaderID header, nsAString &_retval); /* Convenience routines to get and set header's value... @@ -169,7 +169,7 @@ public: protected: char* m_headers[MSG_MAX_HEADERS]; - char* m_body; + nsCString m_body; nsCOMPtr m_attachments; PRBool m_attachVCard; PRBool m_forcePlainText; @@ -178,7 +178,6 @@ protected: PRBool m_returnReceipt; PRBool m_bodyIsAsciiOnly; PRInt32 m_receiptHeaderType; /* receipt header type */ - nsCString m_internalCharSet; nsCString m_DefaultCharacterSet; nsCOMPtr mSecureCompFields; diff --git a/mozilla/mailnews/compose/src/nsMsgCompUtils.cpp b/mozilla/mailnews/compose/src/nsMsgCompUtils.cpp index 3e8dea03e86..43cdba2b810 100644 --- a/mozilla/mailnews/compose/src/nsMsgCompUtils.cpp +++ b/mozilla/mailnews/compose/src/nsMsgCompUtils.cpp @@ -1673,9 +1673,9 @@ msg_pick_real_name (nsMsgAttachmentHandler *attachment, const PRUnichar *propose { /* Convert to unicode */ nsAutoString uStr; - rv = ConvertToUnicode(nsMsgI18NFileSystemCharset(), attachment->m_real_name, uStr); + rv = nsMsgI18NCopyNativeToUTF16(attachment->m_real_name, uStr); if (NS_FAILED(rv)) - uStr.AssignWithConversion(attachment->m_real_name); + CopyASCIItoUTF16(attachment->m_real_name, uStr); } diff --git a/mozilla/mailnews/compose/src/nsMsgCompose.cpp b/mozilla/mailnews/compose/src/nsMsgCompose.cpp index f3da827838e..fe53bd12aa4 100644 --- a/mozilla/mailnews/compose/src/nsMsgCompose.cpp +++ b/mozilla/mailnews/compose/src/nsMsgCompose.cpp @@ -1037,8 +1037,8 @@ NS_IMETHODIMP nsMsgCompose::SendMsg(MSG_DeliverMode deliverMode, nsIMsgIdentity if (progress) { mProgress = progress; - nsXPIDLString msgSubject; - m_compFields->GetSubject(getter_Copies(msgSubject)); + nsAutoString msgSubject; + m_compFields->GetSubject(msgSubject); PRBool showProgress = PR_FALSE; nsCOMPtr prefs (do_GetService(NS_PREF_CONTRACTID)); @@ -1051,7 +1051,7 @@ NS_IMETHODIMP nsMsgCompose::SendMsg(MSG_DeliverMode deliverMode, nsIMsgIdentity if (NS_FAILED(rv) || !params) return NS_ERROR_FAILURE; - params->SetSubject((const PRUnichar*) msgSubject); + params->SetSubject(msgSubject.get()); params->SetDeliveryMode(deliverMode); mProgress->OpenProgressDialog(m_window, aMsgWindow, "chrome://messenger/content/messengercompose/sendProgress.xul", params); @@ -1525,10 +1525,6 @@ nsresult nsMsgCompose::CreateMessage(const char * originalMsgURI, charsetOverride = PR_TRUE; } -#ifdef DEBUG_jungshik - printf ("charset=%s\n", charset.get()); -#endif - PRBool isFirstPass = PR_TRUE; char *uri = uriList; char *nextUri; @@ -1586,7 +1582,6 @@ nsresult nsMsgCompose::CreateMessage(const char * originalMsgURI, nsCaseInsensitiveCStringComparator())) charset = "EUC-KR"; - // get an original charset, used for a label, UTF-8 is used for the internal processing if (isFirstPass && !charset.IsEmpty()) m_compFields->SetCharacterSet(charset); @@ -1666,7 +1661,7 @@ nsresult nsMsgCompose::CreateMessage(const char * originalMsgURI, mQuotingToFollow = PR_TRUE; subject.Insert(NS_LITERAL_STRING("Re: "), 0); - m_compFields->SetSubject(subject.get()); + m_compFields->SetSubject(subject); nsXPIDLCString author; rv = msgHdr->GetAuthor(getter_Copies(author)); @@ -1709,7 +1704,7 @@ nsresult nsMsgCompose::CreateMessage(const char * originalMsgURI, { subject.Insert(NS_LITERAL_STRING("[Fwd: ").get(), 0); subject.Append(NS_LITERAL_STRING("]").get()); - m_compFields->SetSubject(subject.get()); + m_compFields->SetSubject(subject); } break; } @@ -2032,7 +2027,7 @@ NS_IMETHODIMP QuotingOutputStreamListener::OnStopRequest(nsIRequest *request, ns compose->GetCompFields(getter_AddRefs(compFields)); if (compFields) { - aCharset.AssignWithConversion(msgCompHeaderInternalCharset()); + aCharset = NS_LITERAL_STRING("UTF-8"); nsAutoString recipient; nsAutoString cc; nsAutoString replyTo; @@ -2041,7 +2036,6 @@ NS_IMETHODIMP QuotingOutputStreamListener::OnStopRequest(nsIRequest *request, ns nsAutoString messageId; nsAutoString references; nsXPIDLCString outCString; - PRUnichar emptyUnichar = 0; PRBool needToRemoveDup = PR_FALSE; if (!mMimeConverter) { @@ -2068,7 +2062,7 @@ NS_IMETHODIMP QuotingOutputStreamListener::OnStopRequest(nsIRequest *request, ns if (recipient.Length() > 0 && cc.Length() > 0) recipient.Append(NS_LITERAL_STRING(", ")); recipient += cc; - compFields->SetCc(recipient.get()); + compFields->SetCc(recipient); needToRemoveDup = PR_TRUE; } @@ -2105,7 +2099,7 @@ NS_IMETHODIMP QuotingOutputStreamListener::OnStopRequest(nsIRequest *request, ns if (! replyTo.IsEmpty()) { - compFields->SetTo(replyTo.get()); + compFields->SetTo(replyTo); needToRemoveDup = PR_TRUE; } @@ -2114,7 +2108,7 @@ NS_IMETHODIMP QuotingOutputStreamListener::OnStopRequest(nsIRequest *request, ns if ((type != nsIMsgCompType::Reply) && (type != nsIMsgCompType::ReplyToSender)) compFields->SetNewsgroups(NS_LossyConvertUCS2toASCII(newgroups).get()); if (type == nsIMsgCompType::ReplyToGroup) - compFields->SetTo(&emptyUnichar); + compFields->SetTo(EmptyString()); } if (! followUpTo.IsEmpty()) @@ -2132,7 +2126,7 @@ NS_IMETHODIMP QuotingOutputStreamListener::OnStopRequest(nsIRequest *request, ns // If reply-to is empty, use the from header to fetch // the original sender's email if (!replyTo.IsEmpty()) - compFields->SetTo(replyTo.get()); + compFields->SetTo(replyTo); else { mHeaders->ExtractHeader(HEADER_FROM, PR_FALSE, getter_Copies(outCString)); @@ -2140,7 +2134,7 @@ NS_IMETHODIMP QuotingOutputStreamListener::OnStopRequest(nsIRequest *request, ns { nsAutoString from; mMimeConverter->DecodeMimeHeader(outCString, from, charset); - compFields->SetTo(from.get()); + compFields->SetTo(from); } } @@ -2154,7 +2148,7 @@ NS_IMETHODIMP QuotingOutputStreamListener::OnStopRequest(nsIRequest *request, ns if (type != nsIMsgCompType::ReplyToSender) compFields->SetNewsgroups(NS_LossyConvertUCS2toASCII(followUpTo).get()); if (type == nsIMsgCompType::Reply) - compFields->SetTo(&emptyUnichar); + compFields->SetTo(EmptyString()); } } @@ -2279,7 +2273,7 @@ NS_IMETHODIMP QuotingOutputStreamListener::OnDataAvailable(nsIRequest *request, if (NS_SUCCEEDED(rv)) { // Use this local buffer if possible. - const PRUint32 kLocalBufSize = 4096; + const PRInt32 kLocalBufSize = 4096; PRUnichar localBuf[kLocalBufSize]; PRUnichar *unichars = localBuf; @@ -2826,8 +2820,8 @@ nsresult nsMsgComposeSendListener::OnStopSending(const char *aMsgID, nsresult aS compose->ProcessReplyFlags(); // Close the window ONLY if we are not going to do a save operation - nsXPIDLString fieldsFCC; - if (NS_SUCCEEDED(compFields->GetFcc(getter_Copies(fieldsFCC)))) + nsAutoString fieldsFCC; + if (NS_SUCCEEDED(compFields->GetFcc(fieldsFCC))) { if (!fieldsFCC.IsEmpty()) { @@ -3085,7 +3079,7 @@ nsMsgComposeSendListener::RemoveCurrentDraftMessage(nsIMsgCompose *compObj, PRBo nsCAutoString srcStr(str+1); PRInt32 num=0, err; num = srcStr.ToInteger(&err); - if (num != nsMsgKey_None) + if (num != PRInt32(nsMsgKey_None)) { messageID.Add(num); rv = imapFolder->StoreImapFlags(kImapMsgDeletedFlag, PR_TRUE, messageID.GetArray(), messageID.GetSize()); @@ -3282,8 +3276,7 @@ nsMsgCompose::LoadDataFromFile(nsFileSpec& fSpec, nsString &sigData) } tempFile.close(); - nsCAutoString sigEncoding; - sigEncoding.Assign(nsMsgI18NParseMetaCharset(&fSpec)); + nsCAutoString sigEncoding(nsMsgI18NParseMetaCharset(&fSpec)); PRBool removeSigCharset = !sigEncoding.IsEmpty() && m_composeHTML; //default to platform encoding for signature files w/o meta charset @@ -3291,14 +3284,13 @@ nsMsgCompose::LoadDataFromFile(nsFileSpec& fSpec, nsString &sigData) sigEncoding.Assign(nsMsgI18NFileSystemCharset()); if (NS_FAILED(ConvertToUnicode(sigEncoding.get(), readBuf, sigData))) - sigData.AssignWithConversion(readBuf); + CopyASCIItoUTF16(readBuf, sigData); //remove sig meta charset to allow user charset override during composition if (removeSigCharset) { - nsAutoString metaCharset; - metaCharset.Assign(NS_LITERAL_STRING("charset=")); - metaCharset.AppendWithConversion(sigEncoding.get()); + nsAutoString metaCharset(NS_LITERAL_STRING("charset=")); + AppendASCIItoUTF16(sigEncoding, metaCharset); nsAString::const_iterator realstart, start, end; sigData.BeginReading(start); sigData.EndReading(end); @@ -3509,7 +3501,6 @@ nsMsgCompose::ProcessSignature(nsIMsgIdentity *identity, PRBool aQuoted, nsStrin nsresult nsMsgCompose::BuildBodyMessageAndSignature() { - PRUnichar *bod = nsnull; nsresult rv = NS_OK; // @@ -3522,7 +3513,8 @@ nsMsgCompose::BuildBodyMessageAndSignature() // Now, we have the body so we can just blast it into the // composition editor window. // - m_compFields->GetBody(&bod); + nsAutoString body; + m_compFields->GetBody(body); /* Some time we want to add a signature and sometime we wont. Let's figure that now...*/ PRBool addSignature; @@ -3546,7 +3538,7 @@ nsMsgCompose::BuildBodyMessageAndSignature() break; case nsIMsgCompType::MailToUrl : - addSignature = !(bod && *bod != 0); + addSignature = body.IsEmpty(); break; default : @@ -3554,17 +3546,15 @@ nsMsgCompose::BuildBodyMessageAndSignature() break; } - nsAutoString empty; - nsAutoString bodStr(bod); nsAutoString tSignature; if (addSignature) ProcessSignature(m_identity, PR_FALSE, &tSignature); - rv = ConvertAndLoadComposeWindow(empty, bodStr, tSignature, + nsString empty; + rv = ConvertAndLoadComposeWindow(empty, body, tSignature, PR_FALSE, m_composeHTML); - PR_FREEIF(bod); return rv; } @@ -3849,10 +3839,10 @@ NS_IMETHODIMP nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, /* First, build an array with original recipients */ nsCOMArray recipientsList[MAX_OF_RECIPIENT_ARRAY]; - nsXPIDLString originalRecipients[MAX_OF_RECIPIENT_ARRAY]; - m_compFields->GetTo(getter_Copies(originalRecipients[0])); - m_compFields->GetCc(getter_Copies(originalRecipients[1])); - m_compFields->GetBcc(getter_Copies(originalRecipients[2])); + nsAutoString originalRecipients[MAX_OF_RECIPIENT_ARRAY]; + m_compFields->GetTo(originalRecipients[0]); + m_compFields->GetCc(originalRecipients[1]); + m_compFields->GetBcc(originalRecipients[2]); nsCOMPtr addressArray; nsCOMPtr emailArray; @@ -3860,7 +3850,8 @@ NS_IMETHODIMP nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, { if (originalRecipients[i].IsEmpty()) continue; - rv = m_compFields->SplitRecipientsEx((const PRUnichar *)(originalRecipients[i]), getter_AddRefs(addressArray), getter_AddRefs(emailArray)); + rv = m_compFields->SplitRecipientsEx(originalRecipients[i].get(), + getter_AddRefs(addressArray), getter_AddRefs(emailArray)); if (NS_SUCCEEDED(rv)) { PRInt32 nbrRecipients; @@ -3995,7 +3986,7 @@ NS_IMETHODIMP nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, if (!fullAddress.IsEmpty()) { /* We need to convert back the result from UTF-8 to Unicode */ - (void)ConvertToUnicode(msgCompHeaderInternalCharset(), fullAddress.get(), fullNameStr); + CopyUTF8toUTF16(fullAddress, fullNameStr); } } if (fullNameStr.IsEmpty()) @@ -4159,9 +4150,9 @@ NS_IMETHODIMP nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, { switch (i) { - case 0 : m_compFields->SetTo(recipientsStr.get()); break; - case 1 : m_compFields->SetCc(recipientsStr.get()); break; - case 2 : m_compFields->SetBcc(recipientsStr.get()); break; + case 0 : m_compFields->SetTo(recipientsStr); break; + case 1 : m_compFields->SetCc(recipientsStr); break; + case 2 : m_compFields->SetBcc(recipientsStr); break; } } } @@ -4853,18 +4844,19 @@ nsMsgMailList::nsMsgMailList(nsString listName, nsString listDescription, nsIAbD if (parser) { - nsXPIDLCString fullAddress; nsXPIDLCString utf8Email; if (listDescription.IsEmpty()) - utf8Email.Adopt(ToNewUTF8String(listName)); + CopyUTF16toUTF8(listName, utf8Email); else - utf8Email.Adopt(ToNewUTF8String(listDescription)); + CopyUTF16toUTF8(listDescription, utf8Email); - parser->MakeFullAddress(nsnull, NS_ConvertUCS2toUTF8(listName).get(), utf8Email, getter_Copies(fullAddress)); + nsXPIDLCString fullAddress; + parser->MakeFullAddress(nsnull, NS_ConvertUTF16toUTF8(listName).get(), + utf8Email, getter_Copies(fullAddress)); if (!fullAddress.IsEmpty()) { /* We need to convert back the result from UTF-8 to Unicode */ - (void)ConvertToUnicode(msgCompHeaderInternalCharset(), fullAddress, mFullName); + CopyUTF8toUTF16(fullAddress, mFullName); } } diff --git a/mozilla/mailnews/compose/src/nsMsgComposeService.cpp b/mozilla/mailnews/compose/src/nsMsgComposeService.cpp index b75dd1cf340..81187443484 100644 --- a/mozilla/mailnews/compose/src/nsMsgComposeService.cpp +++ b/mozilla/mailnews/compose/src/nsMsgComposeService.cpp @@ -511,14 +511,14 @@ NS_IMETHODIMP nsMsgComposeService::GetParamsForMailto(nsIURI * aURI, nsIMsgCompo nsnull /* priority */, getter_Copies(aNewsgroup), nsnull /* host */, &requestedComposeFormat); - nsString sanitizedBody; + nsAutoString sanitizedBody; // Since there is a buffer for each of the body types ('body', 'html-body') and // only one can be used, we give precedence to 'html-body' in the case where // both 'body' and 'html-body' are found in the url. - nsString rawBody = NS_ConvertUTF8toUCS2(aHTMLBodyPart); + NS_ConvertUTF8toUTF16 rawBody(aHTMLBodyPart); if(rawBody.IsEmpty()) - rawBody = NS_ConvertUTF8toUCS2(aBodyPart); + CopyUTF8toUTF16(aBodyPart, rawBody); PRBool composeHTMLFormat; DetermineComposeHTML(NULL, requestedComposeFormat, &composeHTMLFormat); @@ -542,7 +542,7 @@ NS_IMETHODIMP nsMsgComposeService::GetParamsForMailto(nsIURI * aURI, nsIMsgCompo nsCOMPtr sanSink(do_QueryInterface(sink)); if (sanSink) { - sanSink->Initialize(&sanitizedBody, 0, NS_ConvertASCIItoUCS2(allowedTags.get())); + sanSink->Initialize(&sanitizedBody, 0, NS_ConvertASCIItoUTF16(allowedTags)); parser->SetContentSink(sink); nsCOMPtr dtd = do_CreateInstance(kNavDTDCID); @@ -572,12 +572,12 @@ NS_IMETHODIMP nsMsgComposeService::GetParamsForMailto(nsIURI * aURI, nsIMsgCompo if (pMsgCompFields) { //ugghh more conversion work!!!! - pMsgCompFields->SetTo(NS_ConvertUTF8toUCS2(aToPart).get()); - pMsgCompFields->SetCc(NS_ConvertUTF8toUCS2(aCcPart).get()); - pMsgCompFields->SetBcc(NS_ConvertUTF8toUCS2(aBccPart).get()); + pMsgCompFields->SetTo(NS_ConvertUTF8toUTF16(aToPart)); + pMsgCompFields->SetCc(NS_ConvertUTF8toUTF16(aCcPart)); + pMsgCompFields->SetBcc(NS_ConvertUTF8toUTF16(aBccPart)); pMsgCompFields->SetNewsgroups(aNewsgroup); - pMsgCompFields->SetSubject(NS_ConvertUTF8toUCS2(aSubjectPart).get()); - pMsgCompFields->SetBody(composeHTMLFormat ? sanitizedBody.get() : rawBody.get()); + pMsgCompFields->SetSubject(NS_ConvertUTF8toUTF16(aSubjectPart)); + pMsgCompFields->SetBody(composeHTMLFormat ? sanitizedBody : rawBody); pMsgComposeParams->SetComposeFields(pMsgCompFields); NS_ADDREF(*aParams = pMsgComposeParams); @@ -601,68 +601,6 @@ NS_IMETHODIMP nsMsgComposeService::OpenComposeWindowWithURI(const char * aMsgCom return rv; } -nsresult nsMsgComposeService::OpenComposeWindowWithValues(const char *msgComposeWindowURL, - MSG_ComposeType type, - MSG_ComposeFormat format, - const PRUnichar *to, - const PRUnichar *cc, - const PRUnichar *bcc, - const char *newsgroups, - const PRUnichar *subject, - const PRUnichar *body, - const char *attachment, - nsIMsgIdentity *identity) -{ - NS_ASSERTION(0, "nsMsgComposeService::OpenComposeWindowWithValues is not supported anymore, use OpenComposeWindowWithParams instead\n"); - - nsresult rv; - nsCOMPtr pCompFields (do_CreateInstance(NS_MSGCOMPFIELDS_CONTRACTID, &rv)); - if (NS_SUCCEEDED(rv) && pCompFields) - { - if (to) {pCompFields->SetTo(to);} - if (cc) {pCompFields->SetCc(cc);} - if (bcc) {pCompFields->SetBcc(bcc);} - if (newsgroups) {pCompFields->SetNewsgroups(newsgroups);} - if (subject) {pCompFields->SetSubject(subject);} -// if (attachment) {pCompFields->SetAttachments(attachment);} - if (body) {pCompFields->SetBody(body);} - - rv = OpenComposeWindowWithCompFields(msgComposeWindowURL, type, format, pCompFields, identity); - } - - return rv; -} - -nsresult nsMsgComposeService::OpenComposeWindowWithCompFields(const char *msgComposeWindowURL, - MSG_ComposeType type, - MSG_ComposeFormat format, - nsIMsgCompFields *compFields, - nsIMsgIdentity *identity) -{ - NS_ASSERTION(0, "nsMsgComposeService::OpenComposeWindowWithCompFields is not supported anymore, use OpenComposeWindowWithParams instead\n"); - - nsresult rv; - - nsCOMPtr pMsgComposeParams (do_CreateInstance(NS_MSGCOMPOSEPARAMS_CONTRACTID, &rv)); - if (NS_SUCCEEDED(rv) && pMsgComposeParams) - { - pMsgComposeParams->SetType(type); - pMsgComposeParams->SetFormat(format); - pMsgComposeParams->SetIdentity(identity); - pMsgComposeParams->SetComposeFields(compFields); - - if(mLogComposePerformance) - { -#ifdef MSGCOMP_TRACE_PERFORMANCE - TimeStamp("Start opening the window", PR_TRUE); -#endif - }//end -if (mLogComposePerformance) - rv = OpenWindow(msgComposeWindowURL, pMsgComposeParams); - } - - return rv; -} - nsresult nsMsgComposeService::OpenComposeWindowWithParams(const char *msgComposeWindowURL, nsIMsgComposeParams *params) { diff --git a/mozilla/mailnews/compose/src/nsMsgSend.cpp b/mozilla/mailnews/compose/src/nsMsgSend.cpp index 6998feb1336..d47073a578a 100644 --- a/mozilla/mailnews/compose/src/nsMsgSend.cpp +++ b/mozilla/mailnews/compose/src/nsMsgSend.cpp @@ -110,6 +110,7 @@ #include "nsIRDFService.h" #include "nsRDFCID.h" #include "nsIMsgAccountManager.h" +#include "nsNativeCharsetUtils.h" static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); @@ -737,7 +738,8 @@ nsMsgComposeAndSend::GatherMimeAttachments() { nsAutoString error_msg; nsAutoString path; - nsMsgGetNativePathString(mHTMLFileSpec->GetNativePathCString(),path); + NS_CopyNativeToUnicode( + nsDependentCString(mHTMLFileSpec->GetNativePathCString()), path); nsMsgBuildErrorMessageByID(NS_MSG_UNABLE_TO_OPEN_TMP_FILE, error_msg, &path, nsnull); mSendReport->SetMessage(nsIMsgSendReport::process_Current, error_msg.get(), PR_FALSE); } @@ -821,7 +823,8 @@ nsMsgComposeAndSend::GatherMimeAttachments() { nsAutoString error_msg; nsAutoString path; - nsMsgGetNativePathString(mTempFileSpec->GetNativePathCString(),path); + NS_CopyNativeToUnicode( + nsDependentCString(mTempFileSpec->GetNativePathCString()), path); nsMsgBuildErrorMessageByID(NS_MSG_UNABLE_TO_OPEN_TMP_FILE, error_msg, &path, nsnull); mSendReport->SetMessage(nsIMsgSendReport::process_Current, error_msg.get(), PR_FALSE); } @@ -4300,7 +4303,8 @@ nsMsgComposeAndSend::MimeDoFCC(nsFileSpec *input_file, { nsAutoString error_msg; nsAutoString path; - nsMsgGetNativePathString(tFileSpec->GetNativePathCString(),path); + NS_CopyNativeToUnicode( + nsDependentCString(tFileSpec->GetNativePathCString()), path); nsMsgBuildErrorMessageByID(NS_MSG_UNABLE_TO_OPEN_TMP_FILE, error_msg, &path, nsnull); mSendReport->SetMessage(nsIMsgSendReport::process_Current, error_msg.get(), PR_FALSE); } @@ -4320,7 +4324,8 @@ nsMsgComposeAndSend::MimeDoFCC(nsFileSpec *input_file, { nsAutoString error_msg; nsAutoString path; - nsMsgGetNativePathString(input_file->GetNativePathCString(),path); + NS_CopyNativeToUnicode( + nsDependentCString(input_file->GetNativePathCString()), path); nsMsgBuildErrorMessageByID(NS_MSG_UNABLE_TO_OPEN_FILE, error_msg, &path, nsnull); mSendReport->SetMessage(nsIMsgSendReport::process_Current, error_msg.get(), PR_FALSE); } diff --git a/mozilla/mailnews/compose/src/nsMsgSendPart.cpp b/mozilla/mailnews/compose/src/nsMsgSendPart.cpp index e2ae6c7b525..3d4627abf69 100644 --- a/mozilla/mailnews/compose/src/nsMsgSendPart.cpp +++ b/mozilla/mailnews/compose/src/nsMsgSendPart.cpp @@ -51,6 +51,7 @@ #include "prmem.h" #include "nsMsgPrompts.h" #include "nsMsgComposeStringBundle.h" +#include "nsNativeCharsetUtils.h" // defined in msgCompGlue.cpp static char *mime_mailto_stream_read_buffer = 0; @@ -662,7 +663,8 @@ nsMsgSendPart::Write() { nsAutoString error_msg; nsAutoString path; - nsMsgGetNativePathString(m_filespec->GetNativePathCString(),path); + NS_CopyNativeToUnicode( + nsDependentCString(m_filespec->GetNativePathCString()), path); nsMsgBuildErrorMessageByID(NS_MSG_UNABLE_TO_OPEN_TMP_FILE, error_msg, &path, nsnull); sendReport->SetMessage(nsIMsgSendReport::process_Current, error_msg.get(), PR_FALSE); } diff --git a/mozilla/mailnews/db/msgdb/public/nsDBFolderInfo.h b/mozilla/mailnews/db/msgdb/public/nsDBFolderInfo.h index eb98bb46c7e..c1a2d33e807 100644 --- a/mozilla/mailnews/db/msgdb/public/nsDBFolderInfo.h +++ b/mozilla/mailnews/db/msgdb/public/nsDBFolderInfo.h @@ -80,10 +80,10 @@ public: nsresult InitFromExistingDB(); // get and set arbitrary property, aka row cell value. - nsresult SetPropertyWithToken(mdb_token aProperty, nsString *propertyStr); + nsresult SetPropertyWithToken(mdb_token aProperty, const nsAString &propertyStr); nsresult SetUint32PropertyWithToken(mdb_token aProperty, PRUint32 propertyValue); nsresult SetInt32PropertyWithToken(mdb_token aProperty, PRInt32 propertyValue); - nsresult GetPropertyWithToken(mdb_token aProperty, nsString *resultProperty); + nsresult GetPropertyWithToken(mdb_token aProperty, nsAString &resultProperty); nsresult GetUint32PropertyWithToken(mdb_token aProperty, PRUint32 &propertyValue, PRUint32 defaultValue = 0); nsresult GetInt32PropertyWithToken(mdb_token aProperty, PRInt32 &propertyValue, PRInt32 defaultValue = 0); nsresult GetConstCharPtrCharacterSet(const char**result); diff --git a/mozilla/mailnews/db/msgdb/public/nsIDBFolderInfo.idl b/mozilla/mailnews/db/msgdb/public/nsIDBFolderInfo.idl index 1366a0edeb8..39bba5f6952 100644 --- a/mozilla/mailnews/db/msgdb/public/nsIDBFolderInfo.idl +++ b/mozilla/mailnews/db/msgdb/public/nsIDBFolderInfo.idl @@ -38,11 +38,6 @@ #include "nsISupports.idl" #include "MailNewsTypes2.idl" -[ptr] native nsString(nsString); -%{ C++ -#include "nsString.h" -%} - [scriptable, uuid(5cb11c00-cb8b-11d2-8d67-00805f8a6617)] interface nsIDBFolderInfo : nsISupports { attribute long Flags; @@ -74,30 +69,28 @@ interface nsIDBFolderInfo : nsISupports { void ChangeExpungedBytes(in long delta); - void GetCharPtrProperty(in string propertyName, out string resultProperty); - void SetCharPtrProperty(in string aPropertyName, in string aPropertyValue); - void SetUint32Property(in string propertyName, in unsigned long propertyValue); - void GetUint32Property(in string propertyName, out unsigned long result, in unsigned long defaultValue); - void getBooleanProperty(in string propertyName, out boolean result, in boolean defaultValue); + string getCharPtrProperty(in string propertyName); + void setCharPtrProperty(in string aPropertyName, in string aPropertyValue); + void setUint32Property(in string propertyName, in unsigned long propertyValue); + unsigned long getUint32Property(in string propertyName, in unsigned long defaultValue); + boolean getBooleanProperty(in string propertyName, in boolean defaultValue); void setBooleanProperty(in string propertyName, in boolean aPropertyValue); - void GetTransferInfo(out nsIDBFolderInfo transferInfo); - void InitFromTransferInfo(in nsIDBFolderInfo transferInfo); + nsIDBFolderInfo GetTransferInfo(); + void initFromTransferInfo(in nsIDBFolderInfo transferInfo); - [noscript] void getCharacterSet(in nsString charSet, out boolean usedDefault); - [noscript] void setCharacterSet(in wstring charSet); - void getCharacterSetOverride(out boolean characterSetOverride); - void setCharacterSetOverride(in boolean characterSetOverride); + void getCharacterSet(out AString charSet, out boolean overriden); + void setCharacterSet(in wstring charSet); - void getCharPtrCharacterSet(out string result); + attribute boolean characterSetOverride; - [noscript] void getLocale(in nsString result); - [noscript] void setLocale(in nsString locale); + string getCharPtrCharacterSet(); - [noscript] void setMailboxName(in nsString newBoxName); - [noscript] void getMailboxName(in nsString boxName); + attribute AString locale; + attribute AString mailboxName; - [noscript] void getProperty(in string propertyName, in nsString resultProperty); - [noscript] void setProperty(in string propertyName, in nsString propertyStr); + + AString getProperty(in string propertyName); + void setProperty(in string propertyName, in AString propertyStr); attribute string knownArtsSet; attribute string folderName; diff --git a/mozilla/mailnews/db/msgdb/public/nsMsgDatabase.h b/mozilla/mailnews/db/msgdb/public/nsMsgDatabase.h index 8ca457ad718..797d05a1342 100644 --- a/mozilla/mailnews/db/msgdb/public/nsMsgDatabase.h +++ b/mozilla/mailnews/db/msgdb/public/nsMsgDatabase.h @@ -101,7 +101,7 @@ public: static nsMsgDatabase* FindInCache(nsFileSpec &dbName); //helper function to fill in nsStrings from hdr row cell contents. - nsresult RowCellColumnTonsString(nsIMdbRow *row, mdb_token columnToken, nsString &resultStr); + nsresult RowCellColumnTonsString(nsIMdbRow *row, mdb_token columnToken, nsAString &resultStr); nsresult RowCellColumnToUInt32(nsIMdbRow *row, mdb_token columnToken, PRUint32 *uint32Result, PRUint32 defaultValue = 0); nsresult RowCellColumnToUInt32(nsIMdbRow *row, mdb_token columnToken, PRUint32 &uint32Result, PRUint32 defaultValue = 0); nsresult RowCellColumnToMime2DecodedString(nsIMdbRow *row, mdb_token columnToken, PRUnichar **); @@ -113,12 +113,12 @@ public: // they should be used when the properties aren't accessed a lot nsresult GetProperty(nsIMdbRow *row, const char *propertyName, char **result); nsresult SetProperty(nsIMdbRow *row, const char *propertyName, const char *propertyVal); - nsresult GetPropertyAsNSString(nsIMdbRow *row, const char *propertyName, nsString *result); - nsresult SetPropertyFromNSString(nsIMdbRow *row, const char *propertyName, nsString *propertyVal); + nsresult GetPropertyAsNSString(nsIMdbRow *row, const char *propertyName, nsAString &result); + nsresult SetPropertyFromNSString(nsIMdbRow *row, const char *propertyName, const nsAString &propertyVal); nsresult GetUint32Property(nsIMdbRow *row, const char *propertyName, PRUint32 *result, PRUint32 defaultValue = 0); nsresult SetUint32Property(nsIMdbRow *row, const char *propertyName, PRUint32 propertyVal); // helper function for once we have the token. - nsresult SetNSStringPropertyWithToken(nsIMdbRow *row, mdb_token aProperty, nsString *propertyStr); + nsresult SetNSStringPropertyWithToken(nsIMdbRow *row, mdb_token aProperty, const nsAString &propertyStr); // helper functions to put values in cells for the passed-in row nsresult UInt32ToRowCellColumn(nsIMdbRow *row, mdb_token columnToken, PRUint32 value); @@ -127,10 +127,10 @@ public: // helper functions to copy an nsString to a yarn, int32 to yarn, and vice versa. - static struct mdbYarn *nsStringToYarn(struct mdbYarn *yarn, nsString *str); + static struct mdbYarn *nsStringToYarn(struct mdbYarn *yarn, const nsAString &str); static struct mdbYarn *UInt32ToYarn(struct mdbYarn *yarn, PRUint32 i); - static void YarnTonsString(struct mdbYarn *yarn, nsString *str); - static void YarnTonsCString(struct mdbYarn *yarn, nsCString *str); + static void YarnTonsString(struct mdbYarn *yarn, nsAString &str); + static void YarnTonsCString(struct mdbYarn *yarn, nsACString &str); static void YarnToUInt32(struct mdbYarn *yarn, PRUint32 *i); diff --git a/mozilla/mailnews/db/msgdb/src/nsDBFolderInfo.cpp b/mozilla/mailnews/db/msgdb/src/nsDBFolderInfo.cpp index 10365c011b0..36130da4d93 100644 --- a/mozilla/mailnews/db/msgdb/src/nsDBFolderInfo.cpp +++ b/mozilla/mailnews/db/msgdb/src/nsDBFolderInfo.cpp @@ -409,7 +409,7 @@ nsresult nsDBFolderInfo::LoadMemberVariables() m_version = (PRUint16) version; m_charSetOverride = gDefaultCharacterOverride; PRUint32 propertyValue; - nsresult rv = GetUint32Property(kCharacterSetOverrideColumnName, &propertyValue, gDefaultCharacterOverride); + nsresult rv = GetUint32Property(kCharacterSetOverrideColumnName, gDefaultCharacterOverride, &propertyValue); if (NS_SUCCEEDED(rv)) m_charSetOverride = propertyValue; @@ -502,12 +502,12 @@ nsDBFolderInfo::ChangeExpungedBytes(PRInt32 delta) return SetExpungedBytes(m_expungedBytes + delta); } -NS_IMETHODIMP nsDBFolderInfo::SetMailboxName(nsString *newBoxName) +NS_IMETHODIMP nsDBFolderInfo::SetMailboxName(const nsAString &newBoxName) { return SetPropertyWithToken(m_mailboxNameColumnToken, newBoxName); } -NS_IMETHODIMP nsDBFolderInfo::GetMailboxName(nsString *boxName) +NS_IMETHODIMP nsDBFolderInfo::GetMailboxName(nsAString &boxName) { return GetPropertyWithToken(m_mailboxNameColumnToken, boxName); } @@ -629,15 +629,15 @@ PRBool nsDBFolderInfo::TestFlag(PRInt32 flags) } NS_IMETHODIMP -nsDBFolderInfo::GetCharacterSet(nsString *result, PRBool *usedDefault) +nsDBFolderInfo::GetCharacterSet(nsAString &result, PRBool *usedDefault) { + *usedDefault = PR_FALSE; + nsresult rv = GetProperty(kCharacterSetColumnName, result); - *usedDefault = PR_FALSE; - - if (NS_SUCCEEDED(rv) && result->IsEmpty()) + if (NS_SUCCEEDED(rv) && result.IsEmpty()) { - result->AssignWithConversion(gDefaultCharacterSet.get()); + CopyASCIItoUTF16(gDefaultCharacterSet, result); *usedDefault = PR_TRUE; } @@ -686,13 +686,13 @@ NS_IMETHODIMP nsDBFolderInfo::SetCharacterSetOverride(PRBool characterSetOverrid } NS_IMETHODIMP -nsDBFolderInfo::GetLocale(nsString *result) +nsDBFolderInfo::GetLocale(nsAString &result) { GetProperty(kLocaleColumnName, result); return NS_OK; } -NS_IMETHODIMP nsDBFolderInfo::SetLocale(nsString *locale) +NS_IMETHODIMP nsDBFolderInfo::SetLocale(const nsAString &locale) { return SetProperty(kLocaleColumnName, locale); } @@ -760,7 +760,7 @@ void nsDBFolderInfo::ChangeImapUnreadPendingMessages(PRInt32 delta) NS_IMETHODIMP nsDBFolderInfo::GetViewType(nsMsgViewTypeValue *aViewType) { PRUint32 viewTypeValue; - nsresult rv = GetUint32Property("viewType", &viewTypeValue, nsMsgViewType::eShowAllThreads); + nsresult rv = GetUint32Property("viewType", nsMsgViewType::eShowAllThreads, &viewTypeValue); *aViewType = viewTypeValue; return rv; } @@ -777,7 +777,7 @@ NS_IMETHODIMP nsDBFolderInfo::GetViewFlags(nsMsgViewFlagsTypeValue *aViewFlags) NS_ENSURE_SUCCESS(rv,rv); PRUint32 viewFlagsValue; - rv = GetUint32Property("viewFlags", &viewFlagsValue, defaultViewFlags); + rv = GetUint32Property("viewFlags", defaultViewFlags, &viewFlagsValue); *aViewFlags = viewFlagsValue; return rv; } @@ -794,7 +794,7 @@ NS_IMETHODIMP nsDBFolderInfo::GetSortType(nsMsgViewSortTypeValue *aSortType) NS_ENSURE_SUCCESS(rv,rv); PRUint32 sortTypeValue; - rv = GetUint32Property("sortType", &sortTypeValue, defaultSortType); + rv = GetUint32Property("sortType", defaultSortType, &sortTypeValue); *aSortType = sortTypeValue; return rv; } @@ -807,7 +807,7 @@ NS_IMETHODIMP nsDBFolderInfo::SetSortType(nsMsgViewSortTypeValue aSortType) NS_IMETHODIMP nsDBFolderInfo::GetSortOrder(nsMsgViewSortOrderValue *aSortOrder) { PRUint32 sortOrderValue; - nsresult rv = GetUint32Property("sortOrder", &sortOrderValue, nsMsgViewSortOrder::ascending); + nsresult rv = GetUint32Property("sortOrder", nsMsgViewSortOrder::ascending, &sortOrderValue); *aSortOrder = sortOrderValue; return rv; } @@ -829,7 +829,7 @@ NS_IMETHODIMP nsDBFolderInfo::GetKnownArtsSet(char **newsArtSet) } // get arbitrary property, aka row cell value. -NS_IMETHODIMP nsDBFolderInfo::GetProperty(const char *propertyName, nsString *resultProperty) +NS_IMETHODIMP nsDBFolderInfo::GetProperty(const char *propertyName, nsAString &resultProperty) { return m_mdb->GetPropertyAsNSString(m_mdbRow, propertyName, resultProperty); } @@ -851,12 +851,12 @@ NS_IMETHODIMP nsDBFolderInfo::SetUint32Property(const char *propertyName, PRUint return m_mdb->SetUint32Property(m_mdbRow, propertyName, propertyValue); } -NS_IMETHODIMP nsDBFolderInfo::SetProperty(const char *propertyName, nsString *propertyStr) +NS_IMETHODIMP nsDBFolderInfo::SetProperty(const char *propertyName, const nsAString &propertyStr) { return m_mdb->SetPropertyFromNSString(m_mdbRow, propertyName, propertyStr); } -nsresult nsDBFolderInfo::SetPropertyWithToken(mdb_token aProperty, nsString *propertyStr) +nsresult nsDBFolderInfo::SetPropertyWithToken(mdb_token aProperty, const nsAString &propertyStr) { return m_mdb->SetNSStringPropertyWithToken(m_mdbRow, aProperty, propertyStr); } @@ -868,16 +868,14 @@ nsresult nsDBFolderInfo::SetUint32PropertyWithToken(mdb_token aProperty, PRUint nsresult nsDBFolderInfo::SetInt32PropertyWithToken(mdb_token aProperty, PRInt32 propertyValue) { - nsString propertyStr; + nsAutoString propertyStr; propertyStr.AppendInt(propertyValue, 16); - return SetPropertyWithToken(aProperty, &propertyStr); + return SetPropertyWithToken(aProperty, propertyStr); } -nsresult nsDBFolderInfo::GetPropertyWithToken(mdb_token aProperty, nsString *resultProperty) +nsresult nsDBFolderInfo::GetPropertyWithToken(mdb_token aProperty, nsAString &resultProperty) { - if (!resultProperty) - return NS_ERROR_NULL_POINTER; - return m_mdb->RowCellColumnTonsString(m_mdbRow, aProperty, *resultProperty); + return m_mdb->RowCellColumnTonsString(m_mdbRow, aProperty, resultProperty); } nsresult nsDBFolderInfo::GetUint32PropertyWithToken(mdb_token aProperty, PRUint32 &propertyValue, PRUint32 defaultValue) @@ -890,12 +888,12 @@ nsresult nsDBFolderInfo::GetInt32PropertyWithToken(mdb_token aProperty, PRInt32 return m_mdb->RowCellColumnToUInt32(m_mdbRow, aProperty, (PRUint32 &) propertyValue, defaultValue); } -NS_IMETHODIMP nsDBFolderInfo::GetUint32Property(const char *propertyName, PRUint32 *propertyValue, PRUint32 defaultValue) +NS_IMETHODIMP nsDBFolderInfo::GetUint32Property(const char *propertyName, PRUint32 defaultValue, PRUint32 *propertyValue) { return m_mdb->GetUint32Property(m_mdbRow, propertyName, propertyValue, defaultValue); } -NS_IMETHODIMP nsDBFolderInfo::GetBooleanProperty(const char *propertyName, PRBool *propertyValue, PRBool defaultValue) +NS_IMETHODIMP nsDBFolderInfo::GetBooleanProperty(const char *propertyName, PRBool defaultValue, PRBool *propertyValue) { PRUint32 defaultUint32Value = (defaultValue) ? 1 : 0; PRUint32 returnValue; @@ -923,8 +921,8 @@ class nsTransferDBFolderInfo : public nsDBFolderInfo public: nsTransferDBFolderInfo(); virtual ~nsTransferDBFolderInfo(); - NS_IMETHOD GetMailboxName(nsString *boxName); - NS_IMETHOD SetMailboxName(nsString *boxName); + NS_IMETHOD GetMailboxName(nsAString &boxName); + NS_IMETHOD SetMailboxName(const nsAString &boxName); NS_IMETHOD GetViewType(nsMsgViewTypeValue *aViewType); NS_IMETHOD SetViewType(nsMsgViewTypeValue aViewType); NS_IMETHOD GetViewFlags(nsMsgViewFlagsTypeValue *aViewFlags); @@ -956,14 +954,15 @@ nsTransferDBFolderInfo::~nsTransferDBFolderInfo() NS_IMETHODIMP nsDBFolderInfo::GetTransferInfo(nsIDBFolderInfo **transferInfo) { NS_ENSURE_ARG_POINTER(transferInfo); - nsAutoString folderNameStr; nsTransferDBFolderInfo *newInfo = new nsTransferDBFolderInfo; *transferInfo = newInfo; NS_ADDREF(newInfo); newInfo->m_flags = m_flags; - GetMailboxName(&folderNameStr); - newInfo->SetMailboxName(&folderNameStr); + + nsAutoString folderNameStr; + GetMailboxName(folderNameStr); + newInfo->SetMailboxName(folderNameStr); // ### add whatever other fields we want to copy here. nsMsgViewTypeValue viewType; nsMsgViewFlagsTypeValue viewFlags; @@ -1000,15 +999,15 @@ NS_IMETHODIMP nsTransferDBFolderInfo::GetFolderName(char **folderName) return NS_OK; } -NS_IMETHODIMP nsTransferDBFolderInfo::GetMailboxName(nsString *boxName) +NS_IMETHODIMP nsTransferDBFolderInfo::GetMailboxName(nsAString &boxName) { - *boxName = m_boxName; + boxName = m_boxName; return NS_OK; } -NS_IMETHODIMP nsTransferDBFolderInfo::SetMailboxName(nsString *boxName) +NS_IMETHODIMP nsTransferDBFolderInfo::SetMailboxName(const nsAString &boxName) { - m_boxName = *boxName; + m_boxName = boxName; return NS_OK; } @@ -1026,8 +1025,8 @@ NS_IMETHODIMP nsDBFolderInfo::InitFromTransferInfo(nsIDBFolderInfo *transferInfo transferInfo->GetFlags(&flags); SetFlags(flags); - transferInfo->GetMailboxName(&folderNameStr); - SetMailboxName(&folderNameStr); + transferInfo->GetMailboxName(folderNameStr); + SetMailboxName(folderNameStr); nsXPIDLCString utf8Name; transferInfo->GetFolderName(getter_Copies(utf8Name)); diff --git a/mozilla/mailnews/db/msgdb/src/nsMsgDatabase.cpp b/mozilla/mailnews/db/msgdb/src/nsMsgDatabase.cpp index 4c885a7f7be..ed802369661 100644 --- a/mozilla/mailnews/db/msgdb/src/nsMsgDatabase.cpp +++ b/mozilla/mailnews/db/msgdb/src/nsMsgDatabase.cpp @@ -52,7 +52,7 @@ #include "nsIEnumerator.h" #include "nsMsgThread.h" #include "nsFileStream.h" -#include "nsString.h" +#include "nsDependentSubstring.h" #include "nsXPIDLString.h" #include "nsReadableUtils.h" #include "nsIMsgHeaderParser.h" @@ -2738,17 +2738,6 @@ nsMsgDatabase::EnumerateMessagesWithFlag(nsISimpleEnumerator* *result, PRUint32 return NS_OK; } -static nsresult -nsMsgReadFilter(nsIMsgDBHdr* msg, void* closure) -{ - nsMsgDatabase* db = (nsMsgDatabase*)closure; - PRBool wasRead = PR_TRUE; - nsresult rv = db->IsHeaderRead(msg, &wasRead); - if (NS_FAILED(rv)) - return rv; - return wasRead ? NS_OK : NS_ERROR_FAILURE; -} - NS_IMETHODIMP nsMsgDatabase::CreateNewHdr(nsMsgKey key, nsIMsgDBHdr **pnewHdr) { nsresult err = NS_OK; @@ -2850,7 +2839,7 @@ NS_IMETHODIMP nsMsgDatabase::CopyHdrFromExistingHdr(nsMsgKey key, nsIMsgDBHdr *e return err; } -nsresult nsMsgDatabase::RowCellColumnTonsString(nsIMdbRow *hdrRow, mdb_token columnToken, nsString &resultStr) +nsresult nsMsgDatabase::RowCellColumnTonsString(nsIMdbRow *hdrRow, mdb_token columnToken, nsAString &resultStr) { nsresult err = NS_OK; @@ -2859,7 +2848,7 @@ nsresult nsMsgDatabase::RowCellColumnTonsString(nsIMdbRow *hdrRow, mdb_token col struct mdbYarn yarn; err = hdrRow->AliasCellYarn(GetEnv(), columnToken, &yarn); if (err == NS_OK) - YarnTonsString(&yarn, &resultStr); + YarnTonsString(&yarn, resultStr); } return err; } @@ -2963,7 +2952,7 @@ nsresult nsMsgDatabase::GetCollationKeyGenerator() if (!m_collationKeyGenerator) { nsCOMPtr locale; - nsString localeName; + nsAutoString localeName; // get a locale service nsCOMPtr localeService = do_GetService(NS_LOCALESERVICE_CONTRACTID, &err); @@ -3135,10 +3124,10 @@ nsresult nsMsgDatabase::RowCellColumnToCharPtr(nsIMdbRow *row, mdb_token columnT -/* static */struct mdbYarn *nsMsgDatabase::nsStringToYarn(struct mdbYarn *yarn, nsString *str) +/* static */struct mdbYarn *nsMsgDatabase::nsStringToYarn(struct mdbYarn *yarn, const nsAString &str) { - yarn->mYarn_Buf = ToNewCString(*str); - yarn->mYarn_Size = PL_strlen((const char *) yarn->mYarn_Buf) + 1; + yarn->mYarn_Buf = ToNewCString(str); + yarn->mYarn_Size = str.Length() + 1; yarn->mYarn_Fill = yarn->mYarn_Size - 1; yarn->mYarn_Form = 0; // what to do with this? we're storing csid in the msg hdr... return yarn; @@ -3152,22 +3141,22 @@ nsresult nsMsgDatabase::RowCellColumnToCharPtr(nsIMdbRow *row, mdb_token columnT return yarn; } -/* static */void nsMsgDatabase::YarnTonsString(struct mdbYarn *yarn, nsString *str) +/* static */void nsMsgDatabase::YarnTonsString(struct mdbYarn *yarn, nsAString &str) { const char* buf = (const char*)yarn->mYarn_Buf; if (buf) - str->AssignWithConversion(buf, yarn->mYarn_Fill); + CopyASCIItoUTF16(Substring(buf, buf + yarn->mYarn_Fill), str); else - str->Truncate(); + str.Truncate(); } -/* static */void nsMsgDatabase::YarnTonsCString(struct mdbYarn *yarn, nsCString *str) +/* static */void nsMsgDatabase::YarnTonsCString(struct mdbYarn *yarn, nsACString &str) { const char* buf = (const char*)yarn->mYarn_Buf; if (buf) - str->Assign(buf, yarn->mYarn_Fill); + str.Assign(buf, yarn->mYarn_Fill); else - str->Truncate(); + str.Truncate(); } // WARNING - if yarn is empty, *pResult will not be changed!!!! @@ -3242,20 +3231,19 @@ nsresult nsMsgDatabase::SetProperty(nsIMdbRow *row, const char *propertyName, co return err; } -nsresult nsMsgDatabase::GetPropertyAsNSString(nsIMdbRow *row, const char *propertyName, nsString *result) +nsresult nsMsgDatabase::GetPropertyAsNSString(nsIMdbRow *row, const char *propertyName, nsAString &result) { nsresult err = NS_OK; mdb_token property_token; - NS_ENSURE_ARG(result); err = m_mdbStore->StringToToken(GetEnv(), propertyName, &property_token); if (err == NS_OK) - err = RowCellColumnTonsString(row, property_token, *result); + err = RowCellColumnTonsString(row, property_token, result); return err; } -nsresult nsMsgDatabase::SetPropertyFromNSString(nsIMdbRow *row, const char *propertyName, nsString *propertyVal) +nsresult nsMsgDatabase::SetPropertyFromNSString(nsIMdbRow *row, const char *propertyName, const nsAString &propertyVal) { nsresult err = NS_OK; mdb_token property_token; @@ -3302,7 +3290,7 @@ nsresult nsMsgDatabase::SetUint32Property(nsIMdbRow *row, const char *propertyNa return err; } -nsresult nsMsgDatabase::SetNSStringPropertyWithToken(nsIMdbRow *row, mdb_token aProperty, nsString *propertyStr) +nsresult nsMsgDatabase::SetNSStringPropertyWithToken(nsIMdbRow *row, mdb_token aProperty, const nsAString &propertyStr) { NS_ENSURE_ARG(row); struct mdbYarn yarn; @@ -4056,13 +4044,13 @@ NS_IMETHODIMP nsMsgDatabase::GetMsgRetentionSettings(nsIMsgRetentionSettings **r PRUint32 daysToKeepBodies = 0; PRBool cleanupBodiesByDays = PR_FALSE; - rv = m_dbFolderInfo->GetUint32Property("retainBy", &retainByPreference, nsIMsgRetentionSettings::nsMsgRetainAll); - m_dbFolderInfo->GetUint32Property("daysToKeepHdrs", &daysToKeepHdrs, 0); - m_dbFolderInfo->GetUint32Property("numHdrsToKeep", &numHeadersToKeep, 0); - m_dbFolderInfo->GetUint32Property("daysToKeepBodies", &daysToKeepBodies, 0); - m_dbFolderInfo->GetUint32Property("keepUnreadOnly", &keepUnreadMessagesProp, 0); - m_dbFolderInfo->GetBooleanProperty("useServerDefaults", &useServerDefaults, PR_TRUE); - m_dbFolderInfo->GetBooleanProperty("cleanupBodies", &cleanupBodiesByDays, PR_FALSE); + rv = m_dbFolderInfo->GetUint32Property("retainBy", nsIMsgRetentionSettings::nsMsgRetainAll, &retainByPreference); + m_dbFolderInfo->GetUint32Property("daysToKeepHdrs", 0, &daysToKeepHdrs); + m_dbFolderInfo->GetUint32Property("numHdrsToKeep", 0, &numHeadersToKeep); + m_dbFolderInfo->GetUint32Property("daysToKeepBodies", 0, &daysToKeepBodies); + m_dbFolderInfo->GetUint32Property("keepUnreadOnly", 0, &keepUnreadMessagesProp); + m_dbFolderInfo->GetBooleanProperty("useServerDefaults", PR_TRUE, &useServerDefaults); + m_dbFolderInfo->GetBooleanProperty("cleanupBodies", PR_FALSE, &cleanupBodiesByDays); keepUnreadMessagesOnly = (keepUnreadMessagesProp == 1); m_retentionSettings->SetRetainByPreference(retainByPreference); m_retentionSettings->SetDaysToKeepHdrs(daysToKeepHdrs); @@ -4121,10 +4109,10 @@ NS_IMETHODIMP nsMsgDatabase::GetMsgDownloadSettings(nsIMsgDownloadSettings **dow PRUint32 ageLimitOfMsgsToDownload; PRBool downloadUnreadOnly; - m_dbFolderInfo->GetBooleanProperty("useServerDefaults", &useServerDefaults, PR_TRUE); - m_dbFolderInfo->GetBooleanProperty("downloadByDate", &downloadByDate, PR_FALSE); - m_dbFolderInfo->GetBooleanProperty("downloadUnreadOnly", &downloadUnreadOnly, PR_FALSE); - m_dbFolderInfo->GetUint32Property("ageLimit", &ageLimitOfMsgsToDownload, 0); + m_dbFolderInfo->GetBooleanProperty("useServerDefaults", PR_TRUE, &useServerDefaults); + m_dbFolderInfo->GetBooleanProperty("downloadByDate", PR_FALSE, &downloadByDate); + m_dbFolderInfo->GetBooleanProperty("downloadUnreadOnly", PR_FALSE, &downloadUnreadOnly); + m_dbFolderInfo->GetUint32Property("ageLimit", 0, &ageLimitOfMsgsToDownload); m_downloadSettings->SetUseServerDefaults(useServerDefaults); m_downloadSettings->SetDownloadByDate(downloadByDate); diff --git a/mozilla/mailnews/db/msgdb/src/nsMsgHdr.cpp b/mozilla/mailnews/db/msgdb/src/nsMsgHdr.cpp index a8392ad5181..bcbe20312dc 100644 --- a/mozilla/mailnews/db/msgdb/src/nsMsgHdr.cpp +++ b/mozilla/mailnews/db/msgdb/src/nsMsgHdr.cpp @@ -283,14 +283,14 @@ NS_IMETHODIMP nsMsgHdr::MarkFlagged(PRBool bFlagged) return rv; } -NS_IMETHODIMP nsMsgHdr::GetProperty(const char *propertyName, nsString &resultProperty) +NS_IMETHODIMP nsMsgHdr::GetProperty(const char *propertyName, nsAString &resultProperty) { - return m_mdb->GetPropertyAsNSString(GetMDBRow(), propertyName, &resultProperty); + return m_mdb->GetPropertyAsNSString(GetMDBRow(), propertyName, resultProperty); } -NS_IMETHODIMP nsMsgHdr::SetProperty(const char *propertyName, nsString &propertyStr) +NS_IMETHODIMP nsMsgHdr::SetProperty(const char *propertyName, const nsAString &propertyStr) { - return m_mdb->SetPropertyFromNSString(m_mdbRow, propertyName, &propertyStr); + return m_mdb->SetPropertyFromNSString(m_mdbRow, propertyName, propertyStr); } NS_IMETHODIMP nsMsgHdr::SetStringProperty(const char *propertyName, const char *propertyValue) @@ -337,7 +337,7 @@ nsresult nsMsgHdr::ParseReferences(const char *references) return NS_OK; } -NS_IMETHODIMP nsMsgHdr::GetStringReference(PRInt32 refNum, nsCString &resultReference) +NS_IMETHODIMP nsMsgHdr::GetStringReference(PRInt32 refNum, nsACString& resultReference) { nsresult err = NS_OK; diff --git a/mozilla/mailnews/extensions/palmsync/src/PalmSyncImp.cpp b/mozilla/mailnews/extensions/palmsync/src/PalmSyncImp.cpp index 6c6e9ba106c..34f8fd7f816 100644 --- a/mozilla/mailnews/extensions/palmsync/src/PalmSyncImp.cpp +++ b/mozilla/mailnews/extensions/palmsync/src/PalmSyncImp.cpp @@ -242,7 +242,7 @@ STDMETHODIMP CPalmSyncImp::nsGetABList(BOOL aIsUnicode, short * aABListCount, { // convert uri to Unicode nsAutoString abUrl; - rv = ConvertToUnicode("UTF-8", uri.get(), abUrl); + rv = ConvertToUnicode("UTF-8", uri, abUrl); if (NS_FAILED(rv)) break; // add to the list @@ -252,15 +252,15 @@ STDMETHODIMP CPalmSyncImp::nsGetABList(BOOL aIsUnicode, short * aABListCount, else { // we need to convert uri to Unicode and then to ASCII nsAutoString abUUrl; - nsCAutoString abName(NS_ConvertUCS2toUTF8(description).get()); - rv = ConvertToUnicode("UTF-8", uri.get(), abUUrl); + rv = ConvertToUnicode("UTF-8", uri, abUUrl); if (NS_FAILED(rv)) break; - nsCAutoString abUrl(NS_ConvertUCS2toUTF8(abUUrl).get()); - CopyCString(&(serverDescList->lpszABName), abName); - CopyCString(&(serverDescList->lpszABUrl), abUrl); + CopyCString(&(serverDescList->lpszABName), + NS_ConvertUTF16toUTF8(description)); + CopyCString(&(serverDescList->lpszABUrl), + NS_ConvertUTF16toUTF8(abUUrl)); } serverDescList++; @@ -429,7 +429,7 @@ STDMETHODIMP CPalmSyncImp::nsRenameAB(BOOL aIsUnicode, long aCategoryIndex, LPTS return S_OK; } -void CPalmSyncImp::CopyUnicodeString(LPTSTR *destStr, nsString srcStr) +void CPalmSyncImp::CopyUnicodeString(LPTSTR *destStr, const nsAFlatString& srcStr) { if (!destStr) return; @@ -440,7 +440,7 @@ void CPalmSyncImp::CopyUnicodeString(LPTSTR *destStr, nsString srcStr) (*destStr)[length-1] = '\0'; } -void CPalmSyncImp::CopyCString(LPTSTR *destStr, nsCString srcStr) +void CPalmSyncImp::CopyCString(LPTSTR *destStr, const nsAFlatCString& srcStr) { if (!destStr) return; diff --git a/mozilla/mailnews/extensions/palmsync/src/PalmSyncImp.h b/mozilla/mailnews/extensions/palmsync/src/PalmSyncImp.h index feb2ccce80f..38d7b4cfd25 100644 --- a/mozilla/mailnews/extensions/palmsync/src/PalmSyncImp.h +++ b/mozilla/mailnews/extensions/palmsync/src/PalmSyncImp.h @@ -102,8 +102,8 @@ public : private : PRInt32 m_cRef; void * m_PalmHotSync; - void CopyUnicodeString(LPTSTR *destStr, nsString srcStr); - void CopyCString(LPTSTR *destStr, nsCString srcStr); + void CopyUnicodeString(LPTSTR *destStr, const nsAFlatString& srcStr); + void CopyCString(LPTSTR *destStr, const nsAFlatCString& srcStr); }; #endif // MSG_MAPI_IMP_H diff --git a/mozilla/mailnews/extensions/smime/src/nsSMimeJSHelper.cpp b/mozilla/mailnews/extensions/smime/src/nsSMimeJSHelper.cpp index fc2e90c6800..783546fce31 100644 --- a/mozilla/mailnews/extensions/smime/src/nsSMimeJSHelper.cpp +++ b/mozilla/mailnews/extensions/smime/src/nsSMimeJSHelper.cpp @@ -393,15 +393,15 @@ nsresult nsSMimeJSHelper::getMailboxList(nsIMsgCompFields *compFields, PRUint32 nsXPIDLString to, cc, bcc; nsXPIDLCString ng; - res = compFields->GetTo(getter_Copies(to)); + res = compFields->GetTo(to); if (NS_FAILED(res)) return res; - res = compFields->GetCc(getter_Copies(cc)); + res = compFields->GetCc(cc); if (NS_FAILED(res)) return res; - res = compFields->GetBcc(getter_Copies(bcc)); + res = compFields->GetBcc(bcc); if (NS_FAILED(res)) return res; diff --git a/mozilla/mailnews/imap/public/nsIImapIncomingServer.idl b/mozilla/mailnews/imap/public/nsIImapIncomingServer.idl index e64f0ad5040..0164cbea8d7 100644 --- a/mozilla/mailnews/imap/public/nsIImapIncomingServer.idl +++ b/mozilla/mailnews/imap/public/nsIImapIncomingServer.idl @@ -96,7 +96,6 @@ interface nsIImapIncomingServer : nsISupports { void pseudoInterruptMsgLoad(in nsIMsgFolder aImapFolder, in nsIMsgWindow aMsgWindow, out boolean interrupted); void ResetConnection(in string folderName); void CloseConnectionForFolder(in nsIMsgFolder aMsgFolder); - void CreatePRUnicharStringFromUTF7(in string aSourceString, out wstring aUnicodeStr); void reDiscoverAllFolders(); nsIURI subscribeToFolder(in wstring name, in boolean subscribe); nsIMsgFolder GetReadMailPFC(in boolean createIfMissing); diff --git a/mozilla/mailnews/imap/src/nsImapIncomingServer.cpp b/mozilla/mailnews/imap/src/nsImapIncomingServer.cpp index e42ec319c0a..15fbf60532f 100644 --- a/mozilla/mailnews/imap/src/nsImapIncomingServer.cpp +++ b/mozilla/mailnews/imap/src/nsImapIncomingServer.cpp @@ -79,7 +79,6 @@ #include "nsIMsgMailNewsUrl.h" #include "nsIImapService.h" #include "nsMsgI18N.h" -#include "nsMsgUtf7Utils.h" #include "nsAutoLock.h" #include "nsIImapMockChannel.h" #include "nsIPrompt.h" @@ -1143,7 +1142,7 @@ NS_IMETHODIMP nsImapIncomingServer::PossibleImapMailbox(const char *folderPath, PRBool isNamespace = PR_FALSE; PRBool noSelect = PR_FALSE; - rv = a_nsIFolder->FindSubFolder(dupFolderPath.get(), getter_AddRefs(msgFolder)); + rv = a_nsIFolder->FindSubFolder(dupFolderPath, getter_AddRefs(msgFolder)); NS_ENSURE_SUCCESS(rv,rv); m_subscribeFolders.AppendObject(msgFolder); noSelect = (boxFlags & kNoselect) != 0; @@ -1296,7 +1295,7 @@ NS_IMETHODIMP nsImapIncomingServer::PossibleImapMailbox(const char *folderPath, imapFolder->SetOnlineName(dupFolderPath.get()); if (hierarchyDelimiter != '/') nsImapUrl::UnescapeSlashes(folderName.BeginWriting()); - if (NS_SUCCEEDED(CreatePRUnicharStringFromUTF7(folderName.get(), getter_Copies(unicodeName)))) + if (NS_SUCCEEDED(CopyMUTF7toUTF16(folderName, unicodeName))) child->SetPrettyName(unicodeName); // Call ConvertFolderName() and HideFolderName() to do special folder name // mapping and hiding, if configured to do so. For example, need to hide AOL's @@ -1709,7 +1708,7 @@ NS_IMETHODIMP nsImapIncomingServer::FolderVerifiedOnline(const char *folderName if (NS_SUCCEEDED(rv) && rootFolder) { nsCOMPtr aFolder; - rv = rootFolder->FindSubFolder(folderName, getter_AddRefs(aFolder)); + rv = rootFolder->FindSubFolder(nsDependentCString(folderName), getter_AddRefs(aFolder)); if (NS_SUCCEEDED(rv) && aFolder) { nsCOMPtr imapFolder = do_QueryInterface(aFolder); @@ -2522,11 +2521,6 @@ NS_IMETHODIMP nsImapIncomingServer::RemoveChannelFromUrl(nsIMsgMailNewsUrl *aUrl return rv; } -NS_IMETHODIMP nsImapIncomingServer::CreatePRUnicharStringFromUTF7(const char * aSourceString, PRUnichar **aUnicodeStr) -{ - return CreateUnicodeStringFromUtf7(aSourceString, aUnicodeStr); -} - nsresult nsImapIncomingServer::RequestOverrideInfo(nsIMsgWindow *aMsgWindow) { @@ -3040,12 +3034,13 @@ nsImapIncomingServer::SubscribeToFolder(const PRUnichar *aName, PRBool subscribe // Locate the folder so that the correct hierarchical delimiter is used in the // folder pathnames, otherwise root's (ie, '^') is used and this is wrong. - nsCAutoString folderCName; - folderCName.AppendWithConversion(aName); + + // aName is not a genuine UTF-16 but just a zero-padded modified UTF-7 + NS_LossyConvertUTF16toASCII folderCName(aName); nsCOMPtr msgFolder; if (rootMsgFolder && aName && (*aName)) { - rv = rootMsgFolder->FindSubFolder(folderCName.get(), getter_AddRefs(msgFolder)); + rv = rootMsgFolder->FindSubFolder(folderCName, getter_AddRefs(msgFolder)); } nsCOMPtr queue; @@ -3057,12 +3052,10 @@ nsImapIncomingServer::SubscribeToFolder(const PRUnichar *aName, PRBool subscribe rv = pEventQService->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(queue)); if (NS_FAILED(rv)) return rv; - // ok, aName is really a fake unicode name, - // just a utf-7 encoded ascii string 0 byte extended to unicode. So convert it - // to real unicode, and pass that into the subscribe routines. - nsXPIDLString unicodeName; - CreateUnicodeStringFromUtf7(folderCName.get(), getter_Copies(unicodeName)); - // we need to convert aName, which is utf-7 encoded, to unicode + nsAutoString unicodeName; + rv = CopyMUTF7toUTF16(folderCName, unicodeName); + NS_ENSURE_SUCCESS(rv, rv); + if (subscribe) rv = imapService->SubscribeFolder(queue, msgFolder, unicodeName.get(), nsnull, aUri); else @@ -3794,16 +3787,16 @@ NS_IMETHODIMP nsImapIncomingServer::SetTrashFolderName(const PRUnichar *chvalue) nsresult rv = GetTrashFolderName(getter_Copies(oldTrashName)); if (NS_SUCCEEDED(rv)) { - char *oldTrashNameUtf7 = CreateUtf7ConvertedStringFromUnicode(oldTrashName); - if (oldTrashNameUtf7) + nsCAutoString oldTrashNameUtf7; + rv = CopyUTF16toMUTF7(oldTrashName, oldTrashNameUtf7); + if (NS_SUCCEEDED(rv)) { nsCOMPtr oldFolder; - rv = GetFolder(oldTrashNameUtf7, getter_AddRefs(oldFolder)); + rv = GetFolder(oldTrashNameUtf7.get(), getter_AddRefs(oldFolder)); if (NS_SUCCEEDED(rv) && oldFolder) { oldFolder->ClearFlag(MSG_FOLDER_FLAG_TRASH); } - PR_Free(oldTrashNameUtf7); } } diff --git a/mozilla/mailnews/imap/src/nsImapMailFolder.cpp b/mozilla/mailnews/imap/src/nsImapMailFolder.cpp index 0072032f667..517b1775807 100644 --- a/mozilla/mailnews/imap/src/nsImapMailFolder.cpp +++ b/mozilla/mailnews/imap/src/nsImapMailFolder.cpp @@ -70,7 +70,7 @@ #include "nsTextFormatter.h" #include "nsIPrefBranch.h" #include "nsIPrefService.h" -#include "nsMsgUtf7Utils.h" +#include "nsMsgI18N.h" #include "nsICacheSession.h" #include "nsEscape.h" #include "nsIDOMWindowInternal.h" @@ -319,7 +319,7 @@ nsShouldIgnoreFile(nsString& name) return PR_TRUE; } -NS_IMETHODIMP nsImapMailFolder::AddSubfolderWithPath(nsAutoString *name, nsIFileSpec *dbPath, +NS_IMETHODIMP nsImapMailFolder::AddSubfolderWithPath(nsAString& name, nsIFileSpec *dbPath, nsIMsgFolder **child) { if(!child) @@ -334,7 +334,7 @@ NS_IMETHODIMP nsImapMailFolder::AddSubfolderWithPath(nsAutoString *name, nsIFile PRInt32 flags = 0; nsCAutoString uri = mURI + NS_LITERAL_CSTRING("/"); - AppendUTF16toUTF8(*name, uri); + AppendUTF16toUTF8(name, uri); //will make sure mSubFolders does not have duplicates because of bogus msf files. @@ -375,22 +375,22 @@ NS_IMETHODIMP nsImapMailFolder::AddSubfolderWithPath(nsAutoString *name, nsIFile if(NS_SUCCEEDED(rv)) { if(isServer && - name->Equals(NS_LITERAL_STRING("Inbox"), + name.Equals(NS_LITERAL_STRING("Inbox"), nsCaseInsensitiveStringComparator())) flags |= MSG_FOLDER_FLAG_INBOX; else if(isServer || isParentInbox) { nsAutoString trashName; GetTrashFolderName(trashName); - if (name->Equals(trashName)) + if (name.Equals(trashName)) flags |= MSG_FOLDER_FLAG_TRASH; } #if 0 - else if(name->Equals(NS_LITERAL_STRING("Sent"), nsCaseInsensitiveStringComparator())) + else if(name.Equals(NS_LITERAL_STRING("Sent"), nsCaseInsensitiveStringComparator())) folder->SetFlag(MSG_FOLDER_FLAG_SENTMAIL); - else if(name->Equals(NS_LITERAL_STRING("Drafts"), nsCaseInsensitiveStringComparator())) + else if(name.Equals(NS_LITERAL_STRING("Drafts"), nsCaseInsensitiveStringComparator())) folder->SetFlag(MSG_FOLDER_FLAG_DRAFTS); - else if (name->Equals(NS_LITERAL_STRING("Templates"), nsCaseInsensitiveStringComparator())) + else if (name.Equals(NS_LITERAL_STRING("Templates"), nsCaseInsensitiveStringComparator())) folder->SetFlag(MSG_FOLDER_FLAG_TEMPLATES); #endif } @@ -487,8 +487,11 @@ nsresult nsImapMailFolder::CreateSubFolders(nsFileSpec &path) else { rv = imapServer->ConvertFolderName(onlineFullUtf7Name.get(), getter_Copies(unicodeName)); - if (NS_FAILED(rv)) - imapServer->CreatePRUnicharStringFromUTF7(onlineFullUtf7Name, getter_Copies(unicodeName)); + if (NS_FAILED(rv)) { + rv = CopyMUTF7toUTF16(onlineFullUtf7Name, unicodeName); + if (NS_FAILED(rv)) // XXX Does this make sense? + CopyASCIItoUTF16(onlineFullUtf7Name, unicodeName); + } } } @@ -501,7 +504,7 @@ nsresult nsImapMailFolder::CreateSubFolders(nsFileSpec &path) currentFolderNameStr.Cut(0, leafPos + 1); // take the utf7 full online name, and determine the utf7 leaf name - utf7LeafName.AssignWithConversion(onlineFullUtf7Name); + CopyASCIItoUTF16(onlineFullUtf7Name, utf7LeafName); leafPos = utf7LeafName.RFindChar(delimiter); if (leafPos > 0) utf7LeafName.Cut(0, leafPos + 1); @@ -519,7 +522,7 @@ nsresult nsImapMailFolder::CreateSubFolders(nsFileSpec &path) msfFileSpec->SetLeafName(leafName.get()); } // use the utf7 name as the uri for the folder. - AddSubfolderWithPath(&utf7LeafName, msfFileSpec, getter_AddRefs(child)); + AddSubfolderWithPath(utf7LeafName, msfFileSpec, getter_AddRefs(child)); if (child) { // use the unicode name as the "pretty" name. Set it so it won't be @@ -817,7 +820,7 @@ NS_IMETHODIMP nsImapMailFolder::CreateClientSubfolderInfo(const char *folderName if(NS_FAILED(rv)) return rv; - nsAutoString leafName; leafName.AssignWithConversion(folderName); + NS_ConvertASCIItoUTF16 leafName(folderName); nsAutoString folderNameStr; nsAutoString parentName = leafName; PRInt32 folderStart = leafName.FindChar('/'); @@ -886,7 +889,7 @@ NS_IMETHODIMP nsImapMailFolder::CreateClientSubfolderInfo(const char *folderName // } //Now let's create the actual new folder - rv = AddSubfolderWithPath(&folderNameStr, dbFileSpec, getter_AddRefs(child)); + rv = AddSubfolderWithPath(folderNameStr, dbFileSpec, getter_AddRefs(child)); // if (NS_SUCCEEDED(rv) && child) // child->SetPath(dbFileSpec); @@ -904,7 +907,7 @@ NS_IMETHODIMP nsImapMailFolder::CreateClientSubfolderInfo(const char *folderName child->SetFlag(MSG_FOLDER_FLAG_ELIDED); nsXPIDLString unicodeName; - rv = CreateUnicodeStringFromUtf7(folderName, getter_Copies(unicodeName)); + rv = CopyMUTF7toUTF16(nsDependentCString(folderName), unicodeName); if (NS_SUCCEEDED(rv)) child->SetPrettyName(unicodeName); @@ -914,7 +917,7 @@ NS_IMETHODIMP nsImapMailFolder::CreateClientSubfolderInfo(const char *folderName if (folderInfo) { nsAutoString unicodeOnlineName; unicodeOnlineName.AssignWithConversion(onlineName.get()); - folderInfo->SetMailboxName(&unicodeOnlineName); + folderInfo->SetMailboxName(unicodeOnlineName); } } @@ -1856,8 +1859,8 @@ NS_IMETHODIMP nsImapMailFolder::SetOnlineName(const char * aOnlineFolderName) if(NS_SUCCEEDED(rv) && folderInfo) { nsAutoString onlineName; onlineName.AssignWithConversion(aOnlineFolderName); - rv = folderInfo->SetProperty("onlineName", &onlineName); - rv = folderInfo->SetMailboxName(&onlineName); + rv = folderInfo->SetProperty("onlineName", onlineName); + rv = folderInfo->SetMailboxName(onlineName); // so, when are we going to commit this? Definitely not every time! // We could check if the online name has changed. db->Commit(nsMsgDBCommitType::kLargeCommit); @@ -1905,7 +1908,7 @@ nsImapMailFolder::GetDBFolderInfoAndDB(nsIDBFolderInfo **folderInfo, nsIMsgDatab { nsAutoString autoOnlineName; // autoOnlineName.AssignWithConversion(name); - (*folderInfo)->GetMailboxName(&autoOnlineName); + (*folderInfo)->GetMailboxName(autoOnlineName); if (autoOnlineName.IsEmpty()) { nsXPIDLCString uri; @@ -1922,7 +1925,7 @@ nsImapMailFolder::GetDBFolderInfoAndDB(nsIDBFolderInfo **folderInfo, nsIMsgDatab m_onlineFolderName.Assign(onlineCName); autoOnlineName.AssignWithConversion(onlineCName.get()); } - rv = (*folderInfo)->SetProperty("onlineName", &autoOnlineName); + rv = (*folderInfo)->SetProperty("onlineName", autoOnlineName); } } } @@ -5222,7 +5225,7 @@ NS_IMETHODIMP nsImapMailFolder::GetAclFlags(PRUint32 *aclFlags) rv = mDatabase->GetDBFolderInfo(getter_AddRefs(dbFolderInfo)); if (NS_SUCCEEDED(rv) && dbFolderInfo) { - rv = dbFolderInfo->GetUint32Property("aclFlags", aclFlags, 0); + rv = dbFolderInfo->GetUint32Property("aclFlags", 0, aclFlags); m_aclFlags = *aclFlags; } } @@ -5267,7 +5270,7 @@ nsresult nsImapMailFolder::GetSupportedUserFlags(PRUint32 *userFlags) rv = mDatabase->GetDBFolderInfo(getter_AddRefs(dbFolderInfo)); if (NS_SUCCEEDED(rv) && dbFolderInfo) { - rv = dbFolderInfo->GetUint32Property("imapFlags", userFlags, 0); + rv = dbFolderInfo->GetUint32Property("imapFlags", 0, userFlags); m_supportedUserFlags = *userFlags; } } @@ -7190,11 +7193,11 @@ NS_IMETHODIMP nsImapMailFolder::RenameClient(nsIMsgWindow *msgWindow, nsIMsgFold rv = unusedDB->GetDBFolderInfo(getter_AddRefs(folderInfo)); //Now let's create the actual new folder - rv = AddSubfolderWithPath(&folderNameStr, dbFileSpec, getter_AddRefs(child)); + rv = AddSubfolderWithPath(folderNameStr, dbFileSpec, getter_AddRefs(child)); if (!child || NS_FAILED(rv)) return rv; nsXPIDLString unicodeName; - rv = CreateUnicodeStringFromUtf7(proposedDBName.get(), getter_Copies(unicodeName)); - if (NS_SUCCEEDED(rv) && unicodeName) + rv = CopyMUTF7toUTF16(proposedDBName, unicodeName); + if (NS_SUCCEEDED(rv)) child->SetName(unicodeName); imapFolder = do_QueryInterface(child); @@ -7215,7 +7218,7 @@ NS_IMETHODIMP nsImapMailFolder::RenameClient(nsIMsgWindow *msgWindow, nsIMsgFold if (folderInfo) { nsAutoString unicodeOnlineName; unicodeOnlineName.AssignWithConversion(onlineName.get()); - folderInfo->SetMailboxName(&unicodeOnlineName); + folderInfo->SetMailboxName(unicodeOnlineName); } PRBool changed = PR_FALSE; msgFolder->MatchOrChangeFilterDestination(child, PR_FALSE /*caseInsensitive*/, &changed); @@ -7307,11 +7310,14 @@ NS_IMETHODIMP nsImapMailFolder::RenameSubFolders(nsIMsgWindow *msgWindow, nsIMsg if (folderName.IsEmpty() || NS_FAILED(rv)) return rv; nsXPIDLCString utf7LeafName; - utf7LeafName.Adopt(CreateUtf7ConvertedStringFromUnicode(folderName.get())); - nsAutoString unicodeLeafName; - unicodeLeafName.AssignWithConversion(utf7LeafName.get()); + rv = CopyUTF16toMUTF7(folderName, utf7LeafName); + NS_ENSURE_SUCCESS(rv, rv); - rv = AddSubfolderWithPath(&unicodeLeafName, dbFileSpec, getter_AddRefs(child)); + // XXX : Fix this non-sense by fixing AddSubfolderWithPath + nsAutoString unicodeLeafName; + CopyASCIItoUTF16(utf7LeafName, unicodeLeafName); + + rv = AddSubfolderWithPath(unicodeLeafName, dbFileSpec, getter_AddRefs(child)); if (!child || NS_FAILED(rv)) return rv; diff --git a/mozilla/mailnews/imap/src/nsImapMailFolder.h b/mozilla/mailnews/imap/src/nsImapMailFolder.h index 26d3d99b20e..75ccd61f475 100644 --- a/mozilla/mailnews/imap/src/nsImapMailFolder.h +++ b/mozilla/mailnews/imap/src/nsImapMailFolder.h @@ -214,7 +214,7 @@ public: NS_IMETHOD UpdateFolder(nsIMsgWindow *aWindow); NS_IMETHOD CreateSubfolder(const PRUnichar *folderName,nsIMsgWindow *msgWindow ); - NS_IMETHOD AddSubfolderWithPath(nsAutoString *name, nsIFileSpec *dbPath, nsIMsgFolder **child); + NS_IMETHOD AddSubfolderWithPath(nsAString& name, nsIFileSpec *dbPath, nsIMsgFolder **child); NS_IMETHODIMP CreateStorageIfMissing(nsIUrlListener* urlListener); NS_IMETHOD Compact(nsIUrlListener *aListener, nsIMsgWindow *aMsgWindow); diff --git a/mozilla/mailnews/imap/src/nsImapProtocol.cpp b/mozilla/mailnews/imap/src/nsImapProtocol.cpp index fc688e4f3e9..3ad7b2f8a3f 100644 --- a/mozilla/mailnews/imap/src/nsImapProtocol.cpp +++ b/mozilla/mailnews/imap/src/nsImapProtocol.cpp @@ -81,7 +81,7 @@ #include "nsAutoLock.h" #include "nsIDNSService.h" #include "nsIMsgHdr.h" -#include "nsMsgUtf7Utils.h" +#include "nsMsgI18N.h" #include "nsEscape.h" // for the memory cache... #include "nsICacheEntryDescriptor.h" @@ -4496,7 +4496,8 @@ nsImapProtocol::ShowProgress() nsXPIDLString unicodeMailboxName; - nsresult rv = CreateUnicodeStringFromUtf7(mailboxName, getter_Copies(unicodeMailboxName)); + nsresult rv = CopyMUTF7toUTF16(nsDependentCString(mailboxName), + unicodeMailboxName); if (NS_SUCCEEDED(rv)) { // ### should convert mailboxName to PRUnichar and change %s to %S in msg text @@ -4527,10 +4528,8 @@ nsImapProtocol::ProgressEventFunctionUsingIdWithString(PRUint32 aMsgId, const { if (m_imapMiscellaneousSink) { - nsXPIDLString unicodeStr; - - nsresult rv = CreateUnicodeStringFromUtf7(aExtraInfo, getter_Copies(unicodeStr)); + nsresult rv = CopyMUTF7toUTF16(nsDependentCString(aExtraInfo), unicodeStr); if (NS_SUCCEEDED(rv)) m_imapMiscellaneousSink->ProgressStatus(this, aMsgId, unicodeStr); } @@ -4574,49 +4573,6 @@ nsImapProtocol::PercentProgressUpdateEvent(PRUnichar *message, PRInt32 currentPr m_imapMiscellaneousSink->PercentProgress(this, &aProgressInfo); } - -/* static */PRUnichar * nsImapProtocol::CreatePRUnicharStringFromUTF7(const char * aSourceString) -{ - PRUnichar *convertedString = NULL; - nsresult res; - - nsCOMPtr ccm = - do_GetService(kCharsetConverterManagerCID, &res); - - if(NS_SUCCEEDED(res) && (nsnull != ccm)) - { - PRUnichar *unichars = nsnull; - PRInt32 unicharLength; - - // convert utf7 to unicode - nsIUnicodeDecoder* decoder = nsnull; - - res = ccm->GetUnicodeDecoderRaw("x-imap4-modified-utf7", &decoder); - if(NS_SUCCEEDED(res) && (nsnull != decoder)) - { - PRInt32 srcLen = PL_strlen(aSourceString); - res = decoder->GetMaxLength(aSourceString, srcLen, &unicharLength); - // temporary buffer to hold unicode string - unichars = new PRUnichar[unicharLength + 1]; - if (unichars == nsnull) - { - res = NS_ERROR_OUT_OF_MEMORY; - } - else - { - res = decoder->Convert(aSourceString, &srcLen, unichars, &unicharLength); - unichars[unicharLength] = 0; - } - NS_IF_RELEASE(decoder); - // convert the unicode to 8 bit ascii. - nsString unicodeStr(unichars); - convertedString = ToNewUnicode(unicodeStr); - } - } - return convertedString; -} - - // imap commands issued by the parser void nsImapProtocol::Store(const char * messageList, const char * messageData, @@ -6620,12 +6576,7 @@ const char * nsImapProtocol::GetTrashFolderName() nsXPIDLString trashFolderName; if (NS_SUCCEEDED(server->GetTrashFolderName(getter_Copies(trashFolderName)))) { - char *trashFolderNameUtf7 = CreateUtf7ConvertedStringFromUnicode(trashFolderName); - if (trashFolderNameUtf7) - { - m_trashFolderName.Assign(trashFolderNameUtf7); - PR_Free(trashFolderNameUtf7); - } + CopyUTF16toMUTF7(trashFolderName, m_trashFolderName); } } } diff --git a/mozilla/mailnews/imap/src/nsImapProtocol.h b/mozilla/mailnews/imap/src/nsImapProtocol.h index 05f424f2070..448b4e62c12 100644 --- a/mozilla/mailnews/imap/src/nsImapProtocol.h +++ b/mozilla/mailnews/imap/src/nsImapProtocol.h @@ -297,8 +297,6 @@ public: // utility function calls made by the server - static PRUnichar * CreatePRUnicharStringFromUTF7(const char * aSourceString); - void Copy(const char * messageList, const char *destinationMailbox, PRBool idsAreUid); void Search(const char * searchCriteria, PRBool useUID, diff --git a/mozilla/mailnews/imap/src/nsImapService.cpp b/mozilla/mailnews/imap/src/nsImapService.cpp index 5b2e9577bc1..79173ba3bce 100644 --- a/mozilla/mailnews/imap/src/nsImapService.cpp +++ b/mozilla/mailnews/imap/src/nsImapService.cpp @@ -81,7 +81,7 @@ #include "nsICacheService.h" #include "nsIStreamListenerTee.h" #include "nsNetCID.h" -#include "nsMsgUtf7Utils.h" +#include "nsMsgI18N.h" #include "nsIOutputStream.h" #include "nsIInputStream.h" #include "nsICopyMsgStreamListener.h" @@ -101,7 +101,6 @@ #include "nsIMsgMailSession.h" #include "nsIStreamConverterService.h" - #define PREF_MAIL_ROOT_IMAP "mail.root.imap" // old - for backward compatibility only #define PREF_MAIL_ROOT_IMAP_REL "mail.root.imap-rel" @@ -2369,26 +2368,27 @@ nsImapService::RenameLeaf(nsIEventQueue* eventQueue, nsIMsgFolder* srcFolder, urlSpec.Append('>'); urlSpec.Append(char(hierarchySeparator)); - char *utfNewName = CreateUtf7ConvertedStringFromUnicode( newLeafName); - nsCAutoString cStrFolderName(NS_STATIC_CAST(const char *, folderName)); - // Unescape the name before looking for parent path - nsUnescape(cStrFolderName.BeginWriting()); - PRInt32 leafNameStart = + nsCAutoString cStrFolderName(NS_STATIC_CAST(const char *, folderName)); + // Unescape the name before looking for parent path + nsUnescape(cStrFolderName.BeginWriting()); + PRInt32 leafNameStart = cStrFolderName.RFindChar(hierarchySeparator); if (leafNameStart != -1) { cStrFolderName.SetLength(leafNameStart+1); urlSpec.Append(cStrFolderName); } - char *escapedNewName = nsEscape(utfNewName, url_Path); + + nsCAutoString utfNewName; + CopyUTF16toMUTF7(nsDependentString(newLeafName), utfNewName); + char* escapedNewName = nsEscape(utfNewName.get(), url_Path); if (!escapedNewName) return NS_ERROR_OUT_OF_MEMORY; nsXPIDLCString escapedSlashName; - rv = nsImapUrl::EscapeSlashes((const char *) escapedNewName, getter_Copies(escapedSlashName)); - if (!escapedSlashName) return NS_ERROR_OUT_OF_MEMORY; - urlSpec.Append(escapedSlashName.get()); + rv = nsImapUrl::EscapeSlashes(escapedNewName, getter_Copies(escapedSlashName)); + NS_ENSURE_SUCCESS(rv, rv); nsCRT::free(escapedNewName); - nsCRT::free(utfNewName); + urlSpec.Append(escapedSlashName.get()); rv = uri->SetSpec(urlSpec); if (NS_SUCCEEDED(rv)) @@ -2436,11 +2436,13 @@ nsImapService::CreateFolder(nsIEventQueue* eventQueue, nsIMsgFolder* parent, urlSpec.Append((const char *) canonicalName); urlSpec.Append(char(hierarchySeparator)); } - char *utfNewName = CreateUtf7ConvertedStringFromUnicode( newFolderName); - char *escapedFolderName = nsEscape(utfNewName, url_Path); + + nsCAutoString utfNewName; + rv = CopyUTF16toMUTF7(nsDependentString(newFolderName), utfNewName); + NS_ENSURE_SUCCESS(rv, rv); + char* escapedFolderName = nsEscape(utfNewName.get(), url_Path); urlSpec.Append(escapedFolderName); nsCRT::free(escapedFolderName); - nsCRT::free(utfNewName); rv = uri->SetSpec(urlSpec); if (NS_SUCCEEDED(rv)) @@ -2484,11 +2486,11 @@ nsImapService::EnsureFolderExists(nsIEventQueue* eventQueue, nsIMsgFolder* paren urlSpec.Append((const char *) folderName); urlSpec.Append(char(hierarchySeparator)); } - char *utfNewName = CreateUtf7ConvertedStringFromUnicode( newFolderName); - char *escapedFolderName = nsEscape(utfNewName, url_Path); + nsCAutoString utfNewName; + CopyUTF16toMUTF7(nsDependentString(newFolderName), utfNewName); + char* escapedFolderName = nsEscape(utfNewName.get(), url_Path); urlSpec.Append(escapedFolderName); - nsCRT::free(escapedFolderName); - nsCRT::free(utfNewName); + nsCRT::free(escapedFolderName); rv = uri->SetSpec(urlSpec); if (NS_SUCCEEDED(rv)) @@ -2631,7 +2633,6 @@ nsresult nsImapService::GetServerFromUrl(nsIImapUrl *aImapUrl, nsIMsgIncomingSer { nsCAutoString userPass; nsCAutoString hostName; - nsXPIDLCString folderName; nsCOMPtr mailnewsUrl = do_QueryInterface(aImapUrl); // extract the user name and host name information... @@ -2643,6 +2644,8 @@ nsresult nsImapService::GetServerFromUrl(nsIImapUrl *aImapUrl, nsIMsgIncomingSer if (!userPass.IsEmpty()) NS_UnescapeURL(userPass); // hopefully we're not unescaping ':' or nasty control chars + nsXPIDLCString folderName; + // if we can't get a folder name out of the url then I think this is an error aImapUrl->CreateCanonicalSourceFolderPathString(getter_Copies(folderName)); if (folderName.IsEmpty()) @@ -2701,7 +2704,6 @@ NS_IMETHODIMP nsImapService::NewURI(const nsACString &aSpec, } nsXPIDLCString folderName; - nsXPIDLCString urlPath; // if we can't get a folder name out of the url then I think this is an error aImapUrl->CreateCanonicalSourceFolderPathString(getter_Copies(folderName)); @@ -2855,8 +2857,9 @@ NS_IMETHODIMP nsImapService::NewChannel(nsIURI *aURI, nsIChannel **_retval) rv = IMAPGetStringBundle(getter_AddRefs(bundle)); NS_ENSURE_SUCCESS(rv, rv); // need to convert folder name from mod-utf7 to unicode - nsXPIDLString unescapedName; - CreateUnicodeStringFromUtf7(fullFolderName, getter_Copies(unescapedName)); + nsAutoString unescapedName; + if (NS_FAILED(CopyMUTF7toUTF16(nsDependentCString(fullFolderName), unescapedName))) + CopyASCIItoUTF16(nsDependentCString(fullFolderName), unescapedName); const PRUnichar *formatStrings[1] = { unescapedName.get() }; rv = bundle->FormatStringFromID(IMAP_SUBSCRIBE_PROMPT, @@ -3149,7 +3152,7 @@ nsImapService::GetListOfFoldersWithPath(nsIImapIncomingServer *aServer, nsIMsgWi changedStr.Append(remStr); - rv = rootMsgFolder->FindSubFolder(changedStr.get(), getter_AddRefs(msgFolder)); + rv = rootMsgFolder->FindSubFolder(changedStr, getter_AddRefs(msgFolder)); } rv = DiscoverChildren(queue, msgFolder, listener, folderPath, nsnull); @@ -3215,12 +3218,12 @@ nsImapService::SubscribeFolder(nsIEventQueue* eventQueue, nsCOMPtr uri = do_QueryInterface(imapUrl); urlSpec.Append("/subscribe>"); urlSpec.Append(char(hierarchySeparator)); - char *utfFolderName = - CreateUtf7ConvertedStringFromUnicode(aFolderName); - char *escapedFolderName = nsEscape(utfFolderName, url_Path); + nsCAutoString utfFolderName; + rv = CopyUTF16toMUTF7(nsDependentString(aFolderName), utfFolderName); + NS_ENSURE_SUCCESS(rv, rv); + char* escapedFolderName = nsEscape(utfFolderName.get(), url_Path); urlSpec.Append(escapedFolderName); nsCRT::free(escapedFolderName); - nsCRT::free(utfFolderName); rv = uri->SetSpec(urlSpec); if (NS_SUCCEEDED(rv)) rv = GetImapConnectionAndLoadUrl(eventQueue, imapUrl, @@ -3254,12 +3257,12 @@ nsImapService::UnsubscribeFolder(nsIEventQueue* eventQueue, nsCOMPtr uri = do_QueryInterface(imapUrl); urlSpec.Append("/unsubscribe>"); urlSpec.Append(char(hierarchySeparator)); - char *utfFolderName = - CreateUtf7ConvertedStringFromUnicode(folderName); - char *escapedFolderName = nsEscape(utfFolderName, url_Path); + nsCAutoString utfFolderName; + rv = CopyUTF16toMUTF7(nsDependentString(folderName), utfFolderName); + NS_ENSURE_SUCCESS(rv, rv); + char* escapedFolderName = nsEscape(utfFolderName.get(), url_Path); urlSpec.Append(escapedFolderName); nsCRT::free(escapedFolderName); - nsCRT::free(utfFolderName); rv = uri->SetSpec(urlSpec); if (NS_SUCCEEDED(rv)) rv = GetImapConnectionAndLoadUrl(eventQueue, imapUrl, diff --git a/mozilla/mailnews/import/comm4x/src/nsComm4xMail.cpp b/mozilla/mailnews/import/comm4x/src/nsComm4xMail.cpp index f47b0348042..e1fe01197cb 100644 --- a/mozilla/mailnews/import/comm4x/src/nsComm4xMail.cpp +++ b/mozilla/mailnews/import/comm4x/src/nsComm4xMail.cpp @@ -48,6 +48,7 @@ #include "nsUnicharUtils.h" #include "Comm4xMailDebugLog.h" #include "prmem.h" +#include "nsNativeCharsetUtils.h" #define kCopyBufferSize 8192 #define kMailReadBufferSize 16384 @@ -168,7 +169,7 @@ nsresult nsComm4xMail::IterateMailDir(nsIFileSpec *pFolder, nsISupportsArray *pA rv = dir->GetCurrentSpec(getter_AddRefs(entry)); if (NS_SUCCEEDED(rv)) { rv = entry->GetLeafName(getter_Copies(pName)); - nsMsgGetNativePathString(pName.get(), currentFolderNameStr); + NS_CopyNativeToUnicode(pName, currentFolderNameStr); isFile = PR_FALSE; entry->IsFile(&isFile); if (isFile) { @@ -211,7 +212,7 @@ nsresult nsComm4xMail::FoundMailbox(nsIFileSpec *mailFile, nsAutoString *pName, if (!pPath.IsEmpty()) IMPORT_LOG2("Found comm4x mailbox: %s, m_depth = %d\n", pPath.get(), m_depth); else - IMPORT_LOG2("Can't get native path but found comm4x mailbox: %s, m_depth = %d\n", NS_ConvertUCS2toUTF8(*pName).get(), m_depth); + IMPORT_LOG2("Can't get native path but found comm4x mailbox: %s, m_depth = %d\n", NS_ConvertUTF16toUTF8(*pName).get(), m_depth); nsresult rv = pImport->CreateNewMailboxDescriptor(getter_AddRefs(desc)); if (NS_SUCCEEDED(rv)) { diff --git a/mozilla/mailnews/import/eudora/src/nsEudoraAddress.cpp b/mozilla/mailnews/import/eudora/src/nsEudoraAddress.cpp index c57ec73cb7b..86e6516b57c 100644 --- a/mozilla/mailnews/import/eudora/src/nsEudoraAddress.cpp +++ b/mozilla/mailnews/import/eudora/src/nsEudoraAddress.cpp @@ -25,6 +25,8 @@ #include "nsIServiceManager.h" #include "nsEudoraImport.h" #include "nsReadableUtils.h" +#include "nsMsgI18N.h" +#include "nsNativeCharsetUtils.h" #include "EudoraDebugLog.h" @@ -33,8 +35,8 @@ #define ADD_FIELD_TO_DB_ROW(pdb, func, dbRow, val, uniStr) \ if (!val.IsEmpty()) \ { \ - ConvertToUnicode(val.get(), uniStr); \ - pdb->func(dbRow, NS_ConvertUCS2toUTF8(uniStr).get()); \ + NS_CopyNativeToUnicode(val, uniStr); \ + pdb->func(dbRow, NS_ConvertUTF16toUTF8(uniStr).get());\ } diff --git a/mozilla/mailnews/import/eudora/src/nsEudoraCompose.cpp b/mozilla/mailnews/import/eudora/src/nsEudoraCompose.cpp index bb9f7dcc72b..d16d83a597d 100644 --- a/mozilla/mailnews/import/eudora/src/nsEudoraCompose.cpp +++ b/mozilla/mailnews/import/eudora/src/nsEudoraCompose.cpp @@ -570,19 +570,6 @@ nsMsgAttachedFile * nsEudoraCompose::GetLocalAttachments( void) return( a); } -void nsEudoraCompose::ConvertSysToUnicode( const char *pStr, nsString& uniStr) -{ - if (!m_pImportService) { - m_pImportService = do_GetService(NS_IMPORTSERVICE_CONTRACTID); - } - if (m_pImportService) { - m_pImportService->SystemStringToUnicode( pStr, uniStr); - } - else - uniStr.AssignWithConversion( pStr); -} - - // Test a message send???? nsresult nsEudoraCompose::SendTheMessage( nsIFileSpec *pMsg) { @@ -599,13 +586,13 @@ nsresult nsEudoraCompose::SendTheMessage( nsIFileSpec *pMsg) nsString headerVal; GetHeaderValue( m_pHeaders, m_headerLen, "From:", headerVal); if (!headerVal.IsEmpty()) - m_pMsgFields->SetFrom( headerVal.get()); + m_pMsgFields->SetFrom( headerVal); GetHeaderValue( m_pHeaders, m_headerLen, "To:", headerVal); if (!headerVal.IsEmpty()) - m_pMsgFields->SetTo( headerVal.get()); + m_pMsgFields->SetTo( headerVal); GetHeaderValue( m_pHeaders, m_headerLen, "Subject:", headerVal); if (!headerVal.IsEmpty()) - m_pMsgFields->SetSubject( headerVal.get()); + m_pMsgFields->SetSubject( headerVal); GetHeaderValue( m_pHeaders, m_headerLen, "Content-type:", headerVal); bodyType = headerVal; ExtractType( bodyType); @@ -633,13 +620,13 @@ nsresult nsEudoraCompose::SendTheMessage( nsIFileSpec *pMsg) charSet = headerVal; GetHeaderValue( m_pHeaders, m_headerLen, "CC:", headerVal); if (!headerVal.IsEmpty()) - m_pMsgFields->SetCc( headerVal.get()); + m_pMsgFields->SetCc( headerVal); GetHeaderValue( m_pHeaders, m_headerLen, "Message-ID:", headerVal); if (!headerVal.IsEmpty()) m_pMsgFields->SetMessageId( NS_LossyConvertUCS2toASCII(headerVal).get() ); GetHeaderValue( m_pHeaders, m_headerLen, "Reply-To:", headerVal); if (!headerVal.IsEmpty()) - m_pMsgFields->SetReplyTo( headerVal.get()); + m_pMsgFields->SetReplyTo( headerVal); // what about all of the other headers?!?!?!?!?!?! char *pMimeType = nsnull; @@ -660,20 +647,19 @@ nsresult nsEudoraCompose::SendTheMessage( nsIFileSpec *pMsg) */ nsString uniBody; - ConvertSysToUnicode( m_pBody, uniBody); + NS_CopyNativeToUnicode( nsDependentCString(m_pBody), uniBody); nsCString body; - nsCString theCharset; - theCharset.AssignWithConversion( charSet); - rv = nsMsgI18NConvertFromUnicode( theCharset, uniBody, body); + rv = nsMsgI18NConvertFromUnicode( NS_LossyConvertUTF16toASCII(charSet).get(), + uniBody, body); if (NS_FAILED( rv)) { // in this case, if we did not use the default compose // charset, then try that. if (!charSet.Equals( m_defCharset)) { - theCharset.AssignWithConversion( m_defCharset); body.Truncate(); - rv = nsMsgI18NConvertFromUnicode( theCharset, uniBody, body); + rv = nsMsgI18NConvertFromUnicode( NS_LossyConvertUTF16toASCII(charSet).get(), + uniBody, body); } } uniBody.Truncate(); @@ -683,12 +669,12 @@ nsresult nsEudoraCompose::SendTheMessage( nsIFileSpec *pMsg) // Eudora saves sent and draft msgs in Out folder (ie, mixed) and it does // store Bcc: header in the msg itself. nsMsgDeliverMode mode = nsIMsgSend::nsMsgDeliverNow; - PRUnichar *from, *to, *cc, *bcc; - rv = m_pMsgFields->GetFrom(&from); - rv = m_pMsgFields->GetTo(&to); - rv = m_pMsgFields->GetCc(&cc); - rv = m_pMsgFields->GetBcc(&bcc); - if ( (!from || !*from) || ((!to || !*to) && (!cc || !*cc) && (!bcc || !*bcc)) ) + nsAutoString from, to, cc, bcc; + rv = m_pMsgFields->GetFrom(from); + rv = m_pMsgFields->GetTo(to); + rv = m_pMsgFields->GetCc(cc); + rv = m_pMsgFields->GetBcc(bcc); + if ( from.IsEmpty() || to.IsEmpty() && cc.IsEmpty() && bcc.IsEmpty() ) mode = nsIMsgSend::nsMsgSaveAsDraft; if (NS_FAILED( rv)) { diff --git a/mozilla/mailnews/import/eudora/src/nsEudoraCompose.h b/mozilla/mailnews/import/eudora/src/nsEudoraCompose.h index fda9aa9af32..958858d1efb 100644 --- a/mozilla/mailnews/import/eudora/src/nsEudoraCompose.h +++ b/mozilla/mailnews/import/eudora/src/nsEudoraCompose.h @@ -26,6 +26,7 @@ #include "nsVoidArray.h" #include "nsISupportsArray.h" #include "nsIImportService.h" +#include "nsNativeCharsetUtils.h" class nsIMsgSend; @@ -130,7 +131,7 @@ private: val.Truncate(); nsCString hVal; GetHeaderValue( pData, dataLen, pHeader, hVal, PR_TRUE); - ConvertSysToUnicode( hVal.get(), val); + NS_CopyNativeToUnicode( hVal, val); } void ExtractCharset( nsString& str); void ExtractType( nsString& str); @@ -144,7 +145,6 @@ private: PRInt32 IsSpecialHeader( const char *pHeader); nsresult WriteHeaders( nsIFileSpec *pDst, SimpleBufferTonyRCopiedOnce& newHeaders); PRBool IsReplaceHeader( const char *pHeader); - void ConvertSysToUnicode( const char *pSysStr, nsString& uniStr); private: nsVoidArray * m_pAttachments; diff --git a/mozilla/mailnews/import/eudora/src/nsEudoraImport.cpp b/mozilla/mailnews/import/eudora/src/nsEudoraImport.cpp index 12bc85e304b..24fa0b1f4d2 100644 --- a/mozilla/mailnews/import/eudora/src/nsEudoraImport.cpp +++ b/mozilla/mailnews/import/eudora/src/nsEudoraImport.cpp @@ -177,26 +177,6 @@ private: PRUint32 m_bytes; }; -//////////////////////////////////////////////////////////////////////// -// Converter functions -//////////////////////////////////////////////////////////////////////// - -static nsCOMPtr gService; - -void ConvertToUnicode(const char *pStr, nsString &dist) -{ - nsresult rv = NS_OK; - - if (!gService) - gService = do_GetService(NS_IMPORTSERVICE_CONTRACTID); - - if (gService) - rv = gService->SystemStringToUnicode(pStr, dist); - - if (!gService || NS_FAILED(rv)) // XXX bad cast - dist.AssignWithConversion(pStr); -} - //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// diff --git a/mozilla/mailnews/import/eudora/src/nsEudoraImport.h b/mozilla/mailnews/import/eudora/src/nsEudoraImport.h index d30d3829d3f..e12384c6b20 100644 --- a/mozilla/mailnews/import/eudora/src/nsEudoraImport.h +++ b/mozilla/mailnews/import/eudora/src/nsEudoraImport.h @@ -33,10 +33,6 @@ #define kEudoraSupportsString NS_IMPORT_MAIL_STR "," NS_IMPORT_ADDRESS_STR "," NS_IMPORT_SETTINGS_STR - -void ConvertToUnicode(const char *pStr, nsString &dist); - - class nsEudoraImport : public nsIImportModule { public: diff --git a/mozilla/mailnews/import/eudora/src/nsEudoraMac.cpp b/mozilla/mailnews/import/eudora/src/nsEudoraMac.cpp index 350df548c70..3c5134dd7c1 100644 --- a/mozilla/mailnews/import/eudora/src/nsEudoraMac.cpp +++ b/mozilla/mailnews/import/eudora/src/nsEudoraMac.cpp @@ -343,11 +343,11 @@ nsresult nsEudoraMac::IterateMailDir( nsIFileSpec *pFolder, nsISupportsArray *pA nsresult nsEudoraMac::FoundMailbox( nsIFileSpec *mailFile, const char *pName, nsISupportsArray *pArray, nsIImportService *pImport) { - nsString displayName; + nsAutoString displayName; nsCOMPtr desc; nsISupports * pInterface; - ConvertToUnicode(pName, displayName); + NS_CopyNativeToUnicode(nsDependentCString(pName), displayName); #ifdef IMPORT_DEBUG char *pPath = nsnull; @@ -386,11 +386,11 @@ nsresult nsEudoraMac::FoundMailbox( nsIFileSpec *mailFile, const char *pName, ns nsresult nsEudoraMac::FoundMailFolder( nsIFileSpec *mailFolder, const char *pName, nsISupportsArray *pArray, nsIImportService *pImport) { - nsString displayName; + nsAutoString displayName; nsCOMPtr desc; nsISupports * pInterface; - ConvertToUnicode(pName, displayName); + NS_CopyNativeToUnicode(nsDependentCString(pName), displayName); #ifdef IMPORT_DEBUG char *pPath = nsnull; @@ -1297,7 +1297,7 @@ nsresult nsEudoraMac::FindAddressBooks( nsIFileSpec *pRoot, nsISupportsArray **p rv = spec->IsFile( &isFile); rv = spec->GetLeafName( &pName); if (pName) { - ConvertToUnicode(pName, displayName); + NS_CopyNativeToUnicode(nsDependentCString(pName), displayName); nsCRT::free( pName); } if (NS_SUCCEEDED( rv) && pName && isFile) { diff --git a/mozilla/mailnews/import/eudora/src/nsEudoraWin32.cpp b/mozilla/mailnews/import/eudora/src/nsEudoraWin32.cpp index 4e53979f3dd..c723daf0a95 100644 --- a/mozilla/mailnews/import/eudora/src/nsEudoraWin32.cpp +++ b/mozilla/mailnews/import/eudora/src/nsEudoraWin32.cpp @@ -420,7 +420,7 @@ nsresult nsEudoraWin32::FoundMailbox( nsIFileSpec *mailFile, const char *pName, nsCOMPtr desc; nsISupports * pInterface; - ConvertToUnicode(pName, displayName); + NS_CopyNativeToUnicode(nsDependentCString(pName), displayName); #ifdef IMPORT_DEBUG char *pPath = nsnull; @@ -463,7 +463,7 @@ nsresult nsEudoraWin32::FoundMailFolder( nsIFileSpec *mailFolder, const char *pN nsCOMPtr desc; nsISupports * pInterface; - ConvertToUnicode(pName, displayName); + NS_CopyNativeToUnicode(nsDependentCString(pName), displayName); #ifdef IMPORT_DEBUG char *pPath = nsnull; @@ -1371,7 +1371,7 @@ nsresult nsEudoraWin32::FoundAddressBook( nsIFileSpec *spec, const PRUnichar *pN return( rv); if (!pLeaf) return( NS_ERROR_FAILURE); - ConvertToUnicode(pLeaf, name); + NS_CopyNativeToUnicode(nsDependentCString(pLeaf), name); nsCRT::free( pLeaf); nsString tStr; name.Right( tStr, 4); diff --git a/mozilla/mailnews/import/oexpress/nsOEScanBoxes.cpp b/mozilla/mailnews/import/oexpress/nsOEScanBoxes.cpp index 09da8c7e2e3..b10e3e3716a 100644 --- a/mozilla/mailnews/import/oexpress/nsOEScanBoxes.cpp +++ b/mozilla/mailnews/import/oexpress/nsOEScanBoxes.cpp @@ -45,6 +45,8 @@ #include "OEDebugLog.h" +#include "nsNativeCharsetUtils.h" + /* .nch file format??? @@ -76,23 +78,6 @@ nsOEScanBoxes::~nsOEScanBoxes() } } - -// convert methods -void nsOEScanBoxes::ConvertToUnicode(const char *pStr, nsString &dist) -{ - nsresult rv = NS_OK; - - if (!mService) - mService = do_GetService(NS_IMPORTSERVICE_CONTRACTID); - - if (mService) - rv = mService->SystemStringToUnicode(pStr, dist); - - if (!mService || NS_FAILED(rv)) // XXX bad cast - dist.AssignWithConversion(pStr); -} - - /* 3.x & 4.x registry Software/Microsoft/Outlook Express/ @@ -490,7 +475,7 @@ nsOEScanBoxes::MailboxEntry *nsOEScanBoxes::NewMailboxEntry(PRUint32 id, PRUint3 pEntry->type = 0; pEntry->sibling = -1; pEntry->processed = PR_FALSE; - ConvertToUnicode(prettyName, pEntry->mailName); + NS_CopyNativeToUnicode(nsDependentCString(prettyName), pEntry->mailName); if (pFileName) pEntry->fileName = pFileName; return pEntry; @@ -624,7 +609,7 @@ PRBool nsOEScanBoxes::Scan50MailboxDir( nsIFileSpec * srcDir) pEntry->type = -1; pEntry->fileName = pLeaf; pLeaf[sLen - 4] = 0; - ConvertToUnicode(pLeaf, pEntry->mailName); + NS_CopyNativeToUnicode(nsDependentCString(pLeaf), pEntry->mailName); m_entryArray.AppendElement( pEntry); } } @@ -695,7 +680,7 @@ void nsOEScanBoxes::ScanMailboxDir( nsIFileSpec * srcDir) pEntry->type = -1; pEntry->fileName = pLeaf; pLeaf[sLen - 4] = 0; - ConvertToUnicode(pLeaf, pEntry->mailName); + NS_CopyNativeToUnicode(nsDependentCString(pLeaf), pEntry->mailName); m_entryArray.AppendElement( pEntry); } if (pLeaf) diff --git a/mozilla/mailnews/import/oexpress/nsOEScanBoxes.h b/mozilla/mailnews/import/oexpress/nsOEScanBoxes.h index b8d81dc19db..fe9facf05ab 100644 --- a/mozilla/mailnews/import/oexpress/nsOEScanBoxes.h +++ b/mozilla/mailnews/import/oexpress/nsOEScanBoxes.h @@ -94,8 +94,6 @@ private: void BuildMailboxList( MailboxEntry *pBox, nsIFileSpec * root, PRInt32 depth, nsISupportsArray *pArray); PRBool GetMailboxList( nsIFileSpec * root, nsISupportsArray **pArray); - void ConvertToUnicode(const char *pStr, nsString &dist); - private: MailboxEntry * m_pFirst; nsVoidArray m_entryArray; diff --git a/mozilla/mailnews/import/outlook/src/nsOutlookCompose.cpp b/mozilla/mailnews/import/outlook/src/nsOutlookCompose.cpp index ca10a7bcf34..4edc1c1985d 100644 --- a/mozilla/mailnews/import/outlook/src/nsOutlookCompose.cpp +++ b/mozilla/mailnews/import/outlook/src/nsOutlookCompose.cpp @@ -31,6 +31,7 @@ #include "nsIProxyObjectManager.h" #include "nsProxiedService.h" #include "nsMsgI18N.h" +#include "nsNativeCharsetUtils.h" #include "nsMsgBaseCID.h" #include "nsMsgCompCID.h" @@ -564,18 +565,6 @@ nsMsgAttachedFile * nsOutlookCompose::GetLocalAttachments( void) return( a); } -void nsOutlookCompose::ConvertSystemStringToUnicode( const char *pStr, nsString& uniStr) -{ - if (!m_pImportService) - m_pImportService = do_GetService(NS_IMPORTSERVICE_CONTRACTID); - NS_ASSERTION(m_pImportService, "no import service, can't convert"); - - if (m_pImportService) - m_pImportService->SystemStringToUnicode( pStr, uniStr); - else - uniStr.AssignWithConversion( pStr); -} - // Test a message send???? nsresult nsOutlookCompose::SendTheMessage( nsIFileSpec *pMsg, nsMsgDeliverMode mode, nsCString &useThisCType) { @@ -587,20 +576,20 @@ nsresult nsOutlookCompose::SendTheMessage( nsIFileSpec *pMsg, nsMsgDeliverMode m // IMPORT_LOG0( "Outlook Compose created necessary components\n"); - nsString bodyType; - nsString charSet; - nsString headerVal; + nsAutoString bodyType; + nsAutoString charSet; + nsAutoString headerVal; nsCAutoString asciiHeaderVal; GetHeaderValue( m_Headers.get(), m_Headers.Length(), "From:", headerVal); if (!headerVal.IsEmpty()) - m_pMsgFields->SetFrom( headerVal.get()); + m_pMsgFields->SetFrom( headerVal); GetHeaderValue( m_Headers.get(), m_Headers.Length(), "To:", headerVal); if (!headerVal.IsEmpty()) - m_pMsgFields->SetTo( headerVal.get()); + m_pMsgFields->SetTo( headerVal); GetHeaderValue( m_Headers.get(), m_Headers.Length(), "Subject:", headerVal); if (!headerVal.IsEmpty()) - m_pMsgFields->SetSubject( headerVal.get()); + m_pMsgFields->SetSubject( headerVal); GetHeaderValue( m_Headers.get(), m_Headers.Length(), "Content-type:", headerVal); // If callers pass in a content type then use it, else get it from the header. @@ -627,19 +616,19 @@ nsresult nsOutlookCompose::SendTheMessage( nsIFileSpec *pMsg, nsMsgDeliverMode m headerVal.Assign(defaultCharset.IsEmpty() ? NS_LITERAL_STRING("ISO-8859-1").get() : defaultCharset.get()); } } - m_pMsgFields->SetCharacterSet( NS_LossyConvertUCS2toASCII(headerVal).get() ); + m_pMsgFields->SetCharacterSet( NS_LossyConvertUTF16toASCII(headerVal).get() ); charSet = headerVal; GetHeaderValue( m_Headers.get(), m_Headers.Length(), "CC:", headerVal); if (!headerVal.IsEmpty()) - m_pMsgFields->SetCc( headerVal.get()); + m_pMsgFields->SetCc( headerVal); GetHeaderValue( m_Headers.get(), m_Headers.Length(), "Message-ID:", headerVal); if (!headerVal.IsEmpty()) { - asciiHeaderVal.AssignWithConversion(headerVal); + LossyCopyUTF16toASCII(headerVal, asciiHeaderVal); m_pMsgFields->SetMessageId(asciiHeaderVal.get()); } GetHeaderValue( m_Headers.get(), m_Headers.Length(), "Reply-To:", headerVal); if (!headerVal.IsEmpty()) - m_pMsgFields->SetReplyTo( headerVal.get()); + m_pMsgFields->SetReplyTo( headerVal); // what about all of the other headers?!?!?!?!?!?! char *pMimeType = nsnull; @@ -651,12 +640,11 @@ nsresult nsOutlookCompose::SendTheMessage( nsIFileSpec *pMsg, nsMsgDeliverMode m // Do body conversion here nsString uniBody; - ConvertSystemStringToUnicode( m_Body.get(), uniBody); + NS_CopyNativeToUnicode( m_Body, uniBody); - nsCString body, theCharset; - theCharset.AssignWithConversion(charSet); - - rv = nsMsgI18NConvertFromUnicode( theCharset, uniBody, body); + nsCString body; + rv = nsMsgI18NConvertFromUnicode( NS_LossyConvertUTF16toASCII(charSet).get(), + uniBody, body); uniBody.Truncate(); rv = m_pSendProxy->CreateAndSendMessage( diff --git a/mozilla/mailnews/import/text/src/nsTextAddress.cpp b/mozilla/mailnews/import/text/src/nsTextAddress.cpp index 50383a32cee..8e00b9ffdd3 100644 --- a/mozilla/mailnews/import/text/src/nsTextAddress.cpp +++ b/mozilla/mailnews/import/text/src/nsTextAddress.cpp @@ -27,6 +27,7 @@ #include "nsReadableUtils.h" #include "nsIPrefService.h" #include "nsIPrefBranch.h" +#include "nsNativeCharsetUtils.h" #include "TextDebugLog.h" @@ -56,19 +57,6 @@ nsTextAddress::~nsTextAddress() NS_IF_RELEASE( m_fieldMap); } - -void nsTextAddress::ConvertToUnicode( const char *pStr, nsString& str) -{ - if (!m_pService) { - m_pService = do_GetService( NS_IMPORTSERVICE_CONTRACTID); - } - if (m_pService) { - m_pService->SystemStringToUnicode( pStr, str); - } - else - str.AssignWithConversion( pStr); -} - nsresult nsTextAddress::ImportLDIF( PRBool *pAbort, const PRUnichar *pName, nsIFileSpec *pSrc, nsIAddrDatabase *pDb, nsString& errors, PRUint32 *pProgress) { NS_IF_RELEASE( m_database); @@ -502,7 +490,7 @@ nsresult nsTextAddress::ProcessLine( const char *pLine, PRInt32 len, nsString& e } } if (newRow) { - ConvertToUnicode( fieldVal.get(), uVal); + NS_CopyNativeToUnicode( fieldVal, uVal); rv = m_fieldMap->SetFieldValue( m_database, newRow, fieldNum, uVal.get()); } } diff --git a/mozilla/mailnews/import/text/src/nsTextAddress.h b/mozilla/mailnews/import/text/src/nsTextAddress.h index a9f76e3f850..8ac320ba744 100644 --- a/mozilla/mailnews/import/text/src/nsTextAddress.h +++ b/mozilla/mailnews/import/text/src/nsTextAddress.h @@ -54,7 +54,6 @@ public: private: nsresult ProcessLine( const char *pLine, PRInt32 len, nsString& errors); - void ConvertToUnicode( const char *pStr, nsString& str); static PRBool IsLineComplete( const char *pLine, PRInt32 len, char delim); static PRInt32 CountFields( const char *pLine, PRInt32 maxLen, char delim); diff --git a/mozilla/mailnews/local/src/nsLocalMailFolder.cpp b/mozilla/mailnews/local/src/nsLocalMailFolder.cpp index 3c417c3379c..c5ea725492d 100644 --- a/mozilla/mailnews/local/src/nsLocalMailFolder.cpp +++ b/mozilla/mailnews/local/src/nsLocalMailFolder.cpp @@ -100,6 +100,7 @@ #include "nsIMsgMailNewsUrl.h" #include "nsISpamSettings.h" #include "nsINoIncomingServer.h" +#include "nsNativeCharsetUtils.h" static NS_DEFINE_CID(kMailboxServiceCID, NS_MAILBOXSERVICE_CID); static NS_DEFINE_CID(kCMailDB, NS_MAILDB_CID); @@ -222,7 +223,7 @@ nsMsgLocalMailFolder::CreateSubFolders(nsFileSpec &path) nsFileSpec currentFolderPath = dir.Spec(); char *leafName = currentFolderPath.GetLeafName(); - nsMsgGetNativePathString(leafName, currentFolderNameStr); + NS_CopyNativeToUnicode(nsDependentCString(leafName), currentFolderNameStr); PR_Free(leafName); // here we should handle the case where the current file is a .sbd directory w/o @@ -230,7 +231,7 @@ nsMsgLocalMailFolder::CreateSubFolders(nsFileSpec &path) if (nsShouldIgnoreFile(currentFolderNameStr)) continue; - rv = AddSubfolder(¤tFolderNameStr, getter_AddRefs(child)); + rv = AddSubfolder(currentFolderNameStr, getter_AddRefs(child)); if (child) { nsXPIDLString folderName; @@ -242,7 +243,7 @@ nsMsgLocalMailFolder::CreateSubFolders(nsFileSpec &path) return rv; } -NS_IMETHODIMP nsMsgLocalMailFolder::AddSubfolder(nsAutoString *name, +NS_IMETHODIMP nsMsgLocalMailFolder::AddSubfolder(const nsAString &name, nsIMsgFolder **child) { NS_ENSURE_ARG_POINTER(child); @@ -257,9 +258,9 @@ NS_IMETHODIMP nsMsgLocalMailFolder::AddSubfolder(nsAutoString *name, // URI should use UTF-8 // (see RFC2396 Uniform Resource Identifiers (URI): Generic Syntax) - nsXPIDLCString escapedName; - rv = NS_MsgEscapeEncodeURLPath((*name).get(), getter_Copies(escapedName)); - NS_ENSURE_SUCCESS(rv,rv); + nsCAutoString escapedName; + rv = NS_MsgEscapeEncodeURLPath(name, escapedName); + NS_ENSURE_SUCCESS(rv, rv); // fix for #192780 // if this is the root folder @@ -315,24 +316,24 @@ NS_IMETHODIMP nsMsgLocalMailFolder::AddSubfolder(nsAutoString *name, //Only set these is these are top level children. if(NS_SUCCEEDED(rv) && isServer) { - if(name->Equals(NS_LITERAL_STRING("Inbox"), nsCaseInsensitiveStringComparator())) + if(name.Equals(NS_LITERAL_STRING("Inbox"), nsCaseInsensitiveStringComparator())) { flags |= MSG_FOLDER_FLAG_INBOX; SetBiffState(nsIMsgFolder::nsMsgBiffState_Unknown); } - else if (name->Equals(NS_LITERAL_STRING("Trash"), nsCaseInsensitiveStringComparator())) + else if (name.Equals(NS_LITERAL_STRING("Trash"), nsCaseInsensitiveStringComparator())) flags |= MSG_FOLDER_FLAG_TRASH; - else if (name->Equals(NS_LITERAL_STRING("Unsent Messages"), nsCaseInsensitiveStringComparator()) || - name->Equals(NS_LITERAL_STRING("Outbox"), nsCaseInsensitiveStringComparator())) + else if (name.Equals(NS_LITERAL_STRING("Unsent Messages"), nsCaseInsensitiveStringComparator()) || + name.Equals(NS_LITERAL_STRING("Outbox"), nsCaseInsensitiveStringComparator())) flags |= MSG_FOLDER_FLAG_QUEUE; #if 0 // the logic for this has been moved into // SetFlagsOnDefaultMailboxes() - else if(name->EqualsIgnoreCase(NS_LITERAL_STRING("Sent"), nsCaseInsensitiveStringComparator())) + else if(name.EqualsIgnoreCase(NS_LITERAL_STRING("Sent"), nsCaseInsensitiveStringComparator())) folder->SetFlag(MSG_FOLDER_FLAG_SENTMAIL); - else if(name->EqualsIgnoreCase(NS_LITERAL_STRING("Drafts"), nsCaseInsensitiveStringComparator())) + else if(name.EqualsIgnoreCase(NS_LITERAL_STRING("Drafts"), nsCaseInsensitiveStringComparator())) folder->SetFlag(MSG_FOLDER_FLAG_DRAFTS); - else if(name->EqualsIgnoreCase(NS_LITERAL_STRING("Templates"), nsCaseInsensitiveStringComparator())) + else if(name.EqualsIgnoreCase(NS_LITERAL_STRING("Templates"), nsCaseInsensitiveStringComparator())) folder->SetFlag(MSG_FOLDER_FLAG_TEMPLATES); #endif } @@ -909,9 +910,8 @@ nsMsgLocalMailFolder::CreateSubfolder(const PRUnichar *folderName, nsIMsgWindow //Now we have a valid directory or we have returned. //Make sure the new folder name is valid - nsXPIDLCString nativeFolderName; - rv = ConvertFromUnicode(nsMsgI18NFileSystemCharset(), nsAutoString(folderName), - getter_Copies(nativeFolderName)); + nsCAutoString nativeFolderName; + rv = nsMsgI18NCopyUTF16ToNative(folderName, nativeFolderName); if (NS_FAILED(rv) || nativeFolderName.IsEmpty()) { ThrowAlertMsg("folderCreationFailed", msgWindow); // I'm returning this value so the dialog stays up @@ -936,10 +936,8 @@ nsMsgLocalMailFolder::CreateSubfolder(const PRUnichar *folderName, nsIMsgWindow outputStream.close(); } - //Now let's create the actual new folder - nsAutoString folderNameStr(folderName); //GetFlags and SetFlags in AddSubfolder will fail because we have no db at this point but mFlags is set. - rv = AddSubfolder(&folderNameStr, getter_AddRefs(child)); + rv = AddSubfolder(nsDependentString(folderName), getter_AddRefs(child)); if (!child || NS_FAILED(rv)) { path.Delete(PR_FALSE); @@ -962,7 +960,7 @@ nsMsgLocalMailFolder::CreateSubfolder(const PRUnichar *folderName, nsIMsgWindow rv = unusedDB->GetDBFolderInfo(getter_AddRefs(folderInfo)); if(NS_SUCCEEDED(rv)) { - folderInfo->SetMailboxName(&folderNameStr); + folderInfo->SetMailboxName(nsDependentString(folderName)); } unusedDB->SetSummaryValid(PR_TRUE); unusedDB->Close(PR_TRUE); @@ -977,7 +975,7 @@ nsMsgLocalMailFolder::CreateSubfolder(const PRUnichar *folderName, nsIMsgWindow { //we need to notify explicitly the flag change because it failed when we did AddSubfolder child->OnFlagChange(mFlags); - child->SetPrettyName(folderNameStr.get()); //because empty trash will create a new trash folder + child->SetPrettyName(folderName); //because empty trash will create a new trash folder NotifyItemAdded(child, "folderView"); } return rv; @@ -1266,8 +1264,8 @@ NS_IMETHODIMP nsMsgLocalMailFolder::Rename(const PRUnichar *aNewName, nsIMsgWind // convert from PRUnichar* to char* due to not having Rename(PRUnichar*) // function in nsIFileSpec - nsXPIDLCString convertedNewName; - if (NS_FAILED(ConvertFromUnicode(nsMsgI18NFileSystemCharset(), nsAutoString(aNewName), getter_Copies(convertedNewName)))) + nsCAutoString convertedNewName; + if (NS_FAILED(nsMsgI18NCopyUTF16ToNative(aNewName, convertedNewName))) return NS_ERROR_FAILURE; nsCAutoString newDiskName; @@ -1327,11 +1325,10 @@ NS_IMETHODIMP nsMsgLocalMailFolder::Rename(const PRUnichar *aNewName, nsIMsgWind nsCOMPtr newFolder; if (parentSupport) { - nsAutoString newFolderName(aNewName); - rv = parentFolder->AddSubfolder(&newFolderName, getter_AddRefs(newFolder)); + rv = parentFolder->AddSubfolder(nsDependentString(aNewName), getter_AddRefs(newFolder)); if (newFolder) { - newFolder->SetPrettyName(newFolderName.get()); + newFolder->SetPrettyName(aNewName); PRBool changed = PR_FALSE; MatchOrChangeFilterDestination(newFolder, PR_TRUE /*caseInsenstive*/, &changed); if (changed) @@ -1372,9 +1369,8 @@ NS_IMETHODIMP nsMsgLocalMailFolder::RenameSubFolders(nsIMsgWindow *msgWindow, ns nsCOMPtrmsgFolder = do_QueryInterface(aSupport); nsXPIDLString folderName; rv = msgFolder->GetName(getter_Copies(folderName)); - nsAutoString folderNameStr(folderName.get()); nsCOMPtr newFolder; - AddSubfolder(&folderNameStr, getter_AddRefs(newFolder)); + AddSubfolder(folderName, getter_AddRefs(newFolder)); if (newFolder) { newFolder->SetPrettyName(folderName.get()); @@ -1909,14 +1905,14 @@ nsMsgLocalMailFolder::CopyFolderAcrossServer(nsIMsgFolder* srcFolder, nsIMsgWind nsresult rv = CreateSubfolder(folderName, msgWindow); if (NS_FAILED(rv)) return rv; - nsXPIDLCString escapedFolderName; - rv = NS_MsgEscapeEncodeURLPath(folderName.get(), getter_Copies(escapedFolderName)); + nsCAutoString escapedFolderName; + rv = NS_MsgEscapeEncodeURLPath(folderName, escapedFolderName); NS_ENSURE_SUCCESS(rv,rv); nsCOMPtr newFolder; nsCOMPtr newMsgFolder; - rv = FindSubFolder(escapedFolderName.get(), getter_AddRefs(newMsgFolder)); + rv = FindSubFolder(escapedFolderName, getter_AddRefs(newMsgFolder)); NS_ENSURE_SUCCESS(rv,rv); nsCOMPtr messages; @@ -2029,10 +2025,8 @@ nsMsgLocalMailFolder::CopyFolderLocal(nsIMsgFolder *srcFolder, PRBool isMoveFold } } - nsXPIDLString idlName; - srcFolder->GetName(getter_Copies(idlName)); - nsAutoString folderName; - folderName.Assign(idlName); + nsXPIDLString folderName; + srcFolder->GetName(getter_Copies(folderName)); srcFolder->ForceDBClosed(); @@ -2072,7 +2066,7 @@ nsMsgLocalMailFolder::CopyFolderLocal(nsIMsgFolder *srcFolder, PRBool isMoveFold rv = summarySpec.CopyToDir(newPath); NS_ENSURE_SUCCESS(rv, rv); - rv = AddSubfolder(&folderName, getter_AddRefs(newMsgFolder)); + rv = AddSubfolder(folderName, getter_AddRefs(newMsgFolder)); NS_ENSURE_SUCCESS(rv, rv); newMsgFolder->SetPrettyName(folderName.get()); @@ -3340,8 +3334,8 @@ nsMsgLocalMailFolder::setSubfolderFlag(const PRUnichar *aFolderName, { // FindSubFolder() expects the folder name to be escaped // see bug #192043 - nsXPIDLCString escapedFolderName; - nsresult rv = NS_MsgEscapeEncodeURLPath(aFolderName, getter_Copies(escapedFolderName)); + nsCAutoString escapedFolderName; + nsresult rv = NS_MsgEscapeEncodeURLPath(nsDependentString(aFolderName), escapedFolderName); NS_ENSURE_SUCCESS(rv,rv); nsCOMPtr msgFolder; rv = FindSubFolder(escapedFolderName, getter_AddRefs(msgFolder)); diff --git a/mozilla/mailnews/local/src/nsLocalMailFolder.h b/mozilla/mailnews/local/src/nsLocalMailFolder.h index edec77fd534..9ceeca669ce 100644 --- a/mozilla/mailnews/local/src/nsLocalMailFolder.h +++ b/mozilla/mailnews/local/src/nsLocalMailFolder.h @@ -126,7 +126,7 @@ public: NS_IMETHOD UpdateFolder(nsIMsgWindow *aWindow); NS_IMETHOD CreateSubfolder(const PRUnichar *folderName ,nsIMsgWindow *msgWindow); - NS_IMETHOD AddSubfolder(nsAutoString *folderName, nsIMsgFolder** newFolder); + NS_IMETHOD AddSubfolder(const nsAString& folderName, nsIMsgFolder** newFolder); NS_IMETHOD Compact(nsIUrlListener *aListener, nsIMsgWindow *aMsgWindow); NS_IMETHOD CompactAll(nsIUrlListener *aListener, nsIMsgWindow *aMsgWindow, nsISupportsArray *aFolderArray, PRBool aCompactOfflineAlso, nsISupportsArray *aOfflineFolderArray); diff --git a/mozilla/mailnews/mapi/mapihook/src/msgMapiHook.cpp b/mozilla/mailnews/mapi/mapihook/src/msgMapiHook.cpp index 32ed89801dd..0efc4cbdd09 100644 --- a/mozilla/mailnews/mapi/mapihook/src/msgMapiHook.cpp +++ b/mozilla/mailnews/mapi/mapihook/src/msgMapiHook.cpp @@ -424,15 +424,14 @@ nsresult nsMapiHook::PopulateCompFields(lpnsMapiMessage aMessage, if (aMessage->lpOriginator) { PRUnichar * From = aMessage->lpOriginator->lpszAddress ; - aCompFields->SetFrom (From) ; + aCompFields->SetFrom (nsDependentString(From)) ; } nsAutoString To ; nsAutoString Cc ; nsAutoString Bcc ; - nsAutoString Comma ; - Comma.AssignWithConversion(","); + NS_NAMED_LITERAL_STRING(Comma, ",") ; if (aMessage->lpRecips) { @@ -465,15 +464,15 @@ nsresult nsMapiHook::PopulateCompFields(lpnsMapiMessage aMessage, } // set To, Cc, Bcc - aCompFields->SetTo (To.get()) ; - aCompFields->SetCc (Cc.get()) ; - aCompFields->SetBcc (Bcc.get()) ; + aCompFields->SetTo (To) ; + aCompFields->SetCc (Cc) ; + aCompFields->SetBcc (Bcc) ; // set subject if (aMessage->lpszSubject) { PRUnichar * Subject = aMessage->lpszSubject ; - aCompFields->SetSubject(Subject) ; + aCompFields->SetSubject(nsDependentString(Subject)) ; } // handle attachments as File URL @@ -484,7 +483,7 @@ nsresult nsMapiHook::PopulateCompFields(lpnsMapiMessage aMessage, if (aMessage->lpszNoteText) { PRUnichar * Body = aMessage->lpszNoteText ; - rv = aCompFields->SetBody(Body) ; + rv = aCompFields->SetBody(nsDependentString(Body)) ; } #ifdef RAJIV_DEBUG @@ -662,15 +661,14 @@ nsresult nsMapiHook::PopulateCompFieldsWithConversion(lpnsMapiMessage aMessage, { nsAutoString From ; From.AssignWithConversion((char *) aMessage->lpOriginator->lpszAddress); - aCompFields->SetFrom (From.get()) ; + aCompFields->SetFrom (From) ; } nsAutoString To ; nsAutoString Cc ; nsAutoString Bcc ; - nsAutoString Comma ; - Comma.AssignWithConversion(","); + NS_NAMED_LITERAL_STRING(Comma, ",") ; if (aMessage->lpRecips) { @@ -703,9 +701,9 @@ nsresult nsMapiHook::PopulateCompFieldsWithConversion(lpnsMapiMessage aMessage, } // set To, Cc, Bcc - aCompFields->SetTo (To.get()) ; - aCompFields->SetCc (Cc.get()) ; - aCompFields->SetBcc (Bcc.get()) ; + aCompFields->SetTo (To) ; + aCompFields->SetCc (Cc) ; + aCompFields->SetBcc (Bcc) ; nsCAutoString platformCharSet; // set subject @@ -716,7 +714,7 @@ nsresult nsMapiHook::PopulateCompFieldsWithConversion(lpnsMapiMessage aMessage, platformCharSet.Assign(nsMsgI18NFileSystemCharset()); rv = ConvertToUnicode(platformCharSet.get(), (char *) aMessage->lpszSubject, Subject); if (NS_FAILED(rv)) return rv ; - aCompFields->SetSubject(Subject.get()) ; + aCompFields->SetSubject(Subject) ; } // handle attachments as File URL @@ -731,7 +729,7 @@ nsresult nsMapiHook::PopulateCompFieldsWithConversion(lpnsMapiMessage aMessage, platformCharSet.Assign(nsMsgI18NFileSystemCharset()); rv = ConvertToUnicode(platformCharSet.get(), (char *) aMessage->lpszNoteText, Body); if (NS_FAILED(rv)) return rv ; - rv = aCompFields->SetBody(Body.get()) ; + rv = aCompFields->SetBody(Body) ; } #ifdef RAJIV_DEBUG diff --git a/mozilla/mailnews/mime/cthandlers/vcard/mimevcrd.cpp b/mozilla/mailnews/mime/cthandlers/vcard/mimevcrd.cpp index cfbd5c18324..0c792da84a5 100644 --- a/mozilla/mailnews/mime/cthandlers/vcard/mimevcrd.cpp +++ b/mozilla/mailnews/mime/cthandlers/vcard/mimevcrd.cpp @@ -226,9 +226,11 @@ static PRInt32 INTL_ConvertCharset(const char* from_charset, const char* to_char } if (NS_SUCCEEDED(res)) { - res = ConvertFromUnicode(to_charset, outString, outBuffer); + nsCAutoString result; + res = ConvertFromUnicode(to_charset, outString, result); if (NS_SUCCEEDED(res)) { - *outLength = strlen(*outBuffer); + *outLength = result.Length(); + *outBuffer = PL_strdup(result.get()); } } diff --git a/mozilla/mailnews/mime/src/mimedrft.cpp b/mozilla/mailnews/mime/src/mimedrft.cpp index 2ebac030cd2..9ec17150122 100644 --- a/mozilla/mailnews/mime/src/mimedrft.cpp +++ b/mozilla/mailnews/mime/src/mimedrft.cpp @@ -229,9 +229,9 @@ CreateTheComposeWindow(nsIMsgCompFields * compFields, if (NS_SUCCEEDED(rv) && attachment) { nsAutoString nameStr; - rv = ConvertToUnicode(msgCompHeaderInternalCharset(), curAttachment->real_name, nameStr); + rv = ConvertToUnicode("UTF-8", curAttachment->real_name, nameStr); if (NS_FAILED(rv)) - nameStr.AssignWithConversion(curAttachment->real_name); + CopyASCIItoUTF16(curAttachment->real_name, nameStr); attachment->SetName(nameStr); attachment->SetUrl(spec.get()); attachment->SetTemporary(PR_TRUE); @@ -318,43 +318,43 @@ CreateCompositionFields(const char *from, if (from) { val = MIME_DecodeMimeHeader(from, charset, PR_FALSE, PR_TRUE); - cFields->SetFrom(NS_ConvertUTF8toUCS2(val ? val : from).get()); + cFields->SetFrom(NS_ConvertUTF8toUTF16(val ? val : from)); PR_FREEIF(val); } if (subject) { val = MIME_DecodeMimeHeader(subject, charset, PR_FALSE, PR_TRUE); - cFields->SetSubject(NS_ConvertUTF8toUCS2(val ? val : subject).get()); + cFields->SetSubject(NS_ConvertUTF8toUTF16(val ? val : subject)); PR_FREEIF(val); } if (reply_to) { val = MIME_DecodeMimeHeader(reply_to, charset, PR_FALSE, PR_TRUE); - cFields->SetReplyTo(NS_ConvertUTF8toUCS2(val ? val : reply_to).get()); + cFields->SetReplyTo(NS_ConvertUTF8toUTF16(val ? val : reply_to)); PR_FREEIF(val); } if (to) { val = MIME_DecodeMimeHeader(to, charset, PR_FALSE, PR_TRUE); - cFields->SetTo(NS_ConvertUTF8toUCS2(val ? val : to).get()); + cFields->SetTo(NS_ConvertUTF8toUTF16(val ? val : to)); PR_FREEIF(val); } if (cc) { val = MIME_DecodeMimeHeader(cc, charset, PR_FALSE, PR_TRUE); - cFields->SetCc(NS_ConvertUTF8toUCS2(val ? val : cc).get()); + cFields->SetCc(NS_ConvertUTF8toUTF16(val ? val : cc)); PR_FREEIF(val); } if (bcc) { val = MIME_DecodeMimeHeader(bcc, charset, PR_FALSE, PR_TRUE); - cFields->SetBcc(NS_ConvertUTF8toUCS2(val ? val : bcc).get()); + cFields->SetBcc(NS_ConvertUTF8toUTF16(val ? val : bcc)); PR_FREEIF(val); } if (fcc) { val = MIME_DecodeMimeHeader(fcc, charset, PR_FALSE, PR_TRUE); - cFields->SetFcc(NS_ConvertUTF8toUCS2(val ? val : fcc).get()); + cFields->SetFcc(NS_ConvertUTF8toUTF16(val ? val : fcc)); PR_FREEIF(val); } @@ -372,7 +372,7 @@ CreateCompositionFields(const char *from, if (organization) { val = MIME_DecodeMimeHeader(organization, charset, PR_FALSE, PR_TRUE); - cFields->SetOrganization(NS_ConvertUTF8toUCS2(val ? val : organization).get()); + cFields->SetOrganization(NS_ConvertUTF8toUTF16(val ? val : organization)); PR_FREEIF(val); } @@ -384,7 +384,7 @@ CreateCompositionFields(const char *from, if (other_random_headers) { val = MIME_DecodeMimeHeader(other_random_headers, charset, PR_FALSE, PR_TRUE); - cFields->SetOtherRandomHeaders(NS_ConvertUTF8toUCS2(val ? val : other_random_headers).get()); + cFields->SetOtherRandomHeaders(NS_ConvertUTF8toUTF16(val ? val : other_random_headers)); PR_FREEIF(val); } @@ -1526,10 +1526,10 @@ mime_parse_stream_complete (nsMIMESession *stream) // setting the charset while we are creating the composition fields //fields->SetCharacterSet(NS_ConvertASCIItoUCS2(mdd->mailcharset)); - // convert from UTF-8 to UCS2 + // convert from UTF-8 to UTF-16 if (body) { - fields->SetBody(NS_ConvertUTF8toUCS2(body).get()); + fields->SetBody(NS_ConvertUTF8toUTF16(body)); PR_Free(body); } @@ -1981,10 +1981,10 @@ mime_decompose_file_output_fn (const char *buf, NS_ASSERTION (mdd && buf, "missing mime draft data and/or buf"); if (!mdd || !buf) return -1; - if (!size) return 0; + if (!size) return NS_OK; if ( !mdd->tmpFileStream ) - return 0; + return NS_OK; if (mdd->decoder_data) { ret = MimeDecoderWrite(mdd->decoder_data, buf, size); @@ -1997,7 +1997,7 @@ mime_decompose_file_output_fn (const char *buf, return MIME_ERROR_WRITING_FILE; } - return 0; + return NS_OK; } nsresult diff --git a/mozilla/mailnews/mime/src/mimehdrs.cpp b/mozilla/mailnews/mime/src/mimehdrs.cpp index 3ed0b4c5125..d52e760dc69 100644 --- a/mozilla/mailnews/mime/src/mimehdrs.cpp +++ b/mozilla/mailnews/mime/src/mimehdrs.cpp @@ -60,23 +60,22 @@ // Forward declares... PRInt32 MimeHeaders_build_heads_list(MimeHeaders *hdrs); -static char * -MimeHeaders_convert_header_value(MimeDisplayOptions *opt, char **value) +static void +MimeHeaders_convert_header_value(MimeDisplayOptions *opt, nsAFlatCString &value) { char *converted; - if (!*value) - return *value; + if (value.IsEmpty()) + return; if (opt && opt->rfc1522_conversion_p) { - converted = MIME_DecodeMimeHeader(*value, opt->default_charset, + converted = MIME_DecodeMimeHeader(value.get(), opt->default_charset, opt->override_charset, PR_TRUE); if (converted) { - PR_FREEIF(*value); - *value = converted; + value = converted; } } else @@ -85,11 +84,8 @@ MimeHeaders_convert_header_value(MimeDisplayOptions *opt, char **value) // from the previous implementation. It may be that this is dead // code, in which case opt->rfc1522_conversion_p is no longer // needed. - PR_FREEIF(*value); - *value = nsnull; + value.Truncate(); } - - return(*value); } @@ -557,10 +553,6 @@ MimeHeaders_write_all_headers (MimeHeaders *hdrs, MimeDisplayOptions *opt, PRBoo : hdrs->heads[i+1]); char *colon, *ocolon; char *contents = end; - char *name = 0; - char *hdr_value; - - hdr_value = 0; /* Hack for BSD Mailbox delimiter. */ if (i == 0 && head[0] == 'F' && !strncmp(head, "From ", 5)) @@ -592,42 +584,30 @@ MimeHeaders_write_all_headers (MimeHeaders *hdrs, MimeDisplayOptions *opt, PRBoo while (end > contents && nsCRT::IsAsciiSpace(end[-1])) end--; - name = (char *)PR_MALLOC(colon - head + 1); - if (!name) return MIME_OUT_OF_MEMORY; - memcpy(name, head, colon - head); - name[colon - head] = 0; - + nsCAutoString name(Substring(head, colon)); + nsCAutoString hdr_value; + if ( (end - contents) > 0 ) { - hdr_value = (char *)PR_MALLOC(end - contents + 1); - if (!hdr_value) - { - PR_Free(name); - return MIME_OUT_OF_MEMORY; - } - memcpy(hdr_value, contents, end - contents); - hdr_value[end - contents] = 0; + hdr_value = Substring(contents, end); } - MimeHeaders_convert_header_value(opt, &hdr_value); + MimeHeaders_convert_header_value(opt, hdr_value); // if we're saving as html, we need to convert headers from utf8 to message charset, if any if (opt->format_out == nsMimeOutput::nsMimeMessageSaveAs && charset) { - char *convertedStr; - if (NS_SUCCEEDED(ConvertFromUnicode(charset, NS_ConvertUTF8toUCS2(hdr_value), &convertedStr))) + nsCAutoString convertedStr; + if (NS_SUCCEEDED(ConvertFromUnicode(charset, NS_ConvertUTF8toUTF16(hdr_value), + convertedStr))) { - PR_FREEIF(hdr_value); hdr_value = convertedStr; } } if (attachment) - status = mimeEmitterAddAttachmentField(opt, name, hdr_value); + status = mimeEmitterAddAttachmentField(opt, name.get(), hdr_value.get()); else - status = mimeEmitterAddHeaderField(opt, name, hdr_value); - - PR_Free(name); - PR_FREEIF(hdr_value); + status = mimeEmitterAddHeaderField(opt, name.get(), hdr_value.get()); if (status < 0) return status; if (!wrote_any_p) diff --git a/mozilla/mailnews/mime/src/mimetpfl.cpp b/mozilla/mailnews/mime/src/mimetpfl.cpp index 19768a27c9e..b51630ff306 100644 --- a/mozilla/mailnews/mime/src/mimetpfl.cpp +++ b/mozilla/mailnews/mime/src/mimetpfl.cpp @@ -363,8 +363,7 @@ MimeInlineTextPlainFlowed_parse_line (char *line, PRInt32 length, MimeObject *ob ((MimeInlineTextClass*)&mimeInlineTextClass)->initialize_charset(obj); mailCharset = inlinetext->charset; if (mailCharset && *mailCharset) { - rv = nsMsgI18NConvertToUnicode(nsDependentCString(mailCharset), - inputStr, lineSource); + rv = nsMsgI18NConvertToUnicode(mailCharset, inputStr, lineSource); NS_ENSURE_SUCCESS(rv, -1); } else // this probably never happens... @@ -470,8 +469,7 @@ MimeInlineTextPlainFlowed_parse_line (char *line, PRInt32 length, MimeObject *ob CopyUTF16toUTF8(lineResult2, outString); else { // convert back to mailCharset before writing. - rv = nsMsgI18NConvertFromUnicode(nsDependentCString(mailCharset), - lineResult2, outString); + rv = nsMsgI18NConvertFromUnicode(mailCharset, lineResult2, outString); NS_ENSURE_SUCCESS(rv, -1); } status = MimeObject_write(obj, outString.get(), outString.Length(), PR_TRUE); diff --git a/mozilla/mailnews/mime/src/mimetpla.cpp b/mozilla/mailnews/mime/src/mimetpla.cpp index bacfe495f1d..55c52342849 100644 --- a/mozilla/mailnews/mime/src/mimetpla.cpp +++ b/mozilla/mailnews/mime/src/mimetpla.cpp @@ -347,8 +347,7 @@ MimeInlineTextPlain_parse_line (char *line, PRInt32 length, MimeObject *obj) ((MimeInlineTextClass*)&mimeInlineTextClass)->initialize_charset(obj); mailCharset = inlinetext->charset; if (mailCharset && *mailCharset) { - rv = nsMsgI18NConvertToUnicode(nsDependentCString(mailCharset), - inputStr, lineSourceStr); + rv = nsMsgI18NConvertToUnicode(mailCharset, inputStr, lineSourceStr); NS_ENSURE_SUCCESS(rv, -1); } else // this probably never happens ... @@ -463,7 +462,7 @@ MimeInlineTextPlain_parse_line (char *line, PRInt32 length, MimeObject *obj) CopyUTF16toUTF8(lineResultUnichar, outString); else { // convert back to mailCharset before writing. - rv = nsMsgI18NConvertFromUnicode(nsDependentCString(mailCharset), + rv = nsMsgI18NConvertFromUnicode(mailCharset, lineResultUnichar, outString); NS_ENSURE_SUCCESS(rv, -1); } diff --git a/mozilla/mailnews/news/src/nsNNTPProtocol.cpp b/mozilla/mailnews/news/src/nsNNTPProtocol.cpp index 595b7e94506..ab91160ed4c 100644 --- a/mozilla/mailnews/news/src/nsNNTPProtocol.cpp +++ b/mozilla/mailnews/news/src/nsNNTPProtocol.cpp @@ -1170,8 +1170,8 @@ nsresult nsNNTPProtocol::LoadUrl(nsIURI * aURL, nsISupports * aConsumer) // to handle non-ASCII newsgroup names, we store them internally as escaped. // decode and unescape the newsgroup name so we'll display a proper name. - nsXPIDLString unescapedName; - rv = NS_MsgDecodeUnescapeURLPath(group.get(), getter_Copies(unescapedName)); + nsAutoString unescapedName; + rv = NS_MsgDecodeUnescapeURLPath(group, unescapedName); NS_ENSURE_SUCCESS(rv,rv); bundleService->CreateBundle(NEWS_MSGS_URL, getter_AddRefs(bundle)); diff --git a/mozilla/mailnews/news/src/nsNewsFolder.cpp b/mozilla/mailnews/news/src/nsNewsFolder.cpp index fa4b32a9068..502e92e1aa1 100644 --- a/mozilla/mailnews/news/src/nsNewsFolder.cpp +++ b/mozilla/mailnews/news/src/nsNewsFolder.cpp @@ -216,8 +216,8 @@ nsMsgNewsFolder::AddNewsgroup(const char *name, const char *setStr, nsIMsgFolder nsAutoString newsgroupName; newsgroupName.AssignWithConversion(name); - nsXPIDLCString escapedName; - rv = NS_MsgEscapeEncodeURLPath(newsgroupName.get(), getter_Copies(escapedName)); + nsCAutoString escapedName; + rv = NS_MsgEscapeEncodeURLPath(newsgroupName, escapedName); if (NS_FAILED(rv)) return rv; rv = nntpServer->AddNewsgroup(escapedName.get()); @@ -615,8 +615,8 @@ NS_IMETHODIMP nsMsgNewsFolder::Delete() rv = GetName(getter_Copies(name)); NS_ENSURE_SUCCESS(rv,rv); - nsXPIDLCString escapedName; - rv = NS_MsgEscapeEncodeURLPath(name.get(), getter_Copies(escapedName)); + nsCAutoString escapedName; + rv = NS_MsgEscapeEncodeURLPath(name, escapedName); NS_ENSURE_SUCCESS(rv,rv); rv = nntpServer->RemoveNewsgroup(escapedName.get()); diff --git a/mozilla/mailnews/news/src/nsNntpIncomingServer.cpp b/mozilla/mailnews/news/src/nsNntpIncomingServer.cpp index e1ac50395d2..5770d4b1df3 100644 --- a/mozilla/mailnews/news/src/nsNntpIncomingServer.cpp +++ b/mozilla/mailnews/news/src/nsNntpIncomingServer.cpp @@ -767,8 +767,8 @@ nsNntpIncomingServer::SubscribeToNewsgroup(const char *name) if (NS_FAILED(rv)) return rv; if (!msgfolder) return NS_ERROR_FAILURE; - nsXPIDLString newsgroupName; - rv = NS_MsgDecodeUnescapeURLPath(name, getter_Copies(newsgroupName)); + nsAutoString newsgroupName; + rv = NS_MsgDecodeUnescapeURLPath(nsDependentCString(name), newsgroupName); NS_ENSURE_SUCCESS(rv,rv); rv = msgfolder->CreateSubfolder(newsgroupName.get(), nsnull); @@ -788,8 +788,8 @@ writeGroupToHostInfoFile(nsCString &aElement, void *aData) return PR_FALSE; } - nsXPIDLString name; - nsresult rv = NS_MsgDecodeUnescapeURLPath(aElement.get(), getter_Copies(name)); + nsAutoString name; + nsresult rv = NS_MsgDecodeUnescapeURLPath(aElement, name); if (NS_FAILED(rv)) { // stop, something is bad. return PR_FALSE; @@ -1197,12 +1197,11 @@ nsNntpIncomingServer::Unsubscribe(const PRUnichar *aUnicharName) // to handle non-ASCII newsgroup names, we store them internally as escaped. // so we need to escape and encode the name, in order to find it. - nsXPIDLCString escapedName; - rv = NS_MsgEscapeEncodeURLPath(aUnicharName, getter_Copies(escapedName)); - NS_ENSURE_SUCCESS(rv,rv); + nsCAutoString escapedName; + rv = NS_MsgEscapeEncodeURLPath(nsDependentString(aUnicharName), escapedName); nsCOMPtr newsgroupFolder; - rv = serverFolder->FindSubFolder(escapedName.get(), getter_AddRefs(newsgroupFolder)); + rv = serverFolder->FindSubFolder(escapedName, getter_AddRefs(newsgroupFolder)); if (NS_FAILED(rv)) return rv; @@ -1534,7 +1533,7 @@ nsNntpIncomingServer::FindGroup(const char *name, nsIMsgNewsFolder **result) if (!serverFolder) return NS_ERROR_FAILURE; nsCOMPtr subFolder; - rv = serverFolder->FindSubFolder(name, getter_AddRefs(subFolder)); + rv = serverFolder->FindSubFolder(nsDependentCString(name), getter_AddRefs(subFolder)); NS_ENSURE_SUCCESS(rv,rv); if (!subFolder) return NS_ERROR_FAILURE; @@ -1888,18 +1887,15 @@ nsNntpIncomingServer::GetCellText(PRInt32 row, const PRUnichar *colID, nsAString if (!IsValidRow(row)) return NS_ERROR_UNEXPECTED; + nsresult rv = NS_OK; if (colID[0] == 'n') { - nsCString str; + nsCAutoString str; mSubscribeSearchResult.CStringAt(row, str); - // some servers have newsgroup names that are non ASCII. we store those as escaped - // unescape here so the UI is consistent - // XXX fix me by converting NS_MsgDecodeUnescapeURLPath to take an nsAString& - nsXPIDLString cellText; - nsresult rv = NS_MsgDecodeUnescapeURLPath(str.get(), getter_Copies(cellText)); - _retval.Assign(cellText); - NS_ENSURE_SUCCESS(rv,rv); + // some servers have newsgroup names that are non ASCII. we store + // those as escaped. unescape here so the UI is consistent + rv = NS_MsgDecodeUnescapeURLPath(str, _retval); } - return NS_OK; + return rv; } NS_IMETHODIMP