From fdbbbfeb1deb6f6bca1223982d0e29ede490141b Mon Sep 17 00:00:00 2001 From: "nhotta%netscape.com" Date: Tue, 23 Apr 2002 02:18:19 +0000 Subject: [PATCH] Added out argument for NS_MsgStripRE to avoid altering the const argument, bug 131983, r=ducarroz, sr=bienvenu. git-svn-id: svn://10.0.0.236/trunk@119592 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/mailnews/base/util/nsMsgUtils.cpp | 12 ++++-------- mozilla/mailnews/base/util/nsMsgUtils.h | 2 +- mozilla/mailnews/local/src/nsParseMailbox.cpp | 8 +++++--- mozilla/mailnews/news/src/nsNNTPNewsgroupList.cpp | 7 ++++--- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/mozilla/mailnews/base/util/nsMsgUtils.cpp b/mozilla/mailnews/base/util/nsMsgUtils.cpp index 4becf293d84..168a721f3d2 100644 --- a/mozilla/mailnews/base/util/nsMsgUtils.cpp +++ b/mozilla/mailnews/base/util/nsMsgUtils.cpp @@ -345,7 +345,7 @@ nsresult NS_MsgCreatePathStringFromFolderURI(const char *folderURI, nsCString& p The string is not altered: the pointer to its head is merely advanced, and the length correspondingly decreased. */ -PRBool NS_MsgStripRE(const char **stringP, PRUint32 *lengthP) +PRBool NS_MsgStripRE(const char **stringP, PRUint32 *lengthP, char **modifiedSubject) { const char *s, *s_end; const char *last; @@ -358,7 +358,8 @@ PRBool NS_MsgStripRE(const char **stringP, PRUint32 *lengthP) nsXPIDLCString decodedString; nsCOMPtr mimeConverter; nsresult rv; - if (strstr(*stringP, "=?")) + // we cannot strip "Re:" for MIME encoded subject without modifying the original + if (modifiedSubject && strstr(*stringP, "=?")) { mimeConverter = do_GetService(kCMimeConverterCID, &rv); if (NS_SUCCEEDED(rv)) @@ -423,15 +424,10 @@ PRBool NS_MsgStripRE(const char **stringP, PRUint32 *lengthP) char charset[kMAX_CSNAME] = ""; if (kMAX_CSNAME >= (p2 - p1)) strncpy(charset, p1, p2 - p1); - nsXPIDLCString encodedString; rv = mimeConverter->EncodeMimePartIIStr_UTF8(s, PR_FALSE, charset, sizeof("Subject:"), - kMIME_ENCODED_WORD_SIZE, getter_Copies(encodedString)); + kMIME_ENCODED_WORD_SIZE, modifiedSubject); if (NS_SUCCEEDED(rv)) - { - strcpy((char *)*stringP, encodedString.get()); - *lengthP = encodedString.Length(); return result; - } } } } diff --git a/mozilla/mailnews/base/util/nsMsgUtils.h b/mozilla/mailnews/base/util/nsMsgUtils.h index 2ceb24fba05..500df089e97 100644 --- a/mozilla/mailnews/base/util/nsMsgUtils.h +++ b/mozilla/mailnews/base/util/nsMsgUtils.h @@ -64,7 +64,7 @@ NS_MSG_BASE nsresult NS_MsgHashIfNecessary(nsCAutoString &name); NS_MSG_BASE nsresult NS_MsgCreatePathStringFromFolderURI(const char *folderURI, nsCString& pathString); -NS_MSG_BASE PRBool NS_MsgStripRE(const char **stringP, PRUint32 *lengthP); +NS_MSG_BASE PRBool NS_MsgStripRE(const char **stringP, PRUint32 *lengthP, char **modifiedSubject=nsnull); NS_MSG_BASE char * NS_MsgSACopy(char **destination, const char *source); diff --git a/mozilla/mailnews/local/src/nsParseMailbox.cpp b/mozilla/mailnews/local/src/nsParseMailbox.cpp index 7669a31aed1..84abc4ef74a 100644 --- a/mozilla/mailnews/local/src/nsParseMailbox.cpp +++ b/mozilla/mailnews/local/src/nsParseMailbox.cpp @@ -1058,7 +1058,8 @@ int nsParseMailMessageState::InternSubject (struct message_header *header) we just parsed the subject header anyway, we expect that parsing to be smartest. (After all, what if someone just went in and edited the subject line by hand?) */ - if (NS_MsgStripRE((const char **) &key, &L)) + nsXPIDLCString modifiedSubject; + if (NS_MsgStripRE((const char **) &key, &L, getter_Copies(modifiedSubject))) flags |= MSG_FLAG_HAS_RE; else flags &= ~MSG_FLAG_HAS_RE; @@ -1068,11 +1069,12 @@ int nsParseMailMessageState::InternSubject (struct message_header *header) // Condense the subject text into as few MIME-2 encoded words as possible. #ifdef WE_CONDENSE_MIME_STRINGS - char *condensedKey = msg_condense_mime2_string(key); + char *condensedKey = msg_condense_mime2_string(modifiedSubject.IsEmpty() ? key : modifiedSubject.get()); #else char *condensedKey = nsnull; #endif - m_newMsgHdr->SetSubject(condensedKey ? condensedKey : key); + m_newMsgHdr->SetSubject(condensedKey ? condensedKey : + (modifiedSubject.IsEmpty() ? key : modifiedSubject.get())); PR_FREEIF(condensedKey); return 0; diff --git a/mozilla/mailnews/news/src/nsNNTPNewsgroupList.cpp b/mozilla/mailnews/news/src/nsNNTPNewsgroupList.cpp index 2bd9365c655..db5a9426ef8 100644 --- a/mozilla/mailnews/news/src/nsNNTPNewsgroupList.cpp +++ b/mozilla/mailnews/news/src/nsNNTPNewsgroupList.cpp @@ -512,7 +512,8 @@ nsNNTPNewsgroupList::ParseLine(char *line, PRUint32 * message_number) rv = newMsgHdr->GetFlags(&flags); if (NS_FAILED(rv)) return rv; /* strip "Re: " */ - if (NS_MsgStripRE(&subject, &subjectLen)) + nsXPIDLCString modifiedSubject; + if (NS_MsgStripRE(&subject, &subjectLen, getter_Copies(modifiedSubject))) { // todo: // use OrFlags()? @@ -525,9 +526,9 @@ nsNNTPNewsgroupList::ParseLine(char *line, PRUint32 * message_number) if (! (flags & MSG_FLAG_READ)) rv = newMsgHdr->OrFlags(MSG_FLAG_NEW, &flags); #ifdef DEBUG_NEWS - printf("subject = %s\n",subject); + printf("subject = %s\n",modifiedSubject.IsEmpty() ? subject : modifiedSubject.get()); #endif - rv = newMsgHdr->SetSubject(subject); + rv = newMsgHdr->SetSubject(modifiedSubject.IsEmpty() ? subject : modifiedSubject.get()); if (NS_FAILED(rv)) return rv; }