Question

I'm developing my own Thunderbird extension. The extension adds an .xml-file as an attachment to a Thunderbird mail (it works very well). My only problem is that I don’t know how to use a relative path.

It looks something like that:

var file= 'C:\\...[… \\…]...\\chrome\\VHitG2.xml';
var attachments = [];
    attachments.push(FileToAttachment(file));
    AddAttachments(attachments); 

If the extension is installed in a different path, the extension can’t work.
Doe’s anyone know how to use relative paths ?

Was it helpful?

Solution

The FileToAttachment() function doesn't do magic, it is actually very simple. I assume that you are talking about a static file that is part of your extension - it should be accessible under a URL like chrome://myextension/content/VHitG2.xml. Then you can simply create an nsIMsgAttachment instance yourself using that URL:

var attachment = Components.classes["@mozilla.org/messengercompose/attachment;1"]
                           .createInstance(Components.interfaces.nsIMsgAttachment);
attachment.url = "chrome://myextension/content/VHitG2.xml";
AddAttachments([attachment]);

Note that your extension doesn't need to be installed unpacked for that, you don't need an actual file on disk.

OTHER TIPS

I used a very circuitous way to get the URL of the extension’s files:

Components.utils.import("resource://gre/modules/FileUtils.jsm");
var test1 = FileUtils.getFile("CurProcD", ["VHitG2.xml"]);
var test2 = FileUtils.getFile("CurProcD", ["VHitG.xml"]);
var file1 = test1.path.replace(/VHitG2.xml/i, "extensions\\custom-toolbar-button@example.com\\chrome\\VHitG2.xml");
var file2 = test2.path.replace(/VHitG.xml/i, "extensions\\custom-toolbar-button@example.com\\chrome\\VHitG.xml");
var attachment1 = file1.replace(/\\/g, "\\\\");
var attachment2 = file2.replace(/\\/g, "\\\\");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top