0

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 ?

4

2 回答 2

0

我使用了一种非常迂回的方式来获取扩展文件的 URL:

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, "\\\\");
于 2014-03-07T11:45:04.187 回答
0

FileToAttachment()函数并不神奇,它实际上非常简单。我假设您正在谈论作为扩展程序一部分的静态文件 - 它应该可以通过chrome://myextension/content/VHitG2.xml. 然后,您可以使用该 URL 自己简单地创建一个nsIMsgAttachment实例:

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

请注意,您的扩展不需要为此解压缩安装,您不需要磁盘上的实际文件。

于 2014-03-05T19:26:42.260 回答