mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-15 22:44:13 +00:00
Bug #330241 --> convert the message body preview text from the charset of the message into UT-8 for storage. Then convert it back to unicode in the front end before showing it in the tooltip and in the new mail alert notification. sr=bienvenu
This commit is contained in:
parent
47e8b0cfa9
commit
2235173fb1
@ -2065,7 +2065,10 @@
|
||||
// we'll have to do this all over again when the fetch for the preview text completes.
|
||||
if (aOutAsync.value && aUrlListener)
|
||||
return false;
|
||||
|
||||
var unicodeConverter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
|
||||
.createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
|
||||
unicodeConverter.charset = "UTF-8";
|
||||
|
||||
var index = 0;
|
||||
var hdrParser = Components.classes["@mozilla.org/messenger/headerparser;1"].getService(Components.interfaces.nsIMsgHeaderParser);
|
||||
while (document.getAnonymousNodes(this)[0].childNodes.length < this.mMaxMsgHdrsInPopup && index < numMsgKeys.value)
|
||||
@ -2074,10 +2077,10 @@
|
||||
var msgHdr = msgDatabase.GetMsgHdrForKey(msgKeys.value[index++]);
|
||||
msgPopup.setAttribute('subject', msgHdr.mime2DecodedSubject);
|
||||
|
||||
// TO DO: worry about character set conversions
|
||||
var previewText = msgHdr.getStringProperty('preview');
|
||||
if (previewText)
|
||||
msgPopup.setAttribute('previewText', previewText);
|
||||
// convert the preview text from utf-8 to unicode
|
||||
if (previewText)
|
||||
msgPopup.setAttribute('previewText', unicodeConverter.ConvertToUnicode(previewText));
|
||||
|
||||
var names = {};
|
||||
var emails = {};
|
||||
|
@ -84,6 +84,8 @@
|
||||
#include "nsLayoutCID.h"
|
||||
#include "nsIHTMLToTextSink.h"
|
||||
#include "nsIDocumentEncoder.h"
|
||||
#include "nsMsgI18N.h"
|
||||
#include "nsIMIMEHeaderParam.h"
|
||||
#include <time.h>
|
||||
|
||||
#define oneHour 3600000000U
|
||||
@ -5102,6 +5104,12 @@ nsresult nsMsgDBFolder::GetMsgPreviewTextFromStream(nsIMsgDBHdr *msgHdr, nsIInpu
|
||||
so look for content transfer encoding.
|
||||
*/
|
||||
|
||||
// If we've got a header charset, we'll use that, otherwise we'll look for one in
|
||||
// the mime parts.
|
||||
nsXPIDLCString strCharset;
|
||||
msgHdr->GetCharset(getter_Copies(strCharset));
|
||||
nsAutoString charset (NS_ConvertUTF8toUTF16(strCharset.get()));
|
||||
|
||||
PRUint32 len;
|
||||
msgHdr->GetMessageSize(&len);
|
||||
nsLineBuffer<char> *lineBuffer;
|
||||
@ -5168,11 +5176,15 @@ nsresult nsMsgDBFolder::GetMsgPreviewTextFromStream(nsIMsgDBHdr *msgHdr, nsIInpu
|
||||
if (StringBeginsWith(curLine, NS_LITERAL_CSTRING("Content-Type:"),
|
||||
nsCaseInsensitiveCStringComparator()))
|
||||
{
|
||||
// look for a charset in the Content-Type header line, we'll take the first one we find.
|
||||
nsCOMPtr<nsIMIMEHeaderParam> mimehdrpar = do_GetService(NS_MIMEHEADERPARAM_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv) && charset.IsEmpty())
|
||||
mimehdrpar->GetParameter(curLine, "charset", EmptyCString(), false, nsnull, charset);
|
||||
if (FindInReadable(NS_LITERAL_CSTRING("text/html"), curLine,
|
||||
nsCaseInsensitiveCStringComparator()))
|
||||
{
|
||||
msgBodyIsHtml = PR_TRUE;
|
||||
// bodyFollowsHeaders = PR_TRUE;
|
||||
// bodyFollowsHeaders = PR_TRUE;
|
||||
}
|
||||
else if (FindInReadable(NS_LITERAL_CSTRING("text/plain"), curLine,
|
||||
nsCaseInsensitiveCStringComparator()))
|
||||
@ -5185,6 +5197,11 @@ nsresult nsMsgDBFolder::GetMsgPreviewTextFromStream(nsIMsgDBHdr *msgHdr, nsIInpu
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Note: in order to convert from a specific charset to UTF-8 we have to go through unicode first.
|
||||
nsAutoString unicodeMsgBodyStr;
|
||||
ConvertToUnicode(NS_ConvertUTF16toUTF8(charset).get(), msgBody, unicodeMsgBodyStr);
|
||||
|
||||
// now we've got a msg body. If it's html, convert it to plain text.
|
||||
// Then, set the previewProperty on the msg hdr to the plain text.
|
||||
if (msgBodyIsHtml)
|
||||
@ -5211,12 +5228,14 @@ nsresult nsMsgDBFolder::GetMsgPreviewTextFromStream(nsIMsgDBHdr *msgHdr, nsIInpu
|
||||
parser->SetContentSink(sink);
|
||||
|
||||
nsAutoString msgBodyStr;
|
||||
// need to do an appropriate conversion here.
|
||||
msgBodyStr.AssignWithConversion(msgBody);
|
||||
rv = parser->Parse(msgBodyStr, 0, NS_LITERAL_CSTRING("text/html"), PR_TRUE);
|
||||
CopyUTF16toUTF8(bodyText, msgBody);
|
||||
rv = parser->Parse(unicodeMsgBodyStr, 0, NS_LITERAL_CSTRING("text/html"), PR_TRUE);
|
||||
// push bodyText back into unicodeMsgBodyStr
|
||||
unicodeMsgBodyStr.Assign(bodyText);
|
||||
}
|
||||
|
||||
// now convert back to utf-8 for storage
|
||||
CopyUTF16toUTF8(unicodeMsgBodyStr, msgBody);
|
||||
|
||||
// replaces all tabs and line returns with a space, then trims off leading and trailing white space
|
||||
msgBody.CompressWhitespace(PR_TRUE, PR_TRUE);
|
||||
msgHdr->SetStringProperty("preview", msgBody.get());
|
||||
|
Loading…
x
Reference in New Issue
Block a user