Added out argument for NS_MsgStripRE to avoid altering the const argument,

bug 131983, r=ducarroz, sr=bienvenu.
This commit is contained in:
nhotta%netscape.com 2002-04-23 02:18:19 +00:00
Родитель 28fbb3122c
Коммит eba02df28e
4 изменённых файлов: 14 добавлений и 15 удалений

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

@ -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, The string is not altered: the pointer to its head is merely advanced,
and the length correspondingly decreased. 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 *s, *s_end;
const char *last; const char *last;
@ -358,7 +358,8 @@ PRBool NS_MsgStripRE(const char **stringP, PRUint32 *lengthP)
nsXPIDLCString decodedString; nsXPIDLCString decodedString;
nsCOMPtr<nsIMimeConverter> mimeConverter; nsCOMPtr<nsIMimeConverter> mimeConverter;
nsresult rv; 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); mimeConverter = do_GetService(kCMimeConverterCID, &rv);
if (NS_SUCCEEDED(rv)) if (NS_SUCCEEDED(rv))
@ -423,15 +424,10 @@ PRBool NS_MsgStripRE(const char **stringP, PRUint32 *lengthP)
char charset[kMAX_CSNAME] = ""; char charset[kMAX_CSNAME] = "";
if (kMAX_CSNAME >= (p2 - p1)) if (kMAX_CSNAME >= (p2 - p1))
strncpy(charset, p1, p2 - p1); strncpy(charset, p1, p2 - p1);
nsXPIDLCString encodedString;
rv = mimeConverter->EncodeMimePartIIStr_UTF8(s, PR_FALSE, charset, sizeof("Subject:"), 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)) if (NS_SUCCEEDED(rv))
{
strcpy((char *)*stringP, encodedString.get());
*lengthP = encodedString.Length();
return result; return result;
}
} }
} }
} }

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

@ -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 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); NS_MSG_BASE char * NS_MsgSACopy(char **destination, const char *source);

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

@ -1058,7 +1058,8 @@ int nsParseMailMessageState::InternSubject (struct message_header *header)
we just parsed the subject header anyway, we expect that parsing we just parsed the subject header anyway, we expect that parsing
to be smartest. (After all, what if someone just went in and to be smartest. (After all, what if someone just went in and
edited the subject line by hand?) */ 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; flags |= MSG_FLAG_HAS_RE;
else else
flags &= ~MSG_FLAG_HAS_RE; 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. // Condense the subject text into as few MIME-2 encoded words as possible.
#ifdef WE_CONDENSE_MIME_STRINGS #ifdef WE_CONDENSE_MIME_STRINGS
char *condensedKey = msg_condense_mime2_string(key); char *condensedKey = msg_condense_mime2_string(modifiedSubject.IsEmpty() ? key : modifiedSubject.get());
#else #else
char *condensedKey = nsnull; char *condensedKey = nsnull;
#endif #endif
m_newMsgHdr->SetSubject(condensedKey ? condensedKey : key); m_newMsgHdr->SetSubject(condensedKey ? condensedKey :
(modifiedSubject.IsEmpty() ? key : modifiedSubject.get()));
PR_FREEIF(condensedKey); PR_FREEIF(condensedKey);
return 0; return 0;

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

@ -512,7 +512,8 @@ nsNNTPNewsgroupList::ParseLine(char *line, PRUint32 * message_number)
rv = newMsgHdr->GetFlags(&flags); rv = newMsgHdr->GetFlags(&flags);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
/* strip "Re: " */ /* strip "Re: " */
if (NS_MsgStripRE(&subject, &subjectLen)) nsXPIDLCString modifiedSubject;
if (NS_MsgStripRE(&subject, &subjectLen, getter_Copies(modifiedSubject)))
{ {
// todo: // todo:
// use OrFlags()? // use OrFlags()?
@ -525,9 +526,9 @@ nsNNTPNewsgroupList::ParseLine(char *line, PRUint32 * message_number)
if (! (flags & MSG_FLAG_READ)) if (! (flags & MSG_FLAG_READ))
rv = newMsgHdr->OrFlags(MSG_FLAG_NEW, &flags); rv = newMsgHdr->OrFlags(MSG_FLAG_NEW, &flags);
#ifdef DEBUG_NEWS #ifdef DEBUG_NEWS
printf("subject = %s\n",subject); printf("subject = %s\n",modifiedSubject.IsEmpty() ? subject : modifiedSubject.get());
#endif #endif
rv = newMsgHdr->SetSubject(subject); rv = newMsgHdr->SetSubject(modifiedSubject.IsEmpty() ? subject : modifiedSubject.get());
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
} }