You need to install the ImportExportTools addon.
ImportExportTools NG
http://addons.thunderbird.net/thunderbird/addon/986686
The ImportExportTools copy message command calls the |copyMSGtoClip| function.
i.e. right click Message Pane > Copy to clipboard > Message
The |copyMSGtoClip| and |IETstoreBody| functions are global functions like the |alert| function.
The above code snippets work in the error console after installing the addon.
Here is a code snippet to set the clipboard content with the |copyMSGtoClip| function, get the clipboard content, replace text, then set the clipboard content again.
Code: Select all
(function () {
copyMSGtoClip(); // asynchronous
alert("Wait.");
var type = Ci.nsIClipboard.kGlobalClipboard;
var text = EnigmailClipboard.getClipboardContent(window, type);
text = text.replace(/.*/, "").substr(1); // remove "Subject:" line
text = text.replace(/.*/, "").substr(1); // remove "From:" line
text = text.replace(/.*/, "").substr(1); // remove "Date:" line
text = text.replace(/.*/, "").substr(1); // remove "To:" line
text = text.replace(/.*/, "").substr(1);
EnigmailClipboard.setClipboardContent(text, type);
alert("Message copied to clipboard.");
})();
Here is a code snippet based on the |IETstoreBody| function that works without the addon.
Code: Select all
(function() {
var msghdr = gFolderDisplay.selectedMessage;
var msguri = msghdr.folder.getUriForMsg(msghdr);
var content = "";
var MsgService = messenger.messageServiceFromURI(msguri);
var MsgStream = Cc["@mozilla.org/network/sync-stream-listener;1"].createInstance();
var consumer = MsgStream.QueryInterface(Ci.nsIInputStream);
var ScriptInput = Cc["@mozilla.org/scriptableinputstream;1"].createInstance();
var ScriptInputStream = ScriptInput.QueryInterface(Ci.nsIScriptableInputStream);
ScriptInputStream.init(consumer);
try {
MsgService.streamMessage(msguri, MsgStream, null, null, true, "header=filter");
} catch (e) {
return content;
}
ScriptInputStream.available();
while (ScriptInputStream.available()) {
content = content + ScriptInputStream.read(512);
}
var toStr = {value: null};
var formatConverter = Cc["@mozilla.org/widget/htmlformatconverter;1"].
createInstance(Ci.nsIFormatConverter);
var fromStr = Cc["@mozilla.org/supports-string;1"].
createInstance(Ci.nsISupportsString);
var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].
createInstance(Ci.nsIScriptableUnicodeConverter);
converter.charset = "UTF-8";
var dataUTF8 = converter.ConvertToUnicode(content);
var text;
fromStr.data = dataUTF8;
try {
const versionChecker = Services.vc;
const currentVersion = Services.appinfo.platformVersion;
if (versionChecker.compare(currentVersion, "61") >= 0) {
formatConverter.convert("text/html", fromStr, "text/unicode", toStr);
} else {
formatConverter.convert("text/html", fromStr, fromStr.toString().length, "text/unicode", toStr, {});
}
} catch (e) {
text = dataUTF8;
}
if (toStr.value) {
toStr = toStr.value.QueryInterface(Ci.nsISupportsString);
var os = navigator.platform.toLowerCase();
var strValue = toStr.toString();
if (os.indexOf("win") > -1)
text = strValue.replace(/(.+\r\n?)*/, "");
else
text = strValue.replace(/(.+\n?)*/, "");
text = text.replace(/\r?\n+/g, "\r\n");
text = text.replace(/^(\r\n)/g, "");
text = text.replace(/(\r\n)$/g, "");
}
text = text.replace("$%$%$", ":");
var clipboard = Components.classes["@mozilla.org/widget/clipboardhelper;1"].
getService(Components.interfaces.nsIClipboardHelper);
clipboard.copyString(text);
alert("Message copied to clipboard.");
})();