ThunderBird event to view message

I am trying to modify a message before it appears in the main Thunderbird window. It seems that I can not find 1) An event that will fire when opening / viewing a new message. 2) A way to change the displayed content of the message.

I think I need a chrome://messenger/content/messenger.xul and you can use a listener, for example:

 window.addEventListener( "SOME MAGIC HERE", modify_message_handler, true ); 

But what kind of event is it, I’m not sure, however, which object I will receive (message header?), And how easily I can change the displayed one.

So the questions are:

  • Do I have the correct overlay?
  • Can this be done with events? If not, how?
  • If so, what event is needed and what object is it taking place?
+6
source share
4 answers

If you want something similar to a Greasemonkey script that will run on every post, you should:

  • Wait for the load event of the window .
  • Retrieve the message bar object using document.getElementById("messagepane") .
  • Bind a handler to a DOMContentLoaded message bar event or similar events, such as load , depending on when exactly you want your handler to be called. DOMContentLoaded will give you Greasemonkey style behavior.
  • In the event handler, event.originalTarget is the document that corresponds to the displayed message. Here you can apply all the usual DOM modification methods.

See this example in the documentation for more details.

+7
source

It is not clear where you have tried it yet, but I suggest the following: this outdated documentation assumes the existence of the OnItemPropertyChanged event that you can listen to the "public" property, which seems to be defined in the source .

However, this does not apply to folders or folders and messages; and you’ll have to dig deeper to find out if the properties of the object’s object will be transferred, allowing you to make changes.

Hope that sheds some light; If you have already done so, let us know what you found out.

+5
source

First of all, I will refer to the thunderbird-extension tag in your question.

The Thunderbird Extension by Paolo "Kaosmos" has many ready-made tools for your consideration.


HeaderToolsLite:

Editing options (changing only the headers or the entire source code of a message ) are available from the "Message" → "HeaderToolsLite" menu or from the context menu in the message panel.

The function of editing the entire source code should be used with caution, because an incorrect change can cause problems when displaying all the messages in the folder.



Attach additional tools:

 attach easily messages selected in the main window<br /> attach attachments from other messages<br /> attach files from 5 favourite directories<br /> attach files and directories in zipped format<br /> 



DSN OPTIONS GUI:

an extension that adds a graphical interface to handle preferences, both global and for each account, of the " Delivery Status Notification " ( DSN ).



Useful links:
Famous Handbook 1: Common use cases for modifying messages
Famous Reference 2: Thunderbird API for Message Box and Message Header
Famous Reference 3: Creating a Thunderbird Extension
Famous Reference 4: Using the XUL Thunderbird Interface in an Extension

+3
source

Generic Human has set me on the right track with a much needed link. First of all, you need to add the load event. I will insert part of the code with my most primitive understanding:

 window.addEventListener("load", function load(event) { window.removeEventListener("load", load, false); myExtension.init(); }, false); 

When this overhead load script loads, run init .

 var myExtension = { init: function() { var appcontent = document.getElementById("appcontent"); // browser app content if (appcontent) { appcontent.addEventListener("OMContentLoaded", myExtension.onPageLoad, true); } var messagepane = document.getElementById("messagepane"); // tunderbird message pane if(messagepane) { messagepane.addEventListener("load", function(event) { myExtension.onPageLoad(event); }, true); } }, 

In init I add a listener that calls onPageLoad every time a message is displayed. I actually do not use afaik appcontent .

  onPageLoad: function(aEvent) { var doc = aEvent.originalTarget; // doc is document that triggered "onload" event // we can now morph the loaded page // doc.location is a 'Location' object var newDat = mutateBody(doc.body.innerHTML); doc.body.innerHTML = newDat; aEvent.originalTarget.defaultView.addEventListener("unload", function(event) { myExtension.onPageUnload(event); }, true); }, onPageUnload: function(aEvent) { // No action necessary yet } }; 

doc.body.textContents seemed like an obvious element, but in fact it did not support formatting (darn HTML) - using innerHTML works much better for my needs.

+1
source

Source: https://habr.com/ru/post/919914/


All Articles