Bug 1800606 - Stop using nsSyncStreamListener. r=mkmelin

Differential Revision: https://phabricator.services.mozilla.com/D162086

--HG--
extra : amend_source : f26d3edc737dcb9795d3de3503db2bd5648eed88
This commit is contained in:
Geoff Lankow 2022-11-15 21:59:40 +13:00
Родитель 8c5dc81358
Коммит 3b990afd94
3 изменённых файлов: 62 добавлений и 44 удалений

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

@ -36,7 +36,7 @@ var calendarTaskButtonDNDObserver;
* @param {Object} aItem - The target calIItemBase.
* @param {Object} aMsgHdr - The nsIMsgHdr to convert from.
*/
calendarItemFromMessage(aItem, aMsgHdr) {
async calendarItemFromMessage(aItem, aMsgHdr) {
let msgFolder = aMsgHdr.folder;
let msgUri = msgFolder.getUriForMsg(aMsgHdr);
@ -47,24 +47,34 @@ var calendarTaskButtonDNDObserver;
cal.dtz.setDefaultStartEndHour(aItem);
cal.alarms.setDefaultValues(aItem);
let messenger = Cc["@mozilla.org/messenger;1"].createInstance(Ci.nsIMessenger);
let streamListener = Cc["@mozilla.org/network/sync-stream-listener;1"].createInstance(
Ci.nsISyncStreamListener
);
messenger
.messageServiceFromURI(msgUri)
.streamMessage(msgUri, streamListener, null, null, false, "", false);
let plainTextMessage = "";
plainTextMessage = msgFolder.getMsgTextFromStream(
streamListener.inputStream,
aMsgHdr.Charset,
65536,
32768,
false,
true,
{}
);
await new Promise((resolve, reject) => {
let messenger = Cc["@mozilla.org/messenger;1"].createInstance(Ci.nsIMessenger);
let streamListener = {
QueryInterface: ChromeUtils.generateQI(["nsIStreamListener"]),
onDataAvailable(request, inputStream, offset, count) {
plainTextMessage = msgFolder.getMsgTextFromStream(
inputStream,
aMsgHdr.Charset,
65536,
32768,
false,
true,
{}
);
},
onStartRequest(request) {},
onStopRequest(request, statusCode) {
if (!Components.isSuccessCode(statusCode)) {
reject(new Error(statusCode));
}
resolve();
},
};
messenger
.messageServiceFromURI(msgUri)
.streamMessage(msgUri, streamListener, null, null, false, "", false);
});
aItem.setProperty("DESCRIPTION", plainTextMessage);
},
@ -721,9 +731,9 @@ var calendarTaskButtonDNDObserver;
*
* @param {nsIMsgHdr} msgHdr
*/
onDropMessage(msgHdr) {
async onDropMessage(msgHdr) {
let newItem = new CalEvent();
itemConversion.calendarItemFromMessage(newItem, msgHdr);
await itemConversion.calendarItemFromMessage(newItem, msgHdr);
createEventWithDialog(null, null, null, null, newItem);
}
@ -816,9 +826,9 @@ var calendarTaskButtonDNDObserver;
*
* @param {nsIMsgHdr} msgHdr
*/
onDropMessage(msgHdr) {
async onDropMessage(msgHdr) {
let todo = new CalTodo();
itemConversion.calendarItemFromMessage(todo, msgHdr);
await itemConversion.calendarItemFromMessage(todo, msgHdr);
createTodoWithDialog(null, null, null, todo);
}

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

@ -80,27 +80,41 @@ var calendarExtract = {
this.extractFromEmail(isEvent, true, locale);
},
extractFromEmail(isEvent, fixedLang, fixedLocale) {
async extractFromEmail(isEvent, fixedLang, fixedLocale) {
// TODO would be nice to handle multiple selected messages,
// though old conversion functionality didn't
let message = gFolderDisplay.selectedMessage;
let messenger = Cc["@mozilla.org/messenger;1"].createInstance(Ci.nsIMessenger);
let listener = Cc["@mozilla.org/network/sync-stream-listener;1"].createInstance(
Ci.nsISyncStreamListener
);
let uri = message.folder.getUriForMsg(message);
messenger.messageServiceFromURI(uri).streamMessage(uri, listener, null, null, false, "");
let folder = message.folder;
let title = message.mime2DecodedSubject;
let content = folder.getMsgTextFromStream(
listener.inputStream,
message.Charset,
65536,
32768,
false,
true,
{}
);
let content = "";
await new Promise((resolve, reject) => {
let messenger = Cc["@mozilla.org/messenger;1"].createInstance(Ci.nsIMessenger);
let listener = {
QueryInterface: ChromeUtils.generateQI(["nsIStreamListener"]),
onDataAvailable(request, inputStream, offset, count) {
content = folder.getMsgTextFromStream(
inputStream,
message.Charset,
65536,
32768,
false,
true,
{}
);
},
onStartRequest(request) {},
onStopRequest(request, statusCode) {
if (!Components.isSuccessCode(statusCode)) {
reject(new Error(statusCode));
}
resolve();
},
};
let uri = message.folder.getUriForMsg(message);
messenger.messageServiceFromURI(uri).streamMessage(uri, listener, null, null, false, "");
});
cal.LOG("[calExtract] Original email content: \n" + title + "\r\n" + content);
let date = new Date(message.date / 1000);
let time = new Date().getTime();

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

@ -319,12 +319,6 @@ Classes = [
"type": "nsUserInfo",
"headers": ["/comm/mailnews/base/src/nsUserInfo.h"],
},
{
"cid": "{439400d3-6f23-43db-8b06-8aafe1869bd8}",
"contract_ids": ["@mozilla.org/network/sync-stream-listener;1"],
"constructor": "nsSyncStreamListener::Create",
"headers": ["/netwerk/base/nsSyncStreamListener.h"],
},
]
if buildconfig.substs["OS_ARCH"] == "Darwin":