ThunderBird Event for Viewing a Message
javascript, thunderbird, thunderbird-addon
Solution
If what you want is something similar to a Greasemonkey script that would run on every message, you should:
- Wait for the `load` event of the `window`.
- Retrieve the message pane object with `document.getElementById("messagepane")`.
- Bind your handler to the message pane's `DOMContentLoaded` event, or similar events like `load` depending on when exactly you want your handler to be called. `DOMContentLoaded` will give you a Greasemonkey-style behavior.
- In the event handler, `event.originalTarget` is the document corresponding to the displayed message. You can apply all the usual DOM modification techniques here.
For more details, see this example from the documentation.
Problem
I'm trying to modify a message before it is displayed in the main window in Thunderbird. I can't seem to find 1) An event that will be triggered when a new message is opened/viewed 2) A way to modify the displayed contents of a message. I believe I need the `chrome://messenger/content/messenger.xul` overlay, and can use a listener such as: ``` window.addEventListener( "SOME MAGIC HERE", modify_message_handler, true ); ``` But what that event is, I am unsure, along with what object I will get (a message header?) and how easily I can modify what is displayed. 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 does it pass?