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.

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) {}
                            }
                        });
                }
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:81 次

字数:7213

最后编辑:6年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文