summaryrefslogtreecommitdiffstats
path: root/modules/imap.py
diff options
context:
space:
mode:
authorUltrabug <ultrabug@gentoo.org>2014-11-23 20:55:53 +0100
committerUltrabug <ultrabug@gentoo.org>2014-11-23 20:55:53 +0100
commitd9747b64e1e62abee12ef0bafd365cf380ff7fe9 (patch)
tree11a1d156c38ec96b83b4a1780719fc856cbbebad /modules/imap.py
parent62b2bd2251997bf8608e9620d91f688585221040 (diff)
move modules folder so we can install it as a module of py3status
Diffstat (limited to 'modules/imap.py')
-rw-r--r--modules/imap.py58
1 files changed, 0 insertions, 58 deletions
diff --git a/modules/imap.py b/modules/imap.py
deleted file mode 100644
index 5953ee3..0000000
--- a/modules/imap.py
+++ /dev/null
@@ -1,58 +0,0 @@
-# -*- coding: utf8 -*-
-
-from time import time
-import imaplib
-
-"""
-Module displaying the number of unread messages
-on an IMAP inbox (configurable).
-
-@author obb
-"""
-
-
-class Py3status:
-
- def __init__(self):
- self.service_name = 'Mail'
- self.imap_server = '<IMAP_SERVER>'
- self.port = '993'
-
- self.user = '<USERNAME>'
- self.password = '<PASSWORD>'
-
- self.mailbox = 'INBOX'
- self.criterion = 'UNSEEN'
-
- self.check_frequency = 60
-
- def check_mail(self, json, i3status_config):
- mail_count = self._get_mail_count()
-
- response = {
- 'name': self.service_name + '_checker',
- 'full_text': '{}: {}'.format(self.service_name, mail_count),
- 'cached_until': time() + self.check_frequency
- }
-
- new_mail_color = i3status_config['color_good']
- check_failed_color = i3status_config['color_bad']
-
- if mail_count == 'N/A':
- response['color'] = check_failed_color
- elif mail_count != '0':
- response['color'] = new_mail_color
-
- return (0, response)
-
- def _get_mail_count(self):
- try:
- connection = imaplib.IMAP4_SSL(self.imap_server, self.port)
- connection.login(self.user, self.password)
- connection.select(self.mailbox)
- unseen_response = connection.search(None, self.criterion)
- mails = unseen_response[1][0].split()
- mail_count = len(mails)
- return mail_count
- except:
- return 'N/A'