This content covers features introduced in Thunderbird 3

This page provides some examples for using gloda. See Creating a gloda message query for more examples.

a) Show all messages in a conversation regardless of the folder in which they are stored,
b) Search messages by subject

Assuming that you have a message (glodaMessage) in the conversation already, this is straight forward using glodaMessage.conversation.getMessagesCollection()

aListener = {
    /* called when new items are returned by the database query or freshly indexed */
    onItemsAdded: function _onItemsAdded(aItems, aCollection) {
    },
    /* called when items that are already in our collection get re-indexed */
    onItemsModified: function _onItemsModified(aItems, aCollection) {
    },
    /* called when items that are in our collection are purged from the system */
    onItemsRemoved: function _onItemsRemoved(aItems, aCollection) {
    },
    /* called when our database query completes */
    onQueryCompleted: function _onQueryCompleted(conversation_coll) {
        try {
            for (var conv in conversation_coll) {
                //do something with the Conversation here
                alert(conv.subject);
            }
        } catch (e) {}
    }
}

glodaMessage.conversation.getMessagesCollection(aListener)

Alternatively if you need to get a conversation based on the subject, you need to do a query (using the same listener as above).

If you search for a message based on subject, use NOUN_MESSAGE instead of NOUN_CONVERSATION and modify the listener accordingly.

query=Gloda.newQuery(Gloda.NOUN_CONVERSATION);
query.subjectMatches("Gloda makes searching easy");
query.getCollection(aListener)

Search messages by tags

Searches for all messages having any (or several) of all tags defined in TB

  let query = Gloda.newQuery(Gloda.NOUN_MESSAGE);
  let tagArray = MailServices.tags.getAllTags({});

  query.tags(...tagArray);
  let collection = query.getCollection(myListener);

 

Search messages by dateRange

Searches for all messages within a date range

id_q=Gloda.newQuery(Gloda.NOUN_MESSAGE);
// Define a date range form yesterday to now
id_q.dateRange([new Date() - 86400000, new Date()]);
var myListener = {
    /* called when new items are returned by the database query or freshly indexed */
    onItemsAdded: function _onItemsAdded(aItems, aCollection) {
    },
    /* called when items that are already in our collection get re-indexed */
    onItemsModified: function _onItemsModified(aItems, aCollection) {
    },
    /* called when items that are in our collection are purged from the system */
    onItemsRemoved: function _onItemsRemoved(aItems, aCollection) {
    },
    /* called when our database query completes */
    onQueryCompleted: function _onQueryCompleted(aCollection) {
        var items = aCollection.items;

        for (msg of items) {
            alert(msg.subject);
        };
    }
  };
collection = id_q.getCollection(myListener);

Show all messages where the from, to and CC values include a specified email address

 At present there doesn't appear to be any way of going directly from an email address to email addresses that it involves. Instead you need to do two queries, first to get the "Identity" object for an email address and then to get the messages.

This requires two chained asynchronous calls:

//First take an email address and turn it into an identity object
id_q = Gloda.newQuery(Gloda.NOUN_IDENTITY);
id_q.kind("email");
id_q.value("test@example.com");
id_coll = id_q.getCollection({
                onItemsAdded: function _onItemsAdded(aItems, aCollection) {
                },
                onItemsModified: function _onItemsModified(aItems, aCollection) {
                },
                onItemsRemoved: function _onItemsRemoved(aItems, aCollection) {
                },
                onQueryCompleted: function _onQueryCompleted(id_coll) {
                    //woops no identity
                    if (id_coll.items.length <= 0) return;
                        id = id_coll.items[0];
                        //now we use the identity to find all messages that person was involved with
                        msg_q=Gloda.newQuery(Gloda.NOUN_MESSAGE)
                        msg_q.involves(id)
                        msg_q.getCollection({
                            /* called when new items are returned by the database query or freshly indexed */
                            onItemsAdded: function _onItemsAdded(aItems, aCollection) {
                            },
                            /* called when items that are already in our collection get re-indexed */
                            onItemsModified: function _onItemsModified(aItems, aCollection) {
                            },
                            /* called when items that are in our collection are purged from the system */
                            onItemsRemoved: function _onItemsRemoved(aItems, aCollection) {
                            },
                            /* called when our database query completes */
                            onQueryCompleted: function _onQueryCompleted(msg_coll) {
                                try {
                                    while(msg = msg_coll.items.pop()) {
                                        //do something with the messages here
                                        alert(msg.subject);
                                    }
                                } catch (e) {}
                            }
                        });
                }
});