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
|
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)
|
* `format` — (required)
|
||||||
* `components` — (required)
|
* `components` — (required)
|
||||||
* `transforms`
|
* `transforms` — (default: `{}`)
|
||||||
* `base_path` — (default: `/`)
|
* `base_path` — (default: `/`)
|
||||||
* `color` — (default: `#FFFFFF`)
|
* `color` — (default: `#FFFFFF`)
|
||||||
* `interval` — (default: `5`)
|
* `interval` — (default: `5`)
|
||||||
@ -139,19 +139,14 @@ The `backends` setting determines the backends to use. Currently available are:
|
|||||||
> ### imap
|
> ### imap
|
||||||
>
|
>
|
||||||
>
|
>
|
||||||
> This class handles IMAP mailservers. The mail server
|
> Checks for mail on a IMAP 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)
|
|
||||||
>
|
>
|
||||||
>
|
>
|
||||||
> * `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`)
|
* `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`)
|
* `color` — (default: `#7181fe`)
|
||||||
* `username` — (required)
|
* `username` — (required)
|
||||||
* `password` — (required)
|
* `password` — (required)
|
||||||
@ -207,7 +202,7 @@ Simple regex file watcher
|
|||||||
* `format` — format string used for output (default: `{0}`)
|
* `format` — format string used for output (default: `{0}`)
|
||||||
* `regex` — (required)
|
* `regex` — (required)
|
||||||
* `file` — file to search for regex matches
|
* `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")
|
required = ("format", "components")
|
||||||
base_path = "/"
|
base_path = "/"
|
||||||
transforms = tuple()
|
transforms = {}
|
||||||
color = "#FFFFFF"
|
color = "#FFFFFF"
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
@ -10,44 +10,23 @@ from i3pystatus.mail import Backend
|
|||||||
|
|
||||||
class IMAP(Backend):
|
class IMAP(Backend):
|
||||||
"""
|
"""
|
||||||
This class handles IMAP mailservers. The mail server
|
Checks for mail on a IMAP 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)
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
settings = required = ("servers",)
|
settings = (
|
||||||
|
"host", "port",
|
||||||
|
"username", "password",
|
||||||
|
"ssl"
|
||||||
|
)
|
||||||
|
required = ("host", "username", "password")
|
||||||
|
|
||||||
def init(self):
|
port = 143
|
||||||
self.server_list = list(map(IMAP.MailServer, self.servers))
|
ssl = False
|
||||||
|
|
||||||
@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.
|
|
||||||
"""
|
|
||||||
|
|
||||||
imap_class = imaplib.IMAP4
|
imap_class = imaplib.IMAP4
|
||||||
connection = None
|
connection = None
|
||||||
|
|
||||||
ssl = False
|
def init(self):
|
||||||
port = 143
|
|
||||||
|
|
||||||
def __init__(self, settings_dict):
|
|
||||||
self.__dict__.update(settings_dict)
|
|
||||||
|
|
||||||
if self.ssl:
|
if self.ssl:
|
||||||
self.imap_class = imaplib.IMAP4_SSL
|
self.imap_class = imaplib.IMAP4_SSL
|
||||||
|
|
||||||
@ -67,10 +46,8 @@ class IMAP(Backend):
|
|||||||
|
|
||||||
return self.connection
|
return self.connection
|
||||||
|
|
||||||
def get_unread_count(self):
|
@property
|
||||||
unread = 0
|
def unread(self):
|
||||||
conn = self.get_connection()
|
conn = self.get_connection()
|
||||||
if conn:
|
if conn:
|
||||||
unread += len(conn.search(None,"UnSeen")[1][0].split())
|
return len(conn.search(None,"UnSeen")[1][0].split())
|
||||||
|
|
||||||
return unread
|
|
||||||
|
@ -68,7 +68,7 @@ class Setting:
|
|||||||
name = ""
|
name = ""
|
||||||
doc = ""
|
doc = ""
|
||||||
required = False
|
required = False
|
||||||
default = None
|
default = sentinel = object()
|
||||||
|
|
||||||
def __init__(self, mod, setting):
|
def __init__(self, mod, setting):
|
||||||
if isinstance(setting, tuple):
|
if isinstance(setting, tuple):
|
||||||
@ -86,7 +86,7 @@ class Setting:
|
|||||||
attrs = []
|
attrs = []
|
||||||
if self.required:
|
if self.required:
|
||||||
attrs.append("required")
|
attrs.append("required")
|
||||||
if self.default:
|
if self.default is not self.sentinel:
|
||||||
attrs.append("default: `{default}`".format(default=self.default))
|
attrs.append("default: `{default}`".format(default=self.default))
|
||||||
|
|
||||||
formatted = "* `{name}` ".format(name=self.name)
|
formatted = "* `{name}` ".format(name=self.name)
|
||||||
|
Loading…
Reference in New Issue
Block a user