Merge pull request #158 from teto/multiple_mail_accounts
[RFC] Display per backend unread emails
This commit is contained in:
commit
03dd6c276f
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,4 +5,5 @@ build/*
|
|||||||
dist/*
|
dist/*
|
||||||
*.egg-info/*
|
*.egg-info/*
|
||||||
*~
|
*~
|
||||||
|
.i3pystatus-*
|
||||||
ci-build
|
ci-build
|
||||||
|
@ -6,6 +6,11 @@ class Backend(SettingsBase):
|
|||||||
"""Handles the details of checking for mail"""
|
"""Handles the details of checking for mail"""
|
||||||
|
|
||||||
unread = 0
|
unread = 0
|
||||||
|
settings = ("account", "Account name")
|
||||||
|
# required = ("account", )
|
||||||
|
|
||||||
|
account = "Default account"
|
||||||
|
|
||||||
"""Number of unread mails
|
"""Number of unread mails
|
||||||
|
|
||||||
You'll probably implement that as a property"""
|
You'll probably implement that as a property"""
|
||||||
@ -34,11 +39,15 @@ class Mail(IntervalModule):
|
|||||||
color = "#ffffff"
|
color = "#ffffff"
|
||||||
color_unread = "#ff0000"
|
color_unread = "#ff0000"
|
||||||
format = "{unread} new email"
|
format = "{unread} new email"
|
||||||
format_plural = "{unread} new emails"
|
format_plural = "{account} : {current_unread}/{unread} new emails"
|
||||||
hide_if_null = True
|
hide_if_null = True
|
||||||
email_client = None
|
email_client = None
|
||||||
|
|
||||||
on_leftclick = "open_client"
|
on_leftclick = "open_client"
|
||||||
|
on_upscroll = ["scroll_backend", 1]
|
||||||
|
on_downscroll = ["scroll_backend", -1]
|
||||||
|
|
||||||
|
current_backend = 0
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
for backend in self.backends:
|
for backend in self.backends:
|
||||||
@ -48,8 +57,13 @@ class Mail(IntervalModule):
|
|||||||
"""
|
"""
|
||||||
Returns the sum of unread messages across all registered backends
|
Returns the sum of unread messages across all registered backends
|
||||||
"""
|
"""
|
||||||
|
unread = 0
|
||||||
unread = sum(map(lambda backend: backend.unread, self.backends))
|
current_unread = 0
|
||||||
|
for id, backend in enumerate(self.backends):
|
||||||
|
temp = backend.unread
|
||||||
|
unread = unread + backend.unread
|
||||||
|
if id == self.current_backend:
|
||||||
|
current_unread = temp
|
||||||
|
|
||||||
if not unread:
|
if not unread:
|
||||||
color = self.color
|
color = self.color
|
||||||
@ -65,12 +79,17 @@ class Mail(IntervalModule):
|
|||||||
if unread > 1:
|
if unread > 1:
|
||||||
format = self.format_plural
|
format = self.format_plural
|
||||||
|
|
||||||
|
account_name = getattr(self.backends[self.current_backend], "account", "No name")
|
||||||
|
|
||||||
self.output = {
|
self.output = {
|
||||||
"full_text": format.format(unread=unread),
|
"full_text": format.format(unread=unread, current_unread=current_unread, account=account_name),
|
||||||
"urgent": urgent,
|
"urgent": urgent,
|
||||||
"color": color,
|
"color": color,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def scroll_backend(self, step):
|
||||||
|
self.current_backend = (self.current_backend + step) % len(self.backends)
|
||||||
|
|
||||||
def open_client(self):
|
def open_client(self):
|
||||||
if self.email_client:
|
if self.email_client:
|
||||||
retcode, _, stderr = run_through_shell(self.email_client)
|
retcode, _, stderr = run_through_shell(self.email_client)
|
||||||
|
@ -18,9 +18,11 @@ class Notmuch(Backend):
|
|||||||
|
|
||||||
settings = (
|
settings = (
|
||||||
("db_path", "Path to the directory of your notmuch database"),
|
("db_path", "Path to the directory of your notmuch database"),
|
||||||
|
("query", "Same query notmuch would accept, by default 'tag:unread and tag:inbox'"),
|
||||||
)
|
)
|
||||||
|
|
||||||
db_path = None
|
db_path = None
|
||||||
|
query = "tag:unread and tag:inbox"
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
if not self.db_path:
|
if not self.db_path:
|
||||||
@ -38,7 +40,7 @@ class Notmuch(Backend):
|
|||||||
@property
|
@property
|
||||||
def unread(self):
|
def unread(self):
|
||||||
db = notmuch.Database(self.db_path)
|
db = notmuch.Database(self.db_path)
|
||||||
result = notmuch.Query(db, "tag:unread and tag:inbox").count_messages()
|
result = notmuch.Query(db, self.query).count_messages()
|
||||||
db.close()
|
db.close()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user