Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # Simple i3blocks mail checker script
- #
- # Config; ~/.mailchecker.ini
- #
- #
- # Example config:
- #
- # [config]
- # username = foo
- # password = bar
- # server = qux.tld
- import imaplib
- import ConfigParser
- import os
- import sys
- # Parse configuration file
- configfile = os.getenv('HOME') + "/.mailchecker.ini"
- if os.path.isfile(configfile):
- try:
- config = ConfigParser.ConfigParser()
- config.read(configfile)
- myuser = config.get('config', 'username')
- mypassword = config.get('config', 'password')
- myserver = config.get('config', 'server')
- except Exception as e:
- print ""
- print "Error while parsing configuration file: " + str(e._Error__message)
- print ""
- sys.exit(200)
- mail = imaplib.IMAP4_SSL(myserver)
- (retcode, capabilities) = mail.login(myuser,mypassword)
- mail.list()
- mail.select('inbox')
- n=0
- (retcode, messages) = mail.search(None, '(UNSEEN)')
- if retcode == 'OK':
- print "Mail: " + str(len(messages)) + " unread (" + myserver
Add Comment
Please, Sign In to add comment