tbkeys
tbkeys copied to clipboard
Quick Filter / Quick Search for Sender / Recipients / Subject
There used to be a shortcut / keybinding ('', but not sure if it has been the default keybinding) to quickly toggle the filter of the message window by "sender", "recipients" and "subject" of the currently selected mail. I believe it was a feature of the https://github.com/trlkly/dorando-keyconfig add-on.
Maybe this feature can already be achieved with tbkeys
. If so, it would be nice to document how to do it.
Thank you very much for this add-on!
Yep, that's already possible. Go to your Add-ons Manager, then to "tbkeys-lite", then to the "Preferences"-tab. Add the following command to "Main key bindings" on a new line and don't forget to add a comma on the line above (otherwise it's not valid JSON anymore): "/": "cmd:cmd_showQuickFilterBar" (I'm using the forward slash key which you can replace with any key you want)
Has worked for me and hope it does for you. Otherwise, let me know.
Thanks for this add-on as well, very usefull!
Note: In case you're curious where I got the command from. I got it from the main command set file of the Thunderbird source code linked in the Command Syntax Section of the README
Final Note: There is also a command called: "cmd:cmd_toggleQuickFilterBar" which I find less intuitive to use though since it'll cause the QuickSearch Bar to disappear when it was already open (cause it's toggling). However, that's usually not what I want. If it's already open, I would like the cursor to just move there, so I find the command given above more useful.
Thank you for your reply!
I already have the same shortcut defined as a workaround. The main problem is, that the original behavior filled the "Filter Textbox" with the sender's email address. Pressing the shortcut again, pre-filled the filter with the recipient's email address of the currently selected mail. And another press filtered the message list by the given subject.
I am missing such a feature with tbkeys
. Any idea how to archive this?
Okay, now I understand what you would like to do. Well, you could probably achieve this with some custom java-script function. Not sure if this would be supported in the light version though because it says it doesn't allow abitrary java script. However, you might be able to insert your own function in the source code and call it with the "func:" prefix like described in the README. Does that help?
Just played around with the source code and found that you could edit the implementations.js and add the following function to the builtins object:
testFunction: function(window) {
window.goDoCommand('cmd_showQuickFilterBar');
let qFilterBox= window.document.querySelector("#qfb-qs-textbox");
qFilterBox.inputField.value = "test";
}
If you add "q": "tbkeys:testFunction"
(yes, it's tbkeys not func if you do it like this) to your preferences JSON and press q
it'll focus on Quick Filter and write "test" in the input.
This is quite hacky and there might be better ways but you could continue like this by grabbing the sender and inserting that instead of "test" as well as selecting the correct filter option.
As I said, there might be better ways, just thought I give it a shot :D
Here is a screenshot of my code:
Ok, cool! Thx! This is something! :+1:
Next step is to find out how to retrieve/toggle Subject, From and To...
Any idea how to get retrieve the header fields out of the message pane?
I tried something like this: qFilterBox.inputField.value = window.currentHeaderData.subject.headerValue;
but this only sets the subject of the last opened mail message (not the one which is selected in the message pane).
I just tried your command and for me, it kinda works. When I select a message with the (e.g. with the arrow keys) in the message list, it is automatically opens on the right (in the message pane). Then I press "q" which (using your command) takes the subject of the current message and puts it in quick search. So that's good. If I then use the arrow keys again, it doesn't automatically update the text to the subject of the selected message, that's true. But you can always press "q" again and then it's updated - at least that's the case for me.
Could you maybe explain your use case in a bit more detail? I'm just wondering if this feature is really necessary because as far as I understood you, you would like to use the subject, from and to fields of a certain message as input for Quick Filter. If I would like that I can select the message with my cursor or the arrow keys and it automatically opens in the message pane. Then I press "q" and everything works fine. So my question would be: Why isn't the behaviour I described enough? Does a selected email not automatically open in your message pane or don't you use a message pane? If you could explain that I might be able to help :) Apologies if I misunderstand what you are trying to do.
Where can I find the documentation for the "window" object? How shall I change "window.currentHeaderData.subject.headerValue" to get the sender?
@p135246
Use the mime2DecodedAuthor property of a message header to get the sender.
Try these:
(function () {
var msgHdr = window.gTabmail.currentAbout3Pane.gDBView.hdrForFirstSelectedMessage;
if (msgHdr) {
var date = new Date(msgHdr.dateInSeconds * 1000).toLocaleString();
window.alert('Subject: ' + msgHdr.mime2DecodedSubject +
'\nFrom: ' + msgHdr.mime2DecodedAuthor +
'\nTo: ' + msgHdr.mime2DecodedRecipients +
'\nDate: ' + date);
}
})();
(function () {
var quickFilterBar = window.gTabmail.currentAbout3Pane.quickFilterBar;
quickFilterBar.filterer.clear();
quickFilterBar.filterer.visible = true;
quickFilterBar.filterer.setFilterValue('starred', true);
quickFilterBar.filterer.setFilterValue('addrBook', true);
quickFilterBar.updateSearch();
})();
(function () {
var quickFilterBar = window.gTabmail.currentAbout3Pane.quickFilterBar;
quickFilterBar.filterer.clear();
quickFilterBar.filterer.visible = true;
quickFilterBar.filterer.filterValues.text = {
states: {sender: false, recipients: false, subject: true, body: false},
text: 'example',
};
quickFilterBar.updateSearch();
})();
About new mail front end http://developer.thunderbird.net/thunderbird-development/codebase-overview/mail-front-end http://developer.thunderbird.net/add-ons/updating/tb115/adapt-to-changes-in-thunderbird-103-115
Reference http://searchfox.org/comm-esr115/search?q=filterer&path=test http://searchfox.org/comm-esr115/search?q=async+setQuickFilter
Thank you very much! However, I would prefer a minimal change of the above code to get the sender instead of the header. In fact, I just want to implement a keyboard shortcut that selects all messages by sender.
@p135246
Try the following code snippets in Thunderbird 115:
(function () {
window.goDoCommand('cmd_showQuickFilterBar');
var textbox = window.gTabmail.currentAbout3Pane.document.getElementById('qfb-qs-textbox');
textbox.inputField.value = window.gTabmail.currentAboutMessage.currentHeaderData.from.headerValue;
})();
(function () {
var quickFilterBar = window.gTabmail.currentAbout3Pane.quickFilterBar;
quickFilterBar.filterer.clear();
quickFilterBar.filterer.visible = true;
quickFilterBar.filterer.filterValues.text = {
states: {sender: true, recipients: false, subject: false, body: false},
text: window.gTabmail.currentAbout3Pane.gDBView.hdrForFirstSelectedMessage.mime2DecodedAuthor,
};
quickFilterBar.updateSearch();
})();
The first code snippet is similar to the solution posted by LasseWolter and jkirk.
The second code snippet is what I would consider to be the correct solution.
Great, thank you very much! The first solution worked---the textbox is now filled with the current sender. Can I also automatically apply the filter? (now I must additionally press enter)
Following examples in the sample repository, I produced the following solution.
In manifest.json
I have
"commands": {
"select-by-sender": {
"suggested_key": {
"default": "Ctrl+Shift+S"
},
"description": "Quick filter by sender"
}
}
and in background.js
I have
messenger.commands.onCommand.addListener(async (command) => {
if (command === "select-by-sender") {
let messageList = await browser.mailTabs.getSelectedMessages();
let message = messageList.messages[0];
let text = { text: message.author, author: true };
await browser.mailTabs.setQuickFilter({ text });
};
});
Pressing Ctrl+Shift+S
while having one message selected then fires the quick filter prefilled with the author exactly as I wanted (no confirmation needed).
Your addon should work exactly like the second code snippet that I posted above.
Reference http://webextension-api.thunderbird.net/en/115/mailTabs.html#setquickfilter-tabid-properties http://searchfox.org/comm-esr115/search?q=async+setQuickFilter
Your solutions were super helpful, thanks! This was my first encounter with Thunderbird extensions and Java and I was a bit disoriented until I found a bit of time to delve into it myself. To close this issue (at least for me), I wrote the following super simple extension quickfilter-kbd,