Bug 1531317 - Message search WebExtension API. r=mkmelin

This commit is contained in:
Marvin Herrmann 2019-06-21 19:40:41 +12:00
Родитель 0666d6429b
Коммит cf8f0f4d7f
2 изменённых файлов: 123 добавлений и 0 удалений

Просмотреть файл

@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
ChromeUtils.defineModuleGetter(this, "Gloda", "resource:///modules/gloda/public.js");
ChromeUtils.defineModuleGetter(this, "MailServices", "resource:///modules/MailServices.jsm"); ChromeUtils.defineModuleGetter(this, "MailServices", "resource:///modules/MailServices.jsm");
ChromeUtils.defineModuleGetter(this, "MessageArchiver", "resource:///modules/MessageArchiver.jsm"); ChromeUtils.defineModuleGetter(this, "MessageArchiver", "resource:///modules/MessageArchiver.jsm");
ChromeUtils.defineModuleGetter(this, "MsgHdrToMimeMessage", "resource:///modules/gloda/mimemsg.js"); ChromeUtils.defineModuleGetter(this, "MsgHdrToMimeMessage", "resource:///modules/gloda/mimemsg.js");
@ -109,6 +110,59 @@ this.messages = class extends ExtensionAPI {
}); });
}); });
}, },
async query(queryInfo) {
let query = Gloda.newQuery(Gloda.NOUN_MESSAGE);
if (queryInfo.subject) {
query.subjectMatches(queryInfo.subject);
}
if (queryInfo.fullText) {
query.fulltextMatches(queryInfo.fullText);
}
if (queryInfo.body) {
query.bodyMatches(queryInfo.body);
}
if (queryInfo.author) {
query.authorMatches(queryInfo.author);
}
if (queryInfo.recipients) {
query.recipientsMatch(queryInfo.recipients);
}
if (queryInfo.fromMe) {
query.fromMe();
}
if (queryInfo.toMe) {
query.toMe();
}
if (queryInfo.flagged !== null) {
query.starred(queryInfo.flagged);
}
if (queryInfo.folder) {
let folder = MailServices.folderLookup.getFolderForURL(
folderPathToURI(queryInfo.folder.accountId, queryInfo.folder.path)
);
query.folder(folder);
}
if (queryInfo.fromDate || queryInfo.toDate) {
query.dateRange([queryInfo.fromDate, queryInfo.toDate]);
}
let collectionArray = await new Promise((resolve) => {
query.getCollection({
onItemsAdded(items, collection) {
},
onItemsModified(items, collection) {
},
onItemsRemoved(items, collection) {
},
onQueryCompleted(collection) {
resolve(collection.items.map(glodaMsg => glodaMsg.folderMessage));
},
});
});
return messageListTracker.startList(collectionArray, context.extension);
},
async update(messageId, newProperties) { async update(messageId, newProperties) {
let msgHdr = messageTracker.getMessage(messageId); let msgHdr = messageTracker.getMessage(messageId);
if (!msgHdr) { if (!msgHdr) {

Просмотреть файл

@ -70,6 +70,75 @@
} }
] ]
}, },
{
"name": "query",
"type": "function",
"description": "Gets all messages that have the specified properties, or all messages if no properties are specified.",
"async": true,
"parameters": [
{
"type": "object",
"name": "queryInfo",
"properties": {
"subject": {
"type": "string",
"optional": true,
"description": "Returns only messages with this value matching the subject."
},
"fullText": {
"type": "string",
"optional": true,
"description": "Returns only messages with this value somewhere in the mail (subject, body or author)."
},
"body": {
"type": "string",
"optional": true,
"description": "Returns only messages with this value in the body of the mail."
},
"author": {
"type": "string",
"optional": true,
"description": "Returns only messages with this value matching the author."
},
"recipients": {
"type": "string",
"optional": true,
"description": "Returns only messages with this value matching one or more recipients."
},
"fromMe": {
"type": "boolean",
"optional": true,
"description": "Returns only messages with the author matching any configured identity."
},
"toMe": {
"type": "boolean",
"optional": true,
"description": "Returns only messages with one or more recipients matching any configured identity."
},
"flagged": {
"type": "boolean",
"optional": true,
"description": "Returns only flagged (or unflagged if false) messages."
},
"folder": {
"$ref": "folders.MailFolder",
"optional": true,
"description": "Returns only messages from the specified folder."
},
"fromDate": {
"$ref": "extensionTypes.Date",
"optional": true,
"description": "Returns only messages with a date after this value."
},
"toDate": {
"$ref": "extensionTypes.Date",
"optional": true,
"description": "Returns only messages with a date before this value."
}
}
}
]
},
{ {
"name": "update", "name": "update",
"type": "function", "type": "function",