-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds plugin that allows marking IMAP messages as read #215
Conversation
Hey andia89, many thanks for your pull request, this feature is very appreciated! 😃 Though can you please add the feature to the daemon itself instead to a plugin? As you already pointed out, your plugin implementation is a bit hackish as the mark-as-read functionality isn't exposed by the plugin api and hence your plugin accesses/patches daemon internals which can easily change and break the plugin in the future. Besides that I also believe most people want to have their mails marked as read on the imap server by default. If not, we can make this optional in mailnag.cfg. |
All done. That was even easier then :) Ive added a section to mailnag.cfg just in case someone doesn't like the change |
Wow, that was lightning fast! :D Awesome, will review and merge it ASAP.
|
Sorry for not merging your PR yet. I reviewed it already but there are a view changes I don't like. I didn't find the time yet to think about a better solution for those changes unfortunatelly. I'll add some comments for the time being. |
for response_part in msg_data: | ||
if isinstance(response_part, tuple): | ||
try: | ||
msg = email.message_from_bytes(response_part[1]) | ||
except: | ||
logging.debug("Couldn't get IMAP message.") | ||
continue | ||
yield (folder, msg) | ||
yield (folder, msg, num.decode("utf-8")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The list_messages() method is defined in the base interface and implemented in several backends like in this imap backend. list_messages() of all other backends returns (folder, msg) pairs, wheras imap now returns (folder, msg, num) tuples, which breaks the interface (inconsistency).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, that is of course an issue. Maybe it would be a way to add some kind of dummy number to the other backends? I don't see any other way of letting mailnag know about this imap specific id though
@@ -126,9 +126,22 @@ def shutdown(self): | |||
|
|||
# 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment should not be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, of course
@@ -110,7 +110,7 @@ def _convert_mails(self, mails): | |||
d['sender_addr'] = addr # string (s) | |||
d['account_name'] = m.account_name # string (s) | |||
d['id'] = m.id # string (s) | |||
|
|||
d['strID'] = m.strID # string (s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is strID exposed by the dbus interface?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that was a mistake on my side, I think I tested that once to let the gnome-shell extension know about the ID (and open the specific mail directly when clicking on it) in the end it didn't really work. I guess it can be removed
@@ -225,8 +225,7 @@ def _select_single_folder(self, conn): | |||
folder = self.folders[0] | |||
else: | |||
folder = "INBOX" | |||
|
|||
conn.select(f'"{folder}"', readonly = True) | |||
conn.select(f'"{folder}"') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really necessary to remove the readonly flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The readonly definitely has to go, I mean one could put readonly = False
, but that is just a matter of taste
self.account_name = account.name | ||
self.account_id = account.get_id() | ||
self.id = id | ||
self.strID = strID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the idea of adding an imap specific mail counter (strID) to the generic mail class. I can't come up with a better solution right now, though.
return | ||
backend = mail.account._get_backend() | ||
if type(backend).__name__ == 'IMAPMailboxBackend': | ||
mailid = mail.strID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The terms mailID and strID are missleading. This is rather a mail counter.
self._memorizer.save() | ||
return | ||
backend = mail.account._get_backend() | ||
if type(backend).__name__ == 'IMAPMailboxBackend': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding backend specific code here feels hackish. This should be implemented within the backend, which marks the mail as read if it supports it.
Thanks again! Will do some refactoring later |
No worries, I fixed all commented issues and refactored some stuff. Will push my changes within the next days :)
|
I pushed all fixes in commit a124d14. |
Thanks for the refactor. It seems to be not working for me though. Messages are not marked as read on my gmail anymore... I will investigate |
Hmm It should work in all configuration scenarios. The main difference to your original patch is basically that messages are not marked as read immediately and seperately on every click , but "batch-marked" upon the next mail check on the server.
Am 6. November 2020 11:15:41 MEZ schrieb Andreas Angerer <notifications@github.com>:
…Thanks for the refactor. It seems to be not working for me though.
Messages are not marked as read on my gmail anymore... I will
investigate
--
You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub:
#215 (comment)
|
@pulb Just saw the hanging comment here: Yes it works, but the delay between marking it as read and it eventually being marked on the server side is a bit annoying when trying to clean up my inbox (at least to me). I "fixed" that for me by adding a
do you think that is a proper fix or to hackish? |
Hi Andreas,
I already thought about that workaround too, but came to the conclusion that it isn't a good idea because
1. check_for_mails() currently does not check idle accounts. (If it would, it would wake up all sleeping idle threads, which all at once would do a further check)
2. it would perform an unnecessary mail check for accounts that don't support server-side mark-as-read (e.g. pop3)
3. marking a mail as read from the gnome-shell extension would block/defer further attempts by the user to mark mails as read until the current mail check has been finished (which may take a long time, depending of the number of checked accounts and unread messages)
4. the "mark all as read" command of the gnome-shell extension does trigger mark-as-read requests for every single mail, so due to the problem stated in 3., marking all mails as read may take... forever.
|
What would speed up things though would be to decrease the poll interval / idle timeout in the config file.
|
I wrote a small plugin that allows marking IMAP messages as read also on the server upon doing it in mailnag. It required some minor changes to the code base of mailnag, but nothing serious (apart from the fact that the folders cannot be readonly anymore). I think that is a nice addition that solves a small annoyance.
I'm not entirely sure overloading a function like that is the idea of plugins for this app, but I didn't want to rewrite the whole dBus implementation
Solves #214