Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Gloda examples

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.

Show all messages in a conversation regardless of the folder in which they are stored

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)

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

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("[email protected]");
	  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) {}	
		  }
  });});
  

Document Tags and Contributors

 Contributors to this page: chrisdavidmills, One, jenzed, DanielT
 Last updated by: chrisdavidmills,