Search Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

Experiment API to save a text file

  • 2 svar
  • 0 har dette problemet
  • 10 views
  • Siste svar av richard344

more options

I'm trying to write a Thunderbird add-on that allows me to export specific messages to some other custom-built software by saving in a specific local folder. I've written an add-on and included an experiment API because I understand that saving a file isn't possible through the built in APIs. I've lifted much of the code from other places and stitched it together. Everything works apart from the implementation of the API (which of course is the difficult bit)

My problem is that I think I need to use IOUtils but can't seem to get this to load. Has this been deprecated?

My experiment API implementation file currently looks like the following and it's the line: XPCOMUtils.defineLazyGlobalGetters(this, ["IOUtils"]); that seems to be causing it to fail

"use strict";

// Using a closure to not leak anything but the API to the outside world. (function (exports) {

 // Get various parts of the WebExtension framework that we need.
 var { ExtensionCommon } = ChromeUtils.import("resource://gre/modules/ExtensionCommon.jsm");
 // You probably already know what this does.
 var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 // A helpful class for listening to windows opening and closing.
 var { ExtensionSupport } = ChromeUtils.import("resource:///modules/ExtensionSupport.jsm");
 var { FileUtils }       = ChromeUtils.import("resource://gre/modules/FileUtils.jsm");
 var { XPCOMUtils }      = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 XPCOMUtils.defineLazyGlobalGetters(this, ["IOUtils"]);
 
 var ContactAPI = class extends ExtensionCommon.ExtensionAPI {
   getAPI(context) {
     return {
       ContactAPI: {
         saveTextFile: async function(fname, mydata) {
           var uint8 = new Uint8Array(mydata);
           uint8.reduce((binary, uint8) => binary + uint8.toString(2), "");
           Services.wm.getMostRecentWindow("mail:3pane").alert(mydata);
           var ret = await IOUtils.write(fname, uint8);
           return ret;
         },
       },
     };
   }
   onShutdown(isAppShutdown) {
     // This function is called if the extension is disabled or removed, or Thunderbird closes.
     // We usually do not have to do any cleanup, if Thunderbird is shutting down entirely
     if (isAppShutdown) {
       return;
     }
     console.log("Goodbye world!");
   }
 };
 // Export the api by assigning in to the exports parameter of the anonymous closure
 // function, which is the global this.
 exports.ContactAPI = ContactAPI;

})(this)

I'm trying to write a Thunderbird add-on that allows me to export specific messages to some other custom-built software by saving in a specific local folder. I've written an add-on and included an experiment API because I understand that saving a file isn't possible through the built in APIs. I've lifted much of the code from other places and stitched it together. Everything works apart from the implementation of the API (which of course is the difficult bit) My problem is that I think I need to use IOUtils but can't seem to get this to load. Has this been deprecated? My experiment API implementation file currently looks like the following and it's the line: XPCOMUtils.defineLazyGlobalGetters(this, ["IOUtils"]); that seems to be causing it to fail "use strict"; // Using a closure to not leak anything but the API to the outside world. (function (exports) { // Get various parts of the WebExtension framework that we need. var { ExtensionCommon } = ChromeUtils.import("resource://gre/modules/ExtensionCommon.jsm"); // You probably already know what this does. var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); // A helpful class for listening to windows opening and closing. var { ExtensionSupport } = ChromeUtils.import("resource:///modules/ExtensionSupport.jsm"); var { FileUtils } = ChromeUtils.import("resource://gre/modules/FileUtils.jsm"); var { XPCOMUtils } = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); XPCOMUtils.defineLazyGlobalGetters(this, ["IOUtils"]); var ContactAPI = class extends ExtensionCommon.ExtensionAPI { getAPI(context) { return { ContactAPI: { saveTextFile: async function(fname, mydata) { var uint8 = new Uint8Array(mydata); uint8.reduce((binary, uint8) => binary + uint8.toString(2), ""); Services.wm.getMostRecentWindow("mail:3pane").alert(mydata); var ret = await IOUtils.write(fname, uint8); return ret; }, }, }; } onShutdown(isAppShutdown) { // This function is called if the extension is disabled or removed, or Thunderbird closes. // We usually do not have to do any cleanup, if Thunderbird is shutting down entirely if (isAppShutdown) { return; } console.log("Goodbye world!"); } }; // Export the api by assigning in to the exports parameter of the anonymous closure // function, which is the global this. exports.ContactAPI = ContactAPI; })(this)

All Replies (2)

more options

I am not even going to try and help you with the actual issue as I am not a developer of anything these days. I suggest you try asking in the addon developers mailing list where add on developers and even some of the paid folks can be found. https://thunderbird.topicbox.com/groups/addons

Expe4iments are not going to be supported going forward is my understanding, so getting involved with the lest is a must I think.

Perhaps this thread might be related enough to offer some ideas. https://thunderbird.topicbox.com/groups/addons/Ta1ba6e8a2d5a27a3/lazy-loading-alternative-for-getfull-when-using-the-messages-api

more options

Thanks will try those suggestions