mirror of
https://github.com/pulb/mailnag.git
synced 2026-05-06 18:35:40 +02:00
Implementating IMAP read feature directly in the daemon
This commit is contained in:
@@ -26,6 +26,7 @@ mailnag_defaults = {
|
||||
'poll_interval' : '10',
|
||||
'imap_idle_timeout' : '10',
|
||||
'autostart' : '1',
|
||||
'mark_imap_read' : '1',
|
||||
'connectivity_test' : 'auto',
|
||||
'enabled_plugins' : 'dbusplugin, soundplugin, libnotifyplugin'
|
||||
}
|
||||
|
||||
@@ -126,9 +126,22 @@ class MailnagDaemon(MailnagController):
|
||||
|
||||
# Part of MailnagController interface
|
||||
def mark_mail_as_read(self, mail_id):
|
||||
# Note: ensure_not_disposed() is not really necessary here
|
||||
# (the memorizer object is available in dispose()),
|
||||
# but better be consistent with other daemon methods.
|
||||
mails = self._mailchecker._all_mails
|
||||
found = False
|
||||
for mail in mails:
|
||||
if mail_id == mail.id:
|
||||
found = True
|
||||
break
|
||||
if (not found) or (not bool(int(self._cfg.get('core', 'mark_imap_read')))):
|
||||
self._ensure_not_disposed()
|
||||
self._memorizer.set_to_seen(mail_id)
|
||||
self._memorizer.save()
|
||||
return
|
||||
backend = mail.account._get_backend()
|
||||
if type(backend).__name__ == 'IMAPMailboxBackend':
|
||||
mailid = mail.strID
|
||||
conn = backend._conn
|
||||
status, res = conn.uid("STORE", mailid, "+FLAGS", "(\Seen)")
|
||||
self._ensure_not_disposed()
|
||||
self._memorizer.set_to_seen(mail_id)
|
||||
self._memorizer.save()
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
# Copyright 2013 - 2020 Andreas Angerer <andreas.angerer>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301, USA.
|
||||
#
|
||||
|
||||
import os
|
||||
import dbus
|
||||
import threading
|
||||
from Mailnag.common.plugins import Plugin
|
||||
from Mailnag.common.i18n import _
|
||||
|
||||
|
||||
class MarkAsReadPlugin(Plugin):
|
||||
def _mark_mail_as_read(self, mail_id):
|
||||
mails = self.controller._mailchecker._all_mails
|
||||
found = False
|
||||
for mail in mails:
|
||||
if mail_id == mail.id:
|
||||
found = True
|
||||
break
|
||||
if not found:
|
||||
self.controller._ensure_not_disposed()
|
||||
self.controller._memorizer.set_to_seen(mail_id)
|
||||
self.controller._memorizer.save()
|
||||
return
|
||||
backend = mail.account._get_backend()
|
||||
mailid = mail.strID
|
||||
conn = backend._conn
|
||||
if type(backend).__name__ == 'IMAPMailboxBackend':
|
||||
status, res = conn.uid("STORE", mailid, "+FLAGS", "(\Seen)")
|
||||
self.controller._ensure_not_disposed()
|
||||
self.controller._memorizer.set_to_seen(mail_id)
|
||||
self.controller._memorizer.save()
|
||||
|
||||
|
||||
|
||||
def _mark_mail_as_read_bak(self, mail_id, mail):
|
||||
self.controller._ensure_not_disposed()
|
||||
self.controller._memorizer.set_to_seen(mail_id)
|
||||
self.controller._memorizer.save()
|
||||
|
||||
def enable(self):
|
||||
self.controller = self.get_mailnag_controller()
|
||||
self.controller.mark_mail_as_read = self._mark_mail_as_read
|
||||
|
||||
|
||||
def disable(self):
|
||||
self.controller.mark_mail_as_read = self._mark_mail_as_read_bak
|
||||
|
||||
|
||||
def get_manifest(self):
|
||||
return (_("MarkAsReadPlugin"),
|
||||
_("Marks mails as read on the IMAP server upon clicking them away."),
|
||||
"1.0",
|
||||
"Andreas Angerer")
|
||||
|
||||
|
||||
def get_default_config(self):
|
||||
return {}
|
||||
|
||||
|
||||
def has_config_ui(self):
|
||||
return False
|
||||
Reference in New Issue
Block a user