diff --git a/Mailnag/common/config.py b/Mailnag/common/config.py index fcbdf2d..f638537 100644 --- a/Mailnag/common/config.py +++ b/Mailnag/common/config.py @@ -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' } diff --git a/Mailnag/daemon/mailnagdaemon.py b/Mailnag/daemon/mailnagdaemon.py index 07b759a..d452a3b 100644 --- a/Mailnag/daemon/mailnagdaemon.py +++ b/Mailnag/daemon/mailnagdaemon.py @@ -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() diff --git a/Mailnag/plugins/markasreadplugin.py b/Mailnag/plugins/markasreadplugin.py deleted file mode 100644 index 12d8fac..0000000 --- a/Mailnag/plugins/markasreadplugin.py +++ /dev/null @@ -1,76 +0,0 @@ -# Copyright 2013 - 2020 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