mirror of
https://github.com/pulb/mailnag.git
synced 2026-05-07 20:28:19 +02:00
plugin hook api changes, enabled single notification mode and misc other fixes
mailchecker, plugins: pass both, new and all mails to MAILS_ADDED hook mailchecker: fixed wrong count for filtered new mails libnotify plugin: added some constants, enabled single notification mode, uncommented notification_id spamfilter plugin: renamed variable
This commit is contained in:
@@ -41,7 +41,7 @@ class HookTypes:
|
||||
# OUT: None
|
||||
MAIL_CHECK = 'mail-check'
|
||||
# func signature:
|
||||
# IN: all mails, count of new mails
|
||||
# IN: new mails, all mails
|
||||
# OUT: None
|
||||
MAILS_ADDED = 'mails-added'
|
||||
# func signature:
|
||||
@@ -49,7 +49,7 @@ class HookTypes:
|
||||
# OUT: None
|
||||
MAILS_REMOVED = 'mails-removed'
|
||||
# func signature:
|
||||
# IN: new mails
|
||||
# IN: all mails
|
||||
# OUT: filtered mails
|
||||
FILTER_MAILS = 'filter-mails'
|
||||
|
||||
|
||||
@@ -67,32 +67,34 @@ class MailChecker:
|
||||
|
||||
all_mails = self._mailsyncer.sync(accounts)
|
||||
unseen_mails = []
|
||||
new_mail_count = 0
|
||||
new_mails = []
|
||||
|
||||
for mail in all_mails:
|
||||
if self._reminder.contains(mail.id): # mail was fetched before
|
||||
if self._reminder.unseen(mail.id): # mail was not marked as seen
|
||||
unseen_mails.append(mail)
|
||||
if self._firstcheck:
|
||||
new_mail_count += 1
|
||||
new_mails.append(mail)
|
||||
|
||||
else: # mail is fetched the first time
|
||||
unseen_mails.append(mail)
|
||||
new_mail_count += 1
|
||||
new_mails.append(mail)
|
||||
|
||||
# apply filter plugin hooks
|
||||
filtered_mails = unseen_mails
|
||||
filtered_unseen_mails = unseen_mails
|
||||
for f in self._hookreg.get_hook_funcs(HookTypes.FILTER_MAILS):
|
||||
filtered_mails = try_call( lambda: f(filtered_mails), filtered_mails )
|
||||
filtered_unseen_mails = try_call( lambda: f(filtered_unseen_mails), filtered_unseen_mails )
|
||||
|
||||
filtered_new_mails = [m for m in new_mails if m in filtered_unseen_mails]
|
||||
|
||||
# TODO : signal MailsRemoved if not all mails have been removed
|
||||
# (i.e. if mailcount has been decreased)
|
||||
if len(all_mails) == 0:
|
||||
for f in self._hookreg.get_hook_funcs(HookTypes.MAILS_REMOVED):
|
||||
try_call( lambda: f(filtered_mails) )
|
||||
elif (new_mail_count > 0) and (filtered_mails > 0):
|
||||
try_call( lambda: f(filtered_unseen_mails) )
|
||||
elif len(filtered_new_mails) > 0:
|
||||
for f in self._hookreg.get_hook_funcs(HookTypes.MAILS_ADDED):
|
||||
try_call( lambda: f(filtered_mails, new_mail_count) )
|
||||
try_call( lambda: f(filtered_new_mails, filtered_unseen_mails) )
|
||||
|
||||
self._reminder.save(all_mails)
|
||||
|
||||
|
||||
@@ -41,9 +41,9 @@ class DBusPlugin(Plugin):
|
||||
controller = self.get_mailnag_controller()
|
||||
self._dbusservice = DBusService(controller)
|
||||
|
||||
def mails_added_hook(all_mails, new_mail_count):
|
||||
def mails_added_hook(new_mails, all_mails):
|
||||
self._dbusservice.set_mails(all_mails)
|
||||
self._dbusservice.MailsAdded(new_mail_count)
|
||||
self._dbusservice.MailsAdded(len(new_mails))
|
||||
|
||||
def mails_removed_hook(remaining_mails):
|
||||
self._dbusservice.set_mails(remaining_mails)
|
||||
|
||||
@@ -25,7 +25,10 @@ from gi.repository import Notify
|
||||
from common.plugins import Plugin, HookTypes
|
||||
from common.i18n import _
|
||||
|
||||
plugin_defaults = { 'notification_mode' : '1' }
|
||||
NOTIFICATION_MODE_SINGLE = '0'
|
||||
NOTIFICATION_MODE_SUMMARY = '1'
|
||||
|
||||
plugin_defaults = { 'notification_mode' : NOTIFICATION_MODE_SUMMARY }
|
||||
|
||||
|
||||
class LibNotifyPlugin(Plugin):
|
||||
@@ -48,12 +51,10 @@ class LibNotifyPlugin(Plugin):
|
||||
Notify.init("Mailnag")
|
||||
self._initialized = True
|
||||
|
||||
def mails_added_hook(all_mails, new_mail_count):
|
||||
def mails_added_hook(new_mails, all_mails):
|
||||
config = self.get_config()
|
||||
if config['notification_mode'] == 0:
|
||||
# TODO : not supported by plugin API yet
|
||||
# self._notify_single(new_mails)
|
||||
pass
|
||||
if config['notification_mode'] == NOTIFICATION_MODE_SINGLE:
|
||||
self._notify_single(new_mails)
|
||||
else:
|
||||
self._notify_summary(all_mails)
|
||||
|
||||
@@ -150,7 +151,7 @@ class LibNotifyPlugin(Plugin):
|
||||
def _notify_single(self, mails):
|
||||
for mail in mails:
|
||||
n = self._get_notification(mail.sender, mail.subject, "mail-unread")
|
||||
# notification_id = str(id(n))
|
||||
notification_id = str(id(n))
|
||||
# n.add_action("mark-as-read", _("Mark as read"), self._notification_action_handler, (mail, notification_id), None)
|
||||
n.show()
|
||||
self._notifications[notification_id] = n
|
||||
|
||||
@@ -40,7 +40,7 @@ class SoundPlugin(Plugin):
|
||||
def enable(self):
|
||||
self._gsettings = Gio.Settings.new('org.gnome.shell')
|
||||
|
||||
def mails_added_hook(all_mails, new_mail_count):
|
||||
def mails_added_hook(new_mails, all_mails):
|
||||
if self._gsettings.get_int('saved-session-presence') != 2:
|
||||
config = self.get_config()
|
||||
gstplay(get_data_file(config['soundfile']))
|
||||
|
||||
@@ -37,9 +37,9 @@ class SpamfilterPlugin(Plugin):
|
||||
config = self.get_config()
|
||||
self._filter_list = config['filter_text'].replace('\n', '').split(',')
|
||||
|
||||
def filter_mails_hook(new_mails):
|
||||
def filter_mails_hook(mails):
|
||||
lst = []
|
||||
for m in new_mails:
|
||||
for m in mails:
|
||||
if not self._is_filtered(m):
|
||||
lst.append(m)
|
||||
return lst
|
||||
|
||||
Reference in New Issue
Block a user