diff --git a/source/lib/thunderbird.js b/source/lib/thunderbird.js index 76f0f25..c6aa1bc 100644 --- a/source/lib/thunderbird.js +++ b/source/lib/thunderbird.js @@ -98,6 +98,23 @@ function showNewEmailNotification(message) { showNotification(title, text, message); } +function deleteMessage(message) { + try { + const win = Cc["@mozilla.org/appshell/window-mediator;1"] + .getService(Ci.nsIWindowMediator).getMostRecentWindow("mail:3pane").msgWindow; + let messages = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray); + message.markRead(true); + message.folder.msgDatabase = null; + messages.appendElement(message, false); + message.folder.deleteMessages(messages, win, false, false, null, true); + message.folder.msgDatabase = null; + } catch (e) { + console.error("Unable to delete messages. Exception: " + e); + return false; + } + return true; +} + function showNotification(title, text, message){ const notifications = require("sdk/notifications"); @@ -112,76 +129,92 @@ function showNotification(title, text, message){ return; } - // Doing notification with buttons if Linux and buttons are supported in - // the notify server - if (sps.engine === 1 && system.platform === "linux") { - const notifApi = require("./linux.js"); - - let id = null; - let actions = null; - if (message) { - if (sps.clickOptionNewEmail === 0) { - actions = [{ - label: _("open"), - handler: ()=>{ - display(message); - notifApi.close(id); - } - }, { - label: _("Mark_as_read"), - handler: ()=>{ - message.markRead(true); - notifApi.close(id); - } - }]; - } else { - actions = [{ - label: _("Mark_as_read"), - handler: ()=>{ - message.markRead(true); - notifApi.close(id); - } - }, { - label: _("open"), - handler: ()=>{ - display(message); - notifApi.close(id); - } - }]; + if (message) { + let id = 0; // Notification ID from libnotify (Linux only). + let notifApi = null; // Notification API for libnotify (Linux only). + let actions = []; + + let openAction = { + label: _("open"), + handler: ()=>{ + display(message); + if (notifApi) + notifApi.close(id); + } + }; + let markReadAction = { + label: _("Mark_as_read"), + handler: ()=>{ + message.markRead(true); + message.folder.msgDatabase = null; + if (notifApi) + notifApi.close(id); + } + }; + let deleteAction = { + label: _("Delete"), + handler: ()=>{ + deleteMessage(message); + if (notifApi) + notifApi.close(id); } + }; + + switch(sps.clickOptionNewEmail) { + case 0: + actions.push(openAction); + actions.push(markReadAction); + actions.push(deleteAction); + break; + case 1: + actions.push(markReadAction); + actions.push(openAction); + actions.push(deleteAction); + break; + case 2: + actions.push(deleteAction); + actions.push(openAction); + actions.push(markReadAction); + break; + } + // Do notification with buttons if Linux and + // buttons are supported in the notify server + if (sps.engine === 1 && system.platform === "linux") { + notifApi = require("./linux.js"); if (notifApi.checkButtonsSupported()) { - /* eslint-disable no-unused-vars */ +/* eslint-disable no-unused-vars */ id = notifApi.notifyWithActions(utils.getIcon(), title, text, system.name, reason=>{}, actions); - /* eslint-enable no-unused-vars */ +/* eslint-enable no-unused-vars */ console.log("notifyWithActions, id: " + id); if (message && id) message.setStringProperty("gnotifier-notification-id", id); return; + } else { +/* eslint-disable no-unused-vars */ + id = notifApi.notify(utils.getIcon(), title, text, system.name, + reason=>{}, data=>{ + // Call first top action (default action) on click + actions[0].handler(); + }); +/* eslint-enable no-unused-vars */ + console.log("notify, id: " + id); + if (message && id) + message.setStringProperty("gnotifier-notification-id", id); + return; } - - /* eslint-disable no-unused-vars */ - id = notifApi.notify(utils.getIcon(), title, text, system.name, - reason=>{}, data=>{ - display(message); - notifApi.close(id); - }); - /* eslint-enable no-unused-vars */ - console.log("notify, id: " + id); - if (message && id) - message.setStringProperty("gnotifier-notification-id", id); - return; } - } - if (message) { notifications.notify({ title: title, text: text, iconURL: utils.getIcon(), /* eslint-disable no-unused-vars */ - onClick: data=>{display(message);} + onClick: data=>{ + // Call first top action (default action) on click + actions[0].handler(); + } /* eslint-enable no-unused-vars */ }); return; @@ -197,7 +230,7 @@ function showNotification(title, text, message){ function showClickableNotification(title, text, clickHandler) { if (sps.engine === 1 && system.platform === "linux") { const notifApi = require("./linux.js"); - /* eslint-disable no-unused-vars */ +/* eslint-disable no-unused-vars */ let id = notifApi.notify(utils.getIcon(), title, text, system.name, reason=>{}, data=>{ if (clickHandler) { @@ -205,7 +238,7 @@ function showClickableNotification(title, text, clickHandler) { notifApi.close(id); } }); - /* eslint-enable no-unused-vars */ +/* eslint-enable no-unused-vars */ } else { const notifications = require("sdk/notifications"); if (clickHandler) { diff --git a/source/locale/de.properties b/source/locale/de.properties index 77ed14b..c467391 100755 --- a/source/locale/de.properties +++ b/source/locale/de.properties @@ -15,3 +15,4 @@ File=Datei Folder=Ordner Empty_subject=[Empty subject] Empty_body=[Empty body] +Delete=Delete diff --git a/source/locale/en.properties b/source/locale/en.properties index c4a6b60..bb2f623 100644 --- a/source/locale/en.properties +++ b/source/locale/en.properties @@ -15,3 +15,4 @@ File=File Folder=Folder Empty_subject=[Empty subject] Empty_body=[Empty body] +Delete=Delete diff --git a/source/locale/es-ES.properties b/source/locale/es-ES.properties index fa61ac8..f87e3e3 100644 --- a/source/locale/es-ES.properties +++ b/source/locale/es-ES.properties @@ -15,3 +15,4 @@ File=Archivo Folder=Carpeta Empty_subject=[Empty subject] Empty_body=[Empty body] +Delete=Delete diff --git a/source/locale/fr.properties b/source/locale/fr.properties index aa07118..8e2bcef 100644 --- a/source/locale/fr.properties +++ b/source/locale/fr.properties @@ -15,3 +15,4 @@ File=Fichier Folder=Dossier Empty_subject=[Empty subject] Empty_body=[Empty body] +Delete=Delete diff --git a/source/locale/it-IT.properties b/source/locale/it-IT.properties index 4783ad1..fb1c0bd 100644 --- a/source/locale/it-IT.properties +++ b/source/locale/it-IT.properties @@ -15,3 +15,4 @@ File=File Folder=Cartella Empty_subject=[Empty subject] Empty_body=[Empty body] +Delete=Delete diff --git a/source/locale/nl.properties b/source/locale/nl.properties index 00b7009..fadbb05 100644 --- a/source/locale/nl.properties +++ b/source/locale/nl.properties @@ -15,3 +15,4 @@ File=File Folder=Folder Empty_subject=[Empty subject] Empty_body=[Empty body] +Delete=Delete diff --git a/source/locale/pl.properties b/source/locale/pl.properties index 8434515..59d41f4 100644 --- a/source/locale/pl.properties +++ b/source/locale/pl.properties @@ -15,3 +15,4 @@ File=Plik Folder=Folder Empty_subject=[Brak tematu] Empty_body=[Brak treści] +Delete=Usuń diff --git a/source/locale/ru-RU.properties b/source/locale/ru-RU.properties index 0c66aef..a060c6d 100644 --- a/source/locale/ru-RU.properties +++ b/source/locale/ru-RU.properties @@ -15,3 +15,4 @@ File=Файл Folder=Папка Empty_subject=[Empty subject] Empty_body=[Empty body] +Delete=Delete diff --git a/source/package.json b/source/package.json index 35970b2..3aee887 100644 --- a/source/package.json +++ b/source/package.json @@ -145,6 +145,10 @@ { "value": "1", "label": "Mark as read" + }, + { + "value": "2", + "label": "Delete" } ] },