User:Andrew Sutherland/MailNews/GlobalDatabase/API/Examples

From MozillaWiki
Jump to: navigation, search

This page captures API use-cases as they currently exist, and where I want them to get to...

Querying Messages

Finding messages from scratch (now):

// make a new messages query object
let query = Gloda.newQuery(Gloda.NOUN_MESSAGE);
// messages from my friend that I haven't read...
let myFriendHome = Gloda.getIdentityForFullMailAddress("");
// synchronous is all we've got for now
let messages = query.getAllSync();

Finding messages just in a folder from scratch (now):

// assume we already have an nsIMsgFolder
let msgFolder = thatFolderWeAlreadyHave;
let query = Gloda.newQuery(Gloda.NOUN_MESSAGE);
let messages = query.getAllSync();

Finding messages related to an existing message (near future):

// assume we already have a message...
let message = thatMessageWeAlreadyHave;
let query = Gloda.newQuery(Gloda.NOUN_MESSAGE);
// find a message sent by the message's author from any of their identities
// syntax and what not very dubious...
query.dateFilter(, "within", "1 month");
let relatedMessages = query.getAllSync();