i'm trying to develop extension for TB38/TB45 to add attachment with paste event, but i am only able to get one file from clipboard.
Code: Select all
Components.utils.import('resource://gre/modules/Services.jsm');
document.addEventListener("paste", function(e) {
var clip = Components.classes["@mozilla.org/widget/clipboard;1"].getService(Components.interfaces.nsIClipboard);
if (!clip) return false;
var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
if (!trans) return false;
trans.addDataFlavor("application/x-moz-file");
clip.getData(trans,clip.kGlobalClipboard);
var file = new Object();
var strLength = new Object();
var flavorObj = new Object();
try {
trans.getAnyTransferData(flavorObj,file,strLength);
} catch(e){
return false;
}
if (file) file = file.value.QueryInterface(Components.interfaces.nsILocalFile);
if ( file.isFile()) {
let fileHandler = Services.io.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler);
let attachment = Components.classes["@mozilla.org/messengercompose/attachment;1"].createInstance(Components.interfaces.nsIMsgAttachment);
attachment.url = fileHandler.getURLSpecFromFile(file);
attachment.size = file.fileSize;
AddAttachments([attachment]);
}
}, true);
Thanks