As we can have multiple backends for mail already,
we don't need the multiple-servers functionality in imap. Just add multiple instances of that backend.
This commit is contained in:
parent
582a35e412
commit
76d86807db
25
README.md
25
README.md
@ -75,7 +75,7 @@ battery status
|
||||
This class shows a clock
|
||||
|
||||
|
||||
* `format` — stftime format string
|
||||
* `format` — stftime format string (default: `None`)
|
||||
|
||||
|
||||
|
||||
@ -100,7 +100,7 @@ of all components). The return value is bound to the key.
|
||||
|
||||
* `format` — (required)
|
||||
* `components` — (required)
|
||||
* `transforms`
|
||||
* `transforms` — (default: `{}`)
|
||||
* `base_path` — (default: `/`)
|
||||
* `color` — (default: `#FFFFFF`)
|
||||
* `interval` — (default: `5`)
|
||||
@ -139,19 +139,14 @@ The `backends` setting determines the backends to use. Currently available are:
|
||||
> ### imap
|
||||
>
|
||||
>
|
||||
> This class handles IMAP mailservers. The mail server
|
||||
> functionality is implemented in the subclass IMAP.MailServer
|
||||
>
|
||||
> The servers parameter should be a list of dicts containing the following
|
||||
> items:
|
||||
> * host
|
||||
> * port (optional, defaults to 143)
|
||||
> * username
|
||||
> * password
|
||||
> * ssl (optional, defaults to False)
|
||||
> Checks for mail on a IMAP server
|
||||
>
|
||||
>
|
||||
> * `servers` — (required)
|
||||
> * `host` — (required)
|
||||
> * `port` — (default: `143`)
|
||||
> * `username` — (required)
|
||||
> * `password` — (required)
|
||||
> * `ssl` — (default: `False`)
|
||||
>
|
||||
>
|
||||
>
|
||||
@ -191,7 +186,7 @@ unread posts in any bookmark in the mods.de forums.
|
||||
|
||||
|
||||
* `format` — Use {unread} as the formatter for number of unread posts (default: `{unread} new posts in bookmarks`)
|
||||
* `offset` — subtract number of posts before output
|
||||
* `offset` — subtract number of posts before output (default: `0`)
|
||||
* `color` — (default: `#7181fe`)
|
||||
* `username` — (required)
|
||||
* `password` — (required)
|
||||
@ -207,7 +202,7 @@ Simple regex file watcher
|
||||
* `format` — format string used for output (default: `{0}`)
|
||||
* `regex` — (required)
|
||||
* `file` — file to search for regex matches
|
||||
* `flags` — Python.re flags
|
||||
* `flags` — Python.re flags (default: `0`)
|
||||
|
||||
|
||||
|
||||
|
@ -29,7 +29,7 @@ class File(IntervalModule):
|
||||
)
|
||||
required = ("format", "components")
|
||||
base_path = "/"
|
||||
transforms = tuple()
|
||||
transforms = {}
|
||||
color = "#FFFFFF"
|
||||
|
||||
def run(self):
|
||||
|
@ -10,44 +10,23 @@ from i3pystatus.mail import Backend
|
||||
|
||||
class IMAP(Backend):
|
||||
"""
|
||||
This class handles IMAP mailservers. The mail server
|
||||
functionality is implemented in the subclass IMAP.MailServer
|
||||
|
||||
The servers parameter should be a list of dicts containing the following
|
||||
items:
|
||||
* host
|
||||
* port (optional, defaults to 143)
|
||||
* username
|
||||
* password
|
||||
* ssl (optional, defaults to False)
|
||||
Checks for mail on a IMAP server
|
||||
"""
|
||||
|
||||
settings = required = ("servers",)
|
||||
settings = (
|
||||
"host", "port",
|
||||
"username", "password",
|
||||
"ssl"
|
||||
)
|
||||
required = ("host", "username", "password")
|
||||
|
||||
def init(self):
|
||||
self.server_list = list(map(IMAP.MailServer, self.servers))
|
||||
|
||||
@property
|
||||
def unread(self):
|
||||
return sum(map(lambda server: server.get_unread_count(), self.server_list))
|
||||
|
||||
class MailServer:
|
||||
"""
|
||||
This class provides the functionality to connect
|
||||
to a mail server and fetch the count of unread emails.
|
||||
When the server connection is lost, it returns 0 and
|
||||
tries to reconnect. It checks every "pause" seconds.
|
||||
"""
|
||||
port = 143
|
||||
ssl = False
|
||||
|
||||
imap_class = imaplib.IMAP4
|
||||
connection = None
|
||||
|
||||
ssl = False
|
||||
port = 143
|
||||
|
||||
def __init__(self, settings_dict):
|
||||
self.__dict__.update(settings_dict)
|
||||
|
||||
def init(self):
|
||||
if self.ssl:
|
||||
self.imap_class = imaplib.IMAP4_SSL
|
||||
|
||||
@ -67,10 +46,8 @@ class IMAP(Backend):
|
||||
|
||||
return self.connection
|
||||
|
||||
def get_unread_count(self):
|
||||
unread = 0
|
||||
@property
|
||||
def unread(self):
|
||||
conn = self.get_connection()
|
||||
if conn:
|
||||
unread += len(conn.search(None,"UnSeen")[1][0].split())
|
||||
|
||||
return unread
|
||||
return len(conn.search(None,"UnSeen")[1][0].split())
|
||||
|
@ -68,7 +68,7 @@ class Setting:
|
||||
name = ""
|
||||
doc = ""
|
||||
required = False
|
||||
default = None
|
||||
default = sentinel = object()
|
||||
|
||||
def __init__(self, mod, setting):
|
||||
if isinstance(setting, tuple):
|
||||
@ -86,7 +86,7 @@ class Setting:
|
||||
attrs = []
|
||||
if self.required:
|
||||
attrs.append("required")
|
||||
if self.default:
|
||||
if self.default is not self.sentinel:
|
||||
attrs.append("default: `{default}`".format(default=self.default))
|
||||
|
||||
formatted = "* `{name}` ".format(name=self.name)
|
||||
|
Loading…
Reference in New Issue
Block a user