зеркало из https://github.com/mozilla/pjs.git
Bug #253807 --> mime encode the feed subject using the character set encoding of the RSS document.
This means moving nsIMimeConverter into a scriptable interface so we can access it from JS. Fixes several issues with the RSS extension not handling non ascii subjects.
This commit is contained in:
Родитель
2e1033934c
Коммит
8f35ac5c52
|
@ -226,6 +226,8 @@ Feed.prototype.parseAsRSS2 = function() {
|
|||
var item = new FeedItem();
|
||||
item.feed = this;
|
||||
|
||||
item.characterSet = this.request.responseXML.characterSet ? this.request.responseXML.characterSet : "UTF-8";
|
||||
|
||||
var link = getNodeValue(itemNode.getElementsByTagName("link")[0]);
|
||||
|
||||
var guidNode = itemNode.getElementsByTagName("guid")[0];
|
||||
|
@ -254,6 +256,10 @@ Feed.prototype.parseAsRSS2 = function() {
|
|||
if (content)
|
||||
item.content = content;
|
||||
|
||||
var content = getNodeValue(itemNode.getElementsByTagNameNS(RSS_CONTENT_NS, "encoded")[0]);
|
||||
if (content)
|
||||
item.content = content;
|
||||
|
||||
this.itemsToStore[i] = item;
|
||||
}
|
||||
|
||||
|
@ -297,6 +303,8 @@ Feed.prototype.parseAsRSS1 = function() {
|
|||
var item = new FeedItem();
|
||||
item.feed = this;
|
||||
|
||||
item.characterSet = this.request.responseXML.characterSet ? this.request.responseXML.characterSet : "UTF-8";
|
||||
|
||||
// Prefer the value of the link tag to the item URI since the URI could be
|
||||
// a relative URN.
|
||||
var uri = itemResource.Value;
|
||||
|
@ -349,6 +357,8 @@ Feed.prototype.parseAsAtom = function() {
|
|||
var item = new FeedItem();
|
||||
item.feed = this;
|
||||
|
||||
item.characterSet = this.request.responseXML.characterSet ? this.request.responseXML.characterSet : "UTF-8";
|
||||
|
||||
var url;
|
||||
var links = itemNode.getElementsByTagName("link");
|
||||
for ( var j=0 ; j<links.length ; j++ ) {
|
||||
|
|
|
@ -286,6 +286,27 @@ FeedItem.prototype.toUtf8 = function(str) {
|
|||
return FeedItem.unicodeConverter.ConvertFromUnicode(str);
|
||||
}
|
||||
|
||||
function mimeEncodeSubject(aSubject, charset)
|
||||
{
|
||||
// get the mime header encoder service
|
||||
var mimeEncoder = Components
|
||||
.classes["@mozilla.org/messenger/mimeconverter;1"]
|
||||
.getService(Components.interfaces.nsIMimeConverter);
|
||||
|
||||
// this routine sometimes throws exceptions for mis encoded data so wrap it
|
||||
// with a try catch for now..
|
||||
var newSubject;
|
||||
|
||||
try {
|
||||
newSubject = mimeEncoder.encodeMimePartIIStr(aSubject, false, charset, 9, 72);
|
||||
}
|
||||
catch (ex) {
|
||||
newSubject = aSubject;
|
||||
}
|
||||
|
||||
return newSubject;
|
||||
}
|
||||
|
||||
FeedItem.prototype.writeToFolder = function() {
|
||||
debug(this.identity + " writing to message folder" + this.feed.name + "\n");
|
||||
|
||||
|
@ -301,6 +322,7 @@ FeedItem.prototype.writeToFolder = function() {
|
|||
|
||||
// Compress white space in the subject to make it look better.
|
||||
this.title = this.title.replace(/[\t\r\n]+/g, " ");
|
||||
this.title = mimeEncodeSubject(this.title, this.characterSet);
|
||||
|
||||
// If the date looks like it's in W3C-DTF format, convert it into
|
||||
// an IETF standard date. Otherwise assume it's in IETF format.
|
||||
|
@ -329,7 +351,7 @@ FeedItem.prototype.writeToFolder = function() {
|
|||
'From: ' + this.author + '\n' +
|
||||
'MIME-Version: 1.0\n' +
|
||||
'Subject: ' + this.title + '\n' +
|
||||
'Content-Type: text/html; charset=UTF-8\n' +
|
||||
'Content-Type: text/html; charset=' + this.characterSet + '\n' +
|
||||
'Content-Transfer-Encoding: 8bit\n' +
|
||||
'Content-Base: ' + this.url + '\n' +
|
||||
'\n' +
|
||||
|
|
Загрузка…
Ссылка в новой задаче